Skip to content

Commit 6679e2c

Browse files
committed
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.
1 parent 5461836 commit 6679e2c

File tree

4 files changed

+138
-5
lines changed

4 files changed

+138
-5
lines changed

compiler/rustc_middle/src/ty/fast_reject.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum SimplifiedType {
3232
CoroutineWitness(DefId),
3333
Function(usize),
3434
Placeholder,
35+
Error,
3536
}
3637

3738
/// Generic parameters are pretty much just bound variables, e.g.
@@ -153,7 +154,8 @@ pub fn simplify_type<'tcx>(
153154
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
154155
},
155156
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
156-
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
157+
ty::Error(_) => Some(SimplifiedType::Error),
158+
ty::Bound(..) | ty::Infer(_) => None,
157159
}
158160
}
159161

compiler/rustc_middle/src/ty/trait_def.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::traits::specialization_graph;
22
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
3-
use crate::ty::visit::TypeVisitableExt;
43
use crate::ty::{Ident, Ty, TyCtxt};
54
use hir::def_id::LOCAL_CRATE;
65
use rustc_hir as hir;
@@ -241,9 +240,6 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
241240
let impl_def_id = impl_def_id.to_def_id();
242241

243242
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
244-
if impl_self_ty.references_error() {
245-
continue;
246-
}
247243

248244
if let Some(simplified_self_ty) =
249245
fast_reject::simplify_type(tcx, impl_self_ty, TreatParams::AsCandidateKey)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Foo {
2+
type Context<'c>
3+
where
4+
Self: 'c;
5+
}
6+
7+
impl Foo for Box<dyn Foo> {}
8+
//~^ ERROR `Foo` cannot be made into an object
9+
//~| ERROR `Foo` cannot be made into an object
10+
//~| ERROR cycle detected
11+
//~| ERROR cycle detected
12+
//~| ERROR cycle detected
13+
//~| ERROR the trait bound `Box<(dyn Foo + 'static)>: Foo` is not satisfied
14+
//~| ERROR not all trait items implemented
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
2+
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
3+
|
4+
LL | impl Foo for Box<dyn Foo> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires finding trait impls of `Foo`...
8+
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
9+
|
10+
LL | trait Foo {
11+
| ^^^^^^^^^
12+
= note: ...which again requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`, completing the cycle
13+
note: cycle used when collecting item types in top-level module
14+
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
15+
|
16+
LL | / trait Foo {
17+
LL | | type Context<'c>
18+
LL | | where
19+
LL | | Self: 'c;
20+
... |
21+
LL | |
22+
LL | | fn main() {}
23+
| |____________^
24+
= 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
25+
26+
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
27+
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
28+
|
29+
LL | impl Foo for Box<dyn Foo> {}
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= note: ...which immediately requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>` again
33+
note: cycle used when collecting item types in top-level module
34+
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
35+
|
36+
LL | / trait Foo {
37+
LL | | type Context<'c>
38+
LL | | where
39+
LL | | Self: 'c;
40+
... |
41+
LL | |
42+
LL | | fn main() {}
43+
| |____________^
44+
= 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
45+
46+
error[E0391]: cycle detected when computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>`
47+
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
48+
|
49+
LL | impl Foo for Box<dyn Foo> {}
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
51+
|
52+
= note: ...which immediately requires computing type of `<impl at $DIR/unknown-lifetime-ice-119827.rs:7:1: 7:26>` again
53+
note: cycle used when collecting item types in top-level module
54+
--> $DIR/unknown-lifetime-ice-119827.rs:1:1
55+
|
56+
LL | / trait Foo {
57+
LL | | type Context<'c>
58+
LL | | where
59+
LL | | Self: 'c;
60+
... |
61+
LL | |
62+
LL | | fn main() {}
63+
| |____________^
64+
= 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
65+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
66+
67+
error[E0038]: the trait `Foo` cannot be made into an object
68+
--> $DIR/unknown-lifetime-ice-119827.rs:7:22
69+
|
70+
LL | impl Foo for Box<dyn Foo> {}
71+
| ^^^ `Foo` cannot be made into an object
72+
|
73+
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>
74+
--> $DIR/unknown-lifetime-ice-119827.rs:2:10
75+
|
76+
LL | trait Foo {
77+
| --- this trait cannot be made into an object...
78+
LL | type Context<'c>
79+
| ^^^^^^^ ...because it contains the generic associated type `Context`
80+
= help: consider moving `Context` to another trait
81+
= help: only type `{type error}` implements the trait, consider using it directly instead
82+
83+
error[E0277]: the trait bound `Box<(dyn Foo + 'static)>: Foo` is not satisfied
84+
--> $DIR/unknown-lifetime-ice-119827.rs:7:14
85+
|
86+
LL | impl Foo for Box<dyn Foo> {}
87+
| ^^^^^^^^^^^^ the trait `Foo` is not implemented for `Box<(dyn Foo + 'static)>`
88+
|
89+
= help: the trait `Foo` is implemented for `Box<(dyn Foo + 'static)>`
90+
91+
error[E0038]: the trait `Foo` cannot be made into an object
92+
--> $DIR/unknown-lifetime-ice-119827.rs:7:14
93+
|
94+
LL | impl Foo for Box<dyn Foo> {}
95+
| ^^^^^^^^^^^^ `Foo` cannot be made into an object
96+
|
97+
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>
98+
--> $DIR/unknown-lifetime-ice-119827.rs:2:10
99+
|
100+
LL | trait Foo {
101+
| --- this trait cannot be made into an object...
102+
LL | type Context<'c>
103+
| ^^^^^^^ ...because it contains the generic associated type `Context`
104+
= help: consider moving `Context` to another trait
105+
= help: only type `std::boxed::Box<(dyn Foo + 'static)>` implements the trait, consider using it directly instead
106+
107+
error[E0046]: not all trait items implemented, missing: `Context`
108+
--> $DIR/unknown-lifetime-ice-119827.rs:7:1
109+
|
110+
LL | type Context<'c>
111+
| ---------------- `Context` from trait
112+
...
113+
LL | impl Foo for Box<dyn Foo> {}
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Context` in implementation
115+
116+
error: aborting due to 7 previous errors
117+
118+
Some errors have detailed explanations: E0038, E0046, E0277, E0391.
119+
For more information about an error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)