Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created June 5, 2018 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/257ec66494a1fb2b0d5cde44ad24f1ce to your computer and use it in GitHub Desktop.
Save nikomatsakis/257ec66494a1fb2b0d5cde44ad24f1ce to your computer and use it in GitHub Desktop.
error[E0495]: this data would have to have static lifetime
--> dyn-trait-underscore.rs:18:20
|
16 | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- SourceArgument
18 | Box::new(items.iter())
| ^^^^^^^^^^^^^^^^^^^^^^ InterestingSpot(Cast)
19 | }
error[E0495]: this data would have to have static lifetime
--> dyn-trait-underscore.rs:18:20
|
16 | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- SourceArgument
18 | Box::new(items.iter())
| ^^^^^^^^^^^^^^^^^^^^^^ InterestingSpot(Cast)
| |
| call to box
19 | }
1. write some function that takes a Location + MIR => ConstraintCategory
2. write some semi-arbitrary ordering on ConstraintCategories to pick the "master" one
3. make the labels and emit the error
then as followup:
4. write code to find the argument (if any) that contains the universal region
- maybe we want to reuse `find_arg_with_region` from `nice_region_error`
- would have to convert from RegionVid to error-region using `RegionInferenceContext::to_error_region`
---
error[E0495]: this data would have to have static lifetime
--> dyn-trait-underscore.rs:18:20
|
16 | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- source value starts here
18 | Box::new(items.iter())
| ^^^^^^^^^^^^^^^^^^^^^^ casting this value to `dyn Iterator<Item=&T> + 'static` requires data to have `'static` lifetime
19 | }
- we filter the edges to interesting ones
- for a given MIR statement, "categorize" why it's interesting
- assignments, call arguments, casts
- we pick some edge to be the "primary point"
- this will just be a heurstic
- for each of those places, we put a label and describe
- "data flows here..."
- the universal region `'1` -- find the argument(s) in which it appears and underline those,
saying "data has to have static lifetime" ("source value starts here")
----
error[E0495]: this data would have to have static lifetime
--> dyn-trait-underscore.rs:18:20
|
16 | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- fully elaborated type is `&'1 [T]`
18 | Box::new(items.iter())
| ^^^^^^^^^^^^^^^^^^^^^^ casting this value to a `dyn Iterator` requires `'1` to outlive `'static`
19 | }
----
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> dyn-trait-underscore.rs:18:20
|
18 | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 16:1...
--> dyn-trait-underscore.rs:16:1
|
16 | / fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
17 | | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
18 | | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
19 | | }
| |_^
note: ...so that reference does not outlive borrowed content
--> dyn-trait-underscore.rs:18:14
|
18 | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^^
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the expression is assignable:
expected std::boxed::Box<std::iter::Iterator<Item=&T> + 'static>
found std::boxed::Box<std::iter::Iterator<Item=&T>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment