about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-18 22:00:43 +0100
committerGitHub <noreply@github.com>2022-01-18 22:00:43 +0100
commitf372476d2cd19fbd4baff24e767f5ee3d8264b49 (patch)
treeaec2a7192a1ce7d5630ddfb9d2a6b574ebc1d310 /src/test
parentdd621a4c5cd967815cdf5ffcbe598a6fd9a3b839 (diff)
parent87a7defa8e08c971a30b152509c6c1ab9f718092 (diff)
downloadrust-f372476d2cd19fbd4baff24e767f5ee3d8264b49.tar.gz
rust-f372476d2cd19fbd4baff24e767f5ee3d8264b49.zip
Rollup merge of #91150 - dtolnay:qpath, r=davidtwco
Let qpath contain NtTy: `<$:ty as $:ty>::…`

Example:

```rust
macro_rules! m {
    (<$type:ty as $trait:ty>::$name:ident) => {
        <$type as $trait>::$name
    };
}

fn main() {
    let _: m!(<str as ToOwned>::Owned);
}
```

Previous behavior:

```console
error: expected identifier, found `ToOwned`
 --> src/main.rs:3:19
  |
3 |         <$type as $trait>::$name
  |                   ^^^^^^ expected identifier
...
8 |     let _: m!(<str as ToOwned>::Owned);
  |            ---------------------------
  |            |
  |            this macro call doesn't expand to a type
  |            in this macro invocation
```

The <code>expected identifier, found \`ToOwned\`</code> error is particularly silly. I think it should be fine to accept this code as long as $trait is of the form `TyKind::Path(None, path)`; if it is any other kind of `NtTy`, we'll keep the same behavior as before.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/macros/macro-interpolation.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/test/ui/macros/macro-interpolation.rs b/src/test/ui/macros/macro-interpolation.rs
index abe1f2aaf15..35003a79ad7 100644
--- a/src/test/ui/macros/macro-interpolation.rs
+++ b/src/test/ui/macros/macro-interpolation.rs
@@ -14,8 +14,20 @@ macro_rules! overly_complicated {
 
 }
 
+macro_rules! qpath {
+    (path, <$type:ty as $trait:path>::$name:ident) => {
+        <$type as $trait>::$name
+    };
+
+    (ty, <$type:ty as $trait:ty>::$name:ident) => {
+        <$type as $trait>::$name
+    };
+}
+
 pub fn main() {
+    let _: qpath!(path, <str as ToOwned>::Owned);
+    let _: qpath!(ty, <str as ToOwned>::Owned);
+
     assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
                                Some(8), Some(y), y) == 8)
-
 }