Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 15, 2023
1 parent 0172d15 commit 019556d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand All @@ -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<DesugaringKind> {
match self.ctxt().outer_expn_data().kind {
match self.peel_ctxt().ctxt().outer_expn_data().kind {
ExpnKind::Desugaring(k) => Some(k),
_ => None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 019556d

Please sign in to comment.