Do not allow Drop impl on foreign fundamental types
This commit is contained in:
parent
40336865fe
commit
fd934c99bc
10 changed files with 51 additions and 18 deletions
|
@ -24,8 +24,8 @@ typeck_lifetimes_or_bounds_mismatch_on_trait =
|
|||
.generics_label = lifetimes in impl do not match this {$item_kind} in trait
|
||||
|
||||
typeck_drop_impl_on_wrong_item =
|
||||
the `Drop` trait may only be implemented for structs, enums, and unions
|
||||
.label = must be a struct, enum, or union
|
||||
the `Drop` trait may only be implemented for local structs, enums, and unions
|
||||
.label = must be a struct, enum, or union in the current crate
|
||||
|
||||
typeck_field_already_declared =
|
||||
field `{$field_name}` is already declared
|
||||
|
|
|
@ -47,9 +47,11 @@ impl<'tcx> Checker<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
||||
// Destructors only work on nominal types.
|
||||
if let ty::Adt(..) | ty::Error(_) = tcx.type_of(impl_did).kind() {
|
||||
return;
|
||||
// Destructors only work on local ADT types.
|
||||
match tcx.type_of(impl_did).kind() {
|
||||
ty::Adt(def, _) if def.did().is_local() => return,
|
||||
ty::Error(_) => return,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let sp = match tcx.hir().expect_item(impl_did).kind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue