Skip to content

Commit 8655cb8

Browse files
committed
don't mangle duplicate #[used] warnings
1 parent ecb1666 commit 8655cb8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,29 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
424424
ArgParser::NameValue(_) => return,
425425
};
426426

427+
let attr_span = cx.attr_span;
428+
429+
// `#[used]` is interpreted as `#[used(linker)]` (though depending on target OS the
430+
// circumstances are more complicated). While we're checking `used_by`, also report
431+
// these cross-`UsedBy` duplicates to warn.
427432
let target = match used_by {
428433
UsedBy::Compiler => &mut group.first_compiler,
429-
UsedBy::Linker => &mut group.first_linker,
430-
UsedBy::Any => &mut group.first_generic,
434+
UsedBy::Linker => {
435+
if let Some(prev) = group.first_generic {
436+
cx.warn_unused_duplicate(prev, attr_span);
437+
return;
438+
}
439+
&mut group.first_linker
440+
}
441+
UsedBy::Any => {
442+
if let Some(prev) = group.first_linker {
443+
cx.warn_unused_duplicate(prev, attr_span);
444+
return;
445+
}
446+
&mut group.first_generic
447+
}
431448
};
432449

433-
let attr_span = cx.attr_span;
434450
if let Some(prev) = *target {
435451
cx.warn_unused_duplicate(prev, attr_span);
436452
} else {

0 commit comments

Comments
 (0)