Skip to content

Commit 4d3eebf

Browse files
committed
Auto merge of #31707 - GuillaumeGomez:macro_name, r=sfackler
I'm wondering if instead of a second help message, a note would be better. I let it up to reviewers.
2 parents 2051a92 + eca0ab2 commit 4d3eebf

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/libsyntax/ext/base.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,12 @@ impl<'a> ExtCtxt<'a> {
760760
err: &mut DiagnosticBuilder<'a>) {
761761
let names = &self.syntax_env.names;
762762
if let Some(suggestion) = find_best_match_for_name(names.iter(), name, None) {
763-
err.fileline_help(span, &format!("did you mean `{}!`?", suggestion));
763+
if suggestion != name {
764+
err.fileline_help(span, &format!("did you mean `{}!`?", suggestion));
765+
} else {
766+
err.fileline_help(span, &format!("have you added the `#[macro_use]` on the \
767+
module/import?"));
768+
}
764769
}
765770
}
766771
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test macro_undefined issue
12+
13+
mod m {
14+
#[macro_export]
15+
macro_rules! kl {
16+
() => ()
17+
}
18+
}
19+
20+
fn main() {
21+
k!(); //~ ERROR macro undefined: 'k!'
22+
//~^ HELP did you mean `kl!`?
23+
kl!(); //~ ERROR macro undefined: 'kl!'
24+
//~^ HELP have you added the `#[macro_use]` on the module/import?
25+
}

0 commit comments

Comments
 (0)