Skip to content

Commit e81522a

Browse files

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed
 

‎compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct ParameterCollector {
5959
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
6060
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
6161
match *t.kind() {
62-
ty::Alias(ty::Projection | ty::Inherent, ..) if !self.include_nonconstraining => {
62+
ty::Alias(..) if !self.include_nonconstraining => {
6363
// projections are not injective
6464
return ControlFlow::Continue(());
6565
}

‎tests/ui/type-alias-impl-trait/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn use_alias<T>(val: T) -> AliasOfForeignType<T> {
1111
foreign_crate::ForeignType(val)
1212
}
1313

14-
impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {}
14+
impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {}
1515
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
1616

1717
fn main() {}

‎tests/ui/type-alias-impl-trait/coherence.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
22
--> $DIR/coherence.rs:14:1
33
|
4-
LL | impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------
6-
| | |
7-
| | `AliasOfForeignType<T>` is not defined in the current crate
4+
LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------
6+
| | |
7+
| | `AliasOfForeignType<()>` is not defined in the current crate
88
| impl doesn't use only types from inside the current crate
99
|
1010
= note: define and implement a trait or new type instead

‎tests/ui/type-alias-impl-trait/coherence_generalization.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
// FIXME(type_alias_impl_trait): What does this test? This needs a comment
44
// explaining what we're worried about here.
5+
56
#![feature(type_alias_impl_trait)]
67
trait Trait {}
78
type Opaque<T> = impl Sized;
89
fn foo<T>() -> Opaque<T> {
910
()
1011
}
1112

12-
impl<T, V> Trait for (T, V, V, u32) {}
13-
impl<U, V> Trait for (Opaque<U>, V, i32, V) {}
13+
impl<T, U, V> Trait for (T, U, V, V, u32) {}
14+
impl<U, V> Trait for (Opaque<U>, U, V, i32, V) {}
1415

1516
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
use std::fmt::Display;
4+
5+
type Opaque<X> = impl Sized + 'static;
6+
fn define<X>() -> Opaque<X> {}
7+
8+
trait Trait {
9+
type Assoc: Display;
10+
}
11+
impl<'a> Trait for Opaque<&'a str> {
12+
//~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
13+
type Assoc = &'a str;
14+
}
15+
16+
// ======= Exploit =======
17+
18+
fn extend<T: Trait + 'static>(s: T::Assoc) -> Box<dyn Display> {
19+
Box::new(s)
20+
}
21+
22+
fn main() {
23+
let val = extend::<Opaque<&'_ str>>(&String::from("blah blah blah"));
24+
println!("{}", val);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/unconstrained-impl-param.rs:11:6
3+
|
4+
LL | impl<'a> Trait for Opaque<&'a str> {
5+
| ^^ unconstrained lifetime parameter
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)
Please sign in to comment.