Skip to content
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

Merged
merged 2 commits into from
Mar 30, 2017
Merged

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Mar 25, 2017

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());
    |                                  ^^^^^^^^ field, not a method
    |
    = help: did you mean to write `self.src_addr` instead of `self.src_addr(...)`?

Fix #38321.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank estebank force-pushed the issue-38321 branch 4 times, most recently from e34af47 to 6341a8b Compare March 25, 2017 19:57
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(...)`?
```
@nikomatsakis
Copy link
Contributor

I wonder if we should suggest (self.src_addr)(...), at least in the event that the field is callable? It's non-obvious.

@nikomatsakis
Copy link
Contributor

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 \
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Copy link
Contributor Author

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.

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
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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

demo.example(1);
//~^ ERROR no method named `example`
//~| HELP use `(demo.example)(...)`
//~| NOTE `example` is a field storing a function, not a method
Copy link
Contributor

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?

Copy link
Contributor

@nikomatsakis nikomatsakis left a 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

@estebank
Copy link
Contributor Author

@nikomatsakis all done!

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 29, 2017

📌 Commit 872d3bc has been approved by nikomatsakis

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 29, 2017
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.
bors added a commit that referenced this pull request Mar 29, 2017
Rollup of 6 pull requests

- Successful merges: #40780, #40814, #40816, #40832, #40901, #40907
- Failed merges:
@bors bors merged commit 872d3bc into rust-lang:master Mar 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants