Skip to content

Commit 30431a3

Browse files
authored
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??
2 parents 5451664 + f1aa8b2 commit 30431a3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/librustc/hir/lowering/expr.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,20 @@ impl LoweringContext<'_> {
235235
/// ```
236236
fn lower_expr_let(&mut self, span: Span, pat: &Pat, scrutinee: &Expr) -> hir::ExprKind {
237237
// If we got here, the `let` expression is not allowed.
238-
self.sess
239-
.struct_span_err(span, "`let` expressions are not supported here")
240-
.note("only supported directly in conditions of `if`- and `while`-expressions")
241-
.note("as well as when nested within `&&` and parenthesis in those conditions")
242-
.emit();
238+
239+
if self.sess.opts.unstable_features.is_nightly_build() {
240+
self.sess
241+
.struct_span_err(span, "`let` expressions are not supported here")
242+
.note("only supported directly in conditions of `if`- and `while`-expressions")
243+
.note("as well as when nested within `&&` and parenthesis in those conditions")
244+
.emit();
245+
}
246+
else {
247+
self.sess
248+
.struct_span_err(span, "expected expression, found statement (`let`)")
249+
.note("variable declaration using `let` is a statement")
250+
.emit();
251+
}
243252

244253
// For better recovery, we emit:
245254
// ```

0 commit comments

Comments
 (0)