Register even erroneous impls

Otherwise the specialization graph fails to pick it up, even though other code assumes that all impl blocks have an entry in the specialization graph.
This commit is contained in:
Oli Scherer 2024-01-11 20:33:52 +00:00
parent 5461836281
commit 6679e2c2f2
4 changed files with 138 additions and 5 deletions

View File

@ -32,6 +32,7 @@ pub enum SimplifiedType {
CoroutineWitness(DefId),
Function(usize),
Placeholder,
Error,
}
/// Generic parameters are pretty much just bound variables, e.g.
@ -153,7 +154,8 @@ pub fn simplify_type<'tcx>(
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
},
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
ty::Error(_) => Some(SimplifiedType::Error),
ty::Bound(..) | ty::Infer(_) => None,
}
}

View File

@ -1,6 +1,5 @@
use crate::traits::specialization_graph;
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
use crate::ty::visit::TypeVisitableExt;
use crate::ty::{Ident, Ty, TyCtxt};
use hir::def_id::LOCAL_CRATE;
use rustc_hir as hir;
@ -241,9 +240,6 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
let impl_def_id = impl_def_id.to_def_id();
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
continue;
}
if let Some(simplified_self_ty) =
fast_reject::simplify_type(tcx, impl_self_ty, TreatParams::AsCandidateKey)

View File

@ -0,0 +1,16 @@
trait Foo {
type Context<'c>
where
Self: 'c;
}
impl Foo for Box<dyn Foo> {}
//~^ ERROR `Foo` cannot be made into an object
//~| ERROR `Foo` cannot be made into an object
//~| ERROR cycle detected
//~| ERROR cycle detected
//~| ERROR cycle detected
//~| ERROR the trait bound `Box<(dyn Foo + 'static)>: Foo` is not satisfied
//~| ERROR not all trait items implemented
fn main() {}

View File

@ -0,0 +1,119 @@
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires finding trait impls of `Foo`...
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
|
LL | trait Foo {
| ^^^^^^^^^
= note: ...which again requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
|
LL | / trait Foo {
LL | | type Context<'c>
LL | | where
LL | | Self: 'c;
... |
LL | |
LL | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which immediately requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>` again
note: cycle used when collecting item types in top-level module
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
|
LL | / trait Foo {
LL | | type Context<'c>
LL | | where
LL | | Self: 'c;
... |
LL | |
LL | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which immediately requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>` again
note: cycle used when collecting item types in top-level module
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
|
LL | / trait Foo {
LL | | type Context<'c>
LL | | where
LL | | Self: 'c;
... |
LL | |
LL | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/unknown-lifetime-ice-119827.rs:7:22
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/unknown-lifetime-ice-119827.rs:2:10
|
LL | trait Foo {
| --- this trait cannot be made into an object...
LL | type Context<'c>
| ^^^^^^^ ...because it contains the generic associated type `Context`
= help: consider moving `Context` to another trait
= help: only type `{type error}` implements the trait, consider using it directly instead
error[E0277]: the trait bound `Box<(dyn Foo + 'static)>: Foo` is not satisfied
--> $DIR/unknown-lifetime-ice-119827.rs:7:14
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^ the trait `Foo` is not implemented for `Box<(dyn Foo + 'static)>`
|
= help: the trait `Foo` is implemented for `Box<(dyn Foo + 'static)>`
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/unknown-lifetime-ice-119827.rs:7:14
|
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/unknown-lifetime-ice-119827.rs:2:10
|
LL | trait Foo {
| --- this trait cannot be made into an object...
LL | type Context<'c>
| ^^^^^^^ ...because it contains the generic associated type `Context`
= help: consider moving `Context` to another trait
= help: only type `std::boxed::Box<(dyn Foo + 'static)>` implements the trait, consider using it directly instead
error[E0046]: not all trait items implemented, missing: `Context`
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
|
LL | type Context<'c>
| ---------------- `Context` from trait
...
LL | impl Foo for Box<dyn Foo> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Context` in implementation
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0038, E0046, E0277, E0391.
For more information about an error, try `rustc --explain E0038`.