Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check associated type satisfy their bounds
This was currently only happening due to eager normalization, which isn't possible if there's specialization or bound variables.
- Loading branch information
1 parent
04e589c
commit d660dbc
Showing
21 changed files
with
625 additions
and
6 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
32 changes: 32 additions & 0 deletions
32
src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.rs
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,32 @@ | ||
// Regression test for #68641 | ||
|
||
#![feature(generic_associated_types)] | ||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not | ||
|
||
trait UnsafeCopy { | ||
type Item<'a>: Copy; | ||
|
||
fn copy<'a>(item: &Self::Item<'a>) -> Self::Item<'a> { | ||
*item | ||
} | ||
} | ||
|
||
impl<T> UnsafeCopy for T { | ||
type Item<'a> = T; | ||
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied | ||
} | ||
|
||
fn main() { | ||
let mut s = String::from("Hello world!"); | ||
|
||
let copy = String::copy(&s); | ||
|
||
// Do we indeed point to the samme memory? | ||
assert!(s.as_ptr() == copy.as_ptr()); | ||
|
||
// Any use of `copy` is certeinly UB after this | ||
drop(s); | ||
|
||
// UB UB UB UB UB!! | ||
println!("{}", copy); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.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,26 @@ | ||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/issue-68641-check-gat-bounds.rs:3:12 | ||
| | ||
LL | #![feature(generic_associated_types)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information | ||
|
||
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied | ||
--> $DIR/issue-68641-check-gat-bounds.rs:15:5 | ||
| | ||
LL | trait UnsafeCopy { | ||
| ---------------- required by `UnsafeCopy` | ||
... | ||
LL | type Item<'a> = T; | ||
| ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` | ||
| | ||
help: consider restricting type parameter `T` | ||
| | ||
LL | impl<T: std::marker::Copy> UnsafeCopy for T { | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
21 changes: 21 additions & 0 deletions
21
src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.rs
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,21 @@ | ||
// Regression test for #68642 | ||
|
||
#![feature(generic_associated_types)] | ||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not | ||
|
||
trait Fun { | ||
type F<'a>: Fn() -> u32; | ||
|
||
fn callme<'a>(f: Self::F<'a>) -> u32 { | ||
f() | ||
} | ||
} | ||
|
||
impl<T> Fun for T { | ||
type F<'a> = Self; | ||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T` | ||
} | ||
|
||
fn main() { | ||
<fn() -> usize>::callme(|| 1); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.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,28 @@ | ||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/issue-68642-broken-llvm-ir.rs:3:12 | ||
| | ||
LL | #![feature(generic_associated_types)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information | ||
|
||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T` | ||
--> $DIR/issue-68642-broken-llvm-ir.rs:15:5 | ||
| | ||
LL | trait Fun { | ||
| --------- required by `Fun` | ||
... | ||
LL | type F<'a> = Self; | ||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` | ||
| | ||
= help: the trait `std::ops::Fn<()>` is not implemented for `T` | ||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ } | ||
help: consider restricting type parameter `T` | ||
| | ||
LL | impl<T: std::ops::Fn<()>> Fun for T { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
21 changes: 21 additions & 0 deletions
21
src/test/ui/generic-associated-types/issue-68643-broken-mir.rs
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,21 @@ | ||
// Regression test for #68643 | ||
|
||
#![feature(generic_associated_types)] | ||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not | ||
|
||
trait Fun { | ||
type F<'a>: Fn() -> u32; | ||
|
||
fn callme<'a>(f: Self::F<'a>) -> u32 { | ||
f() | ||
} | ||
} | ||
|
||
impl<T> Fun for T { | ||
type F<'a> = Self; | ||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T` | ||
} | ||
|
||
pub fn main() { | ||
<fn()>::callme(|| {}); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/ui/generic-associated-types/issue-68643-broken-mir.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,28 @@ | ||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/issue-68643-broken-mir.rs:3:12 | ||
| | ||
LL | #![feature(generic_associated_types)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information | ||
|
||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T` | ||
--> $DIR/issue-68643-broken-mir.rs:15:5 | ||
| | ||
LL | trait Fun { | ||
| --------- required by `Fun` | ||
... | ||
LL | type F<'a> = Self; | ||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` | ||
| | ||
= help: the trait `std::ops::Fn<()>` is not implemented for `T` | ||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ } | ||
help: consider restricting type parameter `T` | ||
| | ||
LL | impl<T: std::ops::Fn<()>> Fun for T { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
21 changes: 21 additions & 0 deletions
21
src/test/ui/generic-associated-types/issue-68644-codegen-selection.rs
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,21 @@ | ||
// Regression test for #68644 | ||
|
||
#![feature(generic_associated_types)] | ||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not | ||
|
||
trait Fun { | ||
type F<'a>: Fn() -> u32; | ||
|
||
fn callme<'a>(f: Self::F<'a>) -> u32 { | ||
f() | ||
} | ||
} | ||
|
||
impl<T> Fun for T { | ||
type F<'a> = Self; | ||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T` | ||
} | ||
|
||
fn main() { | ||
<u8>::callme(0); | ||
} |
Oops, something went wrong.