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

Add suggestion of similar macro names to macro undefined error message #30064

Merged
merged 4 commits into from
Nov 27, 2015

Conversation

fhartwig
Copy link
Contributor

Fixes #13677
This does the same sort of suggestion for misspelt macros that we already do for misspelt identifiers.
Example. Compiling this program:

macro_rules! foo {
    ($e:expr) => ( $e )
}

fn main() {
    fob!("hello!");
}

gives the following error message:

/Users/mcp/temp/test.rs:7:5: 7:8 error: macro undefined: 'fob!'
/Users/mcp/temp/test.rs:7     fob!("hello!");
                              ^~~
/Users/mcp/temp/test.rs:7:5: 7:8 help: did you mean `foo`?
/Users/mcp/temp/test.rs:7     fob!("hello!");

I had to move the levenshtein distance function into libsyntax for this. Maybe this should live somewhere else (some utility crate?), but I couldn't find a crate to put it in that is imported by libsyntax and the other rustc crates.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

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


fn main() {
printlx!("oh noes!"); //~ ERROR macro undefined
//~^ HELP did you mean `println`?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion should also include the exclamation. i.e. println! instead of println.

@fhartwig
Copy link
Contributor Author

Thanks for your feedback! I've implemented your suggestions.

@sanxiyn
Copy link
Member

sanxiyn commented Nov 27, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Nov 27, 2015

📌 Commit 4bb7cf1 has been approved by sanxiyn

bors added a commit that referenced this pull request Nov 27, 2015
Fixes #13677
This does the same sort of suggestion for misspelt macros that we already do for misspelt identifiers.
Example. Compiling this program:

```rust
macro_rules! foo {
    ($e:expr) => ( $e )
}

fn main() {
    fob!("hello!");
}
```

gives the following error message:

```
/Users/mcp/temp/test.rs:7:5: 7:8 error: macro undefined: 'fob!'
/Users/mcp/temp/test.rs:7     fob!("hello!");
                              ^~~
/Users/mcp/temp/test.rs:7:5: 7:8 help: did you mean `foo`?
/Users/mcp/temp/test.rs:7     fob!("hello!");
```

I had to move the levenshtein distance function into libsyntax for this. Maybe this should live somewhere else (some utility crate?), but I couldn't find a crate to put it in that is imported by libsyntax and the other rustc crates.
@bors
Copy link
Contributor

bors commented Nov 27, 2015

⌛ Testing commit 4bb7cf1 with merge 5dc91a7...

@bors bors merged commit 4bb7cf1 into rust-lang:master Nov 27, 2015
@bors bors mentioned this pull request Nov 27, 2015
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