Skip to content

Commit

Permalink
Rollup merge of rust-lang#65893 - jafern14:let-expr-stable-error-mess…
Browse files Browse the repository at this point in the history
…aging, r=Centril

Output previous stable  error messaging when using stable build.

Fixes rust-lang#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??
  • Loading branch information
Centril committed Oct 28, 2019
2 parents 5451664 + f1aa8b2 commit 30431a3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/librustc/hir/lowering/expr.rs
Expand Up @@ -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:
// ```
Expand Down

0 comments on commit 30431a3

Please sign in to comment.