Skip to content

Identify missing item category in impls#40815

Merged
bors merged 3 commits into
rust-lang:masterfrom
estebank:issue-40006
Apr 6, 2017
Merged

Identify missing item category in impls#40815
bors merged 3 commits into
rust-lang:masterfrom
estebank:issue-40006

Conversation

@estebank

@estebank estebank commented Mar 25, 2017

Copy link
Copy Markdown
Contributor
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
error: missing `fn` for method declaration
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn`

Fix #40006. r? @pnkfelix CC @jonathandturner @GuillaumeGomez

```rust
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
```

```rust
error: can't qualify macro invocation with `pub`
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |     ^^^-            - expected `!` here for a macro invocation
  |        |
  |        did you mean to write `fn` here for a method declaration?
  |
  = help: try adjusting the macro to put `pub` inside the invocation
```
@GuillaumeGomez

Copy link
Copy Markdown
Member

👍

@sophiajt

Copy link
Copy Markdown
Contributor

This seems like a step in the right direction, though the help it's giving seems confusing. Is there any way for us to detect if hello_method is a macro? It seems at a glance that these macro messages are distracting the user from the key issue.

@estebank

Copy link
Copy Markdown
Contributor Author

@jonathandturner I'll see if I can find a macro with the name and output the current output, otherwise output:

error: <ERROR>
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn` here for a method declaration?

What do you think the error message should be for this?

@sophiajt

Copy link
Copy Markdown
Contributor

@estebank - yeah, if we can get it down to that, that'd be great.

@estebank

Copy link
Copy Markdown
Contributor Author

@jonathandturner updated output to

error: missing `fn` for method declaration
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn`

It doesn't check if the parsed path is a macro name as I couldn't see a way to check the context in the parser, so I just look ahead to see if a ! is missing and assume it was meant to be a method.

@sophiajt

Copy link
Copy Markdown
Contributor

Hmm, that sounds best as a separate PR from this one.

@estebank

estebank commented Apr 2, 2017

Copy link
Copy Markdown
Contributor Author

Ping.

@GuillaumeGomez

Copy link
Copy Markdown
Member

So for me it's fine as is, so I'll r+. Thanks!

@bors: r+

@bors

bors commented Apr 2, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit c963d61 has been approved by GuillaumeGomez

@bors

bors commented Apr 2, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit c963d61 with merge c84f7d9...

@bors

bors commented Apr 2, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@estebank

estebank commented Apr 3, 2017

Copy link
Copy Markdown
Contributor Author

@bors r=GuillaumeGomez

rebased to master

@bors

bors commented Apr 3, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 8f31e19 has been approved by GuillaumeGomez

@bors

bors commented Apr 3, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 8f31e19 with merge 854dca3...

@bors

bors commented Apr 3, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@alexcrichton

alexcrichton commented Apr 3, 2017 via email

Copy link
Copy Markdown
Member

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 5, 2017
Identify missing item category in `impl`s

```rust
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
```

```rust
error: missing `fn` for method declaration
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn`
```

Fix rust-lang#40006. r? @pnkfelix CC @jonathandturner @GuillaumeGomez
arielb1 pushed a commit to arielb1/rust that referenced this pull request Apr 5, 2017
Identify missing item category in `impl`s

```rust
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
```

```rust
error: missing `fn` for method declaration
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn`
```

Fix rust-lang#40006. r? @pnkfelix CC @jonathandturner @GuillaumeGomez
bors added a commit that referenced this pull request Apr 6, 2017
Rollup of 12 pull requests

- Successful merges: #40479, #40561, #40709, #40815, #40909, #40927, #40943, #41015, #41028, #41052, #41054, #41065
- Failed merges:
@bors bors merged commit 8f31e19 into rust-lang:master Apr 6, 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.

6 participants