Skip to content

Commit b53119b

Browse files
committed
Rustup macro expansion and resolution
1 parent 032ae96 commit b53119b

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

clippy_lints/src/misc.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::ty;
77
use rustc::{declare_lint_pass, declare_tool_lint};
88
use rustc_errors::Applicability;
99
use syntax::ast::LitKind;
10-
use syntax::source_map::{ExpnFormat, Span};
10+
use syntax::source_map::{ExpnKind, Span};
1111

1212
use crate::consts::{constant, Constant};
1313
use crate::utils::sugg::Sugg;
@@ -596,10 +596,18 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
596596
/// Tests whether an expression is in a macro expansion (e.g., something
597597
/// generated by `#[derive(...)]` or the like).
598598
fn in_attributes_expansion(expr: &Expr) -> bool {
599-
expr.span
600-
.ctxt()
601-
.outer_expn_info()
602-
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
599+
use syntax::ext::hygiene::MacroKind;
600+
expr.span.ctxt().outer_expn_info().map_or(false, |info| {
601+
if_chain! {
602+
if let ExpnKind::Macro(kind, _) = info.kind;
603+
if let MacroKind::Attr = kind;
604+
then {
605+
true
606+
} else {
607+
false
608+
}
609+
}
610+
})
603611
}
604612

605613
/// Tests whether `res` is a variable defined outside a macro.

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
317317

318318
// get the def site
319319
fn get_def(span: Span) -> Option<Span> {
320-
span.ctxt().outer_expn_info().and_then(|info| info.def_site)
320+
span.ctxt().outer_expn_info().and_then(|info| Some(info.def_site))
321321
}
322322

323323
// is this expr a `()` unit?

clippy_lints/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
621621
}
622622

623623
fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool {
624-
use syntax_pos::hygiene::CompilerDesugaringKind;
624+
use syntax_pos::hygiene::DesugaringKind;
625625
if let ExprKind::Call(ref callee, _) = expr.node {
626-
callee.span.is_compiler_desugaring(CompilerDesugaringKind::QuestionMark)
626+
callee.span.is_desugaring(DesugaringKind::QuestionMark)
627627
} else {
628628
false
629629
}

clippy_lints/src/utils/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_errors::Applicability;
4343
use smallvec::SmallVec;
4444
use syntax::ast::{self, LitKind};
4545
use syntax::attr;
46-
use syntax::ext::hygiene::ExpnFormat;
46+
use syntax::ext::hygiene::ExpnKind;
4747
use syntax::source_map::{Span, DUMMY_SP};
4848
use syntax::symbol::{kw, Symbol};
4949

@@ -100,7 +100,7 @@ pub fn in_macro_or_desugar(span: Span) -> bool {
100100
/// Returns `true` if this `expn_info` was expanded by any macro.
101101
pub fn in_macro(span: Span) -> bool {
102102
if let Some(info) = span.ctxt().outer_expn_info() {
103-
if let ExpnFormat::CompilerDesugaring(..) = info.format {
103+
if let ExpnKind::Desugaring(..) = info.kind {
104104
false
105105
} else {
106106
true
@@ -686,7 +686,7 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
686686
/// See also `is_direct_expn_of`.
687687
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
688688
loop {
689-
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
689+
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
690690

691691
match span_name_span {
692692
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
@@ -706,7 +706,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
706706
/// `bar!` by
707707
/// `is_direct_expn_of`.
708708
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
709-
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
709+
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
710710

711711
match span_name_span {
712712
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),

0 commit comments

Comments
 (0)