Rollup merge of #94377 - cynecx:fix-used-with-args, r=nikic

`check_used` should only look at actual `used` attributes

cc? https://github.com/rust-lang/rust/issues/94348
r? ``@nikic``
This commit is contained in:
Matthias Krüger 2022-02-26 00:49:23 +01:00 committed by GitHub
commit 04f77803ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1740,8 +1740,8 @@ impl CheckAttrVisitor<'_> {
fn check_used(&self, attrs: &[Attribute], target: Target) {
let mut used_linker_span = None;
let mut used_compiler_span = None;
for attr in attrs {
if attr.has_name(sym::used) && target != Target::Static {
for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) {
if target != Target::Static {
self.tcx
.sess
.span_err(attr.span, "attribute must be applied to a `static` variable");

View File

@ -0,0 +1,9 @@
// check-pass
#![feature(used_with_arg)]
#[used(linker)]
#[no_mangle] // accidentally detected as `used(compiler)`
pub static GLOB: usize = 0;
fn main() {}