Skip to content

Commit 98d80e2

Browse files
committed
Split hir TyKind and ConstArgKind in two and update hir::Visitor
1 parent 0f10ba6 commit 98d80e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+513
-313
lines changed

compiler/rustc_ast_lowering/src/index.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use intravisit::InferKind;
12
use rustc_data_structures::sorted_map::SortedMap;
23
use rustc_hir as hir;
34
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
@@ -265,14 +266,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
265266
});
266267
}
267268

268-
fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir>) {
269-
self.insert(const_arg.span(), const_arg.hir_id, Node::ConstArg(const_arg));
270-
271-
self.with_parent(const_arg.hir_id, |this| {
272-
intravisit::walk_const_arg(this, const_arg);
273-
});
274-
}
275-
276269
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
277270
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
278271

@@ -302,22 +295,41 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
302295
intravisit::walk_path_segment(self, path_segment);
303296
}
304297

305-
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
306-
self.insert(ty.span, ty.hir_id, Node::Ty(ty));
298+
fn visit_ty(&mut self, ty: &'hir Ty<'hir, AmbigArg>) {
299+
self.insert(ty.span, ty.hir_id, Node::Ty(ty.as_unambig_ty()));
307300

308301
self.with_parent(ty.hir_id, |this| {
309302
intravisit::walk_ty(this, ty);
310303
});
311304
}
312305

313-
fn visit_infer(&mut self, inf: &'hir InferArg) {
314-
self.insert(inf.span, inf.hir_id, Node::Infer(inf));
306+
fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir, AmbigArg>) {
307+
self.insert(
308+
const_arg.as_unambig_ct().span(),
309+
const_arg.hir_id,
310+
Node::ConstArg(const_arg.as_unambig_ct()),
311+
);
315312

316-
self.with_parent(inf.hir_id, |this| {
317-
intravisit::walk_inf(this, inf);
313+
self.with_parent(const_arg.hir_id, |this| {
314+
intravisit::walk_ambig_const_arg(this, const_arg);
318315
});
319316
}
320317

318+
fn visit_infer(
319+
&mut self,
320+
inf_id: HirId,
321+
inf_span: Span,
322+
kind: InferKind<'hir>,
323+
) -> Self::Result {
324+
match kind {
325+
InferKind::Ty(ty) => self.insert(inf_span, inf_id, Node::Ty(ty)),
326+
InferKind::Const(ct) => self.insert(inf_span, inf_id, Node::ConstArg(ct)),
327+
InferKind::Ambig(inf) => self.insert(inf_span, inf_id, Node::Infer(inf)),
328+
}
329+
330+
self.visit_id(inf_id);
331+
}
332+
321333
fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
322334
self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
323335

compiler/rustc_ast_lowering/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1111,15 +1111,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11111111

11121112
let ct =
11131113
self.lower_const_path_to_const_arg(path, res, ty.id, ty.span);
1114-
return GenericArg::Const(ct);
1114+
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
11151115
}
11161116
}
11171117
}
11181118
_ => {}
11191119
}
1120-
GenericArg::Type(self.lower_ty(ty, itctx))
1120+
GenericArg::Type(self.lower_ty(ty, itctx).try_as_ambig_ty().unwrap())
1121+
}
1122+
ast::GenericArg::Const(ct) => {
1123+
GenericArg::Const(self.lower_anon_const_to_const_arg(ct).try_as_ambig_ct().unwrap())
11211124
}
1122-
ast::GenericArg::Const(ct) => GenericArg::Const(self.lower_anon_const_to_const_arg(ct)),
11231125
}
11241126
}
11251127

@@ -1189,7 +1191,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11891191

11901192
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
11911193
let kind = match &t.kind {
1192-
TyKind::Infer => hir::TyKind::Infer,
1194+
TyKind::Infer => hir::TyKind::Infer(()),
11931195
TyKind::Err(guar) => hir::TyKind::Err(*guar),
11941196
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
11951197
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
@@ -2045,7 +2047,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20452047
)
20462048
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
20472049
}
2048-
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2050+
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span), ());
20492051
self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
20502052
}
20512053
_ => self.lower_anon_const_to_const_arg(c),

compiler/rustc_ast_lowering/src/path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
525525
}
526526
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
527527
};
528-
let args = smallvec![GenericArg::Type(self.arena.alloc(self.ty_tup(*inputs_span, inputs)))];
528+
let args = smallvec![GenericArg::Type(
529+
self.arena.alloc(self.ty_tup(*inputs_span, inputs)).try_as_ambig_ty().unwrap()
530+
)];
529531

530532
// If we have a bound like `async Fn() -> T`, make sure that we mark the
531533
// `Output = T` associated type bound with the right feature gates.

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::QPath::Resolved;
88
use rustc_hir::WherePredicateKind::BoundPredicate;
99
use rustc_hir::def::Res::Def;
1010
use rustc_hir::def_id::DefId;
11-
use rustc_hir::intravisit::Visitor;
11+
use rustc_hir::intravisit::VisitorExt;
1212
use rustc_hir::{PolyTraitRef, TyKind, WhereBoundPredicate};
1313
use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
1414
use rustc_middle::bug;
@@ -987,7 +987,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
987987
for found_did in found_dids {
988988
let mut traits = vec![];
989989
let mut hir_v = HirTraitObjectVisitor(&mut traits, *found_did);
990-
hir_v.visit_ty(self_ty);
990+
hir_v.visit_unambig_ty(self_ty);
991991
debug!("trait spans found: {:?}", traits);
992992
for span in &traits {
993993
let mut multi_span: MultiSpan = vec![*span].into();

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
432432
// must highlight the variable.
433433
// NOTE(eddyb) this is handled in/by the sole caller
434434
// (`give_name_if_anonymous_region_appears_in_arguments`).
435-
hir::TyKind::Infer => None,
435+
hir::TyKind::Infer(()) => None,
436436

437437
_ => Some(argument_hir_ty),
438438
}
@@ -615,7 +615,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
615615
}
616616

617617
(GenericArgKind::Type(ty), hir::GenericArg::Type(hir_ty)) => {
618-
search_stack.push((ty, hir_ty));
618+
search_stack.push((ty, hir_ty.as_unambig_ty()));
619619
}
620620

621621
(GenericArgKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {

0 commit comments

Comments
 (0)