@@ -314,89 +314,95 @@ pub enum Res<Id = hir::HirId> {
314
314
/// **Belongs to the type namespace.**
315
315
PrimTy ( hir:: PrimTy ) ,
316
316
317
- /// The `Self` type, optionally with the [`DefId`] of the trait it belongs to and
318
- /// optionally with the [`DefId`] of the item introducing the `Self` type alias.
317
+ /// The `Self` type, as used within a trait.
318
+ ///
319
+ /// **Belongs to the type namespace.**
320
+ ///
321
+ /// See the examples on [`Res::SelfTyAlias`] for details.
322
+ SelfTyParam {
323
+ /// The trait this `Self` is a generic parameter for.
324
+ trait_ : DefId ,
325
+ } ,
326
+
327
+ /// The `Self` type, as used somewhere other than within a trait.
319
328
///
320
329
/// **Belongs to the type namespace.**
321
330
///
322
331
/// Examples:
323
332
/// ```
324
- /// struct Bar(Box<Self>);
325
- /// // `Res::SelfTy { trait_: None, alias_of: Some(Bar) }`
333
+ /// struct Bar(Box<Self>); // SelfTyAlias
326
334
///
327
335
/// trait Foo {
328
- /// fn foo() -> Box<Self>;
329
- /// // `Res::SelfTy { trait_: Some(Foo), alias_of: None }`
336
+ /// fn foo() -> Box<Self>; // SelfTyParam
330
337
/// }
331
338
///
332
339
/// impl Bar {
333
340
/// fn blah() {
334
- /// let _: Self;
335
- /// // `Res::SelfTy { trait_: None, alias_of: Some(::{impl#0}) }`
341
+ /// let _: Self; // SelfTyAlias
336
342
/// }
337
343
/// }
338
344
///
339
345
/// impl Foo for Bar {
340
- /// fn foo() -> Box<Self> {
341
- /// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
342
- /// let _: Self;
343
- /// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
346
+ /// fn foo() -> Box<Self> { // SelfTyAlias
347
+ /// let _: Self; // SelfTyAlias
344
348
///
345
349
/// todo!()
346
350
/// }
347
351
/// }
348
352
/// ```
349
- ///
350
353
/// *See also [`Res::SelfCtor`].*
351
354
///
352
- /// -----
353
- ///
354
- /// HACK(min_const_generics): self types also have an optional requirement to **not** mention
355
- /// any generic parameters to allow the following with `min_const_generics`:
356
- /// ```
357
- /// # struct Foo;
358
- /// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
359
- ///
360
- /// struct Bar([u8; baz::<Self>()]);
361
- /// const fn baz<T>() -> usize { 10 }
362
- /// ```
363
- /// We do however allow `Self` in repeat expression even if it is generic to not break code
364
- /// which already works on stable while causing the `const_evaluatable_unchecked` future compat
365
- /// lint:
366
- /// ```
367
- /// fn foo<T>() {
368
- /// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
369
- /// }
370
- /// ```
371
- // FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
372
- SelfTy {
373
- /// The trait this `Self` is a generic arg for.
374
- trait_ : Option < DefId > ,
355
+ SelfTyAlias {
375
356
/// The item introducing the `Self` type alias. Can be used in the `type_of` query
376
- /// to get the underlying type. Additionally whether the `Self` type is disallowed
377
- /// from mentioning generics (i.e. when used in an anonymous constant).
378
- alias_to : Option < ( DefId , bool ) > ,
379
- } ,
357
+ /// to get the underlying type.
358
+ alias_to : DefId ,
380
359
381
- /// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
382
- ///
383
- /// **Belongs to the type namespace.**
384
- ToolMod ,
360
+ /// Whether the `Self` type is disallowed from mentioning generics (i.e. when used in an
361
+ /// anonymous constant).
362
+ ///
363
+ /// HACK(min_const_generics): self types also have an optional requirement to **not**
364
+ /// mention any generic parameters to allow the following with `min_const_generics`:
365
+ /// ```
366
+ /// # struct Foo;
367
+ /// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
368
+ ///
369
+ /// struct Bar([u8; baz::<Self>()]);
370
+ /// const fn baz<T>() -> usize { 10 }
371
+ /// ```
372
+ /// We do however allow `Self` in repeat expression even if it is generic to not break code
373
+ /// which already works on stable while causing the `const_evaluatable_unchecked` future
374
+ /// compat lint:
375
+ /// ```
376
+ /// fn foo<T>() {
377
+ /// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
378
+ /// }
379
+ /// ```
380
+ // FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
381
+ forbid_generic : bool ,
382
+
383
+ /// Is this within an `impl Foo for bar`?
384
+ is_trait_impl : bool ,
385
+ } ,
385
386
386
387
// Value namespace
387
388
/// The `Self` constructor, along with the [`DefId`]
388
389
/// of the impl it is associated with.
389
390
///
390
391
/// **Belongs to the value namespace.**
391
392
///
392
- /// *See also [`Res::SelfTy `].*
393
+ /// *See also [`Res::SelfTyParam`] and [`Res::SelfTyAlias `].*
393
394
SelfCtor ( DefId ) ,
394
395
395
396
/// A local variable or function parameter.
396
397
///
397
398
/// **Belongs to the value namespace.**
398
399
Local ( Id ) ,
399
400
401
+ /// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
402
+ ///
403
+ /// **Belongs to the type namespace.**
404
+ ToolMod ,
405
+
400
406
// Macro namespace
401
407
/// An attribute that is *not* implemented via macro.
402
408
/// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
@@ -606,7 +612,8 @@ impl<Id> Res<Id> {
606
612
607
613
Res :: Local ( ..)
608
614
| Res :: PrimTy ( ..)
609
- | Res :: SelfTy { .. }
615
+ | Res :: SelfTyParam { .. }
616
+ | Res :: SelfTyAlias { .. }
610
617
| Res :: SelfCtor ( ..)
611
618
| Res :: ToolMod
612
619
| Res :: NonMacroAttr ( ..)
@@ -629,7 +636,7 @@ impl<Id> Res<Id> {
629
636
Res :: SelfCtor ( ..) => "self constructor" ,
630
637
Res :: PrimTy ( ..) => "builtin type" ,
631
638
Res :: Local ( ..) => "local variable" ,
632
- Res :: SelfTy { .. } => "self type" ,
639
+ Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. } => "self type" ,
633
640
Res :: ToolMod => "tool module" ,
634
641
Res :: NonMacroAttr ( attr_kind) => attr_kind. descr ( ) ,
635
642
Res :: Err => "unresolved item" ,
@@ -652,7 +659,10 @@ impl<Id> Res<Id> {
652
659
Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
653
660
Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
654
661
Res :: Local ( id) => Res :: Local ( map ( id) ) ,
655
- Res :: SelfTy { trait_, alias_to } => Res :: SelfTy { trait_, alias_to } ,
662
+ Res :: SelfTyParam { trait_ } => Res :: SelfTyParam { trait_ } ,
663
+ Res :: SelfTyAlias { alias_to, forbid_generic, is_trait_impl } => {
664
+ Res :: SelfTyAlias { alias_to, forbid_generic, is_trait_impl }
665
+ }
656
666
Res :: ToolMod => Res :: ToolMod ,
657
667
Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
658
668
Res :: Err => Res :: Err ,
@@ -665,7 +675,10 @@ impl<Id> Res<Id> {
665
675
Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
666
676
Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
667
677
Res :: Local ( id) => Res :: Local ( map ( id) ?) ,
668
- Res :: SelfTy { trait_, alias_to } => Res :: SelfTy { trait_, alias_to } ,
678
+ Res :: SelfTyParam { trait_ } => Res :: SelfTyParam { trait_ } ,
679
+ Res :: SelfTyAlias { alias_to, forbid_generic, is_trait_impl } => {
680
+ Res :: SelfTyAlias { alias_to, forbid_generic, is_trait_impl }
681
+ }
669
682
Res :: ToolMod => Res :: ToolMod ,
670
683
Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
671
684
Res :: Err => Res :: Err ,
@@ -692,7 +705,9 @@ impl<Id> Res<Id> {
692
705
pub fn ns ( & self ) -> Option < Namespace > {
693
706
match self {
694
707
Res :: Def ( kind, ..) => kind. ns ( ) ,
695
- Res :: PrimTy ( ..) | Res :: SelfTy { .. } | Res :: ToolMod => Some ( Namespace :: TypeNS ) ,
708
+ Res :: PrimTy ( ..) | Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. } | Res :: ToolMod => {
709
+ Some ( Namespace :: TypeNS )
710
+ }
696
711
Res :: SelfCtor ( ..) | Res :: Local ( ..) => Some ( Namespace :: ValueNS ) ,
697
712
Res :: NonMacroAttr ( ..) => Some ( Namespace :: MacroNS ) ,
698
713
Res :: Err => None ,
0 commit comments