rust/compiler
Manish Goregaokar 4b568409ad
Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisa
Accept `m!{ .. }.method()` and `m!{ .. }?` statements.

This PR fixes something that I keep running into when using `quote!{}.into()` in a proc macro to convert the `proc_macro2::TokenStream` to a `proc_macro::TokenStream`:

Before:

```
error: expected expression, found `.`
 --> src/lib.rs:6:6
  |
4 |     quote! {
5 |         ...
6 |     }.into()
  |      ^ expected expression
```

After:
```
```
(No output, compiles fine.)

---

Context:

For expressions like `{ 1 }` and `if true { 1 } else { 2 }`, we accept them as full statements without a trailing `;`, which means the following is not accepted:

```rust
{ 1 } - 1 // error
```

since that is parsed as two statements: `{ 1 }` and `-1`. Syntactically correct, but the type of `{ 1 }` should be `()` as there is no `;`.

However, for specifically `.` and `?` after the `}`, we do [continue parsing it as an expression](13db8440bb/compiler/rustc_parse/src/parser/expr.rs (L864-L876)):

```rust
{ "abc" }.len(); // ok
```

For braced macro invocations, we do not do this:

```rust
vec![1, 2, 3].len(); // ok
vec!{1, 2, 3}.len(); // error
```

(It parses `vec!{1, 2, 3}` as a full statement, and then complains about `.len()` not being a valid expression.)

This PR changes this to also look for a `.` and `?` after a braced macro invocation. We can be sure the macro is an expression and not a full statement in those cases, since no statement can start with a `.` or `?`.
2021-09-15 14:56:57 -07:00
..
rustc rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_apfloat rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_arena Remove unused arena macro args 2021-08-30 13:09:38 +02:00
rustc_ast Keep a parent LocalDefId in SpanData. 2021-09-10 20:17:33 +02:00
rustc_ast_lowering Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov 2021-09-11 23:35:28 +00:00
rustc_ast_passes Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_ast_pretty Add let-else to AST 2021-08-30 20:17:45 -05:00
rustc_attr Remove Session.used_attrs and move logic to CheckAttrVisitor 2021-08-21 13:27:27 -05:00
rustc_borrowck Auto merge of #88811 - jackh726:issue-88446, r=nikomatsakis 2021-09-12 17:04:10 +00:00
rustc_builtin_macros Rollup merge of #88209 - Amanieu:asm_in_underscore, r=nagisa 2021-09-11 08:23:40 -07:00
rustc_codegen_cranelift Auto merge of #88839 - nbdd0121:alignof, r=nagisa 2021-09-12 23:49:24 +00:00
rustc_codegen_llvm Auto merge of #87867 - bjorn3:unique_type_id_interner, r=wesleywiser 2021-09-15 12:34:31 +00:00
rustc_codegen_ssa Auto merge of #88839 - nbdd0121:alignof, r=nagisa 2021-09-12 23:49:24 +00:00
rustc_const_eval Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_data_structures Rollup merge of #88711 - Mark-Simulacrum:fix-dfs-bug, r=jackh726 2021-09-12 03:44:57 -07:00
rustc_driver Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
rustc_error_codes Update E0785.md 2021-08-30 22:18:55 -07:00
rustc_errors Auto merge of #87915 - estebank:fancy-spans, r=oli-obk 2021-09-13 16:31:12 +00:00
rustc_expand Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov 2021-09-11 23:35:28 +00:00
rustc_feature Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_fs_util rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_graphviz rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_hir Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_hir_pretty don't convert types into identical types 2021-09-11 10:32:38 +02:00
rustc_incremental Auto merge of #83214 - cjgillot:dep-map, r=michaelwoerister 2021-09-06 23:58:16 +00:00
rustc_index Suggested changes 2021-08-27 16:21:25 -07:00
rustc_infer Rollup merge of #88336 - jackh726:gats-where-constraints, r=estebank 2021-09-12 03:44:53 -07:00
rustc_interface Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoerister 2021-09-15 14:56:56 -07:00
rustc_lexer Fix more “a”/“an” typos 2021-08-22 17:27:18 +02:00
rustc_lint Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_lint_defs Tracking issue for UNSUPPORTED_CALLING_CONVENTIONS 2021-08-27 20:47:00 +03:00
rustc_llvm RustWrapper: remove some uses of AttrBuilder 2021-09-08 10:47:41 -04:00
rustc_macros Use a separate interner type for UniqueTypeId 2021-09-13 14:42:06 +02:00
rustc_metadata Auto merge of #88759 - Amanieu:panic_in_drop, r=nagisa,eddyb 2021-09-12 20:48:09 +00:00
rustc_middle Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_mir_build Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnr 2021-09-12 03:44:56 -07:00
rustc_mir_dataflow Introduce NullOp::AlignOf 2021-09-13 00:08:35 +01:00
rustc_mir_transform Auto merge of #88839 - nbdd0121:alignof, r=nagisa 2021-09-12 23:49:24 +00:00
rustc_monomorphize Rebase fallout. 2021-09-08 20:40:30 +02:00
rustc_parse Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisa 2021-09-15 14:56:57 -07:00
rustc_parse_format rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_passes don't convert types into identical types 2021-09-11 10:32:38 +02:00
rustc_plugin_impl Remove Session.used_attrs and move logic to CheckAttrVisitor 2021-08-21 13:27:27 -05:00
rustc_privacy add a CastKind to Node::Cast 2021-09-09 01:32:03 +01:00
rustc_query_impl Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnr 2021-09-12 03:44:56 -07:00
rustc_query_system Auto merge of #78780 - cjgillot:req, r=Mark-Simulacrum 2021-09-11 20:39:47 +00:00
rustc_resolve Auto merge of #87915 - estebank:fancy-spans, r=oli-obk 2021-09-13 16:31:12 +00:00
rustc_save_analysis Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_serialize rustc: Remove local variable IDs from Exports 2021-09-10 23:41:48 +03:00
rustc_session Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoerister 2021-09-15 14:56:56 -07:00
rustc_span Use a separate interner type for UniqueTypeId 2021-09-13 14:42:06 +02:00
rustc_symbol_mangling Rollup merge of #85534 - csmoe:demagnle-assert, r=michaelwoerister 2021-08-29 16:25:28 +02:00
rustc_target Auto merge of #87794 - bonega:enum_niche_prefer_zero, r=nagisa 2021-09-13 22:14:57 +00:00
rustc_trait_selection Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk 2021-09-15 03:51:03 +00:00
rustc_traits Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth 2021-08-27 01:07:17 +00:00
rustc_ty_utils Remove the queries 2021-09-09 05:21:32 +00:00
rustc_type_ir Use index newtyping for TyVid 2021-09-06 22:38:06 -04:00
rustc_typeck Auto merge of #87915 - estebank:fancy-spans, r=oli-obk 2021-09-13 16:31:12 +00:00