Rollup merge of #139349 - meithecatte:destructor-constness, r=compiler-errors

adt_destructor: sanity-check returned item

Fixes #139278
This commit is contained in:
Matthias Krüger 2025-04-04 08:02:09 +02:00 committed by GitHub
commit 0a9eae161b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 0 deletions

View file

@ -414,6 +414,11 @@ impl<'tcx> TyCtxt<'tcx> {
continue;
};
if self.def_kind(item_id) != DefKind::AssocFn {
self.dcx().span_delayed_bug(self.def_span(item_id), "drop is not a function");
continue;
}
if let Some(old_item_id) = dtor_candidate {
self.dcx()
.struct_span_err(self.def_span(item_id), "multiple drop impls found")

View file

@ -0,0 +1,10 @@
//@ check-fail
struct Foo;
impl Drop for Foo { //~ ERROR: not all trait items implemented
const SPLOK: u32 = 0; //~ ERROR: not a member of trait
}
const X: Foo = Foo;
fn main() {}

View file

@ -0,0 +1,18 @@
error[E0438]: const `SPLOK` is not a member of trait `Drop`
--> $DIR/nonsense-drop-impl-issue-139278.rs:5:5
|
LL | const SPLOK: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Drop`
error[E0046]: not all trait items implemented, missing: `drop`
--> $DIR/nonsense-drop-impl-issue-139278.rs:4:1
|
LL | impl Drop for Foo {
| ^^^^^^^^^^^^^^^^^ missing `drop` in implementation
|
= help: implement the missing item: `fn drop(&mut self) { todo!() }`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0046, E0438.
For more information about an error, try `rustc --explain E0046`.