Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce kw::Empty usage, part 4 #138347 #139039

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

Another step towards #137978.

r? @petrochenkov

It makes it clearer that the symbol is unused and doesn't matter.
To use one `kw::Empty` instead of two. It's a little more direct this
way, and avoids `kw::Empty` being used for both "no string" and "empty
string".
This is part of the implementation of `#[doc(keyword = "match")]`
attributes used by `std` to provide documentation for keywords.

`is_doc_keyword` currently does a crude keyword range test that's
intended to catch all keywords but misses `kw::Yeet`. This commit
changes it to use `Symbol` methods, including the new `is_weak` method
(required for `union`). `Symbol` methods are much less prone to falling
out of date if new keywords are added.
By changing two of the fields to use `Option<Ident>` instead of `Ident`.
As a result, `None` now means "no identifier", which is much clearer
than using an empty identifier.
Using in-band values for exceptional cases is error prone. This commit
changes it to an `Option`.
@rustbot
Copy link
Collaborator

rustbot commented Mar 28, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 28, 2025
@nnethercote nnethercote changed the title Reduce kw::Empty usage, part 2 #138347 Reduce kw::Empty usage, part 4 #138347 Mar 28, 2025
@@ -79,10 +79,11 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
if apa.counter <= 1 || !apa.has_expensive_expr_after_last_attr {
continue;
}
let first_bind_ident = apa.first_bind_ident.unwrap();
Copy link
Member

@blyxyas blyxyas Mar 28, 2025

Choose a reason for hiding this comment

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

.unwrap() use is a little bit dangerous

Suggested change
let first_bind_ident = apa.first_bind_ident.unwrap();
debug_assert!(apa.first_bind_ident.is_some());
let Some(first_bind_ident) = apa.first_bind_ident else { return; };

Copy link
Contributor

Choose a reason for hiding this comment

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

debug_asserts are only for performance-sensitive checks, if something unexpected happens here it's better to have a panic always (unwrap) than only under some build configurations (debug assert).

}

fn is_decode_placeholder(&self) -> bool {
self.dollar_crate_name == kw::Empty
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a placeholder for dollar_crate_name, it means that the whole SyntaxContextData is a placeholder and will never be used (there's a bunch of debug_asserts in this file checking for it).

I think it's ok to use sym::dummy here, but there's an ongoing work (#129827) to eliminate these placeholders entirely, so it's better not to change this otherwise.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 28, 2025
@bors
Copy link
Contributor

bors commented Mar 29, 2025

☔ The latest upstream changes (presumably #129827) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants