Auto merge of #4269 - lzutao:rustup, r=flip1995
Rustup `macro expansion and resolution` Rustup https://github.com/rust-lang/rust/pull/62476 changelog: none
This commit is contained in:
@@ -7,7 +7,7 @@ use rustc::ty;
|
|||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use syntax::ast::LitKind;
|
use syntax::ast::LitKind;
|
||||||
use syntax::source_map::{ExpnFormat, Span};
|
use syntax::source_map::{ExpnKind, Span};
|
||||||
|
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::utils::sugg::Sugg;
|
use crate::utils::sugg::Sugg;
|
||||||
@@ -596,10 +596,14 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||||||
/// Tests whether an expression is in a macro expansion (e.g., something
|
/// Tests whether an expression is in a macro expansion (e.g., something
|
||||||
/// generated by `#[derive(...)]` or the like).
|
/// generated by `#[derive(...)]` or the like).
|
||||||
fn in_attributes_expansion(expr: &Expr) -> bool {
|
fn in_attributes_expansion(expr: &Expr) -> bool {
|
||||||
expr.span
|
use syntax::ext::hygiene::MacroKind;
|
||||||
.ctxt()
|
expr.span.ctxt().outer_expn_info().map_or(false, |info| {
|
||||||
.outer_expn_info()
|
if let ExpnKind::Macro(MacroKind::Attr, _) = info.kind {
|
||||||
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether `res` is a variable defined outside a macro.
|
/// Tests whether `res` is a variable defined outside a macro.
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
|
|||||||
|
|
||||||
// get the def site
|
// get the def site
|
||||||
fn get_def(span: Span) -> Option<Span> {
|
fn get_def(span: Span) -> Option<Span> {
|
||||||
span.ctxt().outer_expn_info().and_then(|info| info.def_site)
|
span.ctxt().outer_expn_info().and_then(|info| Some(info.def_site))
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this expr a `()` unit?
|
// is this expr a `()` unit?
|
||||||
|
|||||||
@@ -621,9 +621,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool {
|
fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool {
|
||||||
use syntax_pos::hygiene::CompilerDesugaringKind;
|
use syntax_pos::hygiene::DesugaringKind;
|
||||||
if let ExprKind::Call(ref callee, _) = expr.node {
|
if let ExprKind::Call(ref callee, _) = expr.node {
|
||||||
callee.span.is_compiler_desugaring(CompilerDesugaringKind::QuestionMark)
|
callee.span.is_desugaring(DesugaringKind::QuestionMark)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ use rustc_errors::Applicability;
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use syntax::ast::{self, LitKind};
|
use syntax::ast::{self, LitKind};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ext::hygiene::ExpnFormat;
|
use syntax::ext::hygiene::ExpnKind;
|
||||||
use syntax::source_map::{Span, DUMMY_SP};
|
use syntax::source_map::{Span, DUMMY_SP};
|
||||||
use syntax::symbol::{kw, Symbol};
|
use syntax::symbol::{kw, Symbol};
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ pub fn in_macro_or_desugar(span: Span) -> bool {
|
|||||||
/// Returns `true` if this `expn_info` was expanded by any macro.
|
/// Returns `true` if this `expn_info` was expanded by any macro.
|
||||||
pub fn in_macro(span: Span) -> bool {
|
pub fn in_macro(span: Span) -> bool {
|
||||||
if let Some(info) = span.ctxt().outer_expn_info() {
|
if let Some(info) = span.ctxt().outer_expn_info() {
|
||||||
if let ExpnFormat::CompilerDesugaring(..) = info.format {
|
if let ExpnKind::Desugaring(..) = info.kind {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
@@ -686,7 +686,7 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
|
|||||||
/// See also `is_direct_expn_of`.
|
/// See also `is_direct_expn_of`.
|
||||||
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
||||||
loop {
|
loop {
|
||||||
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
|
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
|
||||||
|
|
||||||
match span_name_span {
|
match span_name_span {
|
||||||
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
|
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> {
|
|||||||
/// `bar!` by
|
/// `bar!` by
|
||||||
/// `is_direct_expn_of`.
|
/// `is_direct_expn_of`.
|
||||||
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
||||||
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
|
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
|
||||||
|
|
||||||
match span_name_span {
|
match span_name_span {
|
||||||
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),
|
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),
|
||||||
|
|||||||
Reference in New Issue
Block a user