Skip to content

make a help text for 'cannot find macro' actionable #102881

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

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
5 changes: 2 additions & 3 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2441,10 +2441,9 @@ fn show_candidates(

for candidate in accessible_path_strings {
msg.push('\n');
msg.push_str(&candidate.0);
msg.push_str(&format!("use {};", &candidate.0));
}

err.note(&msg);
err.help(&msg);
}
} else if !matches!(mode, DiagnosticMode::Import) {
assert!(!inaccessible_path_strings.is_empty());
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/macros/issue-102601.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod hey {
pub use std::println as bitflags;
}

fn main() {
bitflags! { //~ ERROR cannot find macro `bitflags` in this scope
struct Flags: u32 {
const A = 0b00000001;
}
}
}
//~ HELP consider importing this macro:
// use hey::bitflags;
11 changes: 11 additions & 0 deletions src/test/ui/macros/issue-102601.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: cannot find macro `bitflags` in this scope
--> $DIR/issue-102601.rs:6:5
|
LL | bitflags! {
| ^^^^^^^^
|
= help: consider importing this macro:
use hey::bitflags;
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure there's a way to make this into an actual applicable suggestion, instead of just editing the message that this formats. I think that should be done instead of this.

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 have one question.
As you say, err.span_suggestions() is more appropriate instead of err.help to show a suggestion.
The output will be like this.

help: consider importing this macro
    |
LL  |     use hey::bitflags;
    |

I don't know what to do with the argument Span that I pass to err_suggestions because it is a process in a clause where use_placement_span is None.

if let (IsPattern::Yes, Some(span)) = (is_pattern, use_placement_span){
.....
} else if let Some(span) = use_placement_span {
......
}
else {
         msg.push(':');

          for candidate in accessible_path_strings {
              msg.push('\n');
              msg.push_str(&format!("use {};", &candidate.0));
          }
          err.help(&msg); <- I wanna replace it
      }

https://github.com/togami2864/rust/blob/de66eb0c1831693bac47f088e4eb3fbbf88b15ad/compiler/rustc_resolve/src/diagnostics.rs#L2512-L2552

Do you have any idea or are these any code of similar processing?


error: aborting due to previous error