@@ -266,59 +266,67 @@ pub enum Res<Id = hir::HirId> {
266
266
///
267
267
/// **Belongs to the type namespace.**
268
268
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 .
271
271
///
272
272
/// **Belongs to the type namespace.**
273
273
///
274
- /// For example, the `Self` in
275
- ///
274
+ /// Examples:
276
275
/// ```
276
+ /// struct Bar(Box<Self>);
277
+ /// // `Res::SelfTy { trait_: None, alias_of: Some(Bar) }`
278
+ ///
277
279
/// trait Foo {
278
280
/// fn foo() -> Box<Self>;
281
+ /// // `Res::SelfTy { trait_: Some(Foo), alias_of: None }`
279
282
/// }
280
- /// ```
281
- ///
282
- /// would have the [`DefId`] of `Foo` associated with it. The `Self` in
283
- ///
284
- /// ```
285
- /// struct Bar;
286
283
///
287
284
/// impl Bar {
288
- /// fn new() -> Self { Bar }
285
+ /// fn blah() {
286
+ /// let _: Self;
287
+ /// // `Res::SelfTy { trait_: None, alias_of: Some(::{impl#0}) }`
288
+ /// }
289
289
/// }
290
- /// ```
291
- ///
292
- /// would have the [`DefId`] of the impl associated with it. Finally, the `Self` in
293
290
///
294
- /// ```
295
291
/// 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
+ /// }
297
299
/// }
298
300
/// ```
299
301
///
300
- /// would have both the [`DefId`] of `Foo` and the [`DefId`] of the impl
301
- /// associated with it.
302
- ///
303
302
/// *See also [`Res::SelfCtor`].*
304
303
///
305
304
/// -----
306
305
///
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
308
307
/// any generic parameters to allow the following with `min_const_generics`:
309
308
/// ```
310
309
/// 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 }
311
313
/// ```
312
314
/// 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
+ } ,
322
330
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
323
331
///
324
332
/// **Belongs to the type namespace.**
@@ -550,7 +558,7 @@ impl<Id> Res<Id> {
550
558
551
559
Res :: Local ( ..)
552
560
| Res :: PrimTy ( ..)
553
- | Res :: SelfTy ( .. )
561
+ | Res :: SelfTy { .. }
554
562
| Res :: SelfCtor ( ..)
555
563
| Res :: ToolMod
556
564
| Res :: NonMacroAttr ( ..)
@@ -573,7 +581,7 @@ impl<Id> Res<Id> {
573
581
Res :: SelfCtor ( ..) => "self constructor" ,
574
582
Res :: PrimTy ( ..) => "builtin type" ,
575
583
Res :: Local ( ..) => "local variable" ,
576
- Res :: SelfTy ( .. ) => "self type" ,
584
+ Res :: SelfTy { .. } => "self type" ,
577
585
Res :: ToolMod => "tool module" ,
578
586
Res :: NonMacroAttr ( attr_kind) => attr_kind. descr ( ) ,
579
587
Res :: Err => "unresolved item" ,
@@ -596,7 +604,7 @@ impl<Id> Res<Id> {
596
604
Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
597
605
Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
598
606
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 } ,
600
608
Res :: ToolMod => Res :: ToolMod ,
601
609
Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
602
610
Res :: Err => Res :: Err ,
@@ -620,7 +628,7 @@ impl<Id> Res<Id> {
620
628
pub fn ns ( & self ) -> Option < Namespace > {
621
629
match self {
622
630
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 ) ,
624
632
Res :: SelfCtor ( ..) | Res :: Local ( ..) => Some ( Namespace :: ValueNS ) ,
625
633
Res :: NonMacroAttr ( ..) => Some ( Namespace :: MacroNS ) ,
626
634
Res :: Err => None ,
0 commit comments