Skip to content

Commit 04f7780

Browse files
authored
Rollup merge of rust-lang#94377 - cynecx:fix-used-with-args, r=nikic
`check_used` should only look at actual `used` attributes cc? rust-lang#94348 r? ``@nikic``
2 parents 0c9d5e3 + 45a441b commit 04f7780

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,8 @@ impl CheckAttrVisitor<'_> {
17401740
fn check_used(&self, attrs: &[Attribute], target: Target) {
17411741
let mut used_linker_span = None;
17421742
let mut used_compiler_span = None;
1743-
for attr in attrs {
1744-
if attr.has_name(sym::used) && target != Target::Static {
1743+
for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) {
1744+
if target != Target::Static {
17451745
self.tcx
17461746
.sess
17471747
.span_err(attr.span, "attribute must be applied to a `static` variable");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
#![feature(used_with_arg)]
4+
5+
#[used(linker)]
6+
#[no_mangle] // accidentally detected as `used(compiler)`
7+
pub static GLOB: usize = 0;
8+
9+
fn main() {}

0 commit comments

Comments
 (0)