-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #114742 - compiler-errors:opaques-are-not-injective, r=…
…aliemjay TAITs do not constrain generic params Fixes #108425 Not sure if I should rework those two failing tests. I guess `tests/ui/type-alias-impl-trait/coherence.rs` could just have the type parameter removed from it? IDK what `tests/ui/type-alias-impl-trait/coherence_generalization.rs` is even testing, though. r? `@aliemjay` cc `@lcnr` `@oli-obk` (when he's back from 🌴)
- Loading branch information
Showing
6 changed files
with
43 additions
and
8 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
25 changes: 25 additions & 0 deletions
25
tests/ui/type-alias-impl-trait/unconstrained-impl-param.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,25 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
use std::fmt::Display; | ||
|
||
type Opaque<X> = impl Sized + 'static; | ||
fn define<X>() -> Opaque<X> {} | ||
|
||
trait Trait { | ||
type Assoc: Display; | ||
} | ||
impl<'a> Trait for Opaque<&'a str> { | ||
//~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates | ||
type Assoc = &'a str; | ||
} | ||
|
||
// ======= Exploit ======= | ||
|
||
fn extend<T: Trait + 'static>(s: T::Assoc) -> Box<dyn Display> { | ||
Box::new(s) | ||
} | ||
|
||
fn main() { | ||
let val = extend::<Opaque<&'_ str>>(&String::from("blah blah blah")); | ||
println!("{}", val); | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ui/type-alias-impl-trait/unconstrained-impl-param.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,9 @@ | ||
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates | ||
--> $DIR/unconstrained-impl-param.rs:11:6 | ||
| | ||
LL | impl<'a> Trait for Opaque<&'a str> { | ||
| ^^ unconstrained lifetime parameter | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0207`. |