Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. --I tried this code: I expected to see this happen: the lifetime is correctly inferred when using Instead, this happened: I have to use one of the work arounds described in the linked code. Swap from GAT lifetime to the trait parameterized by a lifetime it works: <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
Interested in fixing this. I think all we need to do is treat like other paths with elided lifetimes (e.g. ). you're the go-to person for GATs, right? If so, does that sound correct? Secondly I might also put up a PR that suggests adding when parsing since that's also what's wrong with the second solution. claim
ah yes, good catch, the second solution does work with . In the way I had originally encountered this it didn't work without more nightly features () - a GAT, on a trait, on a , which parametrized a trait. Which left the type alias way the only way around.
I don't know if I've looked at this code before. But seems about right. I'm wondering if something like works and there's just code somewhere that doesn't take into account that the associated type itself can have substs.
This might be a little bit difficult though. When using a concrete struck like , we can infer that lifetime because we know how it's used in the struct itself. With associated types, we don't know, necessarily. In a way, I would expect that to be somewhat opaque, tbh. I'm not sure how I feel about this tbh. If you can fix it, I'd probably want to get some second thoughts before merging.

Discussion:
let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count; let infer_lifetimes = <del> gen_pos != GenericArgPosition::Type && !gen_args.has_lifetime_params(); </del> <ins> (gen_pos != GenericArgPosition::Type || infer_args) && !gen_args.has_lifetime_params(); </ins> if gen_pos != GenericArgPosition::Type && !gen_args.bindings.is_empty() { Self::prohibit_assoc_ty_binding(tcx, gen_args.bindings[0].span);

) -> subst::GenericArg<'tcx> { let tcx = self.astconv.tcx(); match param.kind { <del> GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(), </del> <ins> GenericParamDefKind::Lifetime => self .astconv .re_infer(Some(param), self.span) .unwrap_or_else(|| { debug!(?param, "unelided lifetime in signature"); // This indicates an illegal lifetime in a non-assoc-trait position tcx.sess.delay_span_bug(self.span, "unelided lifetime in signature"); // Supply some dummy value. We don't have an // `re_error`, annoyingly, so use `'static`. tcx.lifetimes.re_static }) .into(), </ins> GenericParamDefKind::Type { has_default, .. } => { if !infer_args && has_default { // No type parameter provided, but a default exists.

<ins> #![feature(generic_associated_types)] #![allow(unused)] pub trait Trait  { type Assoc<'a> where Self: 'a; fn f(&self) -> Self::Assoc<'_>; // Disallow elision in return position, for now fn g(&self) -> Self::Assoc; //~^ ERROR missing generics for associated type `Trait::Assoc` } pub struct Struct { item: f32 } pub struct GenericStruct<'a> { ref_item: &'a f32 } impl Trait for Struct { type Assoc<'a> = GenericStruct<'a>; fn f(&self) -> Self::Assoc<'_> { Self::Assoc { ref_item: &self.item } } // Disallow elision in return position, for now fn g(&self) -> Self::Assoc { //~^ ERROR missing generics for associated type `Trait::Assoc` todo!() } } fn main() {} </ins>

<ins> error[E0107]: missing generics for associated type `Trait::Assoc` --> $DIR/elided-in-expr-position.rs:10:26 | LL |     fn g(&self) -> Self::Assoc; |                          ^^^^^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` --> $DIR/elided-in-expr-position.rs:5:10 | LL |     type Assoc<'a> where Self: 'a; |          ^^^^^ -- help: add missing lifetime argument | LL |     fn g(&self) -> Self::Assoc<'_>; |                          ~~~~~~~~~ error[E0107]: missing generics for associated type `Trait::Assoc` --> $DIR/elided-in-expr-position.rs:32:26 | LL |     fn g(&self) -> Self::Assoc { |                          ^^^^^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` --> $DIR/elided-in-expr-position.rs:5:10 | LL |     type Assoc<'a> where Self: 'a; |          ^^^^^ -- help: add missing lifetime argument | LL |     fn g(&self) -> Self::Assoc<'_> { |                          ~~~~~~~~~ error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0107`. </ins>