about summary refs log tree commit diff
path: root/src/librustdoc/html/static/source-script.js
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-21 10:21:01 +0000
committerbors <bors@rust-lang.org>2020-12-21 10:21:01 +0000
commit1e88a1769f69f944e16cba13ba174c1d6e494b36 (patch)
tree980edb53a39fd9cb78557816416fadcf30166bb1 /src/librustdoc/html/static/source-script.js
parent463ce4042835526f0bd7bf50d6905ed7e2004a2e (diff)
parentb05ab18aec28c5025212ad44a202072ed2f610d7 (diff)
downloadrust-1e88a1769f69f944e16cba13ba174c1d6e494b36.tar.gz
rust-1e88a1769f69f944e16cba13ba174c1d6e494b36.zip
Auto merge of #80205 - tomprogrammer:prettyprint-pattern-mut-binding, r=davidtwco
Fix pretty printing an AST representing `&(mut ident)`

The PR fixes a misguiding help diagnostic in the parser that I reported in #80186. I discovered that the parsers recovery and reporting logic was correct but the pretty printer produced wrong code for the example. (Details in https://github.com/rust-lang/rust/issues/80186#issuecomment-748498676)

Example:
```rust
#![allow(unused_variables)]
fn main() {
    let mut &x = &0;
}
```

The AST fragment

`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), Mutability::Not)`

was printed to be `&mut ident`. But this wouldn't round trip through parsing again, because then it would be:

`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Not), ..), Mutability::Mut)`

Now the pretty-printer prints `&(mut ident)`. Reparsing that code results in the AST fragment

`PatKind::Ref(PatKind::Paren(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..)), Mutability::Not)`

which I think should behave like the original pattern.

Old diagnostic:
```
error: `mut` must be attached to each individual binding
 --> src/main.rs:3:9
  |
3 |     let mut &x = &0;
  |         ^^^^^^ help: add `mut` to each binding: `&mut x`
  |
  = note: `mut` may be followed by `variable` and `variable @ pattern`
```

New diagnostic:

```
error: `mut` must be attached to each individual binding
 --> src/main.rs:3:9
  |
3 |     let mut &x = &0;
  |         ^^^^^^ help: add `mut` to each binding: `&(mut x)`
  |
  = note: `mut` may be followed by `variable` and `variable @ pattern`
```

Fixes #80186
Diffstat (limited to 'src/librustdoc/html/static/source-script.js')
0 files changed, 0 insertions, 0 deletions