Change:
I'll even accept that this is probably UB if I somehow make it work but crashing on is probably not the way. Replacing some with , or with a second lifetime parameter correctly rejects the code. : <details<summary<strongBacktrace</strong</summary<p</p</details
Regression in nightly-2022-06-08 fetching (via remote github) commits from max(, 2022-06-05) to ending github query because we found starting sha: getcommitsbetween returning commits, len: 7 commit[0] 2022-06-06: Auto merge of - flip1995:clippyup, r=Manishearth commit[1] 2022-06-06: Auto merge of - matthiaskrgr:rollup-ajyvjd3, r=matthiaskrgr commit[2] 2022-06-07: Auto merge of - RalfJung:miri, r=RalfJung commit[3] 2022-06-07: Auto merge of - jackh726:remove-borrowck-mode, r=nikomatsakis commit[4] 2022-06-07: Auto merge of - scottmcm:add-coldcc, r=nagisa,lcnr commit[5] 2022-06-07: Auto merge of - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC commit[6] 2022-06-07: Auto merge of - Dylan-DPC:rollup-0ae3pwp, r=Dylan-DPC
Likely .

Discussion:
// search for relevant arguments. let mut arguments = Vec::new(); for (index, argument) in sig.inputs().skip_binder().iter().enumerate() { <del> if let ty::Ref(argument_region, _, _) = argument.kind() { if argument_region == return_region { // Need to use the `rustc_middle::ty` types to compare against the // `return_region`. Then use the `rustc_hir` type to get only // the lifetime span. if let hir::TyKind::Ref(lifetime, _) = &fn_decl.inputs[index].kind { </del> <ins> if let ty::Ref(argument_region, _, _) = argument.kind() && argument_region == return_region { // Need to use the `rustc_middle::ty` types to compare against the // `return_region`. Then use the `rustc_hir` type to get only // the lifetime span. match &fn_decl.inputs[index].kind { hir::TyKind::Ref(lifetime, _) => { </ins> // With access to the lifetime, we can get // the span of it. arguments.push((*argument, lifetime.ident.span)); <del> } else { bug!("ty type is a ref but hir type is not"); </del> <ins> } // Resolve `self` whose self type is `&T`. hir::TyKind::Path(hir::QPath::Resolved(None, path)) => { if let Res::SelfTyAlias { alias_to, .. } = path.res && let Some(alias_to) = alias_to.as_local() && let hir::Impl { self_ty, .. } = self .infcx .tcx .hir_node_by_def_id(alias_to) .expect_item() .expect_impl() && let hir::TyKind::Ref(lifetime, _) = self_ty.kind { arguments.push((*argument, lifetime.ident.span)); } } _ => { // Don't ICE though. It might be a type alias. </ins> } } }

<del> //@ known-bug: #121816 fn f<'a, T>(_: &'static &'a (), x: &'a T) -> &'static T { x } trait W<'a> { fn g<T>(self, x: &'a T) -> &'static T; } impl<'a> W<'a> for &'static () { fn g<T>(self, x: &'a T) -> &'static T { f(&self, x) } } </del>

<ins> // Don't ICE when trying to annotate signature and we see `&()` fn f<'a, T>(_: &'static &'a (), x: &'a T) -> &'static T { x } trait W<'a> { fn g<T>(self, x: &'a T) -> &'static T; } // Frankly this error message is impossible to parse, but :shrug:. impl<'a> W<'a> for &'static () { fn g<T>(self, x: &'a T) -> &'static T { f(&self, x) //~^ ERROR borrowed data escapes outside of method //~| ERROR `self` does not live long enough } } fn main() {} </ins>

<ins> error[E0521]: borrowed data escapes outside of method --> $DIR/ice-on-non-ref-sig-ty.rs:13:9 | LL | impl<'a> W<'a> for &'static () { |      -- lifetime `'a` defined here LL |     fn g<T>(self, x: &'a T) -> &'static T { |             ----  - `x` is a reference that is only valid in the method body |             | |             `self` declared here, outside of the method body LL |         f(&self, x) |         ^^^^^^^^^^^ |         | |         `x` escapes the method body here |         argument requires that `'a` must outlive `'static` error[E0597]: `self` does not live long enough --> $DIR/ice-on-non-ref-sig-ty.rs:13:11 | LL | impl<'a> W<'a> for &'static () { |                     ------- has lifetime `'static` LL |     fn g<T>(self, x: &'a T) -> &'static T { |                                 ------- also has lifetime `'static` LL |         f(&self, x) |           ^^^^^ `self` would have to be valid for `'static`... ... LL |     } |      - ...but `self` will be dropped here, when the function `g` returns | = help: use data from the highlighted arguments which match the `'static` lifetime of the return type = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments = note: to learn more, visit <https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references> error: aborting due to 2 previous errors Some errors have detailed explanations: E0521, E0597. For more information about an error, try `rustc --explain E0521`. </ins>