From 5f4424bfaf6fc9c66df6e19a3f5e96b0fc9a1441 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 May 2024 08:59:02 +1000 Subject: [PATCH] Handle `ReVar` in `note_and_explain_region`. PR #124918 made this path abort. The added test, from fuzzing, identified that it is reachable. --- .../rustc_infer/src/infer/error_reporting/mod.rs | 5 ++++- tests/ui/inference/note-and-explain-ReVar-124973.rs | 8 ++++++++ .../inference/note-and-explain-ReVar-124973.stderr | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/ui/inference/note-and-explain-ReVar-124973.rs create mode 100644 tests/ui/inference/note-and-explain-ReVar-124973.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 46a7e7b2399..e0894ed31bf 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -173,7 +173,10 @@ pub(super) fn note_and_explain_region<'tcx>( ty::ReError(_) => return, - ty::ReVar(_) | ty::ReBound(..) | ty::ReErased => { + // FIXME(#125431): `ReVar` shouldn't reach here. + ty::ReVar(_) => (format!("lifetime `{region}`"), alt_span), + + ty::ReBound(..) | ty::ReErased => { bug!("unexpected region for note_and_explain_region: {:?}", region); } }; diff --git a/tests/ui/inference/note-and-explain-ReVar-124973.rs b/tests/ui/inference/note-and-explain-ReVar-124973.rs new file mode 100644 index 00000000000..f1e24645636 --- /dev/null +++ b/tests/ui/inference/note-and-explain-ReVar-124973.rs @@ -0,0 +1,8 @@ +//@ edition:2018 + +#![feature(c_variadic)] + +async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, ...) {} +//~^ ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds + +fn main() {} diff --git a/tests/ui/inference/note-and-explain-ReVar-124973.stderr b/tests/ui/inference/note-and-explain-ReVar-124973.stderr new file mode 100644 index 00000000000..574f6508e4c --- /dev/null +++ b/tests/ui/inference/note-and-explain-ReVar-124973.stderr @@ -0,0 +1,13 @@ +error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds + --> $DIR/note-and-explain-ReVar-124973.rs:5:73 + | +LL | async unsafe extern "C" fn multiple_named_lifetimes<'a, 'b>(_: u8, ...) {} + | ----------------------------------------------------------------------- ^^ + | | + | opaque type defined here + | + = note: hidden type `{async fn body of multiple_named_lifetimes<'a, 'b>()}` captures lifetime `'_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0700`.