@@ -266,57 +266,65 @@ 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
- ///
294
- /// ```
290
+ ///
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.
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.
316
322
SelfTy {
317
- /// Optionally, the trait associated with this `Self` type .
323
+ /// The trait this `Self` is a generic arg for .
318
324
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).
320
328
alias_to : Option < ( DefId , bool ) > ,
321
329
} ,
322
330
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
0 commit comments