Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/ui/associated-types/projection-dyn-associated-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Regression test for the projection bug in <https://github.com/rust-lang/rust/issues/123953>
//
//@ compile-flags: -Zincremental-verify-ich=yes
//@ incremental

pub trait A {}
pub trait B: A {}

pub trait Mirror {
type Assoc: ?Sized;
}

impl<T: ?Sized> Mirror for A {
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates [E0207]
//~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
type Assoc = T;
}

pub fn foo<'a>(
x: &'a <dyn A + 'static as Mirror>::Assoc
) -> &'a <dyn B + 'static as Mirror>::Assoc {
//~^ ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
//~| ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
static
} //~ ERROR expected identifier, found `}`

pub fn main() {}
52 changes: 52 additions & 0 deletions tests/ui/associated-types/projection-dyn-associated-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
error: expected identifier, found `}`
--> $DIR/projection-dyn-associated-type.rs:26:1
|
LL | }
| ^ expected identifier

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/projection-dyn-associated-type.rs:13:28
|
LL | impl<T: ?Sized> Mirror for A {
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
help: if this is a dyn-compatible trait, use `dyn`
|
LL | impl<T: ?Sized> Mirror for dyn A {
| +++
help: alternatively use a blanket implementation to implement `Mirror` for all types that also implement `A`
|
LL - impl<T: ?Sized> Mirror for A {
LL + impl<T: ?Sized, U: A> Mirror for U {
|

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/projection-dyn-associated-type.rs:13:6
|
LL | impl<T: ?Sized> Mirror for A {
| ^ unconstrained type parameter

error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
--> $DIR/projection-dyn-associated-type.rs:22:6
|
LL | ) -> &'a <dyn B + 'static as Mirror>::Assoc {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
|
= help: the trait `Mirror` is implemented for `dyn A`

error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
--> $DIR/projection-dyn-associated-type.rs:22:6
|
LL | ) -> &'a <dyn B + 'static as Mirror>::Assoc {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
|
= help: the trait `Mirror` is implemented for `dyn A`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0207, E0277.
For more information about an error, try `rustc --explain E0207`.
Loading