-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Closed
Copy link
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
// The attribute around the whole FFI block works.
#[allow(improper_ctypes)]
extern {
// But this one on an individual FFI item doesn't.
#[allow(improper_ctypes)]
fn exit(_: &String);
}The problem arises because the lint iterates over the children of ForeignMod (extern {...}):
rust/src/librustc_lint/types.rs
Lines 788 to 792 in 2ddc0cb
| fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { | |
| let mut vis = ImproperCTypesVisitor { cx: cx }; | |
| if let hir::ItemKind::ForeignMod(ref nmod) = it.node { | |
| if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic { | |
| for ni in &nmod.items { |
and it does so through
check_item, but only check_foreign_item would be affected by attributes on the individual foreign fn / static / type children of the extern {...} block.check_foreign_item could be used instead, with the small change that the abi has to be obtained from cx.tcx.hir.get_foreign_abi(ni.id), instead of nmod's field (as nmod would be gone).
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.