Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improper_ctypes lint unaffected by lint attributes on the foreign items themselves. #52456

Closed
eddyb opened this issue Jul 17, 2018 · 1 comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@eddyb
Copy link
Member

eddyb commented Jul 17, 2018

// 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 {...}):

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).

cc @nikomatsakis @Manishearth

@eddyb eddyb added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jul 17, 2018
@VPashkov
Copy link
Contributor

I would like to take this on if nobody else is working on that.

cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…s, r=eddyb

Fix improper_ctypes lint for individual foreign items

Fixes rust-lang#52456.

r? @eddyb
cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…s, r=eddyb

Fix improper_ctypes lint for individual foreign items

Fixes rust-lang#52456.

r? @eddyb
cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…s, r=eddyb

Fix improper_ctypes lint for individual foreign items

Fixes rust-lang#52456.

r? @eddyb
cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…s, r=eddyb

Fix improper_ctypes lint for individual foreign items

Fixes rust-lang#52456.

r? @eddyb
bors added a commit that referenced this issue Aug 9, 2018
Fix improper_ctypes lint for individual foreign items

Fixes #52456.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

2 participants