Skip to content

Commit b6b2961

Browse files
committed
add FRTs to HIR
1 parent f92a04b commit b6b2961

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,8 @@ pub enum TyKind<'hir, Unambig = ()> {
37103710
/// We use pointer tagging to represent a `&'hir Lifetime` and `TraitObjectSyntax` pair
37113711
/// as otherwise this type being `repr(C)` would result in `TyKind` increasing in size.
37123712
TraitObject(&'hir [PolyTraitRef<'hir>], TaggedRef<'hir, Lifetime, TraitObjectSyntax>),
3713+
/// Field representing type (`field_of!`)
3714+
FieldOf(&'hir Ty<'hir>, &'hir [Ident]),
37133715
/// Unused for now.
37143716
Typeof(&'hir AnonConst),
37153717
/// Placeholder for a type that has failed to be defined.

compiler/rustc_hir/src/intravisit.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,12 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -
10261026
}
10271027
try_visit!(visitor.visit_lifetime(lifetime));
10281028
}
1029+
TyKind::FieldOf(ty, fields) => {
1030+
try_visit!(visitor.visit_ty_unambig(ty));
1031+
for field in fields {
1032+
try_visit!(visitor.visit_ident(*field));
1033+
}
1034+
}
10291035
TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)),
10301036
TyKind::InferDelegation(..) | TyKind::Err(_) => {}
10311037
TyKind::Pat(ty, pat) => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25582558
let length = self.lower_const_arg(length, FeedConstTy::No);
25592559
Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
25602560
}
2561+
hir::TyKind::FieldOf(container, fields) => {
2562+
self.lower_field_of(hir_ty, container, fields)
2563+
}
25612564
hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(),
25622565
hir::TyKind::Infer(()) => {
25632566
// Infer also appears as the type of arguments or return
@@ -2724,6 +2727,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27242727
fn_ptr_ty
27252728
}
27262729

2730+
fn lower_field_of(
2731+
&self,
2732+
hir_ty: &hir::Ty<'tcx>,
2733+
container: &hir::Ty<'tcx>,
2734+
fields: &[Ident],
2735+
) -> Ty<'tcx> {
2736+
match self.lower_field_path(
2737+
container,
2738+
fields,
2739+
hir_ty.span,
2740+
hir_ty.hir_id,
2741+
FieldPathKind::FieldOf,
2742+
) {
2743+
Ok((container, field_path)) => Ty::new_field_type(self.tcx(), container, field_path),
2744+
Err(err) => Ty::new_error(self.tcx(), err),
2745+
}
2746+
}
2747+
27272748
/// Given a fn_hir_id for a impl function, suggest the type that is found on the
27282749
/// corresponding function in the trait that the impl implements, if it exists.
27292750
/// If arg_idx is Some, then it corresponds to an input type index, otherwise it

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,23 @@ impl<'a> State<'a> {
445445
self.print_const_arg(length);
446446
self.word("]");
447447
}
448+
hir::TyKind::FieldOf(container, fields) => {
449+
self.word("field_of!(");
450+
self.print_type(container);
451+
self.word(",");
452+
self.space();
453+
454+
if let Some((&first, rest)) = fields.split_first() {
455+
self.print_ident(first);
456+
457+
for &field in rest {
458+
self.word(".");
459+
self.print_ident(field);
460+
}
461+
}
462+
463+
self.word(")");
464+
}
448465
hir::TyKind::Typeof(ref e) => {
449466
self.word("typeof(");
450467
self.print_anon_const(e);

compiler/rustc_passes/src/input_stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
408408
OpaqueDef,
409409
TraitAscription,
410410
TraitObject,
411+
FieldOf,
411412
Typeof,
412413
Infer,
413414
Pat,
@@ -683,6 +684,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
683684
TraitObject,
684685
ImplTrait,
685686
Paren,
687+
FieldOf,
686688
Typeof,
687689
Infer,
688690
ImplicitSelf,

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ impl TyCoercionStability {
818818
| TyKind::FnPtr(_)
819819
| TyKind::Pat(..)
820820
| TyKind::Never
821+
| TyKind::FieldOf(..)
821822
| TyKind::Tup(_)
822823
| TyKind::Path(_) => Self::Deref,
823824
TyKind::OpaqueDef(..)

src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
13061306
TyKind::TraitObject(_, lifetime) => {
13071307
self.hash_lifetime(lifetime);
13081308
},
1309+
TyKind::FieldOf(container, fields) => {
1310+
self.hash_ty(container);
1311+
for field in *fields {
1312+
self.hash_name(field.name);
1313+
}
1314+
},
13091315
TyKind::Typeof(anon_const) => {
13101316
self.hash_body(anon_const.body);
13111317
},

0 commit comments

Comments
 (0)