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

Extend macro name suggestion span #47424

Closed
wants to merge 1 commit into from
Closed

Extend macro name suggestion span #47424

wants to merge 1 commit into from

Conversation

etaoins
Copy link
Contributor

@etaoins etaoins commented Jan 14, 2018

When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code.

Fix by extending the suggestion's span by one byte to include the "!". The error span itself still only includes the macro's name.

Fixes #47418

When we suggest the replacement for a macro we include the "!" in the
suggested replacement but the span only contains the name of the macro
itself. Using that replacement would cause a duplicate "!" in the
resulting code.

Fix by extending the suggestion's span by one byte to include the "!".
The error span itself still only includes the macro's name.

Fixes #47418
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@etaoins etaoins changed the title Extend macro suggestion span Extend macro name suggestion span Jan 14, 2018
@estebank estebank added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 14, 2018
@zackmdavis
Copy link
Member

It's legal (despite being extremely irregular style) for there to be space between the macro name and the exclamation point, so we can't simply add a byte to the span.

fn main() {
    println 
                 !("rah"); // successfully prints "rah"
}

@etaoins
Copy link
Contributor Author

etaoins commented Jan 14, 2018

@zackmdavis Ouch, good catch! I'll need to rethink this.

@etaoins etaoins closed this Jan 14, 2018
@etaoins etaoins deleted the extend-macro-suggestion-span branch January 14, 2018 19:07
@estebank
Copy link
Contributor

Thank you for taking the time to fix this!

What about just changing the suggestion to not include !? That way you don't have to worry about @zackmdavis' valid point.

@etaoins
Copy link
Contributor Author

etaoins commented Jan 15, 2018

@estebank

I have a branch for that on my home machine. I think the current message with the ! is a bit nicer but we don't have access to the original span including the ! at this point. If we're okay losing the ! in then I'll open a PR with my branch once I'm back home and add you as a reviewer.

Thanks for the feedback!

@estebank
Copy link
Contributor

If we're okay losing the ! in then I'll open a PR with my branch once I'm back home and add you as a reviewer.

It should be fine, @etaoins. Tools don't care and will do the right thing, and for people it should be apparent enough that the span doesn't include the !. If the updated stderr files look too confusing with the change, what we could do is expand the suggestion's message so that it is shown on it's own:

error: cannot find macro `printlx!` in this scope
  --> $DIR/macro-name-typo.rs:12:5
   |
12 |     printlx!("oh noes!"); //~ ERROR cannot find
   |     ^^^^^^^ help: you could try the macro: `println!`
   = help: although `printlx` wasn't found, there's a macro named `println`:
   |
12 |     println!("oh noes!"); //~ ERROR cannot find
   |     ^^^^^^^

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 16, 2018
…suggestion, r=estebank

Don't include bang in macro replacement suggestion

When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code.

I originally tried to extend the span to be replaced by 1 byte in rust-lang#47424. However, @zackmdavis pointed out that there can be whitespace between the macro name and the bang.

Instead, just remove the bang from the suggested replacement.

Fixes rust-lang#47418

r? @estebank
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 16, 2018
…suggestion, r=estebank

Don't include bang in macro replacement suggestion

When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code.

I originally tried to extend the span to be replaced by 1 byte in rust-lang#47424. However, @zackmdavis pointed out that there can be whitespace between the macro name and the bang.

Instead, just remove the bang from the suggested replacement.

Fixes rust-lang#47418

r? @estebank
kennytm added a commit to kennytm/rust that referenced this pull request Jan 17, 2018
…suggestion, r=estebank

Don't include bang in macro replacement suggestion

When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code.

I originally tried to extend the span to be replaced by 1 byte in rust-lang#47424. However, @zackmdavis pointed out that there can be whitespace between the macro name and the bang.

Instead, just remove the bang from the suggested replacement.

Fixes rust-lang#47418

r? @estebank
kennytm added a commit to kennytm/rust that referenced this pull request Jan 17, 2018
…suggestion, r=estebank

Don't include bang in macro replacement suggestion

When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code.

I originally tried to extend the span to be replaced by 1 byte in rust-lang#47424. However, @zackmdavis pointed out that there can be whitespace between the macro name and the bang.

Instead, just remove the bang from the suggested replacement.

Fixes rust-lang#47418

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants