From b05ab18aec28c5025212ad44a202072ed2f610d7 Mon Sep 17 00:00:00 2001 From: Thomas Bahn Date: Sat, 19 Dec 2020 23:13:50 +0100 Subject: Fix pretty printing an AST representing `&(mut ident)` `PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), ..)` is an AST representing `&(mut ident)`. It was errorneously printed as `&mut ident` which reparsed into a syntactically different AST. This affected help diagnostics in the parser. --- src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.rs | 9 +++++++++ .../ui/pattern/issue-80186-mut-binding-help-suggestion.stderr | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.rs create mode 100644 src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.stderr (limited to 'src/test/ui/pattern') diff --git a/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.rs b/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.rs new file mode 100644 index 00000000000..a5e9b1db546 --- /dev/null +++ b/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.rs @@ -0,0 +1,9 @@ +// Regression test for correct pretty-printing of an AST representing `&(mut x)` in help +// suggestion diagnostic. + +fn main() { + let mut &x = &0; + //~^ ERROR `mut` must be attached to each individual binding + //~| HELP add `mut` to each binding + //~| SUGGESTION &(mut x) +} diff --git a/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.stderr b/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.stderr new file mode 100644 index 00000000000..75b6c163b2c --- /dev/null +++ b/src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.stderr @@ -0,0 +1,10 @@ +error: `mut` must be attached to each individual binding + --> $DIR/issue-80186-mut-binding-help-suggestion.rs:5:9 + | +LL | let mut &x = &0; + | ^^^^^^ help: add `mut` to each binding: `&(mut x)` + | + = note: `mut` may be followed by `variable` and `variable @ pattern` + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5