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

Pass real crate-level attributes to pre_expansion_lint #89214

Merged
merged 2 commits into from
Sep 27, 2021
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
8 changes: 6 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ fn pre_expansion_lint(
sess: &Session,
lint_store: &LintStore,
krate: &ast::Crate,
crate_attrs: &[ast::Attribute],
crate_name: &str,
) {
sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", crate_name).run(|| {
rustc_lint::check_ast_crate(
sess,
lint_store,
&krate,
crate_attrs,
true,
None,
rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
Expand All @@ -266,7 +268,7 @@ pub fn configure_and_expand(
resolver: &mut Resolver<'_>,
) -> Result<ast::Crate> {
tracing::trace!("configure_and_expand");
pre_expansion_lint(sess, lint_store, &krate, crate_name);
pre_expansion_lint(sess, lint_store, &krate, &krate.attrs, crate_name);
rustc_builtin_macros::register_builtin_macros(resolver);

krate = sess.time("crate_injection", || {
Expand Down Expand Up @@ -323,9 +325,10 @@ pub fn configure_and_expand(
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
};

let crate_attrs = krate.attrs.clone();
let extern_mod_loaded = |ident: Ident, attrs, items, span| {
let krate = ast::Crate { attrs, items, span };
pre_expansion_lint(sess, lint_store, &krate, &ident.name.as_str());
pre_expansion_lint(sess, lint_store, &krate, &crate_attrs, &ident.name.as_str());
(krate.attrs, krate.items)
};
let mut ecx = ExtCtxt::new(&sess, cfg, resolver, Some(&extern_mod_loaded));
Expand Down Expand Up @@ -469,6 +472,7 @@ pub fn lower_to_hir<'res, 'tcx>(
sess,
lint_store,
&krate,
&krate.attrs,
false,
Some(std::mem::take(resolver.lint_buffer())),
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,15 @@ impl<'a> EarlyContext<'a> {
sess: &'a Session,
lint_store: &'a LintStore,
krate: &'a ast::Crate,
crate_attrs: &'a [ast::Attribute],
buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> EarlyContext<'a> {
EarlyContext {
sess,
krate,
lint_store,
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store, &krate.attrs),
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store, crate_attrs),
buffered,
}
}
Expand Down
24 changes: 21 additions & 3 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,20 @@ fn early_lint_crate<T: EarlyLintPass>(
sess: &Session,
lint_store: &LintStore,
krate: &ast::Crate,
crate_attrs: &[ast::Attribute],
pass: T,
buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> LintBuffer {
let mut cx = EarlyContextAndPass {
context: EarlyContext::new(sess, lint_store, krate, buffered, warn_about_weird_lints),
context: EarlyContext::new(
sess,
lint_store,
krate,
crate_attrs,
buffered,
warn_about_weird_lints,
),
pass,
};

Expand All @@ -355,6 +363,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
sess: &Session,
lint_store: &LintStore,
krate: &ast::Crate,
crate_attrs: &[ast::Attribute],
pre_expansion: bool,
lint_buffer: Option<LintBuffer>,
builtin_lints: T,
Expand All @@ -365,14 +374,22 @@ pub fn check_ast_crate<T: EarlyLintPass>(
let mut buffered = lint_buffer.unwrap_or_default();

if !sess.opts.debugging_opts.no_interleave_lints {
buffered =
early_lint_crate(sess, lint_store, krate, builtin_lints, buffered, pre_expansion);
buffered = early_lint_crate(
sess,
lint_store,
krate,
crate_attrs,
builtin_lints,
buffered,
pre_expansion,
);

if !passes.is_empty() {
buffered = early_lint_crate(
sess,
lint_store,
krate,
crate_attrs,
EarlyLintPassObjects { lints: &mut passes[..] },
buffered,
false,
Expand All @@ -386,6 +403,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
sess,
lint_store,
krate,
crate_attrs,
EarlyLintPassObjects { lints: slice::from_mut(pass) },
buffered,
pre_expansion && i == 0,
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/lint/known-tool-in-submodule/root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![feature(register_tool)]
#![register_tool(tool)]

mod submodule;

fn main() {
submodule::foo();
}
4 changes: 4 additions & 0 deletions src/test/ui/lint/known-tool-in-submodule/submodule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// ignore-test: not a test

#[allow(tool::lint)]
pub fn foo() {}