From 019556d325a8a9d1457a38378020a48035168851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 15 Mar 2023 04:19:38 +0000 Subject: [PATCH] Small cleanup --- compiler/rustc_errors/src/emitter.rs | 15 ++++++++------- compiler/rustc_lint/src/methods.rs | 2 +- compiler/rustc_middle/src/lint.rs | 2 +- compiler/rustc_span/src/lib.rs | 6 +++--- .../src/traits/error_reporting/suggestions.rs | 6 +++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 1b2e7b7e083b4..aa835c3f53675 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -10,7 +10,7 @@ use Destination::*; use rustc_span::source_map::SourceMap; -use rustc_span::{FileLines, SourceFile, Span}; +use rustc_span::{DesugaringKind, FileLines, SourceFile, Span}; use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString}; use crate::styled_buffer::StyledBuffer; @@ -400,12 +400,13 @@ pub trait Emitter: Translate { // entries we don't want to print, to make sure the indices being // printed are contiguous (or omitted if there's only one entry). let macro_backtrace: Vec<_> = sp.macro_backtrace().collect(); - for (i, trace) in macro_backtrace.iter().rev().enumerate() { - if trace.def_site.is_dummy() { - continue; - } - - if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) { + for (i, trace) in macro_backtrace.iter().rev().enumerate().filter(|(_, trace)| { + !matches!( + trace.kind, + ExpnKind::Inlined | ExpnKind::Desugaring(DesugaringKind::Resize) + ) && !trace.def_site.is_dummy() + }) { + if always_backtrace { new_labels.push(( trace.def_site, format!( diff --git a/compiler/rustc_lint/src/methods.rs b/compiler/rustc_lint/src/methods.rs index 3045fc1a4761e..8bd436ff7a9d9 100644 --- a/compiler/rustc_lint/src/methods.rs +++ b/compiler/rustc_lint/src/methods.rs @@ -36,7 +36,7 @@ declare_lint_pass!(TemporaryCStringAsPtr => [TEMPORARY_CSTRING_AS_PTR]); fn in_macro(span: Span) -> bool { if span.from_expansion() { - !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..)) + !matches!(span.peel_ctxt().ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..)) } else { false } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index c61de97d53271..d25dc4c7e0161 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -466,7 +466,7 @@ pub fn struct_lint_level( /// This is used to test whether a lint should not even begin to figure out whether it should /// be reported on the current node. pub fn in_external_macro(sess: &Session, span: Span) -> bool { - let expn_data = span.ctxt().outer_expn_data(); + let expn_data = span.peel_ctxt().ctxt().outer_expn_data(); match expn_data.kind { ExpnKind::Inlined | ExpnKind::Root diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index a27467580cc83..c60f6bd49cb98 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -610,7 +610,7 @@ impl Span { { true } - ExpnKind::Desugaring(DesugaringKind::Resize) | ExpnKind::Desugaring(_) => { + ExpnKind::Desugaring(_) => { self.parent_callsite().unwrap().can_be_used_for_suggestions() } ExpnKind::Macro(..) => false, @@ -761,7 +761,7 @@ impl Span { /// Checks if this span arises from a compiler desugaring of kind `kind`. pub fn is_desugaring(self, kind: DesugaringKind) -> bool { - match self.ctxt().outer_expn_data().kind { + match self.peel_ctxt().ctxt().outer_expn_data().kind { ExpnKind::Desugaring(k) => k == kind, _ => false, } @@ -770,7 +770,7 @@ impl Span { /// Returns the compiler desugaring that created this span, or `None` /// if this span is not from a desugaring. pub fn desugaring_kind(self) -> Option { - match self.ctxt().outer_expn_data().kind { + match self.peel_ctxt().ctxt().outer_expn_data().kind { ExpnKind::Desugaring(k) => Some(k), _ => None, } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 41e15e2def03d..e367bb999ed0b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -956,7 +956,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { .join(", "); if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. }) - && match obligation.cause.span.ctxt().outer_expn_data().kind { + && match obligation.cause.span.peel_ctxt().ctxt().outer_expn_data().kind { ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) @@ -1249,7 +1249,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { { obligation.cause.code() } else if let ExpnKind::Desugaring(DesugaringKind::ForLoop) = - span.ctxt().outer_expn_data().kind + span.peel_ctxt().ctxt().outer_expn_data().kind { obligation.cause.code() } else { @@ -1324,7 +1324,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // } // ``` if !matches!( - span.ctxt().outer_expn_data().kind, + span.peel_ctxt().ctxt().outer_expn_data().kind, ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) ) { return false;