From 2f4e86b9ef457ff7b465e73e3aaabfcaa1d9d8e1 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 30 Jul 2021 11:30:12 -0500 Subject: Enforce diverging let...else --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'compiler/rustc_infer/src/infer') diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 299dcf5f17a..d54933841fd 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -781,6 +781,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ); } } + ObligationCauseCode::LetElse => { + err.help("try adding a diverging expression, such as `return` or `panic!(..)`"); + err.help("...or use `match` instead of `let...else`"); + } _ => (), } } @@ -2592,6 +2596,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> { } IfExpression { .. } => Error0308("`if` and `else` have incompatible types"), IfExpressionWithNoElse => Error0317("`if` may be missing an `else` clause"), + LetElse => Error0308("`else` clause of `let...else` does not diverge"), MainFunctionType => Error0580("`main` function has wrong type"), StartFunctionType => Error0308("`#[start]` function has wrong type"), IntrinsicType => Error0308("intrinsic has wrong type"), -- cgit 1.4.1-3-g733a5