diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-11-29 04:23:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-29 04:23:24 +0100 |
| commit | 8cfdccf7c87f2d87a72f0b60ea2d16218ca27fb8 (patch) | |
| tree | 866c2abaacd8cdea6a9f2001490c45230311d8f1 /compiler/rustc_passes/src | |
| parent | b7016ae20591cbe2da3f4b747d69714dd690c158 (diff) | |
| parent | dd5abb50cc08a212d23be1fb8482ae166e9bc738 (diff) | |
| download | rust-8cfdccf7c87f2d87a72f0b60ea2d16218ca27fb8.tar.gz rust-8cfdccf7c87f2d87a72f0b60ea2d16218ca27fb8.zip | |
Rollup merge of #118419 - compiler-errors:await-span2, r=cjgillot
Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context This PR does 2 things: 1. Refuses to lower `.await` or `yield` when we are outside of the right coroutine context for the operator. Instead, we lower to `hir::ExprKind::Err`, to silence subsequent redundant errors. 2. Reworks a bit of the span tracking in `LoweringContext` to fix a bad span when we have something like `let x = [0; async_fn().await]` where the `await` is inside of an anon const. The span for the "item" still kinda sucks, since it overlaps with the `await` span, but at least it's accurate.
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_const.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 9 |
2 files changed, 4 insertions, 14 deletions
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index de96746e215..76c7467346d 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -17,7 +17,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::parse::feature_err; use rustc_span::{sym, Span, Symbol}; -use crate::errors::{ExprNotAllowedInContext, SkippingConstChecks}; +use crate::errors::SkippingConstChecks; /// An expression that is not *always* legal in a const context. #[derive(Clone, Copy)] @@ -138,11 +138,10 @@ impl<'tcx> CheckConstVisitor<'tcx> { match missing_gates.as_slice() { [] => { - tcx.sess.emit_err(ExprNotAllowedInContext { + span_bug!( span, - expr: expr.name(), - context: const_kind.keyword_name(), - }); + "we should not have reached this point, since `.await` is denied earlier" + ); } [missing_primary, ref missing_secondary @ ..] => { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 411c9410195..58127445322 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1005,15 +1005,6 @@ pub struct FeaturePreviouslyDeclared<'a, 'b> { pub prev_declared: &'b str, } -#[derive(Diagnostic)] -#[diag(passes_expr_not_allowed_in_context, code = "E0744")] -pub struct ExprNotAllowedInContext<'a> { - #[primary_span] - pub span: Span, - pub expr: String, - pub context: &'a str, -} - pub struct BreakNonLoop<'a> { pub span: Span, pub head: Option<Span>, |
