Change:
The code Emits this diagnostic, which is wrong in this case. It should say cc: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
Cannot reproduce: the code snippet as given produces on stable 1.78.0
Did you mean to write this code snippet instead?
Ooops yes :sweat_smile:, edited
claim

Discussion:
Some(ty) => { let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id]; // Typeck doesn't expect erased regions to be returned from `type_of`. <ins> // This is a heuristic approach. If the scope has region paramters, // we should change fn_sig's lifetime from `ReErased` to `ReError`, // otherwise to `ReStatic`. let has_region_params = generics.params.iter().any(|param| match param.kind { GenericParamKind::Lifetime { .. } => true, _ => false, }); </ins> let fn_sig = tcx.fold_regions(fn_sig, |r, _| match *r { <del> ty::ReErased => tcx.lifetimes.re_static, </del> <ins> ty::ReErased => { if has_region_params { ty::Region::new_error_with_message( tcx, DUMMY_SP, "erased region is not allowed here in return type", ) } else { tcx.lifetimes.re_static } } </ins> _ => r, });

<ins> //@ run-rustfix #[allow(dead_code)] fn main() { struct S<'a>(&'a ()); fn f1(s: S<'_>) -> S<'_> { //~^ ERROR the placeholder `_` is not allowed s } fn f2(s: S<'_>) -> S<'_> { //~^ ERROR the placeholder `_` is not allowed let x = true; if x { s } else { s } } fn f3(s: S<'_>) -> S<'_> { //~^ ERROR the placeholder `_` is not allowed return s; } fn f4(s: S<'_>) -> S<'_> { //~^ ERROR the placeholder `_` is not allowed let _x = 1; return s; } } </ins>

<ins> //@ run-rustfix #[allow(dead_code)] fn main() { struct S<'a>(&'a ()); fn f1(s: S<'_>) -> _ { //~^ ERROR the placeholder `_` is not allowed s } fn f2(s: S<'_>) -> _ { //~^ ERROR the placeholder `_` is not allowed let x = true; if x { s } else { s } } fn f3(s: S<'_>) -> _ { //~^ ERROR the placeholder `_` is not allowed return s; } fn f4(s: S<'_>) -> _ { //~^ ERROR the placeholder `_` is not allowed let _x = 1; return s; } } </ins>

<ins> error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:8:24 | LL |     fn f1(s: S<'_>) -> _ { |                        ^ |                        | |                        not allowed in type signatures |                        help: replace with the correct return type: `S<'_>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:13:24 | LL |     fn f2(s: S<'_>) -> _ { |                        ^ |                        | |                        not allowed in type signatures |                        help: replace with the correct return type: `S<'_>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:23:24 | LL |     fn f3(s: S<'_>) -> _ { |                        ^ |                        | |                        not allowed in type signatures |                        help: replace with the correct return type: `S<'_>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:28:24 | LL |     fn f4(s: S<'_>) -> _ { |                        ^ |                        | |                        not allowed in type signatures |                        help: replace with the correct return type: `S<'_>` error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0121`. </ins>

fn test11(x: &usize) -> &_ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types <del> &x //~ ERROR cannot return reference to function parameter </del> <ins> &x </ins> } unsafe fn test12(x: *const usize) -> *const *const _ {

|                         -^ |                         || |                         |not allowed in type signatures <del> |                         help: replace with the correct return type: `&'static &'static usize` </del> <ins> |                         help: replace with the correct return type: `&&usize` </ins> error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/typeck_type_placeholder_item.rs:53:52

LL + #![feature(const_trait_impl)] | <del> error[E0515]: cannot return reference to function parameter `x` --> $DIR/typeck_type_placeholder_item.rs:50:5 | LL |     &x |     ^^ returns a reference to data owned by the current function error: aborting due to 75 previous errors </del> <ins> error: aborting due to 74 previous errors </ins> <del> Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403, E0515. </del> <ins> Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. </ins> For more information about an error, try `rustc --explain E0015`.