diff options
| author | dianne <diannes.gm@gmail.com> | 2024-12-17 09:49:20 -0800 |
|---|---|---|
| committer | dianne <diannes.gm@gmail.com> | 2024-12-17 13:46:00 -0800 |
| commit | 70b852737795fb6757893495a4f886756b8a7b4e (patch) | |
| tree | 3651888230f86527db812b2e9de28f58bbb44b27 | |
| parent | a676872e0ff6d00d72f322807e6214daec9f5112 (diff) | |
| download | rust-70b852737795fb6757893495a4f886756b8a7b4e.tar.gz rust-70b852737795fb6757893495a4f886756b8a7b4e.zip | |
Correctly check the edition of subpatterns in the pattern migration 2024 lint
| -rw-r--r-- | compiler/rustc_hir_typeck/src/pat.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index f20db5c6501..e27a555eab5 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -2641,12 +2641,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { detailed_label: &str, ) { // Try to trim the span we're labeling to just the `&` or binding mode that's an issue. - // If the subpattern span is a macro call site, no trimming will be done. + // If the subpattern's span is is from an expansion, the emitted label will not be trimmed. let source_map = self.tcx.sess.source_map(); let cutoff_span = source_map .span_extend_prev_while(cutoff_span, char::is_whitespace) .unwrap_or(cutoff_span); - let trimmed_span = subpat_span.until(cutoff_span); + // Ensure we use the syntax context and thus edition of `subpat_span`; this will be a hard + // error if the subpattern is of edition >= 2024. + let trimmed_span = subpat_span.until(cutoff_span).with_ctxt(subpat_span.ctxt()); // Only provide a detailed label if the problematic subpattern isn't from an expansion. // In the case that it's from a macro, we'll add a more detailed note in the emitter. |
