-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relate existential associated types with variance Invariant
- Loading branch information
1 parent
7355816
commit c99164e
Showing
6 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/test/ui/variance/variance-associated-types2.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/variance-associated-types2.rs:13:12 | ||
| | ||
LL | fn take<'a>(_: &'a u32) { | ||
| -- lifetime `'a` defined here | ||
LL | let _: Box<dyn Foo<Bar = &'a u32>> = make(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | ||
| | ||
= help: consider replacing `'a` with `'static` | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Test that dyn Foo<Bar = T> is invariant with respect to T. | ||
// Failure to enforce invariance here can be weaponized, see #71550 for details. | ||
|
||
trait Foo { | ||
type Bar; | ||
} | ||
|
||
fn make() -> Box<dyn Foo<Bar = &'static u32>> { | ||
panic!() | ||
} | ||
|
||
fn take<'a>(_: &'a u32) { | ||
let _: Box<dyn Foo<Bar = &'a u32>> = make(); | ||
//~^ ERROR mismatched types [E0308] | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/variance-associated-types2.rs:13:42 | ||
| | ||
LL | let _: Box<dyn Foo<Bar = &'a u32>> = make(); | ||
| ^^^^^^ lifetime mismatch | ||
| | ||
= note: expected trait object `dyn Foo<Bar = &'a u32>` | ||
found trait object `dyn Foo<Bar = &'static u32>` | ||
note: the lifetime `'a` as defined on the function body at 12:9... | ||
--> $DIR/variance-associated-types2.rs:12:9 | ||
| | ||
LL | fn take<'a>(_: &'a u32) { | ||
| ^^ | ||
= note: ...does not necessarily outlive the static lifetime | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |