Skip to content

Conversation

ada4a
Copy link
Contributor

@ada4a ada4a commented Sep 25, 2025

For #15569

changelog: none

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@ada4a ada4a marked this pull request as draft September 25, 2025 20:00
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 25, 2025
@ada4a ada4a marked this pull request as ready for review September 25, 2025 20:11
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 25, 2025
@ada4a ada4a force-pushed the utils-attrs branch 2 times, most recently from 8751cc0 to 92c8d70 Compare September 25, 2025 20:13
/// Attribute is deprecated and was replaced by the named attribute
Replaced(&'static str),
/// Attribute is deprecated and was possibly replaced by the named attribute
Deprecated(Option<&'static str>),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be Renamed without an option. If we ever actually deprecate an attribute it will have an associated message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least currently, the &str refers to the new name for the attribute, not the associated message. Or did I misunderstand you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current variant should be Renamed (or its old name) and Deprecated shouldn't exist. Really this whole thing should be removed as one of my later comments mentioned. Once the array is inlined as a match this type has no reason to exist.

Comment on lines 76 to 78
let Some((_, deprecation_status)) = BUILTIN_ATTRIBUTES
.iter()
.find_map(|(builtin_name, deprecation_status)| {
if attr_segments[1].name == *builtin_name {
Some(deprecation_status)
} else {
None
}
})
.map_or_else(
|| {
sess.dcx().span_err(attr_segments[1].span, "usage of unknown attribute");
false
},
|deprecation_status| {
let mut diag = sess
.dcx()
.struct_span_err(attr_segments[1].span, "usage of deprecated attribute");
match *deprecation_status {
DeprecationStatus::Deprecated => {
diag.emit();
false
},
DeprecationStatus::Replaced(new_name) => {
diag.span_suggestion(
attr_segments[1].span,
"consider using",
new_name,
Applicability::MachineApplicable,
);
diag.emit();
false
},
DeprecationStatus::None => {
diag.cancel();
attr_segments[1].name == name
},
}
},
)
.find(|(builtin_name, _)| segment2.name == *builtin_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILTIN_ATTRIBUTES should be inlined as a match. This made sense when the names were strings, but since they aren't any more a match over the symbol will be faster.

@ada4a
Copy link
Contributor Author

ada4a commented Sep 28, 2025

@rustbot ready

Their meanings, and the way they're handled in `get_attr`, are pretty
similar
- Move it and its helper function `parse_attrs` together to the end
  of the file, because it's surprising to see front-and-center a struct
  that's only really used in one place (`cognitive_complexity`).
- Avoid panic path in `LimitStack::limit`
- Replace `assert` with `debug_assert` to avoid panics in release builds
pub fn get_unique_attr<'a, A: AttributeExt>(sess: &'a Session, attrs: &'a [A], name: Symbol) -> Option<&'a A> {
/// If `attrs` contain exactly one instance of a built-in Clippy attribute called `name`,
/// returns that attribute, and `None` otherwise
pub fn get_unique_builtin_attr<'a, A: AttributeExt>(sess: &'a Session, attrs: &'a [A], name: Symbol) -> Option<&'a A> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, I wonder whether this function should even exist as it is now. It emits a warning on duplicate attributes, but that should already be covered by duplicated_attributes; well, maybe apart for #[cognitive_complexity(N)] -- if the N is different, that lint wouldn't fire, but this check will.

So maybe its uses could be simplified to just get_builtin_attr.next_back()

Copy link
Contributor

@Jarcho Jarcho Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be better, but I think this also warns on the renamed attributes when both names appear. I would be surprised if that ever actually happens in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants