1
Fork 0

Use a label instead of a note for member constraint errors

This commit is contained in:
Oli Scherer 2021-10-05 12:32:08 +00:00
parent 15f93473f1
commit d435101537
4 changed files with 30 additions and 29 deletions

View file

@ -116,7 +116,7 @@ pub(super) fn note_and_explain_region(
emit_msg_span(err, prefix, description, span, suffix); emit_msg_span(err, prefix, description, span, suffix);
} }
pub(super) fn note_and_explain_free_region( fn explain_free_region(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
prefix: &str, prefix: &str,
@ -125,7 +125,7 @@ pub(super) fn note_and_explain_free_region(
) { ) {
let (description, span) = msg_span_from_free_region(tcx, region, None); 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( fn msg_span_from_free_region(
@ -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( pub fn unexpected_hidden_region_diagnostic(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
span: Span, span: Span,
@ -244,7 +260,7 @@ pub fn unexpected_hidden_region_diagnostic(
// //
// (*) if not, the `tainted_by_errors` field would be set to // (*) if not, the `tainted_by_errors` field would be set to
// `Some(ErrorReported)` in any case, so we wouldn't be here at all. // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
note_and_explain_free_region( explain_free_region(
tcx, tcx,
&mut err, &mut err,
&format!("hidden type `{}` captures ", hidden_ty), &format!("hidden type `{}` captures ", hidden_ty),

View file

@ -2,25 +2,17 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
--> $DIR/hidden-lifetimes.rs:28:54 --> $DIR/hidden-lifetimes.rs:28:54
| |
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { 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 | 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 {
| ^^
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:45:70 --> $DIR/hidden-lifetimes.rs:45:70
| |
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a { 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 | 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 {
| ^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -2,13 +2,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
--> $DIR/error-handling-2.rs:13:60 --> $DIR/error-handling-2.rs:13:60
| |
LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { 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 | 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> {
| ^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -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> LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y>
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
| LL |
note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here
--> $DIR/region-escape-via-bound.rs:17:7
|
LL | where 'x: 'y LL | where 'x: 'y
| ^^ | -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here
error: aborting due to previous error error: aborting due to previous error