Skip to content

Commit b0b6006

Browse files
committed
Auto merge of #166162 - JonathanBrouwer:rollup-rodzZnf, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - #165913 (MirPatch: reduce new statement insertion complexity) - #166081 (test `feature(asm_const_ptr)` with a vtable) - #166094 (Chain the spans of qualified paths instead of having a first-to-last scheme ) - #166113 (Fix dead-code marking dead enum variants as live) - #166118 (rustc_target: catch up with LLVM 24 movement on ppc64le bsd data layout) - #166155 (windows seek_write: document interaction with append mode) - #165935 (Duplicate attribute diagnostic cleanups) - #165948 (lint: Avoid unused_parens warning for ref patterns binding an identifier) - #166018 (`rustc_mir_build`: de-duplicate `local_temp_lifetime()`) - #166111 (Add `cd` alias to `std::env::set_current_dir`) - #166157 (Don't recover invalid literals in attribute parsing)
2 parents e3b9a83 + 260090f commit b0b6006

73 files changed

Lines changed: 638 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl AttributeParser for NakedParser {
221221

222222
if let Some(earlier) = this.span {
223223
let span = cx.attr_span;
224-
cx.warn_unused_duplicate(earlier, span);
224+
cx.warn_unused_duplicate(earlier, span, sym::naked, false);
225225
} else {
226226
this.span = Some(cx.attr_span);
227227
}
@@ -505,22 +505,22 @@ impl AttributeParser for UsedParser {
505505
UsedBy::Compiler => &mut group.first_compiler,
506506
UsedBy::Linker => {
507507
if let Some(prev) = group.first_default {
508-
cx.warn_unused_duplicate(prev, attr_span);
508+
cx.warn_unused_duplicate(prev, attr_span, sym::used, false);
509509
return;
510510
}
511511
&mut group.first_linker
512512
}
513513
UsedBy::Default => {
514514
if let Some(prev) = group.first_linker {
515-
cx.warn_unused_duplicate(prev, attr_span);
515+
cx.warn_unused_duplicate(prev, attr_span, sym::used, false);
516516
return;
517517
}
518518
&mut group.first_default
519519
}
520520
};
521521

522522
if let Some(prev) = *target {
523-
cx.warn_unused_duplicate(prev, attr_span);
523+
cx.warn_unused_duplicate(prev, attr_span, sym::used, false);
524524
} else {
525525
*target = Some(attr_span);
526526
}

‎compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_attr_ir::AttributeKind;
22
use rustc_attr_ir::target::Target;
33
use rustc_feature::AttributeStability;
44
use rustc_lint_defs::builtin::MALFORMED_DIAGNOSTIC_ATTRIBUTES;
5-
use rustc_span::{Span, sym};
5+
use rustc_span::{Span, Symbol, sym};
66

77
use crate::attributes::diagnostic::gate_diagnostic_attr;
88
use crate::attributes::{AcceptMapping, AttributeParser};
@@ -52,7 +52,8 @@ impl OpaqueParser {
5252
fn parse<'sess>(&mut self, cx: &mut AcceptContext<'_, 'sess>, args: &ArgParser) {
5353
let attr_span = cx.attr_span;
5454
if let Some(earlier_span) = self.attr_span {
55-
cx.warn_unused_duplicate(earlier_span, attr_span);
55+
let attr_path_interned = Symbol::intern(&cx.attr_path.to_string());
56+
cx.warn_unused_duplicate(earlier_span, attr_span, attr_path_interned, false);
5657
}
5758
self.attr_span = Some(attr_span);
5859

‎compiler/rustc_attr_parsing/src/attributes/doc.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_span::{Span, Symbol, edition, kw, sym};
1212

1313
use super::prelude::AllowedTargets;
1414
use super::{AcceptMapping, AttributeParser, template};
15+
use crate::DuplicateAttribute;
1516
use crate::attributes::doc_comment::DOC_TARGETS;
1617
use crate::context::{AcceptContext, FinalizeContext};
1718
use crate::diagnostics::{
@@ -24,7 +25,7 @@ use crate::diagnostics::{
2425
DocKeywordNotKeyword, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny,
2526
DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight,
2627
DuplicateNotableTraitColor, ExpectedNameValue, ExpectedNoArgs, IllFormedAttributeInput,
27-
InvalidNotableTraitAttr, InvalidNotableTraitColor, MalformedDoc, UnusedDuplicate,
28+
InvalidNotableTraitAttr, InvalidNotableTraitColor, MalformedDoc,
2829
};
2930
use crate::parser::{
3031
ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser,
@@ -279,7 +280,12 @@ impl DocParser {
279280
let unused_span = path.span();
280281
cx.emit_lint(
281282
INVALID_DOC_ATTRIBUTES,
282-
UnusedDuplicate { this: unused_span, other: used_span, warning: true },
283+
DuplicateAttribute {
284+
this: unused_span,
285+
other: used_span,
286+
name: sym::no_crate_inject,
287+
warning: true,
288+
},
283289
unused_span,
284290
);
285291
return;

‎compiler/rustc_attr_parsing/src/attributes/inline.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_feature::AttributeStability;
33
use rustc_lint_defs::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNUSED_ATTRIBUTES};
44

55
use super::prelude::*;
6-
use crate::diagnostics::{InlineForceInlineConflict, InlineIgnoredForExported, UnusedMultiple};
6+
use crate::diagnostics::{DuplicateAttribute, InlineForceInlineConflict, InlineIgnoredForExported};
77

88
#[derive(Default)]
99
pub(crate) struct InlineParser(Option<(InlineAttr, Span)>);
@@ -70,7 +70,7 @@ impl AttributeParser for InlineParser {
7070
cx.emit_err(InlineForceInlineConflict { inline_span, force_inline_span });
7171
}
7272
Some((_, first_inline_span)) => {
73-
cx.warn_unused_duplicate_future_error(first_inline_span, inline_span);
73+
cx.warn_unused_duplicate(first_inline_span, inline_span, sym::inline, true);
7474
}
7575
}
7676
},
@@ -108,10 +108,11 @@ impl AttributeParser for InlineParser {
108108
match this.0 {
109109
None => this.0 = Some((attr, force_inline_span)),
110110
Some((InlineAttr::Force { .. }, first_force_inline_span)) => {
111-
cx.emit_err(UnusedMultiple {
111+
cx.emit_err(DuplicateAttribute {
112112
this: force_inline_span,
113113
other: first_force_inline_span,
114114
name: sym::rustc_force_inline,
115+
warning: false,
115116
});
116117
}
117118
Some((_, inline_span)) => {

‎compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ impl AttributeParser for MacroUseParser {
5858
"State is UseAll is some so this is not the first attribute",
5959
);
6060
// Since there is a `#[macro_use]` import already, give a warning
61-
cx.warn_unused_duplicate(first_span, span);
61+
cx.warn_unused_duplicate(first_span, span, sym::macro_use, false);
6262
}
6363
MacroUseArgs::UseSpecific(_) => {
6464
group.state = MacroUseArgs::UseAll;
6565
group.first_span = Some(span);
6666
// If there is a `#[macro_use]` attribute, warn on all `#[macro_use(...)]` attributes since everything is already imported
6767
for specific_use in group.uses_attr_spans.drain(..) {
68-
cx.warn_unused_duplicate(span, specific_use);
68+
cx.warn_unused_duplicate(span, specific_use, sym::macro_use, false);
6969
}
7070
}
7171
}
@@ -81,7 +81,7 @@ impl AttributeParser for MacroUseParser {
8181
let first_span = group.first_span.expect(
8282
"State is UseAll is some so this is not the first attribute",
8383
);
84-
cx.warn_unused_duplicate(first_span, span);
84+
cx.warn_unused_duplicate(first_span, span, sym::macro_use, false);
8585
}
8686
MacroUseArgs::UseSpecific(arguments) => {
8787
// Store here so if we encounter a `UseAll` later we can still lint this attribute

‎compiler/rustc_attr_parsing/src/attributes/mod.rs‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::{Span, Symbol};
2727
use thin_vec::ThinVec;
2828

2929
use crate::context::{AcceptContext, FinalizeCheckContext, FinalizeCheckFn, FinalizeContext};
30-
use crate::diagnostics::UnusedMultiple;
30+
use crate::diagnostics::DuplicateAttribute;
3131
use crate::parser::ArgParser;
3232
use crate::target_checking::AllowedTargets;
3333
use crate::{AttributeTemplate, template};
@@ -234,19 +234,15 @@ impl OnDuplicate {
234234
used: Span,
235235
unused: Span,
236236
) {
237+
let name =
238+
Symbol::intern(&P::PATH.iter().map(|i| i.to_string()).collect::<Vec<_>>().join("::"));
237239
match self {
238-
OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused),
239-
OnDuplicate::WarnButFutureError => cx.warn_unused_duplicate_future_error(used, unused),
240+
OnDuplicate::Ignore => {}
241+
OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused, name, false),
242+
OnDuplicate::WarnButFutureError => cx.warn_unused_duplicate(used, unused, name, true),
240243
OnDuplicate::Error => {
241-
cx.emit_err(UnusedMultiple {
242-
this: unused,
243-
other: used,
244-
name: Symbol::intern(
245-
&P::PATH.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(".."),
246-
),
247-
});
244+
cx.emit_err(DuplicateAttribute { this: unused, other: used, name, warning: false });
248245
}
249-
OnDuplicate::Ignore => {}
250246
}
251247
}
252248
}

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ use crate::attributes::unroll::*;
7070
use crate::attributes::{AttributeParser as _, AttributeSafety, Combine, Single, WithoutArgs};
7171
use crate::diagnostics::{
7272
AttributeParseError, AttributeParseErrorReason, AttributeParseErrorSuggestions,
73-
ParsedDescription, UnusedDuplicate,
73+
ParsedDescription,
7474
};
7575
use crate::parser::{
7676
ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, NameValueParser,
7777
RefPathParser,
7878
};
7979
use crate::target_checking::AllowedTargets;
80-
use crate::{AttributeParser, AttributeTemplate, EmitAttribute};
80+
use crate::{AttributeParser, AttributeTemplate, DuplicateAttribute, EmitAttribute};
8181

8282
type GroupType = LazyLock<GroupTypeInner>;
8383

@@ -475,22 +475,16 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> {
475475
(self.emit_lint)(LintId::of(lint), span.into(), kind);
476476
}
477477

478-
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
479-
self.emit_lint(
480-
UNUSED_ATTRIBUTES,
481-
UnusedDuplicate { this: unused_span, other: used_span, warning: false },
482-
unused_span,
483-
)
484-
}
485-
486-
pub(crate) fn warn_unused_duplicate_future_error(
478+
pub(crate) fn warn_unused_duplicate(
487479
&mut self,
488480
used_span: Span,
489481
unused_span: Span,
482+
name: Symbol,
483+
future_error: bool,
490484
) {
491485
self.emit_lint(
492486
UNUSED_ATTRIBUTES,
493-
UnusedDuplicate { this: unused_span, other: used_span, warning: true },
487+
DuplicateAttribute { this: unused_span, other: used_span, name, warning: future_error },
494488
unused_span,
495489
)
496490
}

‎compiler/rustc_attr_parsing/src/diagnostics.rs‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,18 @@ pub(crate) struct UnknownVersionLiteral {
13501350
}
13511351

13521352
#[derive(Diagnostic)]
1353-
#[diag("multiple `{$name}` attributes")]
1354-
pub struct UnusedMultiple {
1353+
#[diag("duplicate `{$name}` attributes")]
1354+
pub struct DuplicateAttribute {
13551355
#[primary_span]
13561356
#[suggestion("remove this attribute", code = "", applicability = "unspecified")]
13571357
pub this: Span,
13581358
#[note("attribute also specified here")]
13591359
pub other: Span,
13601360
pub name: Symbol,
1361+
#[warning(
1362+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
1363+
)]
1364+
pub warning: bool,
13611365
}
13621366

13631367
#[derive(Diagnostic)]
@@ -2191,19 +2195,6 @@ pub(crate) struct AdditionalCommaSuggestion {
21912195
pub span: Span,
21922196
}
21932197

2194-
#[derive(Diagnostic)]
2195-
#[diag("unused attribute")]
2196-
pub(crate) struct UnusedDuplicate {
2197-
#[suggestion("remove this attribute", code = "", applicability = "unspecified")]
2198-
pub this: Span,
2199-
#[note("attribute also specified here")]
2200-
pub other: Span,
2201-
#[warning(
2202-
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
2203-
)]
2204-
pub warning: bool,
2205-
}
2206-
22072198
#[derive(Diagnostic)]
22082199
#[diag("`#[macro_export]` is not allowed on declarative macro definitions")]
22092200
#[note("declarative macros follow the same exporting rules as regular items")]

‎compiler/rustc_attr_parsing/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub use attributes::cfg_select::*;
119119
pub use attributes::crate_level::PREDEFINED_TOOLS;
120120
pub use attributes::util::{is_builtin_attr, parse_version};
121121
pub use context::ShouldEmit;
122-
pub use diagnostics::{ParsedDescription, UnusedMultiple};
122+
pub use diagnostics::{DuplicateAttribute, ParsedDescription};
123123
pub use interface::{AttributeParser, EmitAttribute};
124124
pub use rustc_parse::parser::Recovery;
125125
pub use template::AttributeTemplate;

‎compiler/rustc_attr_parsing/src/parser.rs‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
1515

1616
use rustc_ast::token::{self, Delimiter, MetaVarKind};
1717
use rustc_ast::tokenstream::TokenStream;
18-
use rustc_ast::{
19-
AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp,
20-
};
18+
use rustc_ast::{AttrArgs, Expr, ExprKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp};
2119
use rustc_ast_pretty::pprust;
2220
use rustc_attr_ir::AttrPath;
2321
use rustc_errors::{Applicability, Diag, PResult};
@@ -424,23 +422,7 @@ fn expr_to_lit<'sess>(
424422
Err(psess.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span }))
425423
}
426424
}
427-
Err(err) => {
428-
let err = create_lit_error(psess, err, token_lit, expr.span);
429-
if matches!(
430-
should_emit,
431-
ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden }
432-
) {
433-
Err(err)
434-
} else {
435-
let lit = MetaItemLit {
436-
symbol: token_lit.symbol,
437-
suffix: token_lit.suffix,
438-
kind: LitKind::Err(err.emit_err()),
439-
span: expr.span,
440-
};
441-
Ok(Some(lit))
442-
}
443-
}
425+
Err(err) => Err(create_lit_error(psess, err, token_lit, expr.span)),
444426
}
445427
} else {
446428
if matches!(should_emit, ShouldEmit::Nothing) || matches!(expr.kind, ExprKind::Err(_)) {

0 commit comments

Comments
 (0)