-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check opaque types satisfy their bounds
- Loading branch information
1 parent
b3057f4
commit 5b279c8
Showing
22 changed files
with
158 additions
and
36 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Make sure that we check that impl trait types implement the traits that they | ||
// claim to. | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
type X<T> = impl Clone; | ||
//~^ ERROR the trait bound `T: std::clone::Clone` is not satisfied | ||
|
||
fn f<T: Clone>(t: T) -> X<T> { | ||
t | ||
} | ||
|
||
fn g<T>(o : Option<X<T>>) -> Option<X<T>> { | ||
o.clone() | ||
} | ||
|
||
fn main() { | ||
g(None::<X<&mut ()>>); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/type-alias-impl-trait/bounds-are-checked-2.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,14 @@ | ||
error[E0277]: the trait bound `T: std::clone::Clone` is not satisfied | ||
--> $DIR/bounds-are-checked-2.rs:6:13 | ||
| | ||
LL | type X<T> = impl Clone; | ||
| ^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `T` | ||
| | ||
help: consider restricting type parameter `T` | ||
| | ||
LL | type X<T: std::clone::Clone> = impl Clone; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,25 @@ | ||
// Make sure that we check that impl trait types implement the traits that they | ||
// claim to. | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
type X<'a> = impl Into<&'static str> + From<&'a str>; | ||
//~^ ERROR mismatched types | ||
|
||
fn f<'a: 'static>(t: &'a str) -> X<'a> { | ||
//~^ WARNING unnecessary lifetime parameter | ||
t | ||
} | ||
|
||
fn extend_lt<'a>(o: &'a str) -> &'static str { | ||
X::<'_>::from(o).into() | ||
} | ||
|
||
fn main() { | ||
let r = | ||
{ | ||
let s = "abcdef".to_string(); | ||
extend_lt(&s) | ||
}; | ||
println!("{}", r); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/type-alias-impl-trait/bounds-are-checked.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: unnecessary lifetime parameter `'a` | ||
--> $DIR/bounds-are-checked.rs:9:6 | ||
| | ||
LL | fn f<'a: 'static>(t: &'a str) -> X<'a> { | ||
| ^^^^^^^^^^^ | ||
| | ||
= help: you can use the `'static` lifetime directly, in place of `'a` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/bounds-are-checked.rs:6:14 | ||
| | ||
LL | type X<'a> = impl Into<&'static str> + From<&'a str>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch | ||
| | ||
= note: expected type `std::convert::From<&'a str>` | ||
found type `std::convert::From<&'static str>` | ||
note: the lifetime `'a` as defined on the item at 6:8... | ||
--> $DIR/bounds-are-checked.rs:6:8 | ||
| | ||
LL | type X<'a> = impl Into<&'static str> + From<&'a str>; | ||
| ^^ | ||
= note: ...does not necessarily outlive the static lifetime | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
4 changes: 2 additions & 2 deletions
4
src/test/ui/type-alias-impl-trait/generic_duplicate_param_use10.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
4 changes: 2 additions & 2 deletions
4
src/test/ui/type-alias-impl-trait/generic_duplicate_param_use7.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
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