Change:
<!-- [31mICE[0m: Rustc '' 'error: internal compiler error: expected lifetime parameter, but found another generic parameter', 'error: internal compiler error: expected lifetime parameter, but found another generic parameter' File: --auto-reduced (treereduce-rust): original: Version information ` Command: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongProgram output</strong</summary<p</p</details<!-- query stack: [collectreturnpositionimpltraitintraittys] comparing an impl and trait method signature, inferring any hidden types in the process [typeof] computing type of --
cc

Discussion:
num_trait_args, num_impl_args, def_id, <del> impl_def_id: impl_m.container_id(tcx), </del> <ins> impl_m_def_id: impl_m.def_id, </ins> ty, return_span, }) {

struct RemapHiddenTyRegions<'tcx> { tcx: TyCtxt<'tcx>, <ins> /// Map from early/late params of the impl to identity regions of the RPITIT (GAT) /// in the trait. </ins> map: FxIndexMap<ty::Region<'tcx>, ty::Region<'tcx>>, num_trait_args: usize, num_impl_args: usize, <ins> /// Def id of the RPITIT (GAT) in the *trait*. </ins> def_id: DefId, <del> impl_def_id: DefId, </del> <ins> /// Def id of the impl method which owns the opaque hidden type we're remapping. impl_m_def_id: DefId, /// The hidden type we're remapping. Useful for diagnostics. </ins> ty: Ty<'tcx>, <ins> /// Span of the return type. Useful for diagnostics. </ins> return_span: Span, }

ty::ReLateParam(_) => {} // Remap early-bound regions as long as they don't come from the `impl` itself, // in which case we don't really need to renumber them. <del> ty::ReEarlyParam(ebr) if ebr.index >= self.tcx.generics_of(self.impl_def_id).count() as u32 => {} </del> <ins> ty::ReEarlyParam(ebr) if ebr.index as usize >= self.num_impl_args => {} </ins> _ => return Ok(region), }

); } } else { <del> let guar = match region.opt_param_def_id(self.tcx, self.tcx.parent(self.def_id)) { </del> <ins> let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) { </ins> Some(def_id) => { let return_span = if let ty::Alias(ty::Opaque, opaque_ty) = self.ty.kind() { self.tcx.def_span(opaque_ty.def_id)

let param = self.param_at(param.index as usize, tcx); match param.kind { GenericParamDefKind::Lifetime => param, <del> _ => bug!("expected lifetime parameter, but found another generic parameter"), </del> <ins> _ => { bug!("expected lifetime parameter, but found another generic parameter: {param:#?}") } </ins> } }

let param = self.param_at(param.index as usize, tcx); match param.kind { GenericParamDefKind::Type { .. } => param, <del> _ => bug!("expected type parameter, but found another generic parameter"), </del> <ins> _ => bug!("expected type parameter, but found another generic parameter: {param:#?}"), </ins> } }

let param = self.param_at(param.index as usize, tcx); match param.kind { GenericParamDefKind::Const { .. } => param, <del> _ => bug!("expected const parameter, but found another generic parameter"), </del> <ins> _ => bug!("expected const parameter, but found another generic parameter: {param:#?}"), </ins> } }

<del> //@ known-bug: rust-lang/rust#129850 pub trait Foo2 { fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>; } impl Foo2 for () { fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {} } </del>

<ins> // Make sure we don't ICE when an RPITIT captures more method args than the // trait definition, which is not allowed. Due to the default lifetime capture // rules of RPITITs, this is only doable if we use precise capturing. pub trait Foo { fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits } impl Foo for () { fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} //~^ ERROR return type captures more lifetimes than trait definition //~| WARN impl trait in impl method signature does not match trait method signature } fn main() {} </ins>

<ins> error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits --> $DIR/rpitit-captures-more-method-lifetimes.rs:6:53 | LL |     fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; |                                                     ^^^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope error: return type captures more lifetimes than trait definition --> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 | LL |     fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} |            ---                         ^^^^^^^^^^^^^^^^ |            | |            this lifetime was captured | note: hidden type must only reference lifetimes captured by this impl trait --> $DIR/rpitit-captures-more-method-lifetimes.rs:6:40 | LL |     fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; |                                        ^^^^^^^^^^^^^^^^^^^^^^ = note: hidden type inferred to be `impl Sized + 'im` warning: impl trait in impl method signature does not match trait method signature --> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 | LL |     fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; |                                        ---------------------- return type from trait method defined here ... LL |     fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} |                                        ^^^^^^^^^^^^^^^^ | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information = note: `#[warn(refining_impl_trait_reachable)]` on by default help: replace the return type so that it matches the trait | LL |     fn bar<'im: 'im>(&'im mut self) -> impl Sized {} |                                        ~~~~~~~~~~ error: aborting due to 2 previous errors; 1 warning emitted </ins>