Rollup merge of #139349 - meithecatte:destructor-constness, r=compiler-errors
adt_destructor: sanity-check returned item Fixes #139278
This commit is contained in:
commit
0a9eae161b
3 changed files with 33 additions and 0 deletions
|
@ -414,6 +414,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
continue;
|
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 {
|
if let Some(old_item_id) = dtor_candidate {
|
||||||
self.dcx()
|
self.dcx()
|
||||||
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
|
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
|
||||||
|
|
10
tests/ui/drop/nonsense-drop-impl-issue-139278.rs
Normal file
10
tests/ui/drop/nonsense-drop-impl-issue-139278.rs
Normal 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() {}
|
18
tests/ui/drop/nonsense-drop-impl-issue-139278.stderr
Normal file
18
tests/ui/drop/nonsense-drop-impl-issue-139278.stderr
Normal 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`.
|
Loading…
Add table
Add a link
Reference in a new issue