From d6c63bdb2188d4c90cf0e9958d7744834a132072 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 9 May 2024 11:56:38 +1000 Subject: [PATCH] Fix up `DescriptionCtx::new`. The comment mentions that `ReBound` and `ReVar` aren't expected here. Experimentation with the full test suite indicates this is true, and that `ReErased` also doesn't occur. So the commit introduces `bug!` for those cases. (If any of them show up later on, at least we'll have a test case.) The commit also remove the first sentence in the comment. `RePlaceholder` is now handled in the match arm above this comment and nothing is printed for it, so that sentence is just wrong. Furthermore, issue #13998 was closed some time ago. --- compiler/rustc_infer/src/errors/note_and_explain.rs | 10 +--------- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 8 +++----- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 70d94873530e..c7f07ebed973 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -69,16 +69,8 @@ impl<'a> DescriptionCtx<'a> { ty::RePlaceholder(_) | ty::ReError(_) => return None, - // FIXME(#13998) RePlaceholder should probably print like - // ReLateParam rather than dumping Debug output on the user. - // - // We shouldn't really be having unification failures with ReVar - // and ReBound though. - // - // FIXME(@lcnr): figure out why we have to handle `ReBound` - // here, this feels somewhat off. ty::ReVar(_) | ty::ReBound(..) | ty::ReErased => { - (alt_span, "revar", format!("{region:?}")) + bug!("unexpected region for DescriptionCtx: {:?}", region); } }; Some(DescriptionCtx { span, kind, arg }) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 635bbca37ecc..cb5be47e3046 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -172,11 +172,9 @@ pub(super) fn note_and_explain_region<'tcx>( ty::ReError(_) => return, - // We shouldn't really be having unification failures with ReVar - // and ReBound though. - // - // FIXME(@lcnr): Figure out whether this is reachable and if so, why. - ty::ReVar(_) | ty::ReBound(..) | ty::ReErased => (format!("lifetime `{region}`"), alt_span), + ty::ReVar(_) | ty::ReBound(..) | ty::ReErased => { + bug!("unexpected region for note_and_explain_region: {:?}", region); + } }; emit_msg_span(err, prefix, description, span, suffix);