-
Couldn't load subscription status.
- Fork 13.9k
Pattern Migration 2024: properly label & patterns whose subpatterns are from macro expansions
#137269
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
Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
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.
LGTM with these two nits
|
@bors r+ |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#135296 (interpret: adjust vtable validity check for higher-ranked types) - rust-lang#137106 (Add customized compare for Link in rustdoc) - rust-lang#137253 (Restrict `bevy_ecs` `ParamSet` hack) - rust-lang#137262 (Make fewer crates depend on `rustc_ast_ir`) - rust-lang#137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages) - rust-lang#137266 (MIR visitor tweaks) - rust-lang#137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions) - rust-lang#137277 (stabilize `inherent_str_constructors`) - rust-lang#137281 (Tweak "expected ident" parse error to avoid talking about doc comments) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#137269 - dianne:fix-ref-pat-label-span, r=davidtwco Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions See the failing test output in the first commit for an example of what this going wrong looks like. The error/lint diagnostic tries to point to just the `&` or `&mut` of reference patterns when labeling the causes, to make the output clearer (rust-lang#134394). The trimming there wasn't quite right though: it used the interior of the reference pattern as a cutoff and extended backwards to find where to trim the pattern's span, but this breaks if the `&` and the interior are from different sources. This PR instead trims by starting at the start of the pattern and ending at the final character of the `&` (or `&mut`, `ref`, `ref mut`, or `mut`, depending on what the error/lint is labeling); that way, there's no opportunity for failure from mixing sources. I'm not 100% happy with this approach, but I'm also not sure what the best practices are as far as hacky `SourceMap` munching goes, so please let me know if something else would be preferred. Since `SourceMap::span_through_char` can't change the syntax context of the span, I've also removed a call to `Span::with_ctxt` (we care about the edition of the span in question since this is a hard error in Rust 2024). If we want to be extra safe in case that changes, I can re-add it or track error hardness separately in the `rust_2024_migration_desugared_pats` table.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#135296 (interpret: adjust vtable validity check for higher-ranked types) - rust-lang#137106 (Add customized compare for Link in rustdoc) - rust-lang#137253 (Restrict `bevy_ecs` `ParamSet` hack) - rust-lang#137262 (Make fewer crates depend on `rustc_ast_ir`) - rust-lang#137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages) - rust-lang#137266 (MIR visitor tweaks) - rust-lang#137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions) - rust-lang#137277 (stabilize `inherent_str_constructors`) - rust-lang#137281 (Tweak "expected ident" parse error to avoid talking about doc comments) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#135296 (interpret: adjust vtable validity check for higher-ranked types) - rust-lang#137106 (Add customized compare for Link in rustdoc) - rust-lang#137253 (Restrict `bevy_ecs` `ParamSet` hack) - rust-lang#137262 (Make fewer crates depend on `rustc_ast_ir`) - rust-lang#137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages) - rust-lang#137266 (MIR visitor tweaks) - rust-lang#137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions) - rust-lang#137277 (stabilize `inherent_str_constructors`) - rust-lang#137281 (Tweak "expected ident" parse error to avoid talking about doc comments) r? `@ghost` `@rustbot` modify labels: rollup
See the failing test output in the first commit for an example of what this going wrong looks like. The error/lint diagnostic tries to point to just the
&or&mutof reference patterns when labeling the causes, to make the output clearer (#134394). The trimming there wasn't quite right though: it used the interior of the reference pattern as a cutoff and extended backwards to find where to trim the pattern's span, but this breaks if the&and the interior are from different sources. This PR instead trims by starting at the start of the pattern and ending at the final character of the&(or&mut,ref,ref mut, ormut, depending on what the error/lint is labeling); that way, there's no opportunity for failure from mixing sources.I'm not 100% happy with this approach, but I'm also not sure what the best practices are as far as hacky
SourceMapmunching goes, so please let me know if something else would be preferred.Since
SourceMap::span_through_charcan't change the syntax context of the span, I've also removed a call toSpan::with_ctxt(we care about the edition of the span in question since this is a hard error in Rust 2024). If we want to be extra safe in case that changes, I can re-add it or track error hardness separately in therust_2024_migration_desugared_patstable.