6

Let qpath contain NtTy: `<$:ty as $:ty>::…` by dtolnay · Pull Request #911...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/91150
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Member

dtolnay commented on Nov 23, 2021

Example:

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

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

Previous behavior:

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 expected identifier, found `ToOwned` 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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK