-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Don't give APITs names with macro expansion placeholder fragments in it #142393
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
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
This PR changes a file inside |
LL | let () = x; | ||
| ^^ - this expression has type `impl Foo<bar!()>` | ||
| | | ||
| expected type parameter `impl Foo<bar!()>`, found `()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For contrast, this used to render like impl Foo<!()>
, where !()
is the placeholder fragment.
r=me if @petrochenkov is happy since he's also assigned |
compiler/rustc_expand/src/expand.rs
Outdated
let id = *id; | ||
let name = Symbol::intern(&pprust::ty_to_string(node).replace('\n', " ")); | ||
self.cx.resolver.insert_impl_trait_name(id, name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike this part in particular.
Perhaps the insert_impl_trait_name
call can be moved to InvocationCollectorNode::walk
on types?
In that case the node ID will already be assigned.
It will be also be a more correct location to do this in general (e.g. compatible with supporting #[cfg]
and macro attributes on types).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I move it to InvocationCollectorNode::walk
, then all I have access to is a MutVisitor
, so I can't actually call something like insert_impl_trait_name
.
flipping state back b/c of a pending question @rustbot ready |
☔ The latest upstream changes (presumably #142644) made this pull request unmergeable. Please resolve the merge conflicts. |
#142690 should help with #142393 (comment) |
Yeah, I don't think it matters which node id was being used as a key. I think that PR + using the ty's node id is sufficient. |
☔ The latest upstream changes (presumably #142795) made this pull request unmergeable. Please resolve the merge conflicts. |
The
DefCollector
previously calledpprust::ty_to_string
to construct a name for APITs (arg-position impl traits). Theast::Ty
that was being formatted however has already had its macro calls replaced with "placeholder fragments", which end up rendering like!()
(or ICEing, in the case of #140333, since it led to a placeholder struct field with no name).Instead, collect the name of the APIT before we visit its macros and replace them with placeholders in the macro expander. This makes the implementation a bit more involved, but AFAICT there's no better way to do this since we can't do a reverse mapping from placeholder fragment -> original macro call AST.
Fixes #140333