Make use of new outer_expn_info() function

This commit is contained in:
Lzu Tao 2019-06-01 16:25:51 +07:00
parent f3087c37bf
commit f67c3e4b2a
7 changed files with 12 additions and 25 deletions

View file

@ -594,8 +594,7 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
fn in_attributes_expansion(expr: &Expr) -> bool {
expr.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
}

View file

@ -69,8 +69,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
fn get_outer_span(expr: &Expr) -> Span {
if_chain! {
if let Some(first) = expr.span.ctxt().outer().expn_info();
if let Some(second) = first.call_site.ctxt().outer().expn_info();
if let Some(first) = expr.span.ctxt().outer_expn_info();
if let Some(second) = first.call_site.ctxt().outer_expn_info();
then {
second.call_site
} else {

View file

@ -148,8 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
then {
let span = expr.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map_or(expr.span, |info| info.call_site);
span_lint_and_then(
cx,

View file

@ -272,7 +272,7 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
// get the def site
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| info.def_site)
}
// is this expr a `()` unit?

View file

@ -156,8 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
// actual span that invoked `declare_tool_lint!`:
let lint_span = lint_span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|ei| ei.call_site)
.expect("unable to get call_site");

View file

@ -94,12 +94,12 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
/// Returns `true` if this `expn_info` was expanded by any macro or desugaring
pub fn in_macro_or_desugar(span: Span) -> bool {
span.ctxt().outer().expn_info().is_some()
span.ctxt().outer_expn_info().is_some()
}
/// Returns `true` if this `expn_info` was expanded by any macro.
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 {
false
} else {
@ -691,11 +691,7 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
/// See also `is_direct_expn_of`.
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
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.format.name(), ei.call_site));
match span_name_span {
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
@ -715,11 +711,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
/// `bar!` by
/// `is_direct_expn_of`.
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.format.name(), ei.call_site));
match span_name_span {
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),

View file

@ -49,13 +49,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec {
// report the error around the `vec!` not inside `<std macros>:`
let span = arg.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|info| info.call_site)
.expect("unable to get call_site")
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|info| info.call_site)
.expect("unable to get call_site");
check_vec_macro(cx, &vec_args, span);