rust/compiler
bors 1e88a1769f 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
2020-12-21 10:21:01 +00:00
..
rustc
rustc_apfloat
rustc_arena Use specialization to avoid copying 2020-11-20 21:02:09 +01:00
rustc_ast docs: Edit rustc_ast::token::Token 2020-12-17 11:55:49 -08:00
rustc_ast_lowering Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper 2020-12-17 11:43:55 +09:00
rustc_ast_passes Change the message for if_let_guard feature gate 2020-12-17 17:08:18 +01:00
rustc_ast_pretty Fix pretty printing an AST representing &(mut ident) 2020-12-20 13:11:07 +01:00
rustc_attr Get rid of clean::Deprecation 2020-12-14 22:00:46 -05:00
rustc_builtin_macros fix clippy::unnecessary_filter_map 2020-12-11 23:02:19 +01:00
rustc_codegen_cranelift Make BoundRegion have a kind of BoungRegionKind 2020-12-18 15:27:28 -05:00
rustc_codegen_llvm Revert "cg_llvm: fewer_names in uncached_llvm_type" 2020-12-17 16:40:47 +00:00
rustc_codegen_ssa Use pointer type in AtomicPtr::swap implementation 2020-12-20 00:00:00 +00:00
rustc_data_structures Rollup merge of #79612 - jyn514:compiler-links, r=Aaron1011 2020-12-19 15:16:03 +09:00
rustc_driver Fix unknown-crate when using self-profile with rustdoc 2020-12-01 12:54:03 -05:00
rustc_error_codes Rollup merge of #79639 - sasurau4:feature/add-long-explanation-E0212, r=GuillaumeGomez 2020-12-10 21:33:04 -08:00
rustc_errors Switch compiler/ to intra-doc links 2020-12-18 15:22:51 -05:00
rustc_expand implement edition-specific :pat behavior for 2015/18 2020-12-19 07:13:36 -06:00
rustc_feature tidy: Re-enable check for inline unit tests 2020-12-12 19:18:44 +03:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #79073 - davidtwco:issue-78957-const-param-attrs, r=lcnr 2020-12-19 04:32:50 +00:00
rustc_hir_pretty Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper 2020-12-17 11:43:55 +09:00
rustc_incremental Auto merge of #74967 - Aaron1011:feature/incr-def-path-table, r=pnkfelix 2020-12-01 14:30:02 +00:00
rustc_index Switch compiler/ to intra-doc links 2020-12-18 15:22:51 -05:00
rustc_infer Auto merge of #80163 - jackh726:binder-refactor-part-3, r=lcnr 2020-12-20 07:01:00 +00:00
rustc_interface Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
rustc_lexer Fix typo 2020-12-18 22:13:25 +09:00
rustc_lint Move binder for dyn to each list item 2020-12-11 15:02:46 -05:00
rustc_lint_defs Validate naked functions definitions 2020-12-07 00:00:00 +00:00
rustc_llvm llvm: update ffi bindings for split dwarf 2020-12-16 10:31:42 +00:00
rustc_macros Stop using intermediate macros in definition of symbols 2020-12-17 15:20:45 -08:00
rustc_metadata Rollup merge of #80039 - LeSeulArtichaut:rm-tyencoder-tcx, r=matthewjasper 2020-12-17 11:44:03 +09:00
rustc_middle Rollup merge of #80171 - pierwill:pierwill-rustcmiddle-tykind, r=lcnr 2020-12-21 02:47:41 +01:00
rustc_mir Rollup merge of #80199 - RalfJung:const-fake, r=oli-obk 2020-12-21 02:47:42 +01:00
rustc_mir_build Auto merge of #80104 - Nadrieril:usefulness-merging, r=varkor 2020-12-19 19:14:04 +00:00
rustc_parse implement edition-specific :pat behavior for 2015/18 2020-12-19 07:13:36 -06:00
rustc_parse_format
rustc_passes Auto merge of #79073 - davidtwco:issue-78957-const-param-attrs, r=lcnr 2020-12-19 04:32:50 +00:00
rustc_plugin_impl Store ForeignItem in a side table. 2020-11-26 21:29:27 +01:00
rustc_privacy Move binder for dyn to each list item 2020-12-11 15:02:46 -05:00
rustc_query_system Use def_path_hash_to_def_id when re-using a RawDefId 2020-12-10 16:04:19 -05:00
rustc_resolve Move std_path construction into condition 2020-12-20 23:55:03 +01:00
rustc_save_analysis Remove ForeignMod struct. 2020-11-26 21:32:27 +01:00
rustc_serialize Fix some clippy lints 2020-12-03 17:08:19 -05:00
rustc_session Rollup merge of #80073 - kulikjak:add-target-alias-support, r=varkor 2020-12-17 11:44:08 +09:00
rustc_span Rollup merge of #80130 - pierwill:patch-7, r=oli-obk 2020-12-18 16:22:07 +01:00
rustc_symbol_mangling Make BoundRegion have a kind of BoungRegionKind 2020-12-18 15:27:28 -05:00
rustc_target Add support for target aliases 2020-12-16 10:41:07 +01:00
rustc_trait_selection Handle desugaring in impl trait bound suggestion 2020-12-19 20:37:51 -05:00
rustc_traits Make BoundRegion have a kind of BoungRegionKind 2020-12-18 15:27:28 -05:00
rustc_ty_utils Be cautious of calling upvar_tys before mir 2020-11-29 19:20:28 -05:00
rustc_type_ir Fix typo in DebruijnIndex documentation 2020-12-12 16:13:06 +01:00
rustc_typeck Rollup merge of #80170 - ldm0:fixice, r=lcnr 2020-12-21 02:47:39 +01:00