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

Simplify printf and shell format suggestions #138125

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Mar 6, 2025

Simplify tracking printf and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2025

r? @cjgillot

rustbot has assigned @cjgillot.
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

@rustbot rustbot added 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 6, 2025
Comment on lines 714 to 718
let sub = sub.as_str();
if explained.contains(sub.as_ref()) {
continue;
}
explained.insert(sub);
explained.insert(String::from(sub));
Copy link
Member

Choose a reason for hiding this comment

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

If we're optimizing for readability here, I'd probably write this like:

if !explained.insert(sub.as_str()) {
    continue;
}

Copy link
Member

Choose a reason for hiding this comment

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

And possibly also change the as_str to call it to_string to make it clear that it returns a String.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

This is already on the error path, and we don't typically optimize much but the most egregious performance issues with diagnostics. Specifically, using Cow seems like a microoptimization that isn't really warranted for this code. But 🤷

@thaliaarchi thaliaarchi force-pushed the defer-alloc-printf-suggestion branch from 0fedfb8 to ef6f0d6 Compare March 6, 2025 20:45
@thaliaarchi
Copy link
Contributor Author

It sounds like the readability approach is better, so I'll pivot to that.

@thaliaarchi thaliaarchi force-pushed the defer-alloc-printf-suggestion branch from ef6f0d6 to f8dc132 Compare March 6, 2025 20:50
@thaliaarchi thaliaarchi changed the title Defer allocation for printf suggestions until needed Simplify printf and shell format suggestions Mar 6, 2025
@@ -13,10 +13,10 @@ pub(crate) mod printf {
}

impl<'a> Substitution<'a> {
pub(crate) fn as_str(&self) -> &str {
pub(crate) fn as_string(&self) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

probably call this to_string, or maybe just implement ToString

@thaliaarchi thaliaarchi force-pushed the defer-alloc-printf-suggestion branch from f8dc132 to 2458ccd Compare March 6, 2025 21:55
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 7, 2025

📌 Commit 2458ccd has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 7, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Mar 7, 2025
…gestion, r=compiler-errors

Simplify `printf` and shell format suggestions

Simplify tracking `printf` and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
…kingjubilee

Rollup of 12 pull requests

Successful merges:

 - rust-lang#136667 (Revert vita's c_char back to i8)
 - rust-lang#136780 (std: move stdio to `sys`)
 - rust-lang#137107 (Override default `Write` methods for cursor-like types)
 - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file)
 - rust-lang#137528 (Windows: Fix error in `fs::rename` on Windows 1607)
 - rust-lang#137537 (Prevent `rmake.rs` from using unstable features, and fix 3 run-make tests that currently do)
 - rust-lang#137777 (Specialize `OsString::push` and `OsString as From` for UTF-8)
 - rust-lang#137832 (Fix crash in BufReader::peek())
 - rust-lang#137904 (Improve the generic MIR in the default `PartialOrd::le` and friends)
 - rust-lang#138115 (Suggest typo fix for static lifetime)
 - rust-lang#138125 (Simplify `printf` and shell format suggestions)
 - rust-lang#138129 (Stabilize const_char_classify, const_sockaddr_setters)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 7, 2025
…gestion, r=compiler-errors

Simplify `printf` and shell format suggestions

Simplify tracking `printf` and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136667 (Revert vita's c_char back to i8)
 - rust-lang#137107 (Override default `Write` methods for cursor-like types)
 - rust-lang#137777 (Specialize `OsString::push` and `OsString as From` for UTF-8)
 - rust-lang#137832 (Fix crash in BufReader::peek())
 - rust-lang#137904 (Improve the generic MIR in the default `PartialOrd::le` and friends)
 - rust-lang#138115 (Suggest typo fix for static lifetime)
 - rust-lang#138125 (Simplify `printf` and shell format suggestions)
 - rust-lang#138129 (Stabilize const_char_classify, const_sockaddr_setters)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a928c15 into rust-lang:master Mar 7, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 7, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
Rollup merge of rust-lang#138125 - thaliaarchi:defer-alloc-printf-suggestion, r=compiler-errors

Simplify `printf` and shell format suggestions

Simplify tracking `printf` and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.
@thaliaarchi thaliaarchi deleted the defer-alloc-printf-suggestion branch March 7, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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