Skip to content

Commit 76c87a1

Browse files
committed
Auto merge of #56221 - estebank:remove-dummy-checks, r=varkor
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.
2 parents 7001537 + f077990 commit 76c87a1

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ impl EmitterWriter {
959959
Style::MainHeaderMsg
960960
};
961961

962-
if msp.primary_spans().is_empty() && msp.span_labels().is_empty() && is_secondary
962+
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary
963963
&& !self.short_message {
964964
// This is a secondary message with no span info
965965
for _ in 0..max_line_num_len {

src/librustc_resolve/lib.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -5013,11 +5013,7 @@ impl<'a> Resolver<'a> {
50135013
))
50145014
}
50155015

5016-
if b.span.is_dummy() {
5017-
err.note(&note_msg);
5018-
} else {
5019-
err.span_note(b.span, &note_msg);
5020-
}
5016+
err.span_note(b.span, &note_msg);
50215017
for (i, help_msg) in help_msgs.iter().enumerate() {
50225018
let or = if i == 0 { "" } else { "or " };
50235019
err.help(&format!("{}{}", or, help_msg));
@@ -5132,10 +5128,10 @@ impl<'a> Resolver<'a> {
51325128
container));
51335129

51345130
err.span_label(span, format!("`{}` re{} here", name, new_participle));
5135-
if !old_binding.span.is_dummy() {
5136-
err.span_label(self.session.source_map().def_span(old_binding.span),
5137-
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
5138-
}
5131+
err.span_label(
5132+
self.session.source_map().def_span(old_binding.span),
5133+
format!("previous {} of the {} `{}` here", old_noun, old_kind, name),
5134+
);
51395135

51405136
// See https://github.com/rust-lang/rust/issues/32354
51415137
if old_binding.is_import() || new_binding.is_import() {

src/libsyntax_pos/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ impl MultiSpan {
668668
&self.primary_spans
669669
}
670670

671+
/// Returns whether any of the primary spans is displayable.
672+
pub fn has_primary_spans(&self) -> bool {
673+
self.primary_spans.iter().any(|sp| !sp.is_dummy())
674+
}
675+
671676
/// Returns `true` if this contains only a dummy primary span with any hygienic context.
672677
pub fn is_dummy(&self) -> bool {
673678
let mut is_dummy = true;
@@ -726,6 +731,11 @@ impl MultiSpan {
726731

727732
span_labels
728733
}
734+
735+
/// Returns whether any of the span labels is displayable.
736+
pub fn has_span_labels(&self) -> bool {
737+
self.span_labels.iter().any(|(sp, _)| !sp.is_dummy())
738+
}
729739
}
730740

731741
impl From<Span> for MultiSpan {

src/test/ui/consts/const-size_of-cycle.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`...
99
|
1010
LL | intrinsics::size_of::<T>()
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires computing layout of `Foo`...
13-
note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
12+
= note: ...which requires computing layout of `Foo`...
13+
= note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
1414
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`...
1515
--> $DIR/const-size_of-cycle.rs:6:17
1616
|

src/test/ui/impl-trait/auto-trait-leak.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: ...which requires processing `cycle1`...
99
|
1010
LL | fn cycle1() -> impl Clone {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
12+
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
1313
note: ...which requires processing `cycle2::{{impl-Trait}}`...
1414
--> $DIR/auto-trait-leak.rs:23:16
1515
|
@@ -20,7 +20,7 @@ note: ...which requires processing `cycle2`...
2020
|
2121
LL | fn cycle2() -> impl Clone {
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^
23-
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
23+
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
2424
= note: ...which again requires processing `cycle1::{{impl-Trait}}`, completing the cycle
2525
note: cycle used when checking item types in top-level module
2626
--> $DIR/auto-trait-leak.rs:3:1
@@ -45,7 +45,7 @@ note: ...which requires processing `cycle1`...
4545
|
4646
LL | fn cycle1() -> impl Clone {
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48-
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
48+
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
4949
note: ...which requires processing `cycle2::{{impl-Trait}}`...
5050
--> $DIR/auto-trait-leak.rs:23:16
5151
|

src/test/ui/issues/issue-26548.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
22
|
3-
note: ...which requires computing layout of `S`...
3+
= note: ...which requires computing layout of `S`...
44
= note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
55
note: cycle used when processing `main`
66
--> $DIR/issue-26548.rs:9:1

src/test/ui/issues/issue-44415.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ note: ...which requires const-evaluating `Foo::bytes::{{constant}}`...
99
|
1010
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires computing layout of `Foo`...
13-
note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
12+
= note: ...which requires computing layout of `Foo`...
13+
= note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
1414
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}`...
1515
--> $DIR/issue-44415.rs:6:17
1616
|

0 commit comments

Comments
 (0)