Remove unnecessary dummy span checks

The emitter already verifies wether a given span note or span label
can be emitted to the output. If it can't, because it is a dummy
span, it will be either elided for labels or emitted as an unspanned
note/help when applicable.
This commit is contained in:
Esteban Küber 2018-11-25 13:05:06 -08:00
parent 0c0c585281
commit c4b8df5df2
7 changed files with 24 additions and 18 deletions

View File

@ -959,7 +959,7 @@ impl EmitterWriter {
Style::MainHeaderMsg 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 { && !self.short_message {
// This is a secondary message with no span info // This is a secondary message with no span info
for _ in 0..max_line_num_len { for _ in 0..max_line_num_len {

View File

@ -5013,11 +5013,7 @@ impl<'a> Resolver<'a> {
)) ))
} }
if b.span.is_dummy() {
err.note(&note_msg);
} else {
err.span_note(b.span, &note_msg); err.span_note(b.span, &note_msg);
}
for (i, help_msg) in help_msgs.iter().enumerate() { for (i, help_msg) in help_msgs.iter().enumerate() {
let or = if i == 0 { "" } else { "or " }; let or = if i == 0 { "" } else { "or " };
err.help(&format!("{}{}", or, help_msg)); err.help(&format!("{}{}", or, help_msg));
@ -5132,10 +5128,10 @@ impl<'a> Resolver<'a> {
container)); container));
err.span_label(span, format!("`{}` re{} here", name, new_participle)); err.span_label(span, format!("`{}` re{} here", name, new_participle));
if !old_binding.span.is_dummy() { err.span_label(
err.span_label(self.session.source_map().def_span(old_binding.span), self.session.source_map().def_span(old_binding.span),
format!("previous {} of the {} `{}` here", old_noun, old_kind, name)); format!("previous {} of the {} `{}` here", old_noun, old_kind, name),
} );
// See https://github.com/rust-lang/rust/issues/32354 // See https://github.com/rust-lang/rust/issues/32354
if old_binding.is_import() || new_binding.is_import() { if old_binding.is_import() || new_binding.is_import() {

View File

@ -668,6 +668,11 @@ impl MultiSpan {
&self.primary_spans &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. /// Returns `true` if this contains only a dummy primary span with any hygienic context.
pub fn is_dummy(&self) -> bool { pub fn is_dummy(&self) -> bool {
let mut is_dummy = true; let mut is_dummy = true;
@ -726,6 +731,11 @@ impl MultiSpan {
span_labels 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<Span> for MultiSpan { impl From<Span> for MultiSpan {

View File

@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`...
| |
LL | intrinsics::size_of::<T>() LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing layout of `Foo`... = 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 normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`...
--> $DIR/const-size_of-cycle.rs:6:17 --> $DIR/const-size_of-cycle.rs:6:17
| |

View File

@ -9,7 +9,7 @@ note: ...which requires processing `cycle1`...
| |
LL | fn cycle1() -> impl Clone { 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}}`... note: ...which requires processing `cycle2::{{impl-Trait}}`...
--> $DIR/auto-trait-leak.rs:23:16 --> $DIR/auto-trait-leak.rs:23:16
| |
@ -20,7 +20,7 @@ note: ...which requires processing `cycle2`...
| |
LL | fn cycle2() -> impl Clone { 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: ...which again requires processing `cycle1::{{impl-Trait}}`, completing the cycle
note: cycle used when checking item types in top-level module note: cycle used when checking item types in top-level module
--> $DIR/auto-trait-leak.rs:3:1 --> $DIR/auto-trait-leak.rs:3:1
@ -45,7 +45,7 @@ note: ...which requires processing `cycle1`...
| |
LL | fn cycle1() -> impl Clone { 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}}`... note: ...which requires processing `cycle2::{{impl-Trait}}`...
--> $DIR/auto-trait-leak.rs:23:16 --> $DIR/auto-trait-leak.rs:23:16
| |

View File

@ -1,6 +1,6 @@
error[E0391]: cycle detected when computing layout of `std::option::Option<S>` error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
| |
note: ...which requires computing layout of `S`... = note: ...which requires computing layout of `S`...
= note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle = note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
note: cycle used when processing `main` note: cycle used when processing `main`
--> $DIR/issue-26548.rs:9:1 --> $DIR/issue-26548.rs:9:1

View File

@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`...
| |
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }], LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing layout of `Foo`... = 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 normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`... note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`...
--> $DIR/issue-44415.rs:6:17 --> $DIR/issue-44415.rs:6:17
| |