Skip to content

Commit 5ee4f6f

Browse files
committed
fix pre-expansion linting infra
1 parent 41a0b3e commit 5ee4f6f

File tree

15 files changed

+67
-44
lines changed

15 files changed

+67
-44
lines changed

src/libpanic_unwind/emcc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! Emscripten's runtime always implements those APIs and does not
77
//! implement libunwind.
88
9-
#![allow(private_no_mangle_fns)]
10-
119
use alloc::boxed::Box;
1210
use core::any::Any;
1311
use core::mem;

src/libpanic_unwind/gcc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
//! Once stack has been unwound down to the handler frame level, unwinding stops
3737
//! and the last personality routine transfers control to the catch block.
3838
39-
#![allow(private_no_mangle_fns)]
40-
4139
use alloc::boxed::Box;
4240
use core::any::Any;
4341

src/libpanic_unwind/seh.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
//! [llvm]: http://llvm.org/docs/ExceptionHandling.html#background-on-windows-exceptions
4646
4747
#![allow(nonstandard_style)]
48-
#![allow(private_no_mangle_fns)]
4948

5049
use alloc::boxed::Box;
5150
use core::any::Any;

src/librustc_builtin_macros/proc_macro_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn inject(
5959
handler: &rustc_errors::Handler,
6060
) -> ast::Crate {
6161
let ecfg = ExpansionConfig::default("proc_macro".to_string());
62-
let mut cx = ExtCtxt::new(sess, ecfg, resolver);
62+
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
6363

6464
let mut collect = CollectProcMacros {
6565
macros: Vec::new(),

src/librustc_builtin_macros/standard_library_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn inject(
3939
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id);
4040

4141
let ecfg = ExpansionConfig::default("std_lib_injection".to_string());
42-
let cx = ExtCtxt::new(sess, ecfg, resolver);
42+
let cx = ExtCtxt::new(sess, ecfg, resolver, None);
4343

4444
// .rev() to preserve ordering above in combination with insert(0, ...)
4545
for &name in names.iter().rev() {

src/librustc_builtin_macros/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn generate_test_harness(
202202
let mut econfig = ExpansionConfig::default("test".to_string());
203203
econfig.features = Some(features);
204204

205-
let ext_cx = ExtCtxt::new(sess, econfig, resolver);
205+
let ext_cx = ExtCtxt::new(sess, econfig, resolver, None);
206206

207207
let expn_id = ext_cx.resolver.expansion_for_ast_pass(
208208
DUMMY_SP,

src/librustc_expand/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,23 @@ pub struct ExtCtxt<'a> {
926926
pub resolver: &'a mut dyn Resolver,
927927
pub current_expansion: ExpansionData,
928928
pub expansions: FxHashMap<Span, Vec<String>>,
929+
/// Called directly after having parsed an external `mod foo;` in expansion.
930+
pub(super) extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
929931
}
930932

931933
impl<'a> ExtCtxt<'a> {
932934
pub fn new(
933935
parse_sess: &'a ParseSess,
934936
ecfg: expand::ExpansionConfig<'a>,
935937
resolver: &'a mut dyn Resolver,
938+
extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
936939
) -> ExtCtxt<'a> {
937940
ExtCtxt {
938941
parse_sess,
939942
ecfg,
940-
root_path: PathBuf::new(),
941943
resolver,
944+
extern_mod_loaded,
945+
root_path: PathBuf::new(),
942946
current_expansion: ExpansionData {
943947
id: ExpnId::root(),
944948
depth: 0,

src/librustc_expand/expand.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,19 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
14571457
// We have an outline `mod foo;` so we need to parse the file.
14581458
let (new_mod, dir) =
14591459
parse_external_mod(sess, ident, span, dir, &mut attrs, pushed);
1460-
*old_mod = new_mod;
1461-
item.attrs = attrs;
1460+
1461+
let krate = ast::Crate {
1462+
span: new_mod.inner,
1463+
module: new_mod,
1464+
attrs,
1465+
proc_macros: vec![],
1466+
};
1467+
if let Some(extern_mod_loaded) = self.cx.extern_mod_loaded {
1468+
extern_mod_loaded(&krate);
1469+
}
1470+
1471+
*old_mod = krate.module;
1472+
item.attrs = krate.attrs;
14621473
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
14631474
item = match self.configure(item) {
14641475
Some(node) => node,

src/librustc_interface/passes.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,7 @@ pub fn register_plugins<'a>(
210210
Ok((krate, Lrc::new(lint_store)))
211211
}
212212

213-
fn configure_and_expand_inner<'a>(
214-
sess: &'a Session,
215-
lint_store: &'a LintStore,
216-
mut krate: ast::Crate,
217-
crate_name: &str,
218-
resolver_arenas: &'a ResolverArenas<'a>,
219-
metadata_loader: &'a MetadataLoaderDyn,
220-
) -> Result<(ast::Crate, Resolver<'a>)> {
213+
fn pre_expansion_lint(sess: &Session, lint_store: &LintStore, krate: &ast::Crate) {
221214
sess.time("pre_AST_expansion_lint_checks", || {
222215
rustc_lint::check_ast_crate(
223216
sess,
@@ -228,6 +221,17 @@ fn configure_and_expand_inner<'a>(
228221
rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
229222
);
230223
});
224+
}
225+
226+
fn configure_and_expand_inner<'a>(
227+
sess: &'a Session,
228+
lint_store: &'a LintStore,
229+
mut krate: ast::Crate,
230+
crate_name: &str,
231+
resolver_arenas: &'a ResolverArenas<'a>,
232+
metadata_loader: &'a MetadataLoaderDyn,
233+
) -> Result<(ast::Crate, Resolver<'a>)> {
234+
pre_expansion_lint(sess, lint_store, &krate);
231235

232236
let mut resolver = Resolver::new(sess, &krate, crate_name, metadata_loader, &resolver_arenas);
233237
rustc_builtin_macros::register_builtin_macros(&mut resolver, sess.edition());
@@ -291,7 +295,8 @@ fn configure_and_expand_inner<'a>(
291295
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
292296
};
293297

294-
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver);
298+
let extern_mod_loaded = |k: &ast::Crate| pre_expansion_lint(sess, lint_store, k);
299+
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver, Some(&extern_mod_loaded));
295300

296301
// Expand macros now!
297302
let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));

src/librustc_lint/early.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::context::{EarlyContext, LintContext, LintStore};
1818
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
1919
use rustc_ast::ast;
2020
use rustc_ast::visit as ast_visit;
21-
use rustc_session::lint::{LintBuffer, LintPass};
21+
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
2222
use rustc_session::Session;
2323
use rustc_span::Span;
2424

@@ -37,13 +37,7 @@ struct EarlyContextAndPass<'a, T: EarlyLintPass> {
3737
impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
3838
fn check_id(&mut self, id: ast::NodeId) {
3939
for early_lint in self.context.buffered.take(id) {
40-
let rustc_session::lint::BufferedEarlyLint {
41-
span,
42-
msg,
43-
node_id: _,
44-
lint_id,
45-
diagnostic,
46-
} = early_lint;
40+
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
4741
self.context.lookup_with_diagnostics(
4842
lint_id.lint,
4943
Some(span),
@@ -326,11 +320,9 @@ pub fn check_ast_crate<T: EarlyLintPass>(
326320
lint_buffer: Option<LintBuffer>,
327321
builtin_lints: T,
328322
) {
329-
let mut passes: Vec<_> = if pre_expansion {
330-
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
331-
} else {
332-
lint_store.early_passes.iter().map(|p| (p)()).collect()
333-
};
323+
let passes =
324+
if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes };
325+
let mut passes: Vec<_> = passes.iter().map(|p| (p)()).collect();
334326
let mut buffered = lint_buffer.unwrap_or_default();
335327

336328
if !sess.opts.debugging_opts.no_interleave_lints {

src/test/incremental/change_symbol_export_status.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// compile-flags: -Zquery-dep-graph
33

44
#![feature(rustc_attrs)]
5-
#![allow(private_no_mangle_fns)]
6-
7-
#![rustc_partition_codegened(module="change_symbol_export_status-mod1", cfg="rpass2")]
8-
#![rustc_partition_reused(module="change_symbol_export_status-mod2", cfg="rpass2")]
5+
#![rustc_partition_codegened(module = "change_symbol_export_status-mod1", cfg = "rpass2")]
6+
#![rustc_partition_reused(module = "change_symbol_export_status-mod2", cfg = "rpass2")]
97

108
// This test case makes sure that a change in symbol visibility is detected by
119
// our dependency tracking. We do this by changing a module's visibility to

src/test/ui-fulldeps/auxiliary/linkage-visibility.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
#![feature(rustc_private)]
44

5-
// We're testing linkage visibility; the compiler warns us, but we want to
6-
// do the runtime check that these functions aren't exported.
7-
#![allow(private_no_mangle_fns)]
8-
95
extern crate rustc_metadata;
106

117
use rustc_metadata::dynamic_lib::DynamicLibrary;
128

139
#[no_mangle]
14-
pub fn foo() { bar(); }
10+
pub fn foo() {
11+
bar();
12+
}
1513

1614
pub fn foo2<T>() {
1715
fn bar2() {
@@ -21,11 +19,11 @@ pub fn foo2<T>() {
2119
}
2220

2321
#[no_mangle]
24-
fn bar() { }
22+
fn bar() {}
2523

2624
#[allow(dead_code)]
2725
#[no_mangle]
28-
fn baz() { }
26+
fn baz() {}
2927

3028
pub fn test() {
3129
let lib = DynamicLibrary::open(None).unwrap();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
// compile-flags: -W rust-2018-compatibility
3+
// error-pattern: `try` is a keyword in the 2018 edition
4+
5+
fn main() {}
6+
7+
mod lint_pre_expansion_extern_module_aux;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: `try` is a keyword in the 2018 edition
2+
--> $DIR/lint_pre_expansion_extern_module_aux.rs:3:8
3+
|
4+
LL | pub fn try() {}
5+
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
6+
|
7+
= note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
9+
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
10+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// ignore-test: not a test
2+
3+
pub fn try() {}

0 commit comments

Comments
 (0)