rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.8k stars 12.66k forks source link

libc and test features are special-cased for feature validity checks #53260

Open varkor opened 6 years ago

varkor commented 6 years ago

When implementing https://github.com/rust-lang/rust/pull/52644, where we emit errors when using unknown features, I had to special case two features: libc and test, because they weren't being picked up (and there were time constraints).

The special-casing is here: https://github.com/rust-lang/rust/blob/0aa8d0320266b5579428312095fe49af05ada972/src/librustc/middle/stability.rs#L840-L847

Ideally these should both not be special-cased. The relevant code for feature collection is in src/librustc/middle/lib_features.rs, so that's a good place to start looking.

eddyb commented 6 years ago

cfg_attr shouldn't make libc special. when we build it in-tree, we set feature = "stdbuild" (which is not set when using it from crates.io). All you need to do is make sure you're not touching feature-gates in libsyntax{,_ext}, only later on, in librustc.

varkor commented 6 years ago

All you need to do is make sure you're not touching feature-gates in libsyntax{,_ext}

As in: just ignore any warnings for these? Though that means we would avoid the special-casing, it could lead to a build up of unnecessary feature attributes in the compiler.

eddyb commented 6 years ago

@varkor I mean, don't check for feature-gating attributes on the AST, only on HIR.

varkor commented 6 years ago

It's been using either hir::itemlikevisit::ItemLikeVisitor or hir::intravisit::Visitor, so that's what it should be doing already, no?