Move overlapping span to a note
This commit is contained in:
parent
921f35fe73
commit
e75588934c
|
@ -53,7 +53,36 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
|
|
||||||
// Customize the spans and labels depending on their relative order so
|
// Customize the spans and labels depending on their relative order so
|
||||||
// that split sentences flow correctly.
|
// that split sentences flow correctly.
|
||||||
if sup_origin.span().shrink_to_hi() <= return_sp.shrink_to_lo() {
|
if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() {
|
||||||
|
// Avoid the following:
|
||||||
|
//
|
||||||
|
// error: cannot infer an appropriate lifetime
|
||||||
|
// --> $DIR/must_outlive_least_region_or_bound.rs:18:50
|
||||||
|
// |
|
||||||
|
// LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
|
// | ---- ---------^-
|
||||||
|
// | | | |
|
||||||
|
// | | | ...and is captured here
|
||||||
|
// | | ...is required to be `'static` by this...
|
||||||
|
// | this data with the anonymous lifetime `'_`...
|
||||||
|
//
|
||||||
|
// and instead show:
|
||||||
|
//
|
||||||
|
// error: cannot infer an appropriate lifetime
|
||||||
|
// --> $DIR/must_outlive_least_region_or_bound.rs:18:50
|
||||||
|
// |
|
||||||
|
// LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
|
// | ---- ^ ...is captured here with a `'static` requirement
|
||||||
|
// | |
|
||||||
|
// | this data with the anonymous lifetime `'_`...
|
||||||
|
// |
|
||||||
|
// note: ...is required to be `'static` by this
|
||||||
|
// |
|
||||||
|
// LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
|
// | ^^^^^^^^^^^
|
||||||
|
err.span_label(sup_origin.span(), "...is captured here...");
|
||||||
|
err.span_note(return_sp, "...and required to be `'static` by this");
|
||||||
|
} else if sup_origin.span() <= return_sp {
|
||||||
err.span_label(sup_origin.span(), "...is captured here...");
|
err.span_label(sup_origin.span(), "...is captured here...");
|
||||||
err.span_label(return_sp, "...and required to be `'static` by this");
|
err.span_label(return_sp, "...and required to be `'static` by this");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -109,12 +109,15 @@ error: cannot infer an appropriate lifetime
|
||||||
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
|
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
|
||||||
|
|
|
|
||||||
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
| ---- ---------^-
|
| ---- ^ ...is captured here...
|
||||||
| | | |
|
| |
|
||||||
| | | ...and is captured here
|
|
||||||
| | ...is required to be `'static` by this...
|
|
||||||
| this data with the anonymous lifetime `'_`...
|
| this data with the anonymous lifetime `'_`...
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/must_outlive_least_region_or_bound.rs:18:41
|
||||||
|
|
|
||||||
|
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
|
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
|
||||||
|
@ -124,12 +127,15 @@ error: cannot infer an appropriate lifetime
|
||||||
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
|
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
|
||||||
|
|
|
|
||||||
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
| ------- ---------^-
|
| ------- ^ ...is captured here...
|
||||||
| | | |
|
| |
|
||||||
| | | ...and is captured here
|
|
||||||
| | ...is required to be `'static` by this...
|
|
||||||
| this data with lifetime `'a`...
|
| this data with lifetime `'a`...
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/must_outlive_least_region_or_bound.rs:21:50
|
||||||
|
|
|
||||||
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
|
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
|
||||||
|
|
|
|
||||||
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
|
||||||
|
@ -139,12 +145,15 @@ error: cannot infer an appropriate lifetime
|
||||||
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
|
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
|
||||||
|
|
|
|
||||||
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
||||||
| ---- ---------^-
|
| ---- ^ ...is captured here...
|
||||||
| | | |
|
| |
|
||||||
| | | ...and is captured here
|
|
||||||
| | ...is required to be `'static` by this...
|
|
||||||
| this data with the anonymous lifetime `'_`...
|
| this data with the anonymous lifetime `'_`...
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/must_outlive_least_region_or_bound.rs:24:51
|
||||||
|
|
|
||||||
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
|
||||||
|
@ -158,12 +167,13 @@ error: cannot infer an appropriate lifetime
|
||||||
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
|
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
|
||||||
|
|
|
|
||||||
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
||||||
| ------- ---------^-
|
| ------- this data with lifetime `'a`... ^ ...is captured here...
|
||||||
| | | |
|
|
||||||
| | | ...and is captured here
|
|
||||||
| | ...is required to be `'static` by this...
|
|
||||||
| this data with lifetime `'a`...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/must_outlive_least_region_or_bound.rs:27:60
|
||||||
|
|
|
||||||
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
||||||
|
|
|
|
||||||
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
|
||||||
|
|
|
@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
|
||||||
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
|
||||||
| -- this data with the anonymous lifetime `'_`...
|
| -- this data with the anonymous lifetime `'_`...
|
||||||
LL | Box::new(value) as Box<dyn Any>
|
LL | Box::new(value) as Box<dyn Any>
|
||||||
| ---------^^^^^-
|
| ^^^^^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/issue-16922.rs:4:5
|
||||||
|
|
|
||||||
|
LL | Box::new(value) as Box<dyn Any>
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
|
||||||
|
|
|
@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
|
||||||
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
|
||||||
| ----- this data with the anonymous lifetime `'_`...
|
| ----- this data with the anonymous lifetime `'_`...
|
||||||
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
|
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
|
||||||
| ---------^-
|
| ^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/region-object-lifetime-in-coercion.rs:8:37
|
||||||
|
|
|
||||||
|
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
|
||||||
|
@ -24,11 +26,13 @@ error: cannot infer an appropriate lifetime
|
||||||
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
|
||||||
| ----- this data with the anonymous lifetime `'_`...
|
| ----- this data with the anonymous lifetime `'_`...
|
||||||
LL | Box::new(v)
|
LL | Box::new(v)
|
||||||
| ---------^-
|
| ^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/region-object-lifetime-in-coercion.rs:13:5
|
||||||
|
|
|
||||||
|
LL | Box::new(v)
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
|
||||||
|
@ -45,11 +49,13 @@ LL | fn c(v: &[u8]) -> Box<dyn Foo> {
|
||||||
| ----- this data with the anonymous lifetime `'_`...
|
| ----- this data with the anonymous lifetime `'_`...
|
||||||
...
|
...
|
||||||
LL | Box::new(v)
|
LL | Box::new(v)
|
||||||
| ---------^-
|
| ^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/region-object-lifetime-in-coercion.rs:19:5
|
||||||
|
|
|
||||||
|
LL | Box::new(v)
|
||||||
|
| ^^^^^^^^^^^
|
||||||
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
|
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
|
||||||
|
|
|
@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
|
||||||
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
|
||||||
| ------------------ this data with lifetime `'a`...
|
| ------------------ this data with lifetime `'a`...
|
||||||
LL | box B(&*v) as Box<dyn X>
|
LL | box B(&*v) as Box<dyn X>
|
||||||
| ------^^^---------------
|
| ^^^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/regions-close-object-into-object-2.rs:10:5
|
||||||
|
|
|
||||||
|
LL | box B(&*v) as Box<dyn X>
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
||||||
|
|
|
|
||||||
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {
|
||||||
|
|
|
@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
|
||||||
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
|
||||||
| ---------------- this data with lifetime `'a`...
|
| ---------------- this data with lifetime `'a`...
|
||||||
LL | box B(&*v) as Box<dyn X>
|
LL | box B(&*v) as Box<dyn X>
|
||||||
| ------^^^---------------
|
| ^^^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/regions-close-object-into-object-4.rs:10:5
|
||||||
|
|
|
||||||
|
LL | box B(&*v) as Box<dyn X>
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
||||||
|
|
|
|
||||||
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {
|
||||||
|
|
|
@ -5,11 +5,13 @@ LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
|
||||||
| ------ this data with the anonymous lifetime `'_`...
|
| ------ this data with the anonymous lifetime `'_`...
|
||||||
LL | // This is illegal, because the region bound on `proc` is 'static.
|
LL | // This is illegal, because the region bound on `proc` is 'static.
|
||||||
LL | Box::new(move || { *x })
|
LL | Box::new(move || { *x })
|
||||||
| ---------^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^ ...is captured here...
|
||||||
| | |
|
|
||||||
| | ...and is captured here
|
|
||||||
| ...is required to be `'static` by this...
|
|
||||||
|
|
|
|
||||||
|
note: ...and required to be `'static` by this
|
||||||
|
--> $DIR/regions-proc-bound-capture.rs:9:5
|
||||||
|
|
|
||||||
|
LL | Box::new(move || { *x })
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
||||||
|
|
|
|
||||||
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {
|
||||||
|
|
Loading…
Reference in New Issue