Skip to content
Closed
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
}

// All of these nodes have no parent from which to inherit generics.
Node::Item(_) | Node::ForeignItem(_) => None,
Node::Item(_) | Node::ForeignItem(_) | Node::Crate(_) => None,

// Params don't really have generics, but we use it when instantiating their value paths.
Node::GenericParam(_) => None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Regression test for #144888.
//
// `generics_of` was called with the crate root DefId during dyn-compatibility
// checking, which caused an ICE because Node::Crate was not handled in the
// match in `generics_of`.

trait Super {
type Assoc;
}
impl dyn Foo<()> {}
trait Foo<T>: Super<Assoc = T>
//~^ ERROR type mismatch resolving `<Self as Super>::Assoc == ()`
//~| ERROR the size for values of type `Self` cannot be known
where
<Self as Mirror>::Assoc: Clone,
//~^ ERROR type mismatch resolving `<Self as Super>::Assoc == ()`
//~| ERROR the size for values of type `Self` cannot be known
//~| ERROR type mismatch resolving `<Self as Super>::Assoc == ()`
//~| ERROR the size for values of type `Self` cannot be known
{
fn transmute(&self) {}
//~^ ERROR type mismatch resolving `<Self as Super>::Assoc == ()`
//~| ERROR the size for values of type `Self` cannot be known
//~| ERROR type mismatch resolving `<Self as Super>::Assoc == ()`
//~| ERROR the size for values of type `Self` cannot be known
}

trait Mirror {
type Assoc;
}
impl<T: Super<Assoc = ()>> Mirror for T {}
//~^ ERROR not all trait items implemented

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
--> $DIR/generics-of-crate-node-issue-144888.rs:21:5
|
LL | fn transmute(&self) {}
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found type parameter `T`
|
= note: expected unit type `()`
found type parameter `T`
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ---------- ^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/generics-of-crate-node-issue-144888.rs:21:5
|
LL | fn transmute(&self) {}
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| - ^^^^^^ ^
| |
| unsatisfied trait bound implicitly introduced here

error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
--> $DIR/generics-of-crate-node-issue-144888.rs:11:1
|
LL | trait Foo<T>: Super<Assoc = T>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found type parameter `T`
|
= note: expected unit type `()`
found type parameter `T`
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ---------- ^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/generics-of-crate-node-issue-144888.rs:11:1
|
LL | trait Foo<T>: Super<Assoc = T>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| - ^^^^^^ ^
| |
| unsatisfied trait bound implicitly introduced here
help: consider further restricting `Self`
|
LL | trait Foo<T>: Super<Assoc = T> + Sized
| +++++++

error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
--> $DIR/generics-of-crate-node-issue-144888.rs:15:30
|
LL | trait Foo<T>: Super<Assoc = T>
| - found this type parameter
...
LL | <Self as Mirror>::Assoc: Clone,
| ^^^^^ expected `()`, found type parameter `T`
|
= note: expected unit type `()`
found type parameter `T`
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ---------- ^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/generics-of-crate-node-issue-144888.rs:15:30
|
LL | <Self as Mirror>::Assoc: Clone,
| ^^^^^ doesn't have a size known at compile-time
|
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| - ^^^^^^ ^
| |
| unsatisfied trait bound implicitly introduced here
help: consider further restricting `Self`
|
LL | trait Foo<T>: Super<Assoc = T> + Sized
| +++++++

error[E0046]: not all trait items implemented, missing: `Assoc`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:1
|
LL | type Assoc;
| ---------- `Assoc` from trait
LL | }
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Assoc` in implementation

error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
--> $DIR/generics-of-crate-node-issue-144888.rs:21:5
|
LL | trait Foo<T>: Super<Assoc = T>
| - found this type parameter
...
LL | fn transmute(&self) {}
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found type parameter `T`
|
= note: expected unit type `()`
found type parameter `T`
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ---------- ^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/generics-of-crate-node-issue-144888.rs:21:5
|
LL | fn transmute(&self) {}
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| - ^^^^^^ ^
| |
| unsatisfied trait bound implicitly introduced here
help: consider further restricting `Self`
|
LL | fn transmute(&self) where Self: Sized {}
| +++++++++++++++++

error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
--> $DIR/generics-of-crate-node-issue-144888.rs:15:30
|
LL | trait Foo<T>: Super<Assoc = T>
| - found this type parameter
...
LL | <Self as Mirror>::Assoc: Clone,
| ^^^^^ expected `()`, found type parameter `T`
|
= note: expected unit type `()`
found type parameter `T`
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| ---------- ^^^^^^ ^
| |
| unsatisfied trait bound introduced here
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/generics-of-crate-node-issue-144888.rs:15:30
|
LL | <Self as Mirror>::Assoc: Clone,
| ^^^^^ doesn't have a size known at compile-time
|
note: required for `Self` to implement `Mirror`
--> $DIR/generics-of-crate-node-issue-144888.rs:31:28
|
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
| - ^^^^^^ ^
| |
| unsatisfied trait bound implicitly introduced here
help: consider further restricting `Self`
|
LL | fn transmute(&self) where Self: Sized {}
| +++++++++++++++++

error: aborting due to 11 previous errors

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