Skip to content

Commit 531486e

Browse files
Rollup merge of #142678 - BoxyUwU:gai_cleanup, r=nnethercote
Misc cleanups of `generic_arg_infer` related HIR logic r? ````@nnethercote````
2 parents f34ba77 + fa5895e commit 531486e

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
311311
);
312312

313313
self.with_parent(const_arg.hir_id, |this| {
314-
intravisit::walk_ambig_const_arg(this, const_arg);
314+
intravisit::walk_const_arg(this, const_arg);
315315
});
316316
}
317317

compiler/rustc_hir/src/hir.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,8 @@ impl<'hir> PathSegment<'hir> {
412412
/// that are [just paths](ConstArgKind::Path) (currently just bare const params)
413413
/// versus const args that are literals or have arbitrary computations (e.g., `{ 1 + 3 }`).
414414
///
415-
/// The `Unambig` generic parameter represents whether the position this const is from is
416-
/// unambiguously a const or ambiguous as to whether it is a type or a const. When in an
417-
/// ambiguous context the parameter is instantiated with an uninhabited type making the
418-
/// [`ConstArgKind::Infer`] variant unusable and [`GenericArg::Infer`] is used instead.
415+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
416+
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
419417
#[derive(Clone, Copy, Debug, HashStable_Generic)]
420418
#[repr(C)]
421419
pub struct ConstArg<'hir, Unambig = ()> {
@@ -427,7 +425,7 @@ pub struct ConstArg<'hir, Unambig = ()> {
427425
impl<'hir> ConstArg<'hir, AmbigArg> {
428426
/// Converts a `ConstArg` in an ambiguous position to one in an unambiguous position.
429427
///
430-
/// Functions accepting an unambiguous consts may expect the [`ConstArgKind::Infer`] variant
428+
/// Functions accepting unambiguous consts may expect the [`ConstArgKind::Infer`] variant
431429
/// to be used. Care should be taken to separately handle infer consts when calling this
432430
/// function as it cannot be handled by downstream code making use of the returned const.
433431
///
@@ -3314,14 +3312,12 @@ impl<'hir> AssocItemConstraintKind<'hir> {
33143312
#[derive(Debug, Clone, Copy, HashStable_Generic)]
33153313
pub enum AmbigArg {}
33163314

3317-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
3318-
#[repr(C)]
33193315
/// Represents a type in the `HIR`.
33203316
///
3321-
/// The `Unambig` generic parameter represents whether the position this type is from is
3322-
/// unambiguously a type or ambiguous as to whether it is a type or a const. When in an
3323-
/// ambiguous context the parameter is instantiated with an uninhabited type making the
3324-
/// [`TyKind::Infer`] variant unusable and [`GenericArg::Infer`] is used instead.
3317+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
3318+
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
3319+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
3320+
#[repr(C)]
33253321
pub struct Ty<'hir, Unambig = ()> {
33263322
#[stable_hasher(ignore)]
33273323
pub hir_id: HirId,
@@ -3656,9 +3652,12 @@ pub enum InferDelegationKind {
36563652
}
36573653

36583654
/// The various kinds of types recognized by the compiler.
3659-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
3655+
///
3656+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
3657+
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
36603658
// SAFETY: `repr(u8)` is required so that `TyKind<()>` and `TyKind<!>` are layout compatible
36613659
#[repr(u8, C)]
3660+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
36623661
pub enum TyKind<'hir, Unambig = ()> {
36633662
/// Actual type should be inherited from `DefId` signature
36643663
InferDelegation(DefId, InferDelegationKind),

compiler/rustc_hir/src/intravisit.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ pub trait Visitor<'v>: Sized {
364364
/// All types are treated as ambiguous types for the purposes of hir visiting in
365365
/// order to ensure that visitors can handle infer vars without it being too error-prone.
366366
///
367-
/// See the doc comments on [`Ty`] for an explanation of what it means for a type to be
368-
/// ambiguous.
369-
///
370367
/// The [`Visitor::visit_infer`] method should be overridden in order to handle infer vars.
371368
fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) -> Self::Result {
372369
walk_ty(self, t)
@@ -375,12 +372,9 @@ pub trait Visitor<'v>: Sized {
375372
/// All consts are treated as ambiguous consts for the purposes of hir visiting in
376373
/// order to ensure that visitors can handle infer vars without it being too error-prone.
377374
///
378-
/// See the doc comments on [`ConstArg`] for an explanation of what it means for a const to be
379-
/// ambiguous.
380-
///
381375
/// The [`Visitor::visit_infer`] method should be overridden in order to handle infer vars.
382376
fn visit_const_arg(&mut self, c: &'v ConstArg<'v, AmbigArg>) -> Self::Result {
383-
walk_ambig_const_arg(self, c)
377+
walk_const_arg(self, c)
384378
}
385379

386380
#[allow(unused_variables)]
@@ -522,7 +516,7 @@ pub trait VisitorExt<'v>: Visitor<'v> {
522516
/// Named `visit_const_arg_unambig` instead of `visit_unambig_const_arg` to aid in
523517
/// discovery by IDes when `v.visit_const_arg` is written.
524518
fn visit_const_arg_unambig(&mut self, c: &'v ConstArg<'v>) -> Self::Result {
525-
walk_const_arg(self, c)
519+
walk_unambig_const_arg(self, c)
526520
}
527521
}
528522
impl<'v, V: Visitor<'v>> VisitorExt<'v> for V {}
@@ -985,7 +979,6 @@ pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) ->
985979
Some(ambig_ty) => visitor.visit_ty(ambig_ty),
986980
None => {
987981
let Ty { hir_id, span, kind: _ } = typ;
988-
try_visit!(visitor.visit_id(*hir_id));
989982
visitor.visit_infer(*hir_id, *span, InferKind::Ty(typ))
990983
}
991984
}
@@ -1043,21 +1036,20 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -
10431036
V::Result::output()
10441037
}
10451038

1046-
pub fn walk_const_arg<'v, V: Visitor<'v>>(
1039+
pub fn walk_unambig_const_arg<'v, V: Visitor<'v>>(
10471040
visitor: &mut V,
10481041
const_arg: &'v ConstArg<'v>,
10491042
) -> V::Result {
10501043
match const_arg.try_as_ambig_ct() {
10511044
Some(ambig_ct) => visitor.visit_const_arg(ambig_ct),
10521045
None => {
10531046
let ConstArg { hir_id, kind: _ } = const_arg;
1054-
try_visit!(visitor.visit_id(*hir_id));
10551047
visitor.visit_infer(*hir_id, const_arg.span(), InferKind::Const(const_arg))
10561048
}
10571049
}
10581050
}
10591051

1060-
pub fn walk_ambig_const_arg<'v, V: Visitor<'v>>(
1052+
pub fn walk_const_arg<'v, V: Visitor<'v>>(
10611053
visitor: &mut V,
10621054
const_arg: &'v ConstArg<'v, AmbigArg>,
10631055
) -> V::Result {

0 commit comments

Comments
 (0)