-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Move from {{closure}}#0 syntax to {closure#0} for (def) path components. #70334
Comments
The |
I am trying to give this issue a shot. From what I understand, the and is accessed through In order to generate a proper name complying with the Rust Symbol Mangling: I have a few questions:
Where is the |
@marmeladema Apologies for the delay! Please PM me on Zulip or elsewhere if I don't see something on GitHub (I'm still months behind on most notifications).
I think this is overkill, we can "just" return a two-variant enum DefPathDataName {
Named(Symbol),
Anon { namespace: Symbol },
}
impl DefPathData {
fn name(&self) -> DefPathDataName {
match self {
DefPathData::ValueNs(name) | ... => DefPathDataName::Name(name),
DefPathData::ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
...
}
}
} Used like this: match data.name() {
DefPathDataName::Named(name) => write!(f, "{}", name),
DefPathDataName::Anon { namespace } => write!(f, "{{{}#{}}}", namespace, disambiguator)
}
No, this is gated on upstreaming tool support, see #60705. The
Probably, yeah. If it's a crate hash then it can stay
Yeah, I'm referring about the general pattern of
Weird, I thought we put it into the RFC. This is the reference demangler impl, for the record. IIRC, we ended up with this syntax to mimic C++'s For the user-facing stuff we might want to (but not for this issue, it should probably be separate) replace the
This can probably be done cleanly (without matching on strings or anything weird), as per the |
That is probably because of the rust/src/librustc_middle/ty/print/pretty.rs Lines 1460 to 1467 in d8424f6
|
@arora-aman Hmm, that doesn't apply to the "anonymous" So even for this example, we'd only show fn main() {
let () = { fn f() {} f };
let () = { fn f() {} f };
} You can see the difference here: https://godbolt.org/z/bjjb9r |
…, r=eddyb Move from {{closure}}#0 syntax to {closure#0} for (def) path components Part of rust-lang#70334 I followed the approach described by `@eddyb` and introduced a `DefPathDataName` enum. To preserve compatibility, in various places, I had to rely on formatting manually by calling `format!("{{{{{}}}}}", namespace)`. My questions are: * Do we want to convert for places to use the new naming scheme? Or shall I re-add `DefPathData::as_symbol` but renamed as `DefPathData::as_legacy_symbol` to avoid manually allocating the legacy symbols? * Do we want to `impl Display for DisambiguatedDefPathData` to avoid manually calling `write!(s, "{{{}#{}}}", namespace, component.disambiguator)`? * We might also want to improve naming for `DefPathDataName` and `DefPathData::get_name` r? `@eddyb`
Today if a path refers to unnamed defs such as closures, it's printed using double braces e.g. for the following example,
rustc
refers toFoo
asmain::{{closure}}#0::Foo
:However, the new Rust Symbol Mangling (rust-lang/rfcs#2603 / #60705), uses
{closure#0}
instead.I forget if I wrote about this before, but I prefer the newer form and it would be nice if we could switch everything uniformly to it.
As an aside, I've long believed that the double braces (e.g.
{{closure}}
,{{impl}}
) were meant to be single braces (i.e.{closure}
,{impl}
), escaped forformat!
, and that somehow that got lost.The text was updated successfully, but these errors were encountered: