Auto merge of #86118 - spastorino:tait-soundness-bug, r=nikomatsakis
Create different inference variables for different defining uses of TAITs Fixes #73481 r? `@nikomatsakis` cc `@oli-obk`
This commit is contained in:
commit
c4b5406981
21 changed files with 439 additions and 132 deletions
|
|
@ -0,0 +1,12 @@
|
|||
// check-pass
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
type X<A: ToString + Clone, B: ToString + Clone> = impl ToString;
|
||||
|
||||
fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
|
||||
(a.clone(), a)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", <X<_, _> as ToString>::to_string(&f(42_i32, String::new()).1));
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// https://github.com/rust-lang/rust/issues/73481
|
||||
// This test used to cause unsoundness, since one of the two possible
|
||||
// resolutions was chosen at random instead of erroring due to conflicts.
|
||||
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
type X<A, B> = impl Into<&'static A>;
|
||||
//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
|
||||
|
||||
fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
|
||||
(a, a)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", <X<_, _> as Into<&String>>::into(f(&[1isize, 2, 3], String::new()).1));
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied
|
||||
--> $DIR/multiple-def-uses-in-one-fn.rs:7:16
|
||||
|
|
||||
LL | type X<A, B> = impl Into<&'static A>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Into<&'static B>` for `&A`
|
||||
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
||||
|
|
||||
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) where &'static B: From<&A> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// https://github.com/rust-lang/rust/issues/73481
|
||||
// This test used to cause unsoundness, since one of the two possible
|
||||
// resolutions was chosen at random instead of erroring due to conflicts.
|
||||
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
type X<A: ToString + Clone, B: ToString + Clone> = impl ToString;
|
||||
//~^ ERROR could not find defining uses
|
||||
|
||||
fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>) {
|
||||
(a.clone(), a)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", <X<_, _> as ToString>::to_string(&f(42_i32, String::new()).1));
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: could not find defining uses
|
||||
--> $DIR/multiple-def-uses-in-one-fn2.rs:7:52
|
||||
|
|
||||
LL | type X<A: ToString + Clone, B: ToString + Clone> = impl ToString;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// https://github.com/rust-lang/rust/issues/73481
|
||||
// This test used to cause unsoundness, since one of the two possible
|
||||
// resolutions was chosen at random instead of erroring due to conflicts.
|
||||
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
type X<A: ToString + Clone, B: ToString + Clone> = impl ToString;
|
||||
|
||||
fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>) {
|
||||
(a, b)
|
||||
}
|
||||
|
||||
fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
|
||||
(a, b)
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/multiple-def-uses-in-one-fn3.rs:14:9
|
||||
|
|
||||
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
|
||||
| - - found type parameter
|
||||
| |
|
||||
| expected type parameter
|
||||
LL | (a, b)
|
||||
| ^ expected type parameter `A`, found type parameter `B`
|
||||
|
|
||||
= note: expected type parameter `A`
|
||||
found type parameter `B`
|
||||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue