Skip to content

Commit 577d442

Browse files
De-propagate optional session from lint registration
This is straight up removing dead code, but is a separate commit from the previous to avoid conflating clean up and important changes.
1 parent 47a443c commit 577d442

File tree

4 files changed

+28
-42
lines changed

4 files changed

+28
-42
lines changed

src/librustc/lint/context.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
2626
use crate::lint::builtin::BuiltinLintDiagnostics;
2727
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
2828
use crate::middle::privacy::AccessLevels;
29-
use crate::session::{config, early_error, Session};
29+
use crate::session::Session;
3030
use crate::ty::{self, print::Printer, subst::GenericArg, TyCtxt, Ty};
3131
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
3232
use crate::util::nodemap::FxHashMap;
@@ -169,36 +169,33 @@ impl LintStore {
169169
}
170170

171171
pub fn register_early_pass(&mut self,
172-
sess: Option<&Session>,
173172
from_plugin: bool,
174173
register_only: bool,
175174
pass: EarlyLintPassObject) {
176-
self.push_pass(sess, from_plugin, &pass);
175+
self.push_pass(from_plugin, &pass);
177176
if !register_only {
178177
self.early_passes.as_mut().unwrap().push(pass);
179178
}
180179
}
181180

182181
pub fn register_pre_expansion_pass(
183182
&mut self,
184-
sess: Option<&Session>,
185183
from_plugin: bool,
186184
register_only: bool,
187185
pass: EarlyLintPassObject,
188186
) {
189-
self.push_pass(sess, from_plugin, &pass);
187+
self.push_pass(from_plugin, &pass);
190188
if !register_only {
191189
self.pre_expansion_passes.as_mut().unwrap().push(pass);
192190
}
193191
}
194192

195193
pub fn register_late_pass(&mut self,
196-
sess: Option<&Session>,
197194
from_plugin: bool,
198195
register_only: bool,
199196
per_module: bool,
200197
pass: LateLintPassObject) {
201-
self.push_pass(sess, from_plugin, &pass);
198+
self.push_pass(from_plugin, &pass);
202199
if !register_only {
203200
if per_module {
204201
self.late_module_passes.push(pass);
@@ -210,7 +207,6 @@ impl LintStore {
210207

211208
// Helper method for register_early/late_pass
212209
fn push_pass<P: LintPass + ?Sized + 'static>(&mut self,
213-
sess: Option<&Session>,
214210
from_plugin: bool,
215211
pass: &Box<P>) {
216212
for lint in pass.get_lints() {
@@ -224,14 +220,13 @@ impl LintStore {
224220
}
225221

226222
pub fn register_future_incompatible(&mut self,
227-
sess: Option<&Session>,
228223
lints: Vec<FutureIncompatibleInfo>) {
229224

230225
for edition in edition::ALL_EDITIONS {
231226
let lints = lints.iter().filter(|f| f.edition == Some(*edition)).map(|f| f.id)
232227
.collect::<Vec<_>>();
233228
if !lints.is_empty() {
234-
self.register_group(sess, false, edition.lint_name(), None, lints)
229+
self.register_group(false, edition.lint_name(), None, lints)
235230
}
236231
}
237232

@@ -242,7 +237,6 @@ impl LintStore {
242237
}
243238

244239
self.register_group(
245-
sess,
246240
false,
247241
"future_incompatible",
248242
None,
@@ -268,7 +262,6 @@ impl LintStore {
268262

269263
pub fn register_group(
270264
&mut self,
271-
sess: Option<&Session>,
272265
from_plugin: bool,
273266
name: &'static str,
274267
deprecated_name: Option<&'static str>,

src/librustc_interface/passes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ pub fn register_plugins<'a>(
299299

300300
let mut ls = sess.lint_store.borrow_mut();
301301
for pass in early_lint_passes {
302-
ls.register_early_pass(Some(sess), true, false, pass);
302+
ls.register_early_pass(true, false, pass);
303303
}
304304
for pass in late_lint_passes {
305-
ls.register_late_pass(Some(sess), true, false, false, pass);
305+
ls.register_late_pass(true, false, false, pass);
306306
}
307307

308308
for (name, (to, deprecated_name)) in lint_groups {
309-
ls.register_group(Some(sess), true, name, deprecated_name, to);
309+
ls.register_group(true, name, deprecated_name, to);
310310
}
311311

312312
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;

src/librustc_interface/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ pub fn create_session(
108108

109109
let codegen_backend = get_codegen_backend(&sess);
110110

111-
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
111+
rustc_lint::register_builtins(&mut sess.lint_store.get_mut(),
112+
sess.opts.debugging_opts.no_interleave_lints);
112113
if sess.unstable_options() {
113-
rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess));
114+
rustc_lint::register_internals(&mut sess.lint_store.get_mut());
114115
}
115116

116117
let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg));

src/librustc_lint/lib.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use rustc::lint::builtin::{
4141
PRIVATE_DOC_TESTS,
4242
parser::ILL_FORMED_ATTRIBUTE_INPUT,
4343
};
44-
use rustc::session;
4544
use rustc::hir;
4645
use rustc::hir::def_id::DefId;
4746
use rustc::ty::query::Providers;
@@ -51,7 +50,6 @@ use syntax::ast;
5150
use syntax::edition::Edition;
5251
use syntax_pos::Span;
5352

54-
use session::Session;
5553
use lint::LintId;
5654
use lint::FutureIncompatibleInfo;
5755

@@ -198,16 +196,16 @@ late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLint
198196
/// Tell the `LintStore` about all the built-in lints (the ones
199197
/// defined in this crate and the ones defined in
200198
/// `rustc::lint::builtin`).
201-
pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
199+
pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
202200
macro_rules! add_lint_group {
203-
($sess:ident, $name:expr, $($lint:ident),*) => (
204-
store.register_group($sess, false, $name, None, vec![$(LintId::of($lint)),*]);
201+
($name:expr, $($lint:ident),*) => (
202+
store.register_group(false, $name, None, vec![$(LintId::of($lint)),*]);
205203
)
206204
}
207205

208206
macro_rules! register_pass {
209207
($method:ident, $constructor:expr, [$($args:expr),*]) => (
210-
store.$method(sess, false, false, $($args,)* box $constructor);
208+
store.$method(false, false, $($args,)* box $constructor);
211209
)
212210
}
213211

@@ -219,35 +217,32 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
219217
)
220218
}
221219

222-
if sess.map(|sess| sess.opts.debugging_opts.no_interleave_lints).unwrap_or(false) {
220+
if no_interleave_lints {
223221
pre_expansion_lint_passes!(register_passes, [register_pre_expansion_pass, []]);
224222
early_lint_passes!(register_passes, [register_early_pass, []]);
225223
late_lint_passes!(register_passes, [register_late_pass, [false]]);
226224
late_lint_mod_passes!(register_passes, [register_late_pass, [true]]);
227225
} else {
228226
store.register_pre_expansion_pass(
229-
sess,
230227
false,
231228
true,
232229
box BuiltinCombinedPreExpansionLintPass::new()
233230
);
234-
store.register_early_pass(sess, false, true, box BuiltinCombinedEarlyLintPass::new());
231+
store.register_early_pass(false, true, box BuiltinCombinedEarlyLintPass::new());
235232
store.register_late_pass(
236-
sess, false, true, true, box BuiltinCombinedModuleLateLintPass::new()
233+
false, true, true, box BuiltinCombinedModuleLateLintPass::new()
237234
);
238235
store.register_late_pass(
239-
sess, false, true, false, box BuiltinCombinedLateLintPass::new()
236+
false, true, false, box BuiltinCombinedLateLintPass::new()
240237
);
241238
}
242239

243-
add_lint_group!(sess,
244-
"nonstandard_style",
240+
add_lint_group!("nonstandard_style",
245241
NON_CAMEL_CASE_TYPES,
246242
NON_SNAKE_CASE,
247243
NON_UPPER_CASE_GLOBALS);
248244

249-
add_lint_group!(sess,
250-
"unused",
245+
add_lint_group!("unused",
251246
UNUSED_IMPORTS,
252247
UNUSED_VARIABLES,
253248
UNUSED_ASSIGNMENTS,
@@ -267,8 +262,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
267262
UNUSED_LABELS,
268263
UNUSED_PARENS);
269264

270-
add_lint_group!(sess,
271-
"rust_2018_idioms",
265+
add_lint_group!("rust_2018_idioms",
272266
BARE_TRAIT_OBJECTS,
273267
UNUSED_EXTERN_CRATES,
274268
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
@@ -284,8 +278,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
284278
// MACRO_USE_EXTERN_CRATE,
285279
);
286280

287-
add_lint_group!(sess,
288-
"rustdoc",
281+
add_lint_group!("rustdoc",
289282
INTRA_DOC_LINK_RESOLUTION_FAILURE,
290283
MISSING_DOC_CODE_EXAMPLES,
291284
PRIVATE_DOC_TESTS);
@@ -298,7 +291,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
298291
// and include the full URL, sort items in ascending order of issue numbers.
299292
// - Later, change lint to error
300293
// - Eventually, remove lint
301-
store.register_future_incompatible(sess, vec![
294+
store.register_future_incompatible(vec![
302295
FutureIncompatibleInfo {
303296
id: LintId::of(PRIVATE_IN_PUBLIC),
304297
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
@@ -498,12 +491,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
498491
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
499492
}
500493

501-
pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {
502-
store.register_early_pass(sess, false, false, box DefaultHashTypes::new());
503-
store.register_early_pass(sess, false, false, box LintPassImpl);
504-
store.register_late_pass(sess, false, false, false, box TyTyKind);
494+
pub fn register_internals(store: &mut lint::LintStore) {
495+
store.register_early_pass(false, false, box DefaultHashTypes::new());
496+
store.register_early_pass(false, false, box LintPassImpl);
497+
store.register_late_pass(false, false, false, box TyTyKind);
505498
store.register_group(
506-
sess,
507499
false,
508500
"rustc::internal",
509501
None,

0 commit comments

Comments
 (0)