Auto merge of #79752 - cjgillot:dead-alien, r=lcnr
Visit ForeignItems when marking dead code Follow-up to #79318 r? `@lcnr`
This commit is contained in:
commit
5019791e2d
@ -396,24 +396,6 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(.., trait_item_refs) => {
|
|
||||||
for trait_item_ref in trait_item_refs {
|
|
||||||
let trait_item = self.krate.trait_item(trait_item_ref.id);
|
|
||||||
match trait_item.kind {
|
|
||||||
hir::TraitItemKind::Const(_, Some(_))
|
|
||||||
| hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
|
|
||||||
if has_allow_dead_code_or_lang_attr(
|
|
||||||
self.tcx,
|
|
||||||
trait_item.hir_id,
|
|
||||||
&trait_item.attrs,
|
|
||||||
) {
|
|
||||||
self.worklist.push(trait_item.hir_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hir::ItemKind::Impl { ref of_trait, items, .. } => {
|
hir::ItemKind::Impl { ref of_trait, items, .. } => {
|
||||||
if of_trait.is_some() {
|
if of_trait.is_some() {
|
||||||
self.worklist.push(item.hir_id);
|
self.worklist.push(item.hir_id);
|
||||||
@ -440,15 +422,37 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, _item: &hir::TraitItem<'_>) {
|
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
|
||||||
// ignore: we are handling this in `visit_item` above
|
match trait_item.kind {
|
||||||
|
hir::TraitItemKind::Const(_, Some(_))
|
||||||
|
| hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
|
||||||
|
if has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
|
||||||
|
{
|
||||||
|
self.worklist.push(trait_item.hir_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, _item: &hir::ImplItem<'_>) {
|
fn visit_impl_item(&mut self, _item: &hir::ImplItem<'_>) {
|
||||||
// ignore: we are handling this in `visit_item` above
|
// ignore: we are handling this in `visit_item` above
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, _item: &'v hir::ForeignItem<'v>) {}
|
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
|
||||||
|
match foreign_item.kind {
|
||||||
|
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Fn(..) => {
|
||||||
|
if has_allow_dead_code_or_lang_attr(
|
||||||
|
self.tcx,
|
||||||
|
foreign_item.hir_id,
|
||||||
|
&foreign_item.attrs,
|
||||||
|
) {
|
||||||
|
self.worklist.push(foreign_item.hir_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_and_seed_worklist<'tcx>(
|
fn create_and_seed_worklist<'tcx>(
|
||||||
|
19
src/test/ui/lint/dead-code/type-in-foreign.rs
Normal file
19
src/test/ui/lint/dead-code/type-in-foreign.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Verify that we do not warn on types that are used by foreign functions.
|
||||||
|
// check-pass
|
||||||
|
#![deny(dead_code)]
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct Type(u8);
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct Param(u8);
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn hey(t: Param);
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
static much: Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user