Skip to content

Commit 0986978

Browse files
committed
Small cleanup
1 parent d3eb0f8 commit 0986978

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

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::{
1616
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
@@ -402,12 +402,13 @@ pub trait Emitter: Translate {
402402
// entries we don't want to print, to make sure the indices being
403403
// printed are contiguous (or omitted if there's only one entry).
404404
let macro_backtrace: Vec<_> = sp.macro_backtrace().collect();
405-
for (i, trace) in macro_backtrace.iter().rev().enumerate() {
406-
if trace.def_site.is_dummy() {
407-
continue;
408-
}
409-
410-
if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
405+
for (i, trace) in macro_backtrace.iter().rev().enumerate().filter(|(_, trace)| {
406+
!matches!(
407+
trace.kind,
408+
ExpnKind::Inlined | ExpnKind::Desugaring(DesugaringKind::Resize)
409+
) && !trace.def_site.is_dummy()
410+
}) {
411+
if always_backtrace {
411412
new_labels.push((
412413
trace.def_site,
413414
format!(

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

compiler/rustc_span/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl Span {
618618
{
619619
true
620620
}
621-
ExpnKind::Desugaring(DesugaringKind::Resize) | ExpnKind::Desugaring(_) => {
621+
ExpnKind::Desugaring(_) => {
622622
self.parent_callsite().unwrap().can_be_used_for_suggestions()
623623
}
624624
ExpnKind::Macro(..) => false,
@@ -769,7 +769,7 @@ impl Span {
769769

770770
/// Checks if this span arises from a compiler desugaring of kind `kind`.
771771
pub fn is_desugaring(self, kind: DesugaringKind) -> bool {
772-
match self.ctxt().outer_expn_data().kind {
772+
match self.peel_ctxt().ctxt().outer_expn_data().kind {
773773
ExpnKind::Desugaring(k) => k == kind,
774774
_ => false,
775775
}
@@ -778,7 +778,7 @@ impl Span {
778778
/// Returns the compiler desugaring that created this span, or `None`
779779
/// if this span is not from a desugaring.
780780
pub fn desugaring_kind(self) -> Option<DesugaringKind> {
781-
match self.ctxt().outer_expn_data().kind {
781+
match self.peel_ctxt().ctxt().outer_expn_data().kind {
782782
ExpnKind::Desugaring(k) => Some(k),
783783
_ => None,
784784
}

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(_)
@@ -1248,7 +1248,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12481248
{
12491249
obligation.cause.code()
12501250
} else if let ExpnKind::Desugaring(DesugaringKind::ForLoop) =
1251-
span.ctxt().outer_expn_data().kind
1251+
span.peel_ctxt().ctxt().outer_expn_data().kind
12521252
{
12531253
obligation.cause.code()
12541254
} else {
@@ -1323,7 +1323,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
13231323
// }
13241324
// ```
13251325
if !matches!(
1326-
span.ctxt().outer_expn_data().kind,
1326+
span.peel_ctxt().ctxt().outer_expn_data().kind,
13271327
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
13281328
) {
13291329
return false;

0 commit comments

Comments
 (0)