diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 0443b2228e5..25d09a33c15 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -959,7 +959,7 @@ impl EmitterWriter { Style::MainHeaderMsg }; - if msp.primary_spans().is_empty() && msp.span_labels().is_empty() && is_secondary + if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message { // This is a secondary message with no span info for _ in 0..max_line_num_len { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1cd44042c1d..4c9347afa61 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -5013,11 +5013,7 @@ impl<'a> Resolver<'a> { )) } - if b.span.is_dummy() { - err.note(¬e_msg); - } else { - err.span_note(b.span, ¬e_msg); - } + err.span_note(b.span, ¬e_msg); for (i, help_msg) in help_msgs.iter().enumerate() { let or = if i == 0 { "" } else { "or " }; err.help(&format!("{}{}", or, help_msg)); @@ -5132,10 +5128,10 @@ impl<'a> Resolver<'a> { container)); err.span_label(span, format!("`{}` re{} here", name, new_participle)); - if !old_binding.span.is_dummy() { - err.span_label(self.session.source_map().def_span(old_binding.span), - format!("previous {} of the {} `{}` here", old_noun, old_kind, name)); - } + err.span_label( + self.session.source_map().def_span(old_binding.span), + format!("previous {} of the {} `{}` here", old_noun, old_kind, name), + ); // See https://github.com/rust-lang/rust/issues/32354 if old_binding.is_import() || new_binding.is_import() { diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 6a41a93f0b4..240b86d142a 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -668,6 +668,11 @@ impl MultiSpan { &self.primary_spans } + /// Returns wether any of the primary spans is displayable. + pub fn has_primary_spans(&self) -> bool { + self.primary_spans.iter().any(|sp| *sp != DUMMY_SP) + } + /// Returns `true` if this contains only a dummy primary span with any hygienic context. pub fn is_dummy(&self) -> bool { let mut is_dummy = true; @@ -726,6 +731,11 @@ impl MultiSpan { span_labels } + + /// Returns wether any of the span labels is displayable. + pub fn has_span_labels(&self) -> bool { + self.span_labels.iter().any(|(sp, _)| *sp != DUMMY_SP) + } } impl From for MultiSpan { diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index 8f9498e834d..8f8eb38e938 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... | LL | intrinsics::size_of::() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires computing layout of `Foo`... -note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`... + = note: ...which requires computing layout of `Foo`... + = note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... --> $DIR/const-size_of-cycle.rs:6:17 | diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index 4acc400f8e7..b936fed85f4 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -9,7 +9,7 @@ note: ...which requires processing `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... + = note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... note: ...which requires processing `cycle2::{{impl-Trait}}`... --> $DIR/auto-trait-leak.rs:23:16 | @@ -20,7 +20,7 @@ note: ...which requires processing `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... + = note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... = note: ...which again requires processing `cycle1::{{impl-Trait}}`, completing the cycle note: cycle used when checking item types in top-level module --> $DIR/auto-trait-leak.rs:3:1 @@ -45,7 +45,7 @@ note: ...which requires processing `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... + = note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... note: ...which requires processing `cycle2::{{impl-Trait}}`... --> $DIR/auto-trait-leak.rs:23:16 | diff --git a/src/test/ui/issues/issue-26548.stderr b/src/test/ui/issues/issue-26548.stderr index 84604f31d1e..ff197eeeb0f 100644 --- a/src/test/ui/issues/issue-26548.stderr +++ b/src/test/ui/issues/issue-26548.stderr @@ -1,6 +1,6 @@ error[E0391]: cycle detected when computing layout of `std::option::Option` | -note: ...which requires computing layout of `S`... + = note: ...which requires computing layout of `S`... = note: ...which again requires computing layout of `std::option::Option`, completing the cycle note: cycle used when processing `main` --> $DIR/issue-26548.rs:9:1 diff --git a/src/test/ui/issues/issue-44415.stderr b/src/test/ui/issues/issue-44415.stderr index 441f1b2a069..3f377fd27e7 100644 --- a/src/test/ui/issues/issue-44415.stderr +++ b/src/test/ui/issues/issue-44415.stderr @@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`... | LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires computing layout of `Foo`... -note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`... + = note: ...which requires computing layout of `Foo`... + = note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... --> $DIR/issue-44415.rs:6:17 |