Skip to content

Commit 9130af2

Browse files
committed
change docs on Res::SelfTy
1 parent e81e09a commit 9130af2

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

compiler/rustc_hir/src/def.rs

+35-27
Original file line numberDiff line numberDiff line change
@@ -266,57 +266,65 @@ pub enum Res<Id = hir::HirId> {
266266
///
267267
/// **Belongs to the type namespace.**
268268
PrimTy(hir::PrimTy),
269-
/// The `Self` type, optionally with the trait it is associated with
270-
/// and optionally with the [`DefId`] of the impl it is associated with.
269+
/// The `Self` type, optionally with the [`DefId`] of the trait it belongs to and
270+
/// optionally with the [`DefId`] of the item introducing the `Self` type alias.
271271
///
272272
/// **Belongs to the type namespace.**
273273
///
274-
/// For example, the `Self` in
275-
///
274+
/// Examples:
276275
/// ```
276+
/// struct Bar(Box<Self>);
277+
/// // `Res::SelfTy { trait_: None, alias_of: Some(Bar) }`
278+
///
277279
/// trait Foo {
278280
/// fn foo() -> Box<Self>;
281+
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: None }`
279282
/// }
280-
/// ```
281-
///
282-
/// would have the [`DefId`] of `Foo` associated with it. The `Self` in
283-
///
284-
/// ```
285-
/// struct Bar;
286-
///
283+
///
287284
/// impl Bar {
288-
/// fn new() -> Self { Bar }
285+
/// fn blah() {
286+
/// let _: Self;
287+
/// // `Res::SelfTy { trait_: None, alias_of: Some(::{impl#0}) }`
288+
/// }
289289
/// }
290-
/// ```
291-
///
292-
/// would have the [`DefId`] of the impl associated with it. Finally, the `Self` in
293-
///
294-
/// ```
290+
///
295291
/// impl Foo for Bar {
296-
/// fn foo() -> Box<Self> { Box::new(Bar) }
292+
/// fn foo() -> Box<Self> {
293+
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
294+
/// let _: Self;
295+
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
296+
///
297+
/// todo!()
298+
/// }
297299
/// }
298300
/// ```
299301
///
300-
/// would have both the [`DefId`] of `Foo` and the [`DefId`] of the impl
301-
/// associated with it.
302-
///
303302
/// *See also [`Res::SelfCtor`].*
304303
///
305304
/// -----
306305
///
307-
/// HACK(min_const_generics): impl self types also have an optional requirement to **not** mention
306+
/// HACK(min_const_generics): self types also have an optional requirement to **not** mention
308307
/// any generic parameters to allow the following with `min_const_generics`:
309308
/// ```
310309
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
310+
///
311+
/// struct Bar([u8; baz::<Self>()]);
312+
/// const fn baz<T>() -> usize { 10 }
311313
/// ```
312314
/// We do however allow `Self` in repeat expression even if it is generic to not break code
313-
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
314-
///
315-
/// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
315+
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint:
316+
/// ```
317+
/// fn foo<T>() {
318+
/// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
319+
/// }
320+
/// ```
321+
// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
316322
SelfTy {
317-
/// Optionally, the trait associated with this `Self` type.
323+
/// The trait this `Self` is a generic arg for.
318324
trait_: Option<DefId>,
319-
/// Optionally, the impl or adt associated with this `Self` type.
325+
/// The item introducing the `Self` type alias. Can be used in the `type_of` query
326+
/// to get the underlying type. Additionally whether the `Self` type is disallowed
327+
/// from mentioning generics (i.e. when used in an anonymous constant).
320328
alias_to: Option<(DefId, bool)>,
321329
},
322330
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.

0 commit comments

Comments
 (0)