-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let qpath contain NtTy: <$:ty as $:ty>::…
#91150
Conversation
r? @wesleywiser (rust-highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #85346) made this pull request unmergeable. Please resolve the merge conflicts. |
Currently fails: error: expected identifier, found `ToOwned` --> src/test/ui/macros/macro-interpolation.rs:23:19 | LL | <$type as $trait>::$name | ^^^^^^ expected identifier ... LL | let _: qpath!(ty, <str as ToOwned>::Owned); | ----------------------------------- | | | this macro call doesn't expand to a type | in this macro invocation
|
This is very similar to #91166 (comment) (see it for some more details). There's a definitive method to determine whether something interpolated should parse or not - checking how it would work in token-based expansion model (aka "how it would work in proc macro output"), as opposed to AST-based model that is currently used for implementing
Also see #67062 for the current issues with parsing |
The following (where the rhs of macro_rules! m {
(<$t:ty as $p:path>::$name:ident) => {
type $name = <$t as $p>::$name;
};
}
m!(<str as ToOwned>::Owned); so the path parsing already supports the "parentheses" in that position.
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
#[proc_macro]
pub fn repro(_input: TokenStream) -> TokenStream {
// type T = <str as ⟪ToOwned⟫>::Owned;
TokenStream::from_iter([
TokenTree::Ident(Ident::new("type", Span::call_site())),
TokenTree::Ident(Ident::new("T", Span::call_site())),
TokenTree::Punct(Punct::new('=', Spacing::Alone)),
TokenTree::Punct(Punct::new('<', Spacing::Alone)),
TokenTree::Ident(Ident::new("str", Span::call_site())),
TokenTree::Ident(Ident::new("as", Span::call_site())),
TokenTree::Group(Group::new(Delimiter::None, TokenStream::from_iter([
TokenTree::Ident(Ident::new("ToOwned", Span::call_site()))
]))),
TokenTree::Punct(Punct::new('>', Spacing::Alone)),
TokenTree::Punct(Punct::new(':', Spacing::Joint)),
TokenTree::Punct(Punct::new(':', Spacing::Alone)),
TokenTree::Ident(Ident::new("Owned", Span::call_site())),
TokenTree::Punct(Punct::new(';', Spacing::Alone)),
])
}
Given the above, I can't tell what other change you have in mind by this. |
Ah, ok, if
The current parser currently eliminates all |
r? rust-lang/compiler-team |
r? compiler-team |
r? compiler-team (trying to trigger some logs for this case) |
Apologies for the time this has taken to be reviewed. @bors r+ |
📌 Commit 87a7def has been approved by |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#90782 (Implement raw-dylib support for windows-gnu) - rust-lang#91150 (Let qpath contain NtTy: `<$:ty as $:ty>::…`) - rust-lang#92425 (Improve SIMD casts) - rust-lang#92692 (Simplify and unify rustdoc sidebar styles) - rust-lang#92780 (Directly use ConstValue for single literals in blocks) - rust-lang#92924 (Delete pretty printer tracing) - rust-lang#93018 (Remove some unused `Ord` derives based on `Span`) - rust-lang#93026 (fix typo in `max` description for f32/f64) - rust-lang#93035 (Fix stdarch submodule pointing to commit outside tree) Failed merges: - rust-lang#92861 (Rustdoc mobile: put out-of-band info on its own line) r? `@ghost` `@rustbot` modify labels: rollup
Example:
Previous behavior:
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 formTyKind::Path(None, path)
; if it is any other kind ofNtTy
, we'll keep the same behavior as before.