Skip to content

Commit 019556d

Browse files
committed
Small cleanup
1 parent 0172d15 commit 019556d

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

Diff for: compiler/rustc_errors/src/emitter.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Destination::*;
1111

1212
use rustc_span::source_map::SourceMap;
13-
use rustc_span::{FileLines, SourceFile, Span};
13+
use rustc_span::{DesugaringKind, FileLines, SourceFile, Span};
1414

1515
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString};
1616
use crate::styled_buffer::StyledBuffer;
@@ -400,12 +400,13 @@ pub trait Emitter: Translate {
400400
// entries we don't want to print, to make sure the indices being
401401
// printed are contiguous (or omitted if there's only one entry).
402402
let macro_backtrace: Vec<_> = sp.macro_backtrace().collect();
403-
for (i, trace) in macro_backtrace.iter().rev().enumerate() {
404-
if trace.def_site.is_dummy() {
405-
continue;
406-
}
407-
408-
if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
403+
for (i, trace) in macro_backtrace.iter().rev().enumerate().filter(|(_, trace)| {
404+
!matches!(
405+
trace.kind,
406+
ExpnKind::Inlined | ExpnKind::Desugaring(DesugaringKind::Resize)
407+
) && !trace.def_site.is_dummy()
408+
}) {
409+
if always_backtrace {
409410
new_labels.push((
410411
trace.def_site,
411412
format!(

Diff for: compiler/rustc_lint/src/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_lint_pass!(TemporaryCStringAsPtr => [TEMPORARY_CSTRING_AS_PTR]);
3636

3737
fn in_macro(span: Span) -> bool {
3838
if span.from_expansion() {
39-
!matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
39+
!matches!(span.peel_ctxt().ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
4040
} else {
4141
false
4242
}

Diff for: compiler/rustc_middle/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn struct_lint_level(
466466
/// This is used to test whether a lint should not even begin to figure out whether it should
467467
/// be reported on the current node.
468468
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
469-
let expn_data = span.ctxt().outer_expn_data();
469+
let expn_data = span.peel_ctxt().ctxt().outer_expn_data();
470470
match expn_data.kind {
471471
ExpnKind::Inlined
472472
| ExpnKind::Root

Diff for: compiler/rustc_span/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ impl Span {
610610
{
611611
true
612612
}
613-
ExpnKind::Desugaring(DesugaringKind::Resize) | ExpnKind::Desugaring(_) => {
613+
ExpnKind::Desugaring(_) => {
614614
self.parent_callsite().unwrap().can_be_used_for_suggestions()
615615
}
616616
ExpnKind::Macro(..) => false,
@@ -761,7 +761,7 @@ impl Span {
761761

762762
/// Checks if this span arises from a compiler desugaring of kind `kind`.
763763
pub fn is_desugaring(self, kind: DesugaringKind) -> bool {
764-
match self.ctxt().outer_expn_data().kind {
764+
match self.peel_ctxt().ctxt().outer_expn_data().kind {
765765
ExpnKind::Desugaring(k) => k == kind,
766766
_ => false,
767767
}
@@ -770,7 +770,7 @@ impl Span {
770770
/// Returns the compiler desugaring that created this span, or `None`
771771
/// if this span is not from a desugaring.
772772
pub fn desugaring_kind(self) -> Option<DesugaringKind> {
773-
match self.ctxt().outer_expn_data().kind {
773+
match self.peel_ctxt().ctxt().outer_expn_data().kind {
774774
ExpnKind::Desugaring(k) => Some(k),
775775
_ => None,
776776
}

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
956956
.join(", ");
957957

958958
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. })
959-
&& match obligation.cause.span.ctxt().outer_expn_data().kind {
959+
&& match obligation.cause.span.peel_ctxt().ctxt().outer_expn_data().kind {
960960
ExpnKind::Root
961961
| ExpnKind::AstPass(_)
962962
| ExpnKind::Desugaring(_)
@@ -1249,7 +1249,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12491249
{
12501250
obligation.cause.code()
12511251
} else if let ExpnKind::Desugaring(DesugaringKind::ForLoop) =
1252-
span.ctxt().outer_expn_data().kind
1252+
span.peel_ctxt().ctxt().outer_expn_data().kind
12531253
{
12541254
obligation.cause.code()
12551255
} else {
@@ -1324,7 +1324,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
13241324
// }
13251325
// ```
13261326
if !matches!(
1327-
span.ctxt().outer_expn_data().kind,
1327+
span.peel_ctxt().ctxt().outer_expn_data().kind,
13281328
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
13291329
) {
13301330
return false;

0 commit comments

Comments
 (0)