1e88a1769f
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 |
||
---|---|---|
.. | ||
rustc | ||
rustc_apfloat | ||
rustc_arena | ||
rustc_ast | ||
rustc_ast_lowering | ||
rustc_ast_passes | ||
rustc_ast_pretty | ||
rustc_attr | ||
rustc_builtin_macros | ||
rustc_codegen_cranelift | ||
rustc_codegen_llvm | ||
rustc_codegen_ssa | ||
rustc_data_structures | ||
rustc_driver | ||
rustc_error_codes | ||
rustc_errors | ||
rustc_expand | ||
rustc_feature | ||
rustc_fs_util | ||
rustc_graphviz | ||
rustc_hir | ||
rustc_hir_pretty | ||
rustc_incremental | ||
rustc_index | ||
rustc_infer | ||
rustc_interface | ||
rustc_lexer | ||
rustc_lint | ||
rustc_lint_defs | ||
rustc_llvm | ||
rustc_macros | ||
rustc_metadata | ||
rustc_middle | ||
rustc_mir | ||
rustc_mir_build | ||
rustc_parse | ||
rustc_parse_format | ||
rustc_passes | ||
rustc_plugin_impl | ||
rustc_privacy | ||
rustc_query_system | ||
rustc_resolve | ||
rustc_save_analysis | ||
rustc_serialize | ||
rustc_session | ||
rustc_span | ||
rustc_symbol_mangling | ||
rustc_target | ||
rustc_trait_selection | ||
rustc_traits | ||
rustc_ty_utils | ||
rustc_type_ir | ||
rustc_typeck |