Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --<!-- 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. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
Assigning priority as discussed in the of the Prioritization Working Group. label -I-prioritize +P-low
This is a regression considering it doesn't happen in beta.

Discussion:
}; let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id); <del> let encl_item = self.tcx.hir().expect_item(encl_item_id); if let hir::ItemKind::Fn(..) = encl_item.kind { </del> <ins> if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), span: encl_fn_span, .. })) | Some(hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)), span: encl_fn_span, .. })) | Some(hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), span: encl_fn_span, .. })) = self.tcx.hir().find(encl_item_id) { </ins> // We are inside a function body, so reporting "return statement // outside of function body" needs an explanation.

let encl_body = self.tcx.hir().body(encl_body_id); err.encl_body_span = Some(encl_body.value.span); <del> err.encl_fn_span = Some(encl_item.span); </del> <ins> err.encl_fn_span = Some(*encl_fn_span); </ins> } self.tcx.sess.emit_err(err);

}] }; <ins> struct S {} trait Tr { fn foo(); fn bar() { //~^ NOTE: ...not the enclosing function body [(); return]; //~^ ERROR: return statement outside of function body [E0572] //~| NOTE: the return is part of this body... } } impl Tr for S { fn foo() { //~^ NOTE: ...not the enclosing function body [(); return]; //~^ ERROR: return statement outside of function body [E0572] //~| NOTE: the return is part of this body... } } </ins> fn main() { //~^ NOTE: ...not the enclosing function body [(); return || {

| |_____^ error[E0572]: return statement outside of function body <del> --> $DIR/issue-86188-return-not-in-fn-body.rs:17:10 </del> <ins> --> $DIR/issue-86188-return-not-in-fn-body.rs:20:14 | LL | /     fn bar() { LL | | LL | |         [(); return]; | |              ^^^^^^ the return is part of this body... LL | | LL | | LL | |     } | |_____- ...not the enclosing function body error[E0572]: return statement outside of function body --> $DIR/issue-86188-return-not-in-fn-body.rs:28:14 | LL | /     fn foo() { LL | | LL | |         [(); return]; | |              ^^^^^^ the return is part of this body... LL | | LL | | LL | |     } | |_____- ...not the enclosing function body error[E0572]: return statement outside of function body --> $DIR/issue-86188-return-not-in-fn-body.rs:36:10 </ins> | LL |  / fn main() { LL |  |

LL |  | } |  |_- ...not the enclosing function body <del> error: aborting due to 2 previous errors </del> <ins> error: aborting due to 4 previous errors </ins> For more information about this error, try `rustc --explain E0572`.

<ins> error[E0572]: return statement outside of function body --> $DIR/issue-86721-return-expr-ice.rs:9:22 | LL |     const U: usize = return; |                      ^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0572`. </ins>

<ins> error[E0572]: return statement outside of function body --> $DIR/issue-86721-return-expr-ice.rs:15:20 | LL |     fn foo(a: [(); return]); |                    ^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0572`. </ins>

<ins> // Regression test for the ICE described in #86721. // revisions: rev1 rev2 #![cfg_attr(any(), rev1, rev2)] #![crate_type="lib"] #[cfg(any(rev1))] trait T { const U: usize = return; //[rev1]~^ ERROR: return statement outside of function body [E0572] } #[cfg(any(rev2))] trait T2 { fn foo(a: [(); return]); //[rev2]~^ ERROR: return statement outside of function body [E0572] } </ins>