Rollup merge of #65893 - jafern14:let-expr-stable-error-messaging, r=Centril
Output previous stable error messaging when using stable build. Fixes #65254 As I had mentioned previously there I have the logic running right now however I'm not getting the exact same syntax highlighting as there was originally for this error. I'm currently getting the following: ``` error: expected expression, found statement (`let`) --> src/main.rs:2:14 | 2 | let x = (let y = 6); | ^^^^^^^^^ | = note: variable declaration using `let` is a statement ``` I'd like to get the following instead: ``` | let x = (let y = 6); | ^^^ ``` My current understanding is that the `span` being passed into `lower_expr_let` is coming from `lowering.rs`. I still don't know how the byte range is calculated for the erroneous syntax and need to look into it a bit more. In the meantime does anybody have any hints/tips regarding this??
This commit is contained in:
commit
30431a33ea
1 changed files with 14 additions and 5 deletions
|
|
@ -235,11 +235,20 @@ impl LoweringContext<'_> {
|
|||
/// ```
|
||||
fn lower_expr_let(&mut self, span: Span, pat: &Pat, scrutinee: &Expr) -> hir::ExprKind {
|
||||
// If we got here, the `let` expression is not allowed.
|
||||
self.sess
|
||||
.struct_span_err(span, "`let` expressions are not supported here")
|
||||
.note("only supported directly in conditions of `if`- and `while`-expressions")
|
||||
.note("as well as when nested within `&&` and parenthesis in those conditions")
|
||||
.emit();
|
||||
|
||||
if self.sess.opts.unstable_features.is_nightly_build() {
|
||||
self.sess
|
||||
.struct_span_err(span, "`let` expressions are not supported here")
|
||||
.note("only supported directly in conditions of `if`- and `while`-expressions")
|
||||
.note("as well as when nested within `&&` and parenthesis in those conditions")
|
||||
.emit();
|
||||
}
|
||||
else {
|
||||
self.sess
|
||||
.struct_span_err(span, "expected expression, found statement (`let`)")
|
||||
.note("variable declaration using `let` is a statement")
|
||||
.emit();
|
||||
}
|
||||
|
||||
// For better recovery, we emit:
|
||||
// ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue