Skip to content

Commit

Permalink
Use a label instead of a note for member constraint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 13, 2021
1 parent 15f9347 commit d435101
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
22 changes: 19 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Expand Up @@ -116,7 +116,7 @@ pub(super) fn note_and_explain_region(
emit_msg_span(err, prefix, description, span, suffix);
}

pub(super) fn note_and_explain_free_region(
fn explain_free_region(
tcx: TyCtxt<'tcx>,
err: &mut DiagnosticBuilder<'_>,
prefix: &str,
Expand All @@ -125,7 +125,7 @@ pub(super) fn note_and_explain_free_region(
) {
let (description, span) = msg_span_from_free_region(tcx, region, None);

emit_msg_span(err, prefix, description, span, suffix);
label_msg_span(err, prefix, description, span, suffix);
}

fn msg_span_from_free_region(
Expand Down Expand Up @@ -210,6 +210,22 @@ fn emit_msg_span(
}
}

fn label_msg_span(
err: &mut DiagnosticBuilder<'_>,
prefix: &str,
description: String,
span: Option<Span>,
suffix: &str,
) {
let message = format!("{}{}{}", prefix, description, suffix);

if let Some(span) = span {
err.span_label(span, &message);
} else {
err.note(&message);
}
}

pub fn unexpected_hidden_region_diagnostic(
tcx: TyCtxt<'tcx>,
span: Span,
Expand Down Expand Up @@ -244,7 +260,7 @@ pub fn unexpected_hidden_region_diagnostic(
//
// (*) if not, the `tainted_by_errors` field would be set to
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
note_and_explain_free_region(
explain_free_region(
tcx,
&mut err,
&format!("hidden type `{}` captures ", hidden_ty),
Expand Down
20 changes: 6 additions & 14 deletions src/test/ui/impl-trait/hidden-lifetimes.stderr
Expand Up @@ -2,25 +2,17 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
--> $DIR/hidden-lifetimes.rs:28:54
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
| ^^^^^^^^^^^^^^
|
note: hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
--> $DIR/hidden-lifetimes.rs:28:17
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
| ^^
| -- ^^^^^^^^^^^^^^
| |
| hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:45:70
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
| ^^^^^^^^^^^^^^
|
note: hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here
--> $DIR/hidden-lifetimes.rs:45:24
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
| ^^
| -- ^^^^^^^^^^^^^^
| |
| hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here

error: aborting due to 2 previous errors

Expand Down
Expand Up @@ -2,13 +2,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
--> $DIR/error-handling-2.rs:13:60
|
LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
| ^^^^^^^^^
|
note: hidden type `*mut &'a i32` captures the lifetime `'a` as defined here
--> $DIR/error-handling-2.rs:13:8
|
LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
| ^^
| -- ^^^^^^^^^
| |
| hidden type `*mut &'a i32` captures the lifetime `'a` as defined here

error: aborting due to previous error

Expand Down
7 changes: 2 additions & 5 deletions src/test/ui/impl-trait/region-escape-via-bound.stderr
Expand Up @@ -3,12 +3,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
|
LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y>
| ^^^^^^^^^^^^^^
|
note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here
--> $DIR/region-escape-via-bound.rs:17:7
|
LL |
LL | where 'x: 'y
| ^^
| -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here

error: aborting due to previous error

Expand Down

0 comments on commit d435101

Please sign in to comment.