@@ -266,59 +266,67 @@ 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;
286283 ///
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
293290 ///
294- /// ```
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.
316- SelfTy (
317- /// Optionally, the trait associated with this `Self` type.
318- Option < DefId > ,
319- /// Optionally, the impl associated with this `Self` type.
320- Option < ( DefId , bool ) > ,
321- ) ,
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.
322+ SelfTy {
323+ /// The trait this `Self` is a generic arg for.
324+ trait_ : Option < DefId > ,
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).
328+ alias_to : Option < ( DefId , bool ) > ,
329+ } ,
322330 /// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
323331 ///
324332 /// **Belongs to the type namespace.**
@@ -550,7 +558,7 @@ impl<Id> Res<Id> {
550558
551559 Res :: Local ( ..)
552560 | Res :: PrimTy ( ..)
553- | Res :: SelfTy ( .. )
561+ | Res :: SelfTy { .. }
554562 | Res :: SelfCtor ( ..)
555563 | Res :: ToolMod
556564 | Res :: NonMacroAttr ( ..)
@@ -573,7 +581,7 @@ impl<Id> Res<Id> {
573581 Res :: SelfCtor ( ..) => "self constructor" ,
574582 Res :: PrimTy ( ..) => "builtin type" ,
575583 Res :: Local ( ..) => "local variable" ,
576- Res :: SelfTy ( .. ) => "self type" ,
584+ Res :: SelfTy { .. } => "self type" ,
577585 Res :: ToolMod => "tool module" ,
578586 Res :: NonMacroAttr ( attr_kind) => attr_kind. descr ( ) ,
579587 Res :: Err => "unresolved item" ,
@@ -596,7 +604,7 @@ impl<Id> Res<Id> {
596604 Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
597605 Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
598606 Res :: Local ( id) => Res :: Local ( map ( id) ) ,
599- Res :: SelfTy ( a , b ) => Res :: SelfTy ( a , b ) ,
607+ Res :: SelfTy { trait_ , alias_to } => Res :: SelfTy { trait_ , alias_to } ,
600608 Res :: ToolMod => Res :: ToolMod ,
601609 Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
602610 Res :: Err => Res :: Err ,
@@ -620,7 +628,7 @@ impl<Id> Res<Id> {
620628 pub fn ns ( & self ) -> Option < Namespace > {
621629 match self {
622630 Res :: Def ( kind, ..) => kind. ns ( ) ,
623- Res :: PrimTy ( ..) | Res :: SelfTy ( .. ) | Res :: ToolMod => Some ( Namespace :: TypeNS ) ,
631+ Res :: PrimTy ( ..) | Res :: SelfTy { .. } | Res :: ToolMod => Some ( Namespace :: TypeNS ) ,
624632 Res :: SelfCtor ( ..) | Res :: Local ( ..) => Some ( Namespace :: ValueNS ) ,
625633 Res :: NonMacroAttr ( ..) => Some ( Namespace :: MacroNS ) ,
626634 Res :: Err => None ,
0 commit comments