-
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
Clarify suggetion for field used as method #40816
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
e34af47
to
6341a8b
Compare
Instead of ``` error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ | note: did you mean to write `self.src_addr`? --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ ``` present ``` error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ `src_addr` is a field, not a method | = help: did you mean to write `self.src_addr` instead of `self.src_addr(...)`? ```
I wonder if we should suggest |
But I guess that feels like a separate issue. =) |
stored in the `{1}` field", | ||
expr_string, | ||
item_name)); | ||
err.help(&format!("use `({0}.{1})(...)` if you \ |
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, we do that already =)
stored in the `{1}` field", | ||
expr_string, | ||
item_name)); | ||
err.span_label(span, |
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.
Personally, I think I would give the same span_label
either way (i.e., just "is a field, not a method") but change the help text. I think this syntax is a bit long and specific for a label.
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 just realized I misread this comment. I'm keeping different labels, but much shortened (field, not a method
vs field storing a function, not a method
). Is that ok?
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.
personally, I find "field storing a function" confusing. It makes it sound (to me) like this is an error specifically because the field stores a function (where indeed it would be an error for any field).
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.
Changed so that both cases have the same label as originally requested.
src/test/compile-fail/issue-18343.rs
Outdated
o.closure(); | ||
//~^ ERROR no method named `closure` found | ||
//~| HELP use `(o.closure)(...)` if you meant to call the function stored in the `closure` field | ||
//~| NOTE `closure` is a field storing a function, not a method |
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.
can you change this to a ui
test? I'd personally also rename it to something like suggestion-for-field-with-fn-type-issue-18343.rs
, since issue-18343.rs
seems like a name suitable only for "fix random ICE regression test" to me.
src/test/compile-fail/issue-2392.rs
Outdated
@@ -48,45 +48,58 @@ fn main() { | |||
|
|||
let o_closure = Obj { closure: || 42, not_closure: 42 }; | |||
o_closure.closure(); //~ ERROR no method named `closure` found | |||
//~^ NOTE use `(o_closure.closure)(...)` if you meant to call the function stored | |||
//~^ HELP use `(o_closure.closure)(...)` if you meant to call the function stored | |||
//~| NOTE `closure` is a field storing a function, not a method |
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 should be a UI test too
src/test/compile-fail/issue-32128.rs
Outdated
demo.example(1); | ||
//~^ ERROR no method named `example` | ||
//~| HELP use `(demo.example)(...)` | ||
//~| NOTE `example` is a field storing a function, not a method |
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.
really all of these feel like ui tests to me :)
maybe make a directory like src/test/ui/suggestions/confuse-field-and-method/
and just move the (not renamed) issue-123.rs
files into that directory?
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.
r=me once you make those ui tests
@nikomatsakis all done! |
@bors r+ |
📌 Commit 872d3bc has been approved by |
Clarify suggetion for field used as method Instead of ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ | note: did you mean to write `self.src_addr`? --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ ``` present ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ field, not a method | = help: did you mean to write `self.src_addr` instead of `self.src_addr(...)`? ``` Fix rust-lang#38321.
Instead of
present
Fix #38321.