Skip to content

Commit

Permalink
Add pub struct with allow(dead_code) into worklist
Browse files Browse the repository at this point in the history
  • Loading branch information
mu001999 committed Jun 12, 2024
1 parent 336e6ab commit 6445073
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ fn create_and_seed_worklist(
match tcx.def_kind(id) {
DefKind::Impl { .. } => false,
DefKind::AssocConst | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()),
DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
_ => true
})
.map(|id| (id, ComesFromAllowExpect::No))
Expand Down
33 changes: 33 additions & 0 deletions tests/ui/lint/dead-code/allow-unconstructed-pub-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@ check-pass

mod ffi {
use super::*;

extern "C" {
pub fn DomPromise_AddRef(promise: *const Promise);
pub fn DomPromise_Release(promise: *const Promise);
}
}

#[repr(C)]
#[allow(unused)]
pub struct Promise {
private: [u8; 0],
__nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>,
}

pub unsafe trait RefCounted {
unsafe fn addref(&self);
unsafe fn release(&self);
}

unsafe impl RefCounted for Promise {
unsafe fn addref(&self) {
ffi::DomPromise_AddRef(self)
}
unsafe fn release(&self) {
ffi::DomPromise_Release(self)
}
}

fn main() {}

0 comments on commit 6445073

Please sign in to comment.