Skip to content

Commit 70b8527

Browse files
committed
Correctly check the edition of subpatterns in the pattern migration 2024 lint
1 parent a676872 commit 70b8527

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

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

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

0 commit comments

Comments
 (0)