-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Display raw pointer as *{mut,const} T instead of *-ptr in errors #99517
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @wesleywiser (rust-highfive has picked a reviewer for you, use r? to override) |
This seems reasonable to me, but I'm unsure if there's an existing convention here that we are trying to move towards. @estebank @compiler-errors how do you feel about saying |
I'm ok with calling them by name, but it'd be lovely if we did the same thing we do for references and mention what type they are a pointer for. |
a40d796
to
9e539d3
Compare
raw pointer
instead of *-ptr
in errors
That's a great idea, especially since it's trivial to implement. So I did that. |
@estebank @compiler-errors is this good now? |
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.
Looks good, r=me with one nit
r? @compiler-errors |
✌️ @Nilstrieb can now approve this pull request |
9e539d3
to
860ba27
Compare
860ba27
to
2806cf4
Compare
let tymut_string = match tymut.mutbl { | ||
hir::Mutability::Mut => tymut.to_string(), | ||
hir::Mutability::Not => format!("const {}", tymut.ty), | ||
}; | ||
if tymut_string != "_" && tymut.ty.is_simple_text() { | ||
format!("`*{}`", tymut_string).into() |
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 think this works
let tymut_string = match tymut.mutbl { | |
hir::Mutability::Mut => tymut.to_string(), | |
hir::Mutability::Not => format!("const {}", tymut.ty), | |
}; | |
if tymut_string != "_" && tymut.ty.is_simple_text() { | |
format!("`*{}`", tymut_string).into() | |
if tymut.ty.is_simple_text() { | |
self.to_string() |
I also wonder if we should change the code below for ty::Ref
to match
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 could try it out tomorrow if you want to
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.
Please do, thanks!
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.
It would be pretty bad, the length check is really needed here:
- | expected `&T`, found type parameter `T`
+ | expected reference, found type parameter `T`
- | ---------- ^ expected `&dyn Trait`, found struct `Box`
+ | ---------- ^ expected reference, found struct `Box`
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'm not sure if I understand how removing the length check causes &T
to be rendered as "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.
oh, it's because ty
is not considered simple_text... ugh
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.
Could we modify the logic to make a ref dyn Trait be considered "simple"?
Edit: all it would take is adding a match arm in is_simple_ty
to handle Dynamic
in the same way we handle Adt
in is_simple_text
.
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.
it's more complex than that, since a Dynamic
is a List<Binder<ExistentialPredicate>>
I also think that having the length check is nicer than the is_simple_ty
check, since this exists to avoid bloating the output, so a length check will always be more accurate than a type complexity check.
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.
Length check is fine then. As a final follow-up, is it possible to make the &
and *
printing logic as similar as possible?
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.
raw pointer
is a little too short for the length check imo. I'll use const raw pointer
, even though that is not actually used, but since the type will have a const
prefix for the pointer, that seems fair
r=me with the last comment or not @bors delegate+ |
✌️ @Nilstrieb can now approve this pull request |
2806cf4
to
4e8e49e
Compare
The `*-ptr` is rather confusing, and we have the full information for properly displaying the information.
4e8e49e
to
5021dcd
Compare
Thanks nils @bors r+ |
Rollup of 5 pull requests Successful merges: - rust-lang#99517 (Display raw pointer as *{mut,const} T instead of *-ptr in errors) - rust-lang#99928 (Do not leak type variables from opaque type relation) - rust-lang#100473 (Attempt to normalize `FnDef` signature in `InferCtxt::cmp`) - rust-lang#100653 (Move the cast_float_to_int fallback code to GCC) - rust-lang#100941 (Point at the string inside literal and mention if we need string inte…) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The
*-ptr
is rather confusing, and we have the full information for properly displaying the information.