@@ -314,89 +314,95 @@ pub enum Res<Id = hir::HirId> {
314314 /// **Belongs to the type namespace.**
315315 PrimTy ( hir:: PrimTy ) ,
316316
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.
319328 ///
320329 /// **Belongs to the type namespace.**
321330 ///
322331 /// Examples:
323332 /// ```
324- /// struct Bar(Box<Self>);
325- /// // `Res::SelfTy { trait_: None, alias_of: Some(Bar) }`
333+ /// struct Bar(Box<Self>); // SelfTyAlias
326334 ///
327335 /// trait Foo {
328- /// fn foo() -> Box<Self>;
329- /// // `Res::SelfTy { trait_: Some(Foo), alias_of: None }`
336+ /// fn foo() -> Box<Self>; // SelfTyParam
330337 /// }
331338 ///
332339 /// impl Bar {
333340 /// fn blah() {
334- /// let _: Self;
335- /// // `Res::SelfTy { trait_: None, alias_of: Some(::{impl#0}) }`
341+ /// let _: Self; // SelfTyAlias
336342 /// }
337343 /// }
338344 ///
339345 /// 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
344348 ///
345349 /// todo!()
346350 /// }
347351 /// }
348352 /// ```
349- ///
350353 /// *See also [`Res::SelfCtor`].*
351354 ///
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 {
375356 /// 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 ,
380359
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+ } ,
385386
386387 // Value namespace
387388 /// The `Self` constructor, along with the [`DefId`]
388389 /// of the impl it is associated with.
389390 ///
390391 /// **Belongs to the value namespace.**
391392 ///
392- /// *See also [`Res::SelfTy `].*
393+ /// *See also [`Res::SelfTyParam`] and [`Res::SelfTyAlias `].*
393394 SelfCtor ( DefId ) ,
394395
395396 /// A local variable or function parameter.
396397 ///
397398 /// **Belongs to the value namespace.**
398399 Local ( Id ) ,
399400
401+ /// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
402+ ///
403+ /// **Belongs to the type namespace.**
404+ ToolMod ,
405+
400406 // Macro namespace
401407 /// An attribute that is *not* implemented via macro.
402408 /// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
@@ -606,7 +612,8 @@ impl<Id> Res<Id> {
606612
607613 Res :: Local ( ..)
608614 | Res :: PrimTy ( ..)
609- | Res :: SelfTy { .. }
615+ | Res :: SelfTyParam { .. }
616+ | Res :: SelfTyAlias { .. }
610617 | Res :: SelfCtor ( ..)
611618 | Res :: ToolMod
612619 | Res :: NonMacroAttr ( ..)
@@ -629,7 +636,7 @@ impl<Id> Res<Id> {
629636 Res :: SelfCtor ( ..) => "self constructor" ,
630637 Res :: PrimTy ( ..) => "builtin type" ,
631638 Res :: Local ( ..) => "local variable" ,
632- Res :: SelfTy { .. } => "self type" ,
639+ Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. } => "self type" ,
633640 Res :: ToolMod => "tool module" ,
634641 Res :: NonMacroAttr ( attr_kind) => attr_kind. descr ( ) ,
635642 Res :: Err => "unresolved item" ,
@@ -652,7 +659,10 @@ impl<Id> Res<Id> {
652659 Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
653660 Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
654661 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+ }
656666 Res :: ToolMod => Res :: ToolMod ,
657667 Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
658668 Res :: Err => Res :: Err ,
@@ -665,7 +675,10 @@ impl<Id> Res<Id> {
665675 Res :: SelfCtor ( id) => Res :: SelfCtor ( id) ,
666676 Res :: PrimTy ( id) => Res :: PrimTy ( id) ,
667677 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+ }
669682 Res :: ToolMod => Res :: ToolMod ,
670683 Res :: NonMacroAttr ( attr_kind) => Res :: NonMacroAttr ( attr_kind) ,
671684 Res :: Err => Res :: Err ,
@@ -692,7 +705,9 @@ impl<Id> Res<Id> {
692705 pub fn ns ( & self ) -> Option < Namespace > {
693706 match self {
694707 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+ }
696711 Res :: SelfCtor ( ..) | Res :: Local ( ..) => Some ( Namespace :: ValueNS ) ,
697712 Res :: NonMacroAttr ( ..) => Some ( Namespace :: MacroNS ) ,
698713 Res :: Err => None ,
0 commit comments