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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use syntax::ptr::P;
use syntax::symbol::{Symbol, keywords};
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
use syntax::util::lev_distance::find_best_match_for_name;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::{Span, DUMMY_SP, BytePos};

use std::cell::Cell;
use std::mem;
Expand Down Expand Up @@ -691,7 +691,10 @@ impl<'a> Resolver<'a> {
if let Some(suggestion) = suggestion {
if suggestion != name {
if let MacroKind::Bang = kind {
err.span_suggestion(span, "you could try the macro",
// Our suggested replacement includes the macro's bang. Extend the span by one
// byte to ensure it does as well.
let span_with_bang = span.with_hi(span.hi() + BytePos(1));
err.span_suggestion(span_with_bang, "you could try the macro",
format!("{}!", suggestion));
} else {
err.span_suggestion(span, "try", suggestion.to_string());
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/macros/macro-name-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ 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: you could try the macro: `println!`

error: aborting due to previous error

4 changes: 3 additions & 1 deletion src/test/ui/macros/macro_undefined.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ error: cannot find macro `k!` in this scope
--> $DIR/macro_undefined.rs:21:5
|
21 | k!(); //~ ERROR cannot find
| ^ help: you could try the macro: `kl!`
| ^-
| |
| help: you could try the macro: `kl!`

error: aborting due to 2 previous errors