-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
use stable sort to sort multipart diagnostics #128852
use stable sort to sort multipart diagnostics #128852
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this leave: [(s, "a"), (s, "b"), (s, "a"), (s, "b")]
not deduplicated?
I would rather you do something like:
If possible...? Using |
That seems to almost work, but I think it gets tripped up when macros are involved? when using suggestion.sort_by_key(|(span, _)| *span);
let mut seen = crate::FxHashSet::default();
suggestion.retain(|(span, msg)| seen.insert((span.data(), msg.clone()))); I get this failure
when comparing to the previous solution (top/left) this new solution (bottom/right) does not deduplicate correctly:
so this may need something slightly different from btw the sorting is needed for just 2 test cases:
|
this works suggestion.sort_by_key(|(span, _)| *span);
let mut seen = crate::FxHashSet::default();
suggestion.retain(|(span, msg)| {
seen.insert((
{
let mut data = span.data();
data.ctxt = rustc_span::hygiene::SyntaxContext::root();
data
},
msg.clone(),
))
}); is that too hacky? |
Sorry, I guess you really should be doing something like:
To ignore the syntax context. |
Also, you don't need to be sorting or deduplicating if you use this approach. That's the whole point of the retain call :) |
d1dc694
to
38874a6
Compare
(parent.span, "value".to_string()), | ||
(span.shrink_to_lo(), format!("let mut value = {value};{indent}")), | ||
(parent.span, "value".to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compiler-errors the sorting also matters for at which line the error is reported. In this one case, that actually caused issues. I've swapped the spans here now to preserve the current error message.
@bors r+ rollup |
…able-sort, r=compiler-errors use stable sort to sort multipart diagnostics I think a stable sort should be used to sort the different parts of a multipart selection. The current unstable sort uses the text of the suggestion as a tie-breaker. That just doesn't seem right, and the order of the input is a better choice I think, because it gives the diagnostic author more control. This came up when I was building a suggestion where ```rust fn foo() {} ``` must be turned into an unsafe function, and an attribute must be added ```rust #[target_feature(enable = "...")] unsafe fn foo() {} ``` In this example, the two suggestions occur at the same position, but the order is extremely important: unsafe must come after the attribute. But the situation changes if there is a pub/pub(crate), and if the unsafe is already present. It just out that because of the suggestion text, there is no way for me to order the suggestions correctly. This change probably should be tested, but are there tests of the diagnostics code itself in the tests? r? `@estebank`
…able-sort, r=compiler-errors use stable sort to sort multipart diagnostics I think a stable sort should be used to sort the different parts of a multipart selection. The current unstable sort uses the text of the suggestion as a tie-breaker. That just doesn't seem right, and the order of the input is a better choice I think, because it gives the diagnostic author more control. This came up when I was building a suggestion where ```rust fn foo() {} ``` must be turned into an unsafe function, and an attribute must be added ```rust #[target_feature(enable = "...")] unsafe fn foo() {} ``` In this example, the two suggestions occur at the same position, but the order is extremely important: unsafe must come after the attribute. But the situation changes if there is a pub/pub(crate), and if the unsafe is already present. It just out that because of the suggestion text, there is no way for me to order the suggestions correctly. This change probably should be tested, but are there tests of the diagnostics code itself in the tests? r? ``@estebank``
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#128815 (Add `Steal::is_stolen()`) - rust-lang#128817 (VxWorks code refactored ) - rust-lang#128822 (add `builder-config` into tarball sources) - rust-lang#128838 (rustdoc: do not run doctests with invalid langstrings) - rust-lang#128852 (use stable sort to sort multipart diagnostics) - rust-lang#128859 (Fix the name of signal 19 in library/std/src/sys/pal/unix/process/process_unix/tests.rs for mips/sparc linux) - rust-lang#128864 (Use `SourceMap::end_point` instead of `- BytePos(1)` in arg removal suggestion) - rust-lang#128865 (Ensure let stmt compound assignment removal suggestion respect codepoint boundaries) - rust-lang#128874 (Disable verbose bootstrap command failure logging by default) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128852 - folkertdev:multipart-suggestion-stable-sort, r=compiler-errors use stable sort to sort multipart diagnostics I think a stable sort should be used to sort the different parts of a multipart selection. The current unstable sort uses the text of the suggestion as a tie-breaker. That just doesn't seem right, and the order of the input is a better choice I think, because it gives the diagnostic author more control. This came up when I was building a suggestion where ```rust fn foo() {} ``` must be turned into an unsafe function, and an attribute must be added ```rust #[target_feature(enable = "...")] unsafe fn foo() {} ``` In this example, the two suggestions occur at the same position, but the order is extremely important: unsafe must come after the attribute. But the situation changes if there is a pub/pub(crate), and if the unsafe is already present. It just out that because of the suggestion text, there is no way for me to order the suggestions correctly. This change probably should be tested, but are there tests of the diagnostics code itself in the tests? r? ```@estebank```
…llaumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#128815 (Add `Steal::is_stolen()`) - rust-lang#128822 (add `builder-config` into tarball sources) - rust-lang#128838 (rustdoc: do not run doctests with invalid langstrings) - rust-lang#128852 (use stable sort to sort multipart diagnostics) - rust-lang#128859 (Fix the name of signal 19 in library/std/src/sys/pal/unix/process/process_unix/tests.rs for mips/sparc linux) - rust-lang#128864 (Use `SourceMap::end_point` instead of `- BytePos(1)` in arg removal suggestion) - rust-lang#128865 (Ensure let stmt compound assignment removal suggestion respect codepoint boundaries) - rust-lang#128874 (Disable verbose bootstrap command failure logging by default) r? `@ghost` `@rustbot` modify labels: rollup
I think a stable sort should be used to sort the different parts of a multipart selection. The current unstable sort uses the text of the suggestion as a tie-breaker. That just doesn't seem right, and the order of the input is a better choice I think, because it gives the diagnostic author more control.
This came up when I was building a suggestion where
must be turned into an unsafe function, and an attribute must be added
In this example, the two suggestions occur at the same position, but the order is extremely important: unsafe must come after the attribute. But the situation changes if there is a pub/pub(crate), and if the unsafe is already present. It just out that because of the suggestion text, there is no way for me to order the suggestions correctly.
This change probably should be tested, but are there tests of the diagnostics code itself in the tests?
r? @estebank