mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
fix pre-expansion linting infra
This commit is contained in:
parent
41a0b3ec53
commit
5ee4f6f660
@ -6,8 +6,6 @@
|
||||
//! Emscripten's runtime always implements those APIs and does not
|
||||
//! implement libunwind.
|
||||
|
||||
#![allow(private_no_mangle_fns)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
use core::mem;
|
||||
|
@ -36,8 +36,6 @@
|
||||
//! Once stack has been unwound down to the handler frame level, unwinding stops
|
||||
//! and the last personality routine transfers control to the catch block.
|
||||
|
||||
#![allow(private_no_mangle_fns)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
|
||||
|
@ -45,7 +45,6 @@
|
||||
//! [llvm]: http://llvm.org/docs/ExceptionHandling.html#background-on-windows-exceptions
|
||||
|
||||
#![allow(nonstandard_style)]
|
||||
#![allow(private_no_mangle_fns)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
|
@ -59,7 +59,7 @@ pub fn inject(
|
||||
handler: &rustc_errors::Handler,
|
||||
) -> ast::Crate {
|
||||
let ecfg = ExpansionConfig::default("proc_macro".to_string());
|
||||
let mut cx = ExtCtxt::new(sess, ecfg, resolver);
|
||||
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
|
||||
|
||||
let mut collect = CollectProcMacros {
|
||||
macros: Vec::new(),
|
||||
|
@ -39,7 +39,7 @@ pub fn inject(
|
||||
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id);
|
||||
|
||||
let ecfg = ExpansionConfig::default("std_lib_injection".to_string());
|
||||
let cx = ExtCtxt::new(sess, ecfg, resolver);
|
||||
let cx = ExtCtxt::new(sess, ecfg, resolver, None);
|
||||
|
||||
// .rev() to preserve ordering above in combination with insert(0, ...)
|
||||
for &name in names.iter().rev() {
|
||||
|
@ -202,7 +202,7 @@ fn generate_test_harness(
|
||||
let mut econfig = ExpansionConfig::default("test".to_string());
|
||||
econfig.features = Some(features);
|
||||
|
||||
let ext_cx = ExtCtxt::new(sess, econfig, resolver);
|
||||
let ext_cx = ExtCtxt::new(sess, econfig, resolver, None);
|
||||
|
||||
let expn_id = ext_cx.resolver.expansion_for_ast_pass(
|
||||
DUMMY_SP,
|
||||
|
@ -926,6 +926,8 @@ pub struct ExtCtxt<'a> {
|
||||
pub resolver: &'a mut dyn Resolver,
|
||||
pub current_expansion: ExpansionData,
|
||||
pub expansions: FxHashMap<Span, Vec<String>>,
|
||||
/// Called directly after having parsed an external `mod foo;` in expansion.
|
||||
pub(super) extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
|
||||
}
|
||||
|
||||
impl<'a> ExtCtxt<'a> {
|
||||
@ -933,12 +935,14 @@ impl<'a> ExtCtxt<'a> {
|
||||
parse_sess: &'a ParseSess,
|
||||
ecfg: expand::ExpansionConfig<'a>,
|
||||
resolver: &'a mut dyn Resolver,
|
||||
extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
|
||||
) -> ExtCtxt<'a> {
|
||||
ExtCtxt {
|
||||
parse_sess,
|
||||
ecfg,
|
||||
root_path: PathBuf::new(),
|
||||
resolver,
|
||||
extern_mod_loaded,
|
||||
root_path: PathBuf::new(),
|
||||
current_expansion: ExpansionData {
|
||||
id: ExpnId::root(),
|
||||
depth: 0,
|
||||
|
@ -1457,8 +1457,19 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
// We have an outline `mod foo;` so we need to parse the file.
|
||||
let (new_mod, dir) =
|
||||
parse_external_mod(sess, ident, span, dir, &mut attrs, pushed);
|
||||
*old_mod = new_mod;
|
||||
item.attrs = attrs;
|
||||
|
||||
let krate = ast::Crate {
|
||||
span: new_mod.inner,
|
||||
module: new_mod,
|
||||
attrs,
|
||||
proc_macros: vec![],
|
||||
};
|
||||
if let Some(extern_mod_loaded) = self.cx.extern_mod_loaded {
|
||||
extern_mod_loaded(&krate);
|
||||
}
|
||||
|
||||
*old_mod = krate.module;
|
||||
item.attrs = krate.attrs;
|
||||
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
|
||||
item = match self.configure(item) {
|
||||
Some(node) => node,
|
||||
|
@ -210,14 +210,7 @@ pub fn register_plugins<'a>(
|
||||
Ok((krate, Lrc::new(lint_store)))
|
||||
}
|
||||
|
||||
fn configure_and_expand_inner<'a>(
|
||||
sess: &'a Session,
|
||||
lint_store: &'a LintStore,
|
||||
mut krate: ast::Crate,
|
||||
crate_name: &str,
|
||||
resolver_arenas: &'a ResolverArenas<'a>,
|
||||
metadata_loader: &'a MetadataLoaderDyn,
|
||||
) -> Result<(ast::Crate, Resolver<'a>)> {
|
||||
fn pre_expansion_lint(sess: &Session, lint_store: &LintStore, krate: &ast::Crate) {
|
||||
sess.time("pre_AST_expansion_lint_checks", || {
|
||||
rustc_lint::check_ast_crate(
|
||||
sess,
|
||||
@ -228,6 +221,17 @@ fn configure_and_expand_inner<'a>(
|
||||
rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn configure_and_expand_inner<'a>(
|
||||
sess: &'a Session,
|
||||
lint_store: &'a LintStore,
|
||||
mut krate: ast::Crate,
|
||||
crate_name: &str,
|
||||
resolver_arenas: &'a ResolverArenas<'a>,
|
||||
metadata_loader: &'a MetadataLoaderDyn,
|
||||
) -> Result<(ast::Crate, Resolver<'a>)> {
|
||||
pre_expansion_lint(sess, lint_store, &krate);
|
||||
|
||||
let mut resolver = Resolver::new(sess, &krate, crate_name, metadata_loader, &resolver_arenas);
|
||||
rustc_builtin_macros::register_builtin_macros(&mut resolver, sess.edition());
|
||||
@ -291,7 +295,8 @@ fn configure_and_expand_inner<'a>(
|
||||
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
|
||||
};
|
||||
|
||||
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver);
|
||||
let extern_mod_loaded = |k: &ast::Crate| pre_expansion_lint(sess, lint_store, k);
|
||||
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver, Some(&extern_mod_loaded));
|
||||
|
||||
// Expand macros now!
|
||||
let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));
|
||||
|
@ -18,7 +18,7 @@ use crate::context::{EarlyContext, LintContext, LintStore};
|
||||
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
|
||||
use rustc_ast::ast;
|
||||
use rustc_ast::visit as ast_visit;
|
||||
use rustc_session::lint::{LintBuffer, LintPass};
|
||||
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -37,13 +37,7 @@ struct EarlyContextAndPass<'a, T: EarlyLintPass> {
|
||||
impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
||||
fn check_id(&mut self, id: ast::NodeId) {
|
||||
for early_lint in self.context.buffered.take(id) {
|
||||
let rustc_session::lint::BufferedEarlyLint {
|
||||
span,
|
||||
msg,
|
||||
node_id: _,
|
||||
lint_id,
|
||||
diagnostic,
|
||||
} = early_lint;
|
||||
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
|
||||
self.context.lookup_with_diagnostics(
|
||||
lint_id.lint,
|
||||
Some(span),
|
||||
@ -326,11 +320,9 @@ pub fn check_ast_crate<T: EarlyLintPass>(
|
||||
lint_buffer: Option<LintBuffer>,
|
||||
builtin_lints: T,
|
||||
) {
|
||||
let mut passes: Vec<_> = if pre_expansion {
|
||||
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
|
||||
} else {
|
||||
lint_store.early_passes.iter().map(|p| (p)()).collect()
|
||||
};
|
||||
let passes =
|
||||
if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes };
|
||||
let mut passes: Vec<_> = passes.iter().map(|p| (p)()).collect();
|
||||
let mut buffered = lint_buffer.unwrap_or_default();
|
||||
|
||||
if !sess.opts.debugging_opts.no_interleave_lints {
|
||||
|
@ -2,10 +2,8 @@
|
||||
// compile-flags: -Zquery-dep-graph
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(private_no_mangle_fns)]
|
||||
|
||||
#![rustc_partition_codegened(module="change_symbol_export_status-mod1", cfg="rpass2")]
|
||||
#![rustc_partition_reused(module="change_symbol_export_status-mod2", cfg="rpass2")]
|
||||
#![rustc_partition_codegened(module = "change_symbol_export_status-mod1", cfg = "rpass2")]
|
||||
#![rustc_partition_reused(module = "change_symbol_export_status-mod2", cfg = "rpass2")]
|
||||
|
||||
// This test case makes sure that a change in symbol visibility is detected by
|
||||
// our dependency tracking. We do this by changing a module's visibility to
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
// We're testing linkage visibility; the compiler warns us, but we want to
|
||||
// do the runtime check that these functions aren't exported.
|
||||
#![allow(private_no_mangle_fns)]
|
||||
|
||||
extern crate rustc_metadata;
|
||||
|
||||
use rustc_metadata::dynamic_lib::DynamicLibrary;
|
||||
|
||||
#[no_mangle]
|
||||
pub fn foo() { bar(); }
|
||||
pub fn foo() {
|
||||
bar();
|
||||
}
|
||||
|
||||
pub fn foo2<T>() {
|
||||
fn bar2() {
|
||||
@ -21,11 +19,11 @@ pub fn foo2<T>() {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn bar() { }
|
||||
fn bar() {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[no_mangle]
|
||||
fn baz() { }
|
||||
fn baz() {}
|
||||
|
||||
pub fn test() {
|
||||
let lib = DynamicLibrary::open(None).unwrap();
|
||||
|
7
src/test/ui/lint/lint-pre-expansion-extern-module.rs
Normal file
7
src/test/ui/lint/lint-pre-expansion-extern-module.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// check-pass
|
||||
// compile-flags: -W rust-2018-compatibility
|
||||
// error-pattern: `try` is a keyword in the 2018 edition
|
||||
|
||||
fn main() {}
|
||||
|
||||
mod lint_pre_expansion_extern_module_aux;
|
10
src/test/ui/lint/lint-pre-expansion-extern-module.stderr
Normal file
10
src/test/ui/lint/lint-pre-expansion-extern-module.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
warning: `try` is a keyword in the 2018 edition
|
||||
--> $DIR/lint_pre_expansion_extern_module_aux.rs:3:8
|
||||
|
|
||||
LL | pub fn try() {}
|
||||
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
||||
|
|
||||
= note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
|
||||
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
|
||||
|
3
src/test/ui/lint/lint_pre_expansion_extern_module_aux.rs
Normal file
3
src/test/ui/lint/lint_pre_expansion_extern_module_aux.rs
Normal file
@ -0,0 +1,3 @@
|
||||
// ignore-test: not a test
|
||||
|
||||
pub fn try() {}
|
Loading…
Reference in New Issue
Block a user