Skip to content

Commit

Permalink
Auto merge of #35617 - jseyfried:fix_unused_cfg_attr_path, r=eddyb
Browse files Browse the repository at this point in the history
Fix incorrect unused import warnings on `cfg_attr`ed `path` attributes

Fixes #35584.
r? @eddyb
  • Loading branch information
bors committed Aug 16, 2016
2 parents e25542c + 4943e96 commit 1de5b7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use rustc::lint;
use rustc::session::Session;
use syntax::ast::*;
use syntax::attr;
use syntax::parse::token::{self, keywords};
use syntax::visit::{self, Visitor};
use syntax_pos::Span;
Expand Down Expand Up @@ -168,6 +169,10 @@ impl<'a> Visitor for AstValidator<'a> {
}
}
}
ItemKind::Mod(_) => {
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
attr::first_attr_value_str_by_name(&item.attrs, "path");
}
_ => {}
}

Expand Down
16 changes: 14 additions & 2 deletions src/test/compile-fail/cfg_attr_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[cfg_attr(all(), path = "nonexistent_file.rs")] mod foo;
//~^ ERROR nonexistent_file.rs
#![feature(rustc_attrs)]
#![allow(dead_code)]
#![deny(unused_attributes)] // c.f #35584

mod auxiliary {
#[cfg_attr(any(), path = "nonexistent_file.rs")] pub mod namespaced_enums;
#[cfg_attr(all(), path = "namespaced_enums.rs")] pub mod nonexistent_file;
}

#[rustc_error]
fn main() { //~ ERROR compilation successful
let _ = auxiliary::namespaced_enums::Foo::A;
let _ = auxiliary::nonexistent_file::Foo::A;
}

0 comments on commit 1de5b7e

Please sign in to comment.