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

Checks for unknown attributes before aborting due to unresolved macros #49077

Merged
merged 1 commit into from
Mar 17, 2018
Merged
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
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`.