Skip to content

adt_destructor: sanity-check returned item #139349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/drop/nonsense-drop-impl-issue-139278.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions tests/ui/drop/nonsense-drop-impl-issue-139278.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading