Skip to content

Commit 2411fba

Browse files
committed
Link to dev-guide docs
1 parent c9264a1 commit 2411fba

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,8 @@ impl<'hir> PathSegment<'hir> {
407407
/// that are [just paths](ConstArgKind::Path) (currently just bare const params)
408408
/// versus const args that are literals or have arbitrary computations (e.g., `{ 1 + 3 }`).
409409
///
410-
/// The `Unambig` generic parameter represents whether the position this const is from is
411-
/// unambiguously a const or ambiguous as to whether it is a type or a const. When in an
412-
/// ambiguous context the parameter is instantiated with an uninhabited type making the
413-
/// [`ConstArgKind::Infer`] variant unusable and [`GenericArg::Infer`] is used instead.
410+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
411+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
414412
#[derive(Clone, Copy, Debug, HashStable_Generic)]
415413
#[repr(C)]
416414
pub struct ConstArg<'hir, Unambig = ()> {
@@ -429,6 +427,9 @@ impl<'hir> ConstArg<'hir, AmbigArg> {
429427
/// In practice this may mean overriding the [`Visitor::visit_infer`][visit_infer] method on hir visitors, or
430428
/// specifically matching on [`GenericArg::Infer`] when handling generic arguments.
431429
///
430+
/// For an explanation of what it means for a const arg to be ambig or unambig, see the dev-guide:
431+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
432+
///
432433
/// [visit_infer]: [rustc_hir::intravisit::Visitor::visit_infer]
433434
pub fn as_unambig_ct(&self) -> &ConstArg<'hir> {
434435
// SAFETY: `ConstArg` is `repr(C)` and `ConstArgKind` is marked `repr(u8)` so that the
@@ -444,6 +445,9 @@ impl<'hir> ConstArg<'hir> {
444445
///
445446
/// Functions accepting ambiguous consts will not handle the [`ConstArgKind::Infer`] variant, if
446447
/// infer consts are relevant to you then care should be taken to handle them separately.
448+
///
449+
/// For an explanation of what it means for a const arg to be ambig or unambig, see the dev-guide:
450+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
447451
pub fn try_as_ambig_ct(&self) -> Option<&ConstArg<'hir, AmbigArg>> {
448452
if let ConstArgKind::Infer(_, ()) = self.kind {
449453
return None;
@@ -475,6 +479,9 @@ impl<'hir, Unambig> ConstArg<'hir, Unambig> {
475479
}
476480

477481
/// See [`ConstArg`].
482+
///
483+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
484+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
478485
#[derive(Clone, Copy, Debug, HashStable_Generic)]
479486
#[repr(u8, C)]
480487
pub enum ConstArgKind<'hir, Unambig = ()> {
@@ -3302,10 +3309,8 @@ pub enum AmbigArg {}
33023309
#[repr(C)]
33033310
/// Represents a type in the `HIR`.
33043311
///
3305-
/// The `Unambig` generic parameter represents whether the position this type is from is
3306-
/// unambiguously a type or ambiguous as to whether it is a type or a const. When in an
3307-
/// ambiguous context the parameter is instantiated with an uninhabited type making the
3308-
/// [`TyKind::Infer`] variant unusable and [`GenericArg::Infer`] is used instead.
3312+
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
3313+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
33093314
pub struct Ty<'hir, Unambig = ()> {
33103315
#[stable_hasher(ignore)]
33113316
pub hir_id: HirId,
@@ -3323,6 +3328,9 @@ impl<'hir> Ty<'hir, AmbigArg> {
33233328
/// In practice this may mean overriding the [`Visitor::visit_infer`][visit_infer] method on hir visitors, or
33243329
/// specifically matching on [`GenericArg::Infer`] when handling generic arguments.
33253330
///
3331+
/// For an explanation of what it means for a type to be ambig or unambig, see the dev-guide:
3332+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
3333+
///
33263334
/// [visit_infer]: [rustc_hir::intravisit::Visitor::visit_infer]
33273335
pub fn as_unambig_ty(&self) -> &Ty<'hir> {
33283336
// SAFETY: `Ty` is `repr(C)` and `TyKind` is marked `repr(u8)` so that the layout is
@@ -3338,6 +3346,9 @@ impl<'hir> Ty<'hir> {
33383346
///
33393347
/// Functions accepting ambiguous types will not handle the [`TyKind::Infer`] variant, if
33403348
/// infer types are relevant to you then care should be taken to handle them separately.
3349+
///
3350+
/// For an explanation of what it means for a type to be ambig or unambig, see the dev-guide:
3351+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
33413352
pub fn try_as_ambig_ty(&self) -> Option<&Ty<'hir, AmbigArg>> {
33423353
if let TyKind::Infer(()) = self.kind {
33433354
return None;
@@ -3640,9 +3651,12 @@ pub enum InferDelegationKind {
36403651
}
36413652

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

compiler/rustc_hir/src/intravisit.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ 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.
367+
/// For an explanation of what it means for a type to be ambig, see the dev-guide:
368+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
369369
///
370370
/// The [`Visitor::visit_infer`] method should be overridden in order to handle infer vars.
371371
fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) -> Self::Result {
@@ -375,8 +375,8 @@ pub trait Visitor<'v>: Sized {
375375
/// All consts are treated as ambiguous consts for the purposes of hir visiting in
376376
/// order to ensure that visitors can handle infer vars without it being too error-prone.
377377
///
378-
/// See the doc comments on [`ConstArg`] for an explanation of what it means for a const to be
379-
/// ambiguous.
378+
/// For an explanation of what it means for a const arg to be ambig, see the dev-guide:
379+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
380380
///
381381
/// The [`Visitor::visit_infer`] method should be overridden in order to handle infer vars.
382382
fn visit_const_arg(&mut self, c: &'v ConstArg<'v, AmbigArg>) -> Self::Result {
@@ -516,6 +516,9 @@ pub trait VisitorExt<'v>: Visitor<'v> {
516516
///
517517
/// Named `visit_ty_unambig` instead of `visit_unambig_ty` to aid in discovery
518518
/// by IDes when `v.visit_ty` is written.
519+
///
520+
/// For an explanation of what it means for a type to be unambig, see the dev-guide:
521+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
519522
fn visit_ty_unambig(&mut self, t: &'v Ty<'v>) -> Self::Result {
520523
walk_unambig_ty(self, t)
521524
}
@@ -524,6 +527,9 @@ pub trait VisitorExt<'v>: Visitor<'v> {
524527
///
525528
/// Named `visit_const_arg_unambig` instead of `visit_unambig_const_arg` to aid in
526529
/// discovery by IDes when `v.visit_const_arg` is written.
530+
///
531+
/// For an explanation of what it means for a const arg to be unambig, see the dev-guide:
532+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
527533
fn visit_const_arg_unambig(&mut self, c: &'v ConstArg<'v>) -> Self::Result {
528534
walk_unambig_const_arg(self, c)
529535
}
@@ -975,6 +981,8 @@ pub fn walk_generic_arg<'v, V: Visitor<'v>>(
975981
}
976982
}
977983

984+
/// For an explanation of what it means for a type to be unambig, see the dev-guide:
985+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
978986
pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Result {
979987
match typ.try_as_ambig_ty() {
980988
Some(ambig_ty) => visitor.visit_ty(ambig_ty),
@@ -985,6 +993,8 @@ pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) ->
985993
}
986994
}
987995

996+
/// For an explanation of what it means for a type to be ambig, see the dev-guide:
997+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
988998
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -> V::Result {
989999
let Ty { hir_id, span: _, kind } = typ;
9901000
try_visit!(visitor.visit_id(*hir_id));
@@ -1037,6 +1047,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -
10371047
V::Result::output()
10381048
}
10391049

1050+
/// For an explanation of what it means for a const arg to be unambig, see the dev-guide:
1051+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
10401052
pub fn walk_unambig_const_arg<'v, V: Visitor<'v>>(
10411053
visitor: &mut V,
10421054
const_arg: &'v ConstArg<'v>,
@@ -1050,6 +1062,8 @@ pub fn walk_unambig_const_arg<'v, V: Visitor<'v>>(
10501062
}
10511063
}
10521064

1065+
/// For an explanation of what it means for a const arg to be ambig, see the dev-guide:
1066+
/// https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html
10531067
pub fn walk_const_arg<'v, V: Visitor<'v>>(
10541068
visitor: &mut V,
10551069
const_arg: &'v ConstArg<'v, AmbigArg>,

0 commit comments

Comments
 (0)