Skip to content

Commit b1a6410

Browse files
Fix not to use vec
1 parent 3f0bf55 commit b1a6410

File tree

1 file changed

+27
-14
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+27
-14
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ struct TopInfo<'tcx> {
7979
span: Option<Span>,
8080
}
8181

82-
#[derive(Clone)]
82+
#[derive(Copy, Clone)]
8383
struct PatInfo<'tcx, 'a> {
8484
binding_mode: BindingMode,
8585
top_info: TopInfo<'tcx>,
8686
decl_origin: Option<DeclOrigin<'a>>,
87-
history: Vec<PatKind<'tcx>>,
87+
88+
parent_kind: Option<PatKind<'tcx>>,
89+
current_kind: Option<PatKind<'tcx>>,
8890
}
8991

9092
impl<'tcx> FnCtxt<'_, 'tcx> {
@@ -154,8 +156,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154156
decl_origin: Option<DeclOrigin<'tcx>>,
155157
) {
156158
let info = TopInfo { expected, origin_expr, span };
157-
let pat_info =
158-
PatInfo { binding_mode: INITIAL_BM, top_info: info, decl_origin, history: Vec::new() };
159+
let pat_info = PatInfo {
160+
binding_mode: INITIAL_BM,
161+
top_info: info,
162+
decl_origin,
163+
parent_kind: None,
164+
current_kind: None,
165+
};
159166
self.check_pat(pat, expected, pat_info);
160167
}
161168

@@ -166,7 +173,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166173
/// Conversely, inside this module, `check_pat_top` should never be used.
167174
#[instrument(level = "debug", skip(self, pat_info))]
168175
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx, '_>) {
169-
let PatInfo { binding_mode: def_bm, top_info: ti, mut history, .. } = pat_info;
176+
let PatInfo { binding_mode: def_bm, top_info: ti, current_kind, parent_kind, .. } =
177+
pat_info;
178+
179+
println!("{:#?} -> {:#?}", parent_kind, current_kind);
180+
170181
let path_res = match &pat.kind {
171182
PatKind::Path(qpath) => Some(
172183
self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span, None),
@@ -175,12 +186,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
175186
};
176187
let adjust_mode = self.calc_adjust_mode(pat, path_res.map(|(res, ..)| res));
177188
let (expected, def_bm) = self.calc_default_binding_mode(pat, expected, def_bm, adjust_mode);
178-
history.push(pat.kind);
179189
let pat_info = PatInfo {
180190
binding_mode: def_bm,
181191
top_info: ti,
182192
decl_origin: pat_info.decl_origin,
183-
history,
193+
parent_kind: current_kind,
194+
current_kind: Some(pat.kind),
184195
};
185196

186197
let ty = match pat.kind {
@@ -1054,7 +1065,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10541065
expected: Ty<'tcx>,
10551066
pat_info: PatInfo<'tcx, '_>,
10561067
) -> Ty<'tcx> {
1057-
let PatInfo { binding_mode: def_bm, top_info: ti, decl_origin, history } = pat_info;
1068+
let PatInfo { binding_mode: def_bm, top_info: ti, decl_origin, parent_kind, current_kind } =
1069+
pat_info;
10581070
let tcx = self.tcx;
10591071
let on_error = |e| {
10601072
for pat in subpats {
@@ -1065,7 +1077,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10651077
binding_mode: def_bm,
10661078
top_info: ti,
10671079
decl_origin,
1068-
history: history.clone(),
1080+
parent_kind,
1081+
current_kind,
10691082
},
10701083
);
10711084
}
@@ -1140,7 +1153,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11401153
binding_mode: def_bm,
11411154
top_info: ti,
11421155
decl_origin,
1143-
history: history.clone(),
1156+
parent_kind,
1157+
current_kind,
11441158
},
11451159
);
11461160

@@ -2296,7 +2310,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22962310
expected_ty: Ty<'tcx>,
22972311
pat_info: PatInfo<'tcx, '_>,
22982312
) -> ErrorGuaranteed {
2299-
let PatInfo { top_info: ti, history, .. } = pat_info;
2313+
let PatInfo { top_info: ti, parent_kind, .. } = pat_info;
23002314

23012315
let mut err = struct_span_code_err!(
23022316
self.dcx(),
@@ -2334,9 +2348,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23342348
_ => (),
23352349
}
23362350

2337-
let enclosure_is_struct = history
2338-
.get(history.len() - 2)
2339-
.map_or(false, |enclosure| matches!(enclosure, PatKind::Struct(..)));
2351+
let enclosure_is_struct =
2352+
parent_kind.map_or(false, |enclosure| matches!(enclosure, PatKind::Struct(..)));
23402353

23412354
if is_slice_or_array_or_vector && !enclosure_is_struct {
23422355
err.span_suggestion(

0 commit comments

Comments
 (0)