Skip to content

Commit 578bc43

Browse files
committed
Do not ICE on trait aliases with missing obligations
1 parent 5c5b8af commit 578bc43

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12261226

12271227
/// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
12281228
/// removing the dummy `Self` type (`trait_object_dummy_self`).
1229-
fn trait_ref_to_existential(&self, trait_ref: ty::TraitRef<'tcx>)
1230-
-> ty::ExistentialTraitRef<'tcx> {
1229+
fn trait_ref_to_existential(
1230+
&self,
1231+
trait_ref: ty::TraitRef<'tcx>,
1232+
) -> ty::ExistentialTraitRef<'tcx> {
12311233
if trait_ref.self_ty() != self.tcx().types.trait_object_dummy_self {
1232-
bug!("trait_ref_to_existential called on {:?} with non-dummy Self", trait_ref);
1234+
self.tcx().sess.delay_span_bug(DUMMY_SP, &format!(
1235+
"trait_ref_to_existential called on {:?} with non-dummy Self",
1236+
trait_ref,
1237+
));
12331238
}
12341239
ty::ExistentialTraitRef::erase_self_ty(self.tcx(), trait_ref)
12351240
}

src/test/ui/issues/issue-65673.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(trait_alias)]
2+
trait Trait {}
3+
trait WithType {
4+
type Ctx;
5+
}
6+
trait Alias<T> = where T: Trait;
7+
8+
impl<T> WithType for T {
9+
type Ctx = dyn Alias<T>;
10+
//~^ ERROR the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
11+
}
12+
fn main() {}

src/test/ui/issues/issue-65673.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
2+
--> $DIR/issue-65673.rs:9:5
3+
|
4+
LL | type Ctx;
5+
| --- associated type defined here
6+
...
7+
LL | impl<T> WithType for T {
8+
| ---------------------- in this `impl` item
9+
LL | type Ctx = dyn Alias<T>;
10+
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
11+
|
12+
= help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
13+
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)