Skip to content

Fix pretty printing an AST representing &(mut ident) #80205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,15 @@ impl<'a> State<'a> {
if mutbl == ast::Mutability::Mut {
self.s.word("mut ");
}
self.print_pat(inner);
if let PatKind::Ident(ast::BindingMode::ByValue(ast::Mutability::Mut), ..) =
inner.kind
{
self.popen();
self.print_pat(inner);
self.pclose();
} else {
self.print_pat(inner);
}
}
PatKind::Lit(ref e) => self.print_expr(&**e),
PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 10 additions & 0 deletions src/test/ui/pattern/issue-80186-mut-binding-help-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -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