Skip to content

Commit db485a1

Browse files
dianneDiuDiu777
authored andcommitted
Correctly check the edition of subpatterns in the pattern migration 2024 lint
1 parent f14b351 commit db485a1

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+4
-2
lines changed

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,12 +2640,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26402640
detailed_label: &str,
26412641
) {
26422642
// Try to trim the span we're labeling to just the `&` or binding mode that's an issue.
2643-
// If the subpattern span is a macro call site, no trimming will be done.
2643+
// If the subpattern's span is is from an expansion, the emitted label will not be trimmed.
26442644
let source_map = self.tcx.sess.source_map();
26452645
let cutoff_span = source_map
26462646
.span_extend_prev_while(cutoff_span, char::is_whitespace)
26472647
.unwrap_or(cutoff_span);
2648-
let trimmed_span = subpat_span.until(cutoff_span);
2648+
// Ensure we use the syntax context and thus edition of `subpat_span`; this will be a hard
2649+
// error if the subpattern is of edition >= 2024.
2650+
let trimmed_span = subpat_span.until(cutoff_span).with_ctxt(subpat_span.ctxt());
26492651

26502652
// Only provide a detailed label if the problematic subpattern isn't from an expansion.
26512653
// In the case that it's from a macro, we'll add a more detailed note in the emitter.

0 commit comments

Comments
 (0)