-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve &-ptr printing #35611
Improve &-ptr printing #35611
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
(adding Niko as reviewer since he said he wanted to be) |
omg yessssssssssss |
match tymut { | ||
ty::TypeAndMut{ref ty, ref mutbl} => { | ||
if ty.to_string() == "_" || //unknown type name, | ||
ty.to_string().len() > 10 || //name longer than saying "reference", |
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.
This should really not call to_string
twice, better save it.
LGTM, my nitpicking notwithstanding 👍. |
@eddyb - hehe, no worries. Refactored with some of your nits fixed. |
} | ||
} | ||
} else { | ||
format!("&{}", tymut_string) |
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.
Do we want to print &mut
in the case of mutability?
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.
Oh, I see, we do, never mind.
@bors r+ |
📌 Commit 4224737 has been approved by |
…atsakis Improve &-ptr printing This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics. If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type. Before: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found &-ptr | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ``` After: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found mutable reference | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ```
@bors rollup |
…atsakis Improve &-ptr printing This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics. If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type. Before: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found &-ptr | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ``` After: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found mutable reference | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ```
…atsakis Improve &-ptr printing This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics. If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type. Before: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found &-ptr | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ``` After: ``` error[E0308]: mismatched types --> src/test/compile-fail/issue-7061.rs:14:46 | 14 | fn foo(&'a mut self) -> Box<BarStruct> { self } | ^^^^ expected box, found mutable reference | = note: expected type `Box<BarStruct>` = note: found type `&'a mut BarStruct` error: aborting due to previous error ```
Rollup of 30 pull requests - Successful merges: #34941, #35392, #35444, #35447, #35491, #35533, #35539, #35558, #35573, #35574, #35577, #35586, #35588, #35594, #35596, #35597, #35598, #35606, #35611, #35615, #35616, #35620, #35622, #35640, #35643, #35644, #35646, #35647, #35648, #35661 - Failed merges: #35395, #35415
This PR replaces printing
&-ptr
with a more readable description. To do so it uses a few heuristics.If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type.
Before:
After: