Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_attr_parsing/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ attr_parsing_deprecated_item_suggestion =

attr_parsing_empty_attribute =
unused attribute
.suggestion = remove this attribute
.suggestion = {$valid_without_list ->
[true] remove these parentheses
*[other] remove this attribute
}
.note = {$valid_without_list ->
[true] using `{$attr_path}` with an empty list is equivalent to not using a list at all
*[other] using `{$attr_path}` with an empty list has no effect
}


attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
.help = `#[{$name}]` can {$only}be applied to {$applied}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,12 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
}

pub(crate) fn warn_empty_attribute(&mut self, span: Span) {
self.emit_lint(AttributeLintKind::EmptyAttribute { first_span: span }, span);
let attr_path = self.attr_path.clone();
let valid_without_list = self.template.word;
self.emit_lint(
AttributeLintKind::EmptyAttribute { first_span: span, attr_path, valid_without_list },
span,
);
}
}

Expand Down
18 changes: 12 additions & 6 deletions compiler/rustc_attr_parsing/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<L::Id>, lint_emi
),
},
),
AttributeLintKind::EmptyAttribute { first_span } => lint_emitter.emit_node_span_lint(
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
*id,
*first_span,
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
),
AttributeLintKind::EmptyAttribute { first_span, attr_path, valid_without_list } => {
lint_emitter.emit_node_span_lint(
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
*id,
*first_span,
session_diagnostics::EmptyAttributeList {
attr_span: *first_span,
attr_path: attr_path.clone(),
valid_without_list: *valid_without_list,
},
)
}
AttributeLintKind::InvalidTarget { name, target, applied, only } => lint_emitter
.emit_node_span_lint(
// This check is here because `deprecated` had its own lint group and removing this would be a breaking change
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,12 @@ pub(crate) struct EmptyConfusables {

#[derive(LintDiagnostic)]
#[diag(attr_parsing_empty_attribute)]
#[note]
pub(crate) struct EmptyAttributeList {
#[suggestion(code = "", applicability = "machine-applicable")]
pub attr_span: Span,
pub attr_path: AttrPath,
pub valid_without_list: bool,
}

#[derive(LintDiagnostic)]
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_hir/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub struct AttributeLint<Id> {

#[derive(Clone, Debug, HashStable_Generic)]
pub enum AttributeLintKind {
/// Copy of `IllFormedAttributeInput`
/// specifically for the `invalid_macro_export_arguments` lint until that is removed,
/// see <https://github.com/rust-lang/rust/pull/143857#issuecomment-3079175663>
InvalidMacroExportArguments {
suggestions: Vec<String>,
},
UnusedDuplicate {
this: Span,
other: Span,
Expand All @@ -41,13 +47,8 @@ pub enum AttributeLintKind {
},
EmptyAttribute {
first_span: Span,
},

/// Copy of `IllFormedAttributeInput`
/// specifically for the `invalid_macro_export_arguments` lint until that is removed,
/// see <https://github.com/rust-lang/rust/pull/143857#issuecomment-3079175663>
InvalidMacroExportArguments {
suggestions: Vec<String>,
attr_path: AttrPath,
valid_without_list: bool,
},
InvalidTarget {
name: AttrPath,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/attributes/empty-repr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error: unused attribute
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
= note: using `repr` with an empty list has no effect
note: the lint level is defined here
--> $DIR/empty-repr.rs:4:9
|
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/empty/empty-attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ error: unused attribute
|
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
= note: using `repr` with an empty list has no effect

error: unused attribute
--> $DIR/empty-attributes.rs:12:1
|
LL | #[target_feature()]
| ^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
= note: using `target_feature` with an empty list has no effect

error: aborting due to 8 previous errors

3 changes: 2 additions & 1 deletion tests/ui/macros/macro-use-all-and-none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ warning: unused attribute
--> $DIR/macro-use-all-and-none.rs:7:12
|
LL | #[macro_use()]
| ^^ help: remove this attribute
| ^^ help: remove these parentheses
|
= note: using `macro_use` with an empty list is equivalent to not using a list at all
note: the lint level is defined here
--> $DIR/macro-use-all-and-none.rs:4:9
|
Expand Down
1 change: 1 addition & 0 deletions tests/ui/repr/repr-empty-packed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ error: unused attribute
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
= note: using `repr` with an empty list has no effect
note: the lint level is defined here
--> $DIR/repr-empty-packed.rs:2:9
|
Expand Down
Loading