rust/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr
Aaron Hill e3a048c3c9
Ensure that early-bound function lifetimes are always 'local'
During borrowchecking, we treat any free (early-bound) regions on
the 'defining type' as `RegionClassification::External`. According
to the doc comments, we should only have 'external' regions when
checking a closure/generator.

However, a plain function can also have some if its regions
be considered 'early bound' - this occurs when the region is
constrained by an argument, appears in a `where` clause, or
in an opaque type. This was causing us to incorrectly mark these
regions as 'external', which caused some diagnostic code
to act as if we were referring to a 'parent' region from inside
a closure.

This PR marks all instantiated region variables as 'local'
when we're borrow-checking something other than a
closure/generator/inline-const.
2021-12-31 18:42:54 -05:00

35 lines
1.5 KiB
Plaintext

error: lifetime may not live long enough
--> $DIR/variance-use-invariant-struct-1.rs:12:5
|
LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>)
| ---- ---- lifetime `'max` defined here
| |
| lifetime `'min` defined here
...
LL | v
| ^ function was supposed to return data with lifetime `'max` but it is returning data with lifetime `'min`
|
= help: consider adding the following bound: `'min: 'max`
= note: requirement occurs because of the type SomeStruct<&()>, which makes the generic argument &() invariant
= note: the struct SomeStruct<T> is invariant over the parameter T
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/variance-use-invariant-struct-1.rs:19:5
|
LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>)
| ---- ---- lifetime `'max` defined here
| |
| lifetime `'min` defined here
...
LL | v
| ^ function was supposed to return data with lifetime `'max` but it is returning data with lifetime `'min`
|
= help: consider adding the following bound: `'min: 'max`
= note: requirement occurs because of the type SomeStruct<&()>, which makes the generic argument &() invariant
= note: the struct SomeStruct<T> is invariant over the parameter T
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 2 previous errors