Skip to content

Commit 724b885

Browse files
committed
pattern migration: move labels out of the suggestion struct
1 parent 613bdd4 commit 724b885

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

compiler/rustc_mir_build/src/errors.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1097,20 +1097,18 @@ pub(crate) enum MiscPatternSuggestion {
10971097

10981098
#[derive(LintDiagnostic)]
10991099
#[diag(mir_build_rust_2024_incompatible_pat)]
1100-
pub(crate) struct Rust2024IncompatiblePat<'a> {
1100+
pub(crate) struct Rust2024IncompatiblePat {
11011101
#[subdiagnostic]
1102-
pub(crate) sugg: Rust2024IncompatiblePatSugg<'a>,
1102+
pub(crate) sugg: Rust2024IncompatiblePatSugg,
11031103
}
11041104

1105-
pub(crate) struct Rust2024IncompatiblePatSugg<'a> {
1105+
pub(crate) struct Rust2024IncompatiblePatSugg {
11061106
pub(crate) suggestion: Vec<(Span, String)>,
11071107
pub(crate) ref_pattern_count: usize,
11081108
pub(crate) binding_mode_count: usize,
1109-
/// Labeled spans for subpatterns invalid in Rust 2024.
1110-
pub(crate) labels: &'a [(Span, String)],
11111109
}
11121110

1113-
impl<'a> Subdiagnostic for Rust2024IncompatiblePatSugg<'a> {
1111+
impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11141112
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
11151113
self,
11161114
diag: &mut Diag<'_, G>,

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct PatCtxt<'a, 'tcx> {
3535
typeck_results: &'a ty::TypeckResults<'tcx>,
3636

3737
/// Used by the Rust 2024 migration lint.
38-
rust_2024_migration_suggestion: Option<Rust2024IncompatiblePatSugg<'a>>,
38+
rust_2024_migration_suggestion: Option<Rust2024IncompatiblePatSugg>,
3939
}
4040

4141
pub(super) fn pat_from_hir<'a, 'tcx>(
@@ -44,25 +44,23 @@ pub(super) fn pat_from_hir<'a, 'tcx>(
4444
typeck_results: &'a ty::TypeckResults<'tcx>,
4545
pat: &'tcx hir::Pat<'tcx>,
4646
) -> Box<Pat<'tcx>> {
47+
let migration_labels = typeck_results.rust_2024_migration_desugared_pats().get(pat.hir_id);
4748
let mut pcx = PatCtxt {
4849
tcx,
4950
typing_env,
5051
typeck_results,
51-
rust_2024_migration_suggestion: typeck_results
52-
.rust_2024_migration_desugared_pats()
53-
.get(pat.hir_id)
54-
.map(|labels| Rust2024IncompatiblePatSugg {
55-
suggestion: Vec::new(),
56-
ref_pattern_count: 0,
57-
binding_mode_count: 0,
58-
labels: labels.as_slice(),
59-
}),
52+
rust_2024_migration_suggestion: migration_labels.and(Some(Rust2024IncompatiblePatSugg {
53+
suggestion: Vec::new(),
54+
ref_pattern_count: 0,
55+
binding_mode_count: 0,
56+
})),
6057
};
6158
let result = pcx.lower_pattern(pat);
6259
debug!("pat_from_hir({:?}) = {:?}", pat, result);
63-
if let Some(sugg) = pcx.rust_2024_migration_suggestion {
64-
let mut spans = MultiSpan::from_spans(sugg.labels.iter().map(|(span, _)| *span).collect());
65-
for (span, label) in sugg.labels {
60+
if let Some(labels) = migration_labels {
61+
let sugg = pcx.rust_2024_migration_suggestion.expect("suggestion should be present");
62+
let mut spans = MultiSpan::from_spans(labels.iter().map(|(span, _)| *span).collect());
63+
for (span, label) in labels {
6664
spans.push_span_label(*span, label.clone());
6765
}
6866
// If a relevant span is from at least edition 2024, this is a hard error.

0 commit comments

Comments
 (0)