Skip to content

Commit 4be3e96

Browse files
committed
Checks for unknown attributes before aborting
...due to unresolved macros.
1 parent a7170b0 commit 4be3e96

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/librustc_driver/driver.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
877877
Ok(())
878878
})?;
879879

880-
if resolver.found_unresolved_macro {
881-
sess.parse_sess.span_diagnostic.abort_if_errors();
882-
}
883-
884880
// Needs to go *after* expansion to be able to check the results of macro expansion.
885881
time(sess, "complete gated feature checking", || {
886882
sess.track_errors(|| {
@@ -892,6 +888,12 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
892888
})
893889
})?;
894890

891+
// Unresolved macros might be due to mistyped `#[macro_use]`,
892+
// so abort after checking for unknown attributes. (#49074)
893+
if resolver.found_unresolved_macro {
894+
sess.parse_sess.span_diagnostic.abort_if_errors();
895+
}
896+
895897
// Lower ast -> hir.
896898
// First, we need to collect the dep_graph.
897899
let dep_graph = match future_dep_graph {

src/test/ui/issue-49074.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2018 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+
// Check that unknown attribute error is shown even if there are unresolved macros.
12+
13+
#[marco_use] // typo
14+
//~^ ERROR The attribute `marco_use` is currently unknown to the compiler
15+
mod foo {
16+
macro_rules! bar {
17+
() => ();
18+
}
19+
}
20+
21+
fn main() {
22+
bar!();
23+
//~^ ERROR cannot find macro `bar!`
24+
}

src/test/ui/issue-49074.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: cannot find macro `bar!` in this scope
2+
--> $DIR/issue-49074.rs:22:4
3+
|
4+
LL | bar!();
5+
| ^^^
6+
|
7+
= help: have you added the `#[macro_use]` on the module/import?
8+
9+
error[E0658]: The attribute `marco_use` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
10+
--> $DIR/issue-49074.rs:13:1
11+
|
12+
LL | #[marco_use] // typo
13+
| ^^^^^^^^^^^^
14+
|
15+
= help: add #![feature(custom_attribute)] to the crate attributes to enable
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)