Skip to content

Commit 5839841

Browse files
committed
forbid manually implementing Sized
1 parent a9afe42 commit 5839841

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

chalk-solve/src/wf.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ where
232232

233233
pub fn verify_trait_impl(&self, impl_id: ImplId<I>) -> Result<(), WfError<I>> {
234234
let interner = self.db.interner();
235+
235236
let impl_datum = self.db.impl_datum(impl_id);
237+
let trait_id = impl_datum.trait_id();
238+
239+
// You can't manually implement Sized
240+
if let Some(WellKnownTrait::SizedTrait) = self.db.trait_datum(trait_id).well_known {
241+
return Err(WfError::IllFormedTraitImpl(trait_id));
242+
}
236243

237244
let impl_goal = Goal::all(
238245
interner,
@@ -258,8 +265,7 @@ where
258265
if is_legal {
259266
Ok(())
260267
} else {
261-
let trait_ref = &impl_datum.binders.value.trait_ref;
262-
Err(WfError::IllFormedTraitImpl(trait_ref.trait_id))
268+
Err(WfError::IllFormedTraitImpl(trait_id))
263269
}
264270
}
265271
}

tests/test/wf_lowering.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,17 @@ fn struct_sized_constraints() {
711711
}
712712
}
713713
}
714+
715+
lowering_error! {
716+
program {
717+
#[lang(sized)]
718+
trait Sized { }
719+
720+
struct Foo {}
721+
722+
impl Sized for Foo {}
723+
} error_msg {
724+
"trait impl for `Sized` does not meet well-formedness requirements"
725+
}
726+
}
714727
}

0 commit comments

Comments
 (0)