extern crate rustc_ast;
extern crate rustc_ast_pretty;
extern crate rustc_attr;
-extern crate rustc_const_eval;
extern crate rustc_data_structures;
extern crate rustc_errors;
extern crate rustc_hir;
/// Returns `true` if this `span` was expanded by any macro.
#[must_use]
pub fn in_macro(span: Span) -> bool {
- if span.from_expansion() {
- !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
- } else {
- false
- }
+ span.from_expansion() && !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
}
pub fn is_unit_expr(expr: &Expr<'_>) -> bool {
/// constructor from the std library
fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<'_>) -> bool {
let std_types_symbols = &[
- sym::string_type,
- sym::vec_type,
- sym::vecdeque_type,
+ sym::String,
+ sym::Vec,
+ sym::VecDeque,
sym::LinkedList,
- sym::hashmap_type,
+ sym::HashMap,
sym::BTreeMap,
- sym::hashset_type,
+ sym::HashSet,
sym::BTreeSet,
sym::BinaryHeap,
];
}
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
- value == v
- } else {
- false
+ return value == v;
}
+ false
}
/// Checks whether the given expression is a constant literal of the given value.
/// Returns the pre-expansion span if is this comes from an expansion of the
/// macro `name`.
-/// See also `is_direct_expn_of`.
+/// See also [`is_direct_expn_of`].
#[must_use]
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
loop {
/// Returns the pre-expansion span if the span directly comes from an expansion
/// of the macro `name`.
-/// The difference with `is_expn_of` is that in
-/// ```rust,ignore
+/// The difference with [`is_expn_of`] is that in
+/// ```rust
+/// # macro_rules! foo { ($e:tt) => { $e } }; macro_rules! bar { ($e:expr) => { $e } }
/// foo!(bar!(42));
/// ```
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only
-/// `bar!` by
-/// `is_direct_expn_of`.
+/// from `bar!` by `is_direct_expn_of`.
#[must_use]
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
if span.from_expansion() {
}
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
- if_chain! {
- if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind;
- if let Res::SelfTy(..) = path.res;
- then {
- return true
+ if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
+ if let Res::SelfTy(..) = path.res {
+ return true;
}
}
false
}
pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
- if_chain! {
- if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind;
- if let Res::Def(_, def_id) = path.res;
- then {
- cx.tcx.has_attr(def_id, sym::cfg) || cx.tcx.has_attr(def_id, sym::cfg_attr)
- } else {
- false
+ if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind {
+ if let Res::Def(_, def_id) = path.res {
+ return cx.tcx.has_attr(def_id, sym::cfg) || cx.tcx.has_attr(def_id, sym::cfg_attr);
}
}
+ false
}
/// Checks whether item either has `test` attribute applied, or
}
}
- matches!(item.kind, ItemKind::Mod(..)) && item.ident.name.as_str().contains("test")
+ matches!(item.kind, ItemKind::Mod(..)) && item.ident.name.as_str().split('_').any(|a| a == "test" || a == "tests")
}
macro_rules! op_utils {