-
Notifications
You must be signed in to change notification settings - Fork 13k
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
More distinctive pretty-printing of function item types #99927
More distinctive pretty-printing of function item types #99927
Conversation
…nguish from fn pointers.
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
I’m wondering if there’s a way (and a desire) to (be able to) test colors of compiler output, for the highlighting logic. |
We have access to tcx in pretty printing, right? We should be able to check the Otherwise, I do like this change, even if the output is a bit heavier. cc @rust-lang/wg-diagnostics |
cc @estebank who recently complained about the closure type display; this makes fn items more like closures. Bikeshed: why don't we just call it Either way, I think the ideal situation (including closure numbering) would treat Using the "type ascription" form would allow closures to use A proper survey would consider all unnamed types and how we display them. Fn items are Footnotes |
Current tests have no color output, and this is the correct default, provided by default |
Yeah, I thought follow-up. |
Anyone know how to run 32bit mir-opt test cases to bless them, while working on a 64bit machine? Ah, I found the command in the CI output, let’s try that.
|
This comment has been minimized.
This comment has been minimized.
@steffahn I think you've gotta run edit: lol i didnt see your comment haha |
Hmmm… I’m getting some errors (During |
Well, it’s few enough changes that I can do it manually… Edit: Ah, I’ve missed fixing one of them. Edit2: Oh, neat, so after that, it actually passes now. |
This comment has been minimized.
This comment has been minimized.
ecdfd54
to
7ce3e43
Compare
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.
Implementation changes look good to me. I don't have a strong opinion on the actual changes being made, I'll let this sit for a little bit to see if anyone else has opinions.
Can we get a screenshot to see the highlighting? |
I’ve started working on differentiating between constructors and non-constructors, however, it’s running into problems in the ui test that runs I also made some small further changes to the highlighting there… also I wouldn’t mind trying to get it to work and then integrate it into this PR already. In that case, @estebank, perhaps it makes most sense to show screenshots of the highlighting only after those changes since they change highlighting a little… @rustbot author Currently working on this branch (new commits: 65eb340 and cb0db7f); the relevant new call that’s presumably still causing problems is the one to For fixing the problem, I’m considering either to look for an alternative to the Edit: Actually… upon inspection of the error message, I think I’m perhaps simply reaching the |
☔ The latest upstream changes (presumably #100213) made this pull request unmergeable. Please resolve the merge conflicts. |
Given the large number of affected files, merge conflicts in test outputs are inevitable, and it won't make sense to fix them before there is agreement that this PR should be merged in the first place. |
r? @estebank |
We'll have a t-compiler meeting to follow up on this. There's a subset of this PR that I think is uncontroversial (and could be landed faster), but for the larger visible representation of the output I believe merits discussion. |
Apologies, I failed to create a meeting to address this. I'll do so shortly. CC #19939 |
Opened https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/More.20distinctive.20pretty-printing.20of.20function.20item.20types to try and arrive to agreement on what the output should be. |
I'll label this as @rustbot label S-blocked |
Changing this to waiting-on-team, since that's a more appropriate label than blocked (since there is no concrete item to unblock this) |
Visited during the compiler team triage meeting. There was some rough consensus that @bstrie's suggestion from Zulip might be a reasonable compromise between concerns:
We think it would be useful to try implementing that informational note and then re-evaluate how well the diagnostics work after that. |
That sounds like an unrelated change, both in terms of what it achieves and how it would be implemented. It can of course be very useful improvement, too. So if the consensus is that
So then the idea would not be to close this PR but “block” is on someone implementing some additional diagnostics? Note that in my mind, the ability to avoid confusion was only part of the motivation for this PR. I also just don’t see much value in the design of the current way these types are printed; besides the “legacy” value of “experienced Rust programmers may be used to this way”. E.g. it would’t make a difference for any aspect listed in the following paragraph from the PR description, whether or not there was a useful note in relevant error messages, except partially for the point of it being “more clearly different from a fn pointer type”. (I.e. the aspect that clearly different looking types could avoid confusion would be addressed, the aspect that unnecessarily similar looking types are just bad design wouldn’t be addressed.) (from the PR description)
To re-iterate the points: I do believe it’s a nicer design to have some way of printing the type that makes the function name come first. I do believe that there’s value in conveying in the design of the way diagnostics print them that closure types and fn items types are similar, and fn pointer types are quite different from those two. I do believe that the syntax On that last note, I also think there might be value on changing all cases where unnamable types are currently looking a lot like valid Rust syntax to name that type. Another example (maybe the only other one? 1) could be Another idea could be to just avoid printing anything for such types in more cases. E.g. I’ve just noticed that for futures, in some cases the async fn foo() {}
async fn bar() {}
fn f() {
let mut f = foo();
f = bar();
}
Compared to these other cases that all do have the fn f() {
let mut f = || "";
f = || "";
}
fn f() {
let mut f = async {};
f = async {};
}
fn foo() {}
fn bar() {}
fn f() {
let mut f = foo;
f = bar;
}
Footnotes
|
@steffahn any updates on this? thanks |
Thanks for the ping. I missed that there was a call to action in the last reply. Sure, I can rebase and get this into working condition again, now with |
@steffahn any updates since the last check? thanks |
Closing this pr as it's been inactive for a long time. Feel free to reöpen if you plan on continuing otherwise preferably open a new pr and link the approved MCP. |
Change the way “fn item” types are displayed: make them easier to distinguish from fn pointers.
My first point here is to figure out if CI passes, or how much more needs to be done to make it pass. (Edit: It does pass 🥳) Then there still needs to be discussion if we want such a change, and also how exactly they should best be rendered.
As you can see, this affects quite a lot of output. In particular, not only error messages but also pretty printed MIR (with types), as far as I can tell.
Context: https://internals.rust-lang.org/t/extending-implicit-coercion-of-function-items-to-function-pointers-during-trait-resolution/17093/6
My initial idea was to use something like
[function item `guess`: for<'r> fn(&'r [Guess]) -> String]
, butfn item
is more consistent with other parts of the error messages, and the backticks don’t look nice in an error message that also puts backticks around the whole type, so it became[fn item {guess}: for<'r> fn(&'r [Guess]) -> String]
. I’ve also considered something like[fn-item guess: for<'r> fn(&'r [Guess]) -> String]
, but the colon looks suboptimal after a longer path; wrapping the path into an extra set of parentheses works nicely IMO, and it could also be seen as a reference to the previous way of rendering the type,for<'r> fn(&'r [Guess]) -> String {guess}
, which used the curly braces, too.Really, all that changes now is: the order is switched, the thing becomes more clearly grouped as one coherent thing with the
[]
s (which are also meant to make the thing look more similar to a closure type, and more clearly different from a fn pointer type), and the thing becomes more self-describing (since it is special diagnostics-only syntax, after all) with the string “fn item” included.As of now, there’s a minor downside that tuple-structs’ and tuple-struct-style-enum-variants’ constructors render as something like
[fn item {Foo}: u8 -> Foo]
, too, whereas something like e.g.[tuple struct constructor {Foo}: u8 -> Foo]
might be nicer. It’s also already described as “'fn item`” currently though anyway, by error messages such as(which would after this PR look like this instead:)