mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
Clean up visual output logic
This commit is contained in:
parent
d10fe26f39
commit
dd81e98466
@ -139,89 +139,39 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
// | ...is captured here...
|
// | ...is captured here...
|
||||||
(false, sup_origin.span())
|
(false, sup_origin.span())
|
||||||
} else {
|
} else {
|
||||||
(true, param.param_ty_span)
|
(!sup_origin.span().overlaps(return_sp), param.param_ty_span)
|
||||||
};
|
};
|
||||||
err.span_label(capture_point, &format!("this data with {}...", lifetime));
|
err.span_label(capture_point, &format!("this data with {}...", lifetime));
|
||||||
|
|
||||||
debug!("try_report_static_impl_trait: param_info={:?}", param);
|
debug!("try_report_static_impl_trait: param_info={:?}", param);
|
||||||
|
|
||||||
// We try to make the output have fewer overlapping spans if possible.
|
let mut spans = spans.clone();
|
||||||
if (sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span()))
|
|
||||||
&& sup_origin.span() != return_sp
|
|
||||||
{
|
|
||||||
// Customize the spans and labels depending on their relative order so
|
|
||||||
// that split sentences flow correctly.
|
|
||||||
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 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) }
|
|
||||||
// | ---- ^
|
|
||||||
err.span_label(
|
|
||||||
sup_origin.span(),
|
|
||||||
&format!(
|
|
||||||
"...is captured here, requiring it to live as long as `'static`{}",
|
|
||||||
if spans.is_empty() { "" } else { "..." },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if return_sp < sup_origin.span() && mention_capture {
|
|
||||||
err.span_label(sup_origin.span(), "...is captured here...");
|
|
||||||
err.span_note(
|
|
||||||
return_sp,
|
|
||||||
"...and is required to live as long as `'static` here",
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
err.span_label(
|
|
||||||
return_sp,
|
|
||||||
&format!(
|
|
||||||
"...is required to live as long as `'static` here{}",
|
|
||||||
if spans.is_empty() { "" } else { "..." },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if mention_capture {
|
if mention_capture {
|
||||||
let span = sup_origin.span();
|
spans.push(sup_origin.span());
|
||||||
let msg = if spans.iter().any(|sp| *sp > span) {
|
}
|
||||||
"...is captured here..."
|
spans.sort();
|
||||||
|
spans.dedup();
|
||||||
|
|
||||||
|
// We try to make the output have fewer overlapping spans if possible.
|
||||||
|
let (require_msg, require_span) = if sup_origin.span().overlaps(return_sp) {
|
||||||
|
("...is captured and required to live as long as `'static` here", sup_origin.span())
|
||||||
} else {
|
} else {
|
||||||
"...and is captured here"
|
("...and is required to live as long as `'static` here", return_sp)
|
||||||
};
|
};
|
||||||
err.span_label(span, msg);
|
|
||||||
}
|
for span in &spans {
|
||||||
}
|
err.span_label(*span, "...is captured here...");
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err.span_label(
|
|
||||||
return_sp,
|
|
||||||
&format!(
|
|
||||||
"...is captured and required to live as long as `'static` here{}",
|
|
||||||
if spans.is_empty() { "" } else { "..." },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for span in spans {
|
if spans.iter().any(|sp| sp.overlaps(return_sp) || *sp > return_sp) {
|
||||||
let msg =
|
err.span_note(require_span, require_msg);
|
||||||
format!("...and is captured here{}", if mention_capture { " too" } else { "" });
|
|
||||||
if span.overlaps(return_sp) {
|
|
||||||
err.span_note(*span, &msg);
|
|
||||||
} else {
|
} else {
|
||||||
err.span_label(*span, &msg);
|
err.span_label(require_span, require_msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let SubregionOrigin::RelateParamBound(_, _, Some(bound)) = sub_origin {
|
if let SubregionOrigin::RelateParamBound(_, _, Some(bound)) = sub_origin {
|
||||||
err.span_note(*bound, "`'static` lifetime requirement introduced by this trait bound");
|
err.span_note(*bound, "`'static` lifetime requirement introduced by this bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
||||||
|
@ -4,7 +4,7 @@ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime
|
|||||||
LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
|
LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
|
||||||
| ------- this data with lifetime `'a`...
|
| ------- this data with lifetime `'a`...
|
||||||
LL | bar(foo, x)
|
LL | bar(foo, x)
|
||||||
| ----^^^---- ...is captured and required to live as long as `'static` here
|
| ^^^ - ...is captured and required to live as long as `'static` here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ LL | fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> {
|
|||||||
| -------- this data with lifetime `'a`...
|
| -------- this data with lifetime `'a`...
|
||||||
...
|
...
|
||||||
LL | bar(foo, x)
|
LL | bar(foo, x)
|
||||||
| ----^^^---- ...is captured and required to live as long as `'static` here
|
| ^^^ - ...is captured and required to live as long as `'static` here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -4,14 +4,14 @@ error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'
|
|||||||
LL | pub async fn run_dummy_fn(&self) {
|
LL | pub async fn run_dummy_fn(&self) {
|
||||||
| ^^^^^ this data with an anonymous lifetime `'_`...
|
| ^^^^^ this data with an anonymous lifetime `'_`...
|
||||||
LL | foo(|| self.bar()).await;
|
LL | foo(|| self.bar()).await;
|
||||||
| --- ...is required to live as long as `'static` here...
|
| ------------------------ ...is captured here...
|
||||||
|
|
|
|
||||||
note: ...and is captured here
|
note: ...and is required to live as long as `'static` here
|
||||||
--> $DIR/issue-62097.rs:13:9
|
--> $DIR/issue-62097.rs:13:9
|
||||||
|
|
|
|
||||||
LL | foo(|| self.bar()).await;
|
LL | foo(|| self.bar()).await;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^
|
||||||
note: `'static` lifetime requirement introduced by this trait bound
|
note: `'static` lifetime requirement introduced by this bound
|
||||||
--> $DIR/issue-62097.rs:4:19
|
--> $DIR/issue-62097.rs:4:19
|
||||||
|
|
|
|
||||||
LL | F: FnOnce() + 'static
|
LL | F: FnOnce() + 'static
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// edition:2018
|
// edition:2018
|
||||||
fn require_static<T: 'static>(val: T) -> T {
|
fn require_static<T: 'static>(val: T) -> T {
|
||||||
//~^ NOTE 'static` lifetime requirement introduced by this trait bound
|
//~^ NOTE 'static` lifetime requirement introduced by this bound
|
||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,8 +10,8 @@ impl Problem {
|
|||||||
pub async fn start(&self) { //~ ERROR E0759
|
pub async fn start(&self) { //~ ERROR E0759
|
||||||
//~^ NOTE this data with an anonymous lifetime `'_`
|
//~^ NOTE this data with an anonymous lifetime `'_`
|
||||||
//~| NOTE in this expansion of desugaring of `async` block or function
|
//~| NOTE in this expansion of desugaring of `async` block or function
|
||||||
require_static(async move { //~ NOTE ...is required to live as long as `'static` here
|
require_static(async move { //~ NOTE ...and is required to live as long as `'static` here
|
||||||
&self; //~ NOTE ...and is captured here
|
&self; //~ NOTE ...is captured here...
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,15 @@ error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'
|
|||||||
LL | pub async fn start(&self) {
|
LL | pub async fn start(&self) {
|
||||||
| ^^^^^ this data with an anonymous lifetime `'_`...
|
| ^^^^^ this data with an anonymous lifetime `'_`...
|
||||||
...
|
...
|
||||||
LL | require_static(async move {
|
|
||||||
| -------------- ...is required to live as long as `'static` here...
|
|
||||||
LL | &self;
|
LL | &self;
|
||||||
| ----- ...and is captured here
|
| ----- ...is captured here...
|
||||||
|
|
|
|
||||||
note: `'static` lifetime requirement introduced by this trait bound
|
note: ...and is required to live as long as `'static` here
|
||||||
|
--> $DIR/issue-72312.rs:13:9
|
||||||
|
|
|
||||||
|
LL | require_static(async move {
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
note: `'static` lifetime requirement introduced by this bound
|
||||||
--> $DIR/issue-72312.rs:2:22
|
--> $DIR/issue-72312.rs:2:22
|
||||||
|
|
|
|
||||||
LL | fn require_static<T: 'static>(val: T) -> T {
|
LL | fn require_static<T: 'static>(val: T) -> T {
|
||||||
|
@ -80,7 +80,7 @@ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'sta
|
|||||||
--> $DIR/must_outlive_least_region_or_bound.rs:24:65
|
--> $DIR/must_outlive_least_region_or_bound.rs:24:65
|
||||||
|
|
|
|
||||||
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
|
||||||
| ---- this data with an anonymous lifetime `'_`... ^ ...is captured here, requiring it to live as long as `'static`
|
| ---- this data with an anonymous lifetime `'_`... ^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
|
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
|
||||||
|
|
|
|
||||||
@ -136,7 +136,7 @@ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'sta
|
|||||||
--> $DIR/must_outlive_least_region_or_bound.rs:16:50
|
--> $DIR/must_outlive_least_region_or_bound.rs:16: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, requiring it to live as long as `'static`
|
| ---- ^ ...is captured and required to live as long as `'static` here
|
||||||
| |
|
| |
|
||||||
| this data with an anonymous lifetime `'_`...
|
| this data with an anonymous lifetime `'_`...
|
||||||
|
|
|
|
||||||
@ -149,7 +149,7 @@ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime
|
|||||||
--> $DIR/must_outlive_least_region_or_bound.rs:18:59
|
--> $DIR/must_outlive_least_region_or_bound.rs:18: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, requiring it to live as long as `'static`
|
| ------- ^ ...is captured and required to live as long as `'static` here
|
||||||
| |
|
| |
|
||||||
| this data with lifetime `'a`...
|
| this data with lifetime `'a`...
|
||||||
|
|
|
|
||||||
@ -162,7 +162,7 @@ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'sta
|
|||||||
--> $DIR/must_outlive_least_region_or_bound.rs:20:60
|
--> $DIR/must_outlive_least_region_or_bound.rs:20: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, requiring it to live as long as `'static`
|
| ---- ^ ...is captured and required to live as long as `'static` here
|
||||||
| |
|
| |
|
||||||
| this data with an anonymous lifetime `'_`...
|
| this data with an anonymous lifetime `'_`...
|
||||||
|
|
|
|
||||||
@ -179,7 +179,7 @@ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime
|
|||||||
--> $DIR/must_outlive_least_region_or_bound.rs:22:69
|
--> $DIR/must_outlive_least_region_or_bound.rs:22: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, requiring it to live as long as `'static`
|
| ------- this data with lifetime `'a`... ^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
|
||||||
|
|
|
|
||||||
|
@ -4,7 +4,7 @@ error[E0759]: `value` has an anonymous lifetime `'_` but it needs to satisfy a `
|
|||||||
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
|
||||||
| -- this data with an anonymous lifetime `'_`...
|
| -- this data with an anonymous lifetime `'_`...
|
||||||
LL | Box::new(value) as Box<dyn Any>
|
LL | Box::new(value) as Box<dyn Any>
|
||||||
| ^^^^^ ...is captured here, requiring it to live as long as `'static`
|
| ^^^^^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: to declare that the trait object captures data from argument `value`, you can add an explicit `'_` lifetime bound
|
help: to declare that the trait object captures data from argument `value`, you can add an explicit `'_` lifetime bound
|
||||||
|
|
|
|
||||||
|
@ -4,7 +4,7 @@ error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'sta
|
|||||||
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
|
||||||
| ----- this data with an anonymous lifetime `'_`...
|
| ----- this data with an 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, requiring it to live as long as `'static`
|
| ^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
||||||
|
|
|
|
||||||
@ -21,7 +21,7 @@ error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'sta
|
|||||||
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
|
||||||
| ----- this data with an anonymous lifetime `'_`...
|
| ----- this data with an anonymous lifetime `'_`...
|
||||||
LL | Box::new(v)
|
LL | Box::new(v)
|
||||||
| ^ ...is captured here, requiring it to live as long as `'static`
|
| ^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
||||||
|
|
|
|
||||||
@ -39,7 +39,7 @@ LL | fn c(v: &[u8]) -> Box<dyn Foo> {
|
|||||||
| ----- this data with an anonymous lifetime `'_`...
|
| ----- this data with an anonymous lifetime `'_`...
|
||||||
...
|
...
|
||||||
LL | Box::new(v)
|
LL | Box::new(v)
|
||||||
| ^ ...is captured here, requiring it to live as long as `'static`
|
| ^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: to declare that the trait object captures data from argument `v`, you can add an explicit `'_` lifetime bound
|
help: to declare that the trait object captures data from argument `v`, you can add an explicit `'_` lifetime bound
|
||||||
|
|
|
|
||||||
|
@ -4,7 +4,7 @@ error[E0759]: `v` has lifetime `'a` but it needs to satisfy a `'static` 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::new(B(&*v)) as Box<dyn X>
|
LL | Box::new(B(&*v)) as Box<dyn X>
|
||||||
| ^^^ ...is captured here, requiring it to live as long as `'static`
|
| ^^^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
||||||
|
|
|
|
||||||
|
@ -4,7 +4,7 @@ error[E0759]: `v` has lifetime `'a` but it needs to satisfy a `'static` 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::new(B(&*v)) as Box<dyn X>
|
LL | Box::new(B(&*v)) as Box<dyn X>
|
||||||
| ^^^ ...is captured here, requiring it to live as long as `'static`
|
| ^^^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
||||||
|
|
|
|
||||||
|
@ -5,7 +5,7 @@ LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
|
|||||||
| ------ this data with an anonymous lifetime `'_`...
|
| ------ this data with an 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, requiring it to live as long as `'static`
|
| ^^^^^^^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
|
||||||
|
|
|
|
||||||
|
@ -39,13 +39,13 @@ LL | let y = x as &dyn Bar<'_, '_>;
|
|||||||
| ...is captured here...
|
| ...is captured here...
|
||||||
LL |
|
LL |
|
||||||
LL | y.get_b() // ERROR
|
LL | y.get_b() // ERROR
|
||||||
| --------- ...is required to live as long as `'static` here...
|
| - ...is captured here...
|
||||||
|
|
|
|
||||||
note: ...and is captured here too
|
note: ...and is required to live as long as `'static` here
|
||||||
--> $DIR/type-checking-test-4.rs:29:5
|
--> $DIR/type-checking-test-4.rs:29:5
|
||||||
|
|
|
|
||||||
LL | y.get_b() // ERROR
|
LL | y.get_b() // ERROR
|
||||||
| ^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
||||||
--> $DIR/type-checking-test-4.rs:33:5
|
--> $DIR/type-checking-test-4.rs:33:5
|
||||||
@ -53,7 +53,7 @@ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime
|
|||||||
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
|
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
|
||||||
| ------------ this data with lifetime `'a`...
|
| ------------ this data with lifetime `'a`...
|
||||||
LL | <_ as Bar>::get_b(x) // ERROR
|
LL | <_ as Bar>::get_b(x) // ERROR
|
||||||
| ^^^^^^^^^^^^^^^^^ ...is captured here, requiring it to live as long as `'static`
|
| ^^^^^^^^^^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||||
|
|
||||||
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
||||||
--> $DIR/type-checking-test-4.rs:38:15
|
--> $DIR/type-checking-test-4.rs:38:15
|
||||||
@ -61,7 +61,7 @@ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime
|
|||||||
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
|
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
|
||||||
| ------------ this data with lifetime `'a`...
|
| ------------ this data with lifetime `'a`...
|
||||||
LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
|
LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
|
||||||
| ----------^^---------------- ...is captured and required to live as long as `'static` here
|
| ----------^^------------- ...is captured and required to live as long as `'static` here
|
||||||
|
|
||||||
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
||||||
--> $DIR/type-checking-test-4.rs:43:27
|
--> $DIR/type-checking-test-4.rs:43:27
|
||||||
@ -74,16 +74,16 @@ LL | let y = x as &dyn Bar<'_, '_>;
|
|||||||
| ...is captured here...
|
| ...is captured here...
|
||||||
LL |
|
LL |
|
||||||
LL | y.get_b(); // ERROR
|
LL | y.get_b(); // ERROR
|
||||||
| - ...and is captured here too
|
| - ...is captured here...
|
||||||
LL | let z = y;
|
LL | let z = y;
|
||||||
LL | z.get_b() // ERROR
|
LL | z.get_b() // ERROR
|
||||||
| --------- ...is required to live as long as `'static` here...
|
| - ...is captured here...
|
||||||
|
|
|
|
||||||
note: ...and is captured here too
|
note: ...and is required to live as long as `'static` here
|
||||||
--> $DIR/type-checking-test-4.rs:47:5
|
--> $DIR/type-checking-test-4.rs:47:5
|
||||||
|
|
|
|
||||||
LL | z.get_b() // ERROR
|
LL | z.get_b() // ERROR
|
||||||
| ^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
|
|||||||
| ---- this data with an anonymous lifetime `'_`...
|
| ---- this data with an anonymous lifetime `'_`...
|
||||||
LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
|
LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
|
||||||
LL | Box::new(items.iter())
|
LL | Box::new(items.iter())
|
||||||
| ---------------^^^^--- ...is captured and required to live as long as `'static` here
|
| ----- ^^^^
|
||||||
|
| |
|
||||||
|
| ...is captured and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
help: to declare that the trait object captures data from argument `items`, you can add an explicit `'_` lifetime bound
|
help: to declare that the trait object captures data from argument `items`, you can add an explicit `'_` lifetime bound
|
||||||
|
|
|
|
||||||
|
Loading…
Reference in New Issue
Block a user