Skip to content

Commit

Permalink
Rollup merge of rust-lang#49077 - sinkuu:macro_use_typo, r=estebank
Browse files Browse the repository at this point in the history
Checks for unknown attributes before aborting due to unresolved macros

Fixes rust-lang#49074

The ``attribute `...` is currently unknown to the compiler`` error was not shown if there are any unresolved macros, which might be caused by mistyped `macro_use`.
  • Loading branch information
kennytm committed Mar 17, 2018
2 parents c78426b + 4be3e96 commit f24e35c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
Ok(())
})?;

if resolver.found_unresolved_macro {
sess.parse_sess.span_diagnostic.abort_if_errors();
}

// Needs to go *after* expansion to be able to check the results of macro expansion.
time(sess, "complete gated feature checking", || {
sess.track_errors(|| {
Expand All @@ -892,6 +888,12 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
})
})?;

// Unresolved macros might be due to mistyped `#[macro_use]`,
// so abort after checking for unknown attributes. (#49074)
if resolver.found_unresolved_macro {
sess.parse_sess.span_diagnostic.abort_if_errors();
}

// Lower ast -> hir.
// First, we need to collect the dep_graph.
let dep_graph = match future_dep_graph {
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/issue-49074.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Check that unknown attribute error is shown even if there are unresolved macros.

#[marco_use] // typo
//~^ ERROR The attribute `marco_use` is currently unknown to the compiler
mod foo {
macro_rules! bar {
() => ();
}
}

fn main() {
bar!();
//~^ ERROR cannot find macro `bar!`
}
19 changes: 19 additions & 0 deletions src/test/ui/issue-49074.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: cannot find macro `bar!` in this scope
--> $DIR/issue-49074.rs:22:4
|
LL | bar!();
| ^^^
|
= help: have you added the `#[macro_use]` on the module/import?

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)
--> $DIR/issue-49074.rs:13:1
|
LL | #[marco_use] // typo
| ^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

0 comments on commit f24e35c

Please sign in to comment.