Skip to content

Commit 5f1924c

Browse files
committed
Auto merge of #60714 - varkor:existential-global-lift-ice, r=oli-obk
Fix ICE with un-feature-gated existential type Fixes #60371. r? @oli-obk
2 parents af39a1f + aa9369c commit 5f1924c

File tree

3 files changed

+70
-19
lines changed

3 files changed

+70
-19
lines changed

src/librustc_typeck/check/writeback.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -611,26 +611,33 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
611611
}
612612
}
613613

614-
let new = ty::ResolvedOpaqueTy {
615-
concrete_type: definition_ty,
616-
substs: self.tcx().lift_to_global(&opaque_defn.substs).unwrap(),
617-
};
618-
619-
let old = self.tables
620-
.concrete_existential_types
621-
.insert(def_id, new);
622-
if let Some(old) = old {
623-
if old.concrete_type != definition_ty || old.substs != opaque_defn.substs {
624-
span_bug!(
625-
span,
626-
"visit_opaque_types tried to write \
627-
different types for the same existential type: {:?}, {:?}, {:?}, {:?}",
628-
def_id,
629-
definition_ty,
630-
opaque_defn,
631-
old,
632-
);
614+
if let Some(substs) = self.tcx().lift_to_global(&opaque_defn.substs) {
615+
let new = ty::ResolvedOpaqueTy {
616+
concrete_type: definition_ty,
617+
substs,
618+
};
619+
620+
let old = self.tables
621+
.concrete_existential_types
622+
.insert(def_id, new);
623+
if let Some(old) = old {
624+
if old.concrete_type != definition_ty || old.substs != opaque_defn.substs {
625+
span_bug!(
626+
span,
627+
"visit_opaque_types tried to write \
628+
different types for the same existential type: {:?}, {:?}, {:?}, {:?}",
629+
def_id,
630+
definition_ty,
631+
opaque_defn,
632+
old,
633+
);
634+
}
633635
}
636+
} else {
637+
self.tcx().sess.delay_span_bug(
638+
span,
639+
"cannot lift `opaque_defn` substs to global type context",
640+
);
634641
}
635642
}
636643
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Bug {
2+
type Item: Bug;
3+
4+
const FUN: fn() -> Self::Item;
5+
}
6+
7+
impl Bug for &() {
8+
existential type Item: Bug; //~ ERROR existential types are unstable
9+
//~^ ERROR the trait bound `(): Bug` is not satisfied
10+
//~^^ ERROR could not find defining uses
11+
12+
const FUN: fn() -> Self::Item = || ();
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0658]: existential types are unstable
2+
--> $DIR/issue-60371.rs:8:5
3+
|
4+
LL | existential type Item: Bug;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/34511
8+
= help: add #![feature(existential_type)] to the crate attributes to enable
9+
10+
error[E0277]: the trait bound `(): Bug` is not satisfied
11+
--> $DIR/issue-60371.rs:8:5
12+
|
13+
LL | existential type Item: Bug;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bug` is not implemented for `()`
15+
|
16+
= help: the following implementations were found:
17+
<&() as Bug>
18+
= note: the return type of a function must have a statically known size
19+
20+
error: could not find defining uses
21+
--> $DIR/issue-60371.rs:8:5
22+
|
23+
LL | existential type Item: Bug;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
26+
error: aborting due to 3 previous errors
27+
28+
Some errors have detailed explanations: E0277, E0658.
29+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)