Skip to content

Commit 64c794c

Browse files
committed
Use a label instead of a note for member constraint errors
1 parent 10f7769 commit 64c794c

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(super) fn note_and_explain_region(
116116
emit_msg_span(err, prefix, description, span, suffix);
117117
}
118118

119-
pub(super) fn note_and_explain_free_region(
119+
fn explain_free_region(
120120
tcx: TyCtxt<'tcx>,
121121
err: &mut DiagnosticBuilder<'_>,
122122
prefix: &str,
@@ -125,7 +125,7 @@ pub(super) fn note_and_explain_free_region(
125125
) {
126126
let (description, span) = msg_span_from_free_region(tcx, region, None);
127127

128-
emit_msg_span(err, prefix, description, span, suffix);
128+
label_msg_span(err, prefix, description, span, suffix);
129129
}
130130

131131
fn msg_span_from_free_region(
@@ -210,6 +210,22 @@ fn emit_msg_span(
210210
}
211211
}
212212

213+
fn label_msg_span(
214+
err: &mut DiagnosticBuilder<'_>,
215+
prefix: &str,
216+
description: String,
217+
span: Option<Span>,
218+
suffix: &str,
219+
) {
220+
let message = format!("{}{}{}", prefix, description, suffix);
221+
222+
if let Some(span) = span {
223+
err.span_label(span, &message);
224+
} else {
225+
err.note(&message);
226+
}
227+
}
228+
213229
pub fn unexpected_hidden_region_diagnostic(
214230
tcx: TyCtxt<'tcx>,
215231
span: Span,
@@ -244,7 +260,7 @@ pub fn unexpected_hidden_region_diagnostic(
244260
//
245261
// (*) if not, the `tainted_by_errors` field would be set to
246262
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
247-
note_and_explain_free_region(
263+
explain_free_region(
248264
tcx,
249265
&mut err,
250266
&format!("hidden type `{}` captures ", hidden_ty),

src/test/ui/impl-trait/hidden-lifetimes.stderr

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
22
--> $DIR/hidden-lifetimes.rs:28:54
33
|
44
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
5-
| ^^^^^^^^^^^^^^
6-
|
7-
note: hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
8-
--> $DIR/hidden-lifetimes.rs:28:17
9-
|
10-
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
11-
| ^^
5+
| -- ^^^^^^^^^^^^^^
6+
| |
7+
| hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
128

139
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
1410
--> $DIR/hidden-lifetimes.rs:45:70
1511
|
1612
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
17-
| ^^^^^^^^^^^^^^
18-
|
19-
note: hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here
20-
--> $DIR/hidden-lifetimes.rs:45:24
21-
|
22-
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
23-
| ^^
13+
| -- ^^^^^^^^^^^^^^
14+
| |
15+
| hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here
2416

2517
error: aborting due to 2 previous errors
2618

src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
22
--> $DIR/error-handling-2.rs:13:60
33
|
44
LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
5-
| ^^^^^^^^^
6-
|
7-
note: hidden type `*mut &'a i32` captures the lifetime `'a` as defined here
8-
--> $DIR/error-handling-2.rs:13:8
9-
|
10-
LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
11-
| ^^
5+
| -- ^^^^^^^^^
6+
| |
7+
| hidden type `*mut &'a i32` captures the lifetime `'a` as defined here
128

139
error: aborting due to previous error
1410

src/test/ui/impl-trait/region-escape-via-bound.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
33
|
44
LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y>
55
| ^^^^^^^^^^^^^^
6-
|
7-
note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here
8-
--> $DIR/region-escape-via-bound.rs:17:7
9-
|
6+
LL |
107
LL | where 'x: 'y
11-
| ^^
8+
| -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here
129

1310
error: aborting due to previous error
1411

0 commit comments

Comments
 (0)