Skip to content

Commit f58db20

Browse files
committed
move rustc::lint::{context, passes} to rustc_lint.
Also do some cleanup of the interface.
1 parent 8c12c42 commit f58db20

24 files changed

+505
-513
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3789,6 +3789,7 @@ dependencies = [
37893789
"rustc_error_codes",
37903790
"rustc_errors",
37913791
"rustc_hir",
3792+
"rustc_lint",
37923793
"rustc_metadata",
37933794
"rustc_span",
37943795
"syntax",

src/librustc/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ extern crate rustc_data_structures;
7272
#[macro_use]
7373
extern crate log;
7474
#[macro_use]
75-
extern crate syntax;
76-
#[macro_use]
7775
extern crate smallvec;
7876

7977
#[cfg(test)]

src/librustc/lint.rs

+49-394
Large diffs are not rendered by default.

src/librustc_ast_lowering/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use rustc::arena::Arena;
3737
use rustc::dep_graph::DepGraph;
3838
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
3939
use rustc::hir::map::Map;
40-
use rustc::lint::builtin;
4140
use rustc::{bug, span_bug};
4241
use rustc_data_structures::captures::Captures;
4342
use rustc_data_structures::fx::FxHashSet;
@@ -51,7 +50,7 @@ use rustc_hir::intravisit;
5150
use rustc_hir::{ConstArg, GenericArg, ParamName};
5251
use rustc_index::vec::IndexVec;
5352
use rustc_session::config::nightly_options;
54-
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
53+
use rustc_session::lint::{builtin, BuiltinLintDiagnostics, LintBuffer};
5554
use rustc_session::node_id::NodeMap;
5655
use rustc_session::Session;
5756
use rustc_span::hygiene::ExpnId;

src/librustc_driver/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ extern crate lazy_static;
2323

2424
pub extern crate rustc_plugin_impl as plugin;
2525

26-
//use rustc_resolve as resolve;
27-
use rustc::lint;
28-
use rustc::lint::Lint;
26+
use rustc::lint::{Lint, LintId};
2927
use rustc::middle::cstore::MetadataLoader;
3028
use rustc::session::config::nightly_options;
3129
use rustc::session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
@@ -41,6 +39,7 @@ use rustc_feature::{find_gated_cfg, UnstableFeatures};
4139
use rustc_hir::def_id::LOCAL_CRATE;
4240
use rustc_interface::util::get_builtin_codegen_backend;
4341
use rustc_interface::{interface, Queries};
42+
use rustc_lint::LintStore;
4443
use rustc_metadata::locator;
4544
use rustc_save_analysis as save;
4645
use rustc_save_analysis::DumpHandler;
@@ -811,7 +810,7 @@ the command line flag directly.
811810
);
812811
}
813812

814-
fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins: bool) {
813+
fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
815814
println!(
816815
"
817816
Available lint options:
@@ -832,8 +831,8 @@ Available lint options:
832831
}
833832

834833
fn sort_lint_groups(
835-
lints: Vec<(&'static str, Vec<lint::LintId>, bool)>,
836-
) -> Vec<(&'static str, Vec<lint::LintId>)> {
834+
lints: Vec<(&'static str, Vec<LintId>, bool)>,
835+
) -> Vec<(&'static str, Vec<LintId>)> {
837836
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
838837
lints.sort_by_key(|l| l.0);
839838
lints
@@ -892,7 +891,7 @@ Available lint options:
892891
println!(" {} {}", padded("----"), "---------");
893892
println!(" {} {}", padded("warnings"), "all lints that are set to issue warnings");
894893

895-
let print_lint_groups = |lints: Vec<(&'static str, Vec<lint::LintId>)>| {
894+
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
896895
for (name, to) in lints {
897896
let name = name.to_lowercase().replace("_", "-");
898897
let desc = to

src/librustc_interface/interface.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_data_structures::OnDrop;
1414
use rustc_errors::registry::Registry;
15+
use rustc_lint::LintStore;
1516
use rustc_parse::new_parser_from_source_str;
1617
use rustc_span::edition;
1718
use rustc_span::source_map::{FileLoader, FileName, SourceMap};
@@ -36,7 +37,7 @@ pub struct Compiler {
3637
pub(crate) output_dir: Option<PathBuf>,
3738
pub(crate) output_file: Option<PathBuf>,
3839
pub(crate) crate_name: Option<String>,
39-
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
40+
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
4041
pub(crate) override_queries:
4142
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
4243
}
@@ -136,7 +137,7 @@ pub struct Config {
136137
///
137138
/// Note that if you find a Some here you probably want to call that function in the new
138139
/// function being registered.
139-
pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
140+
pub register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
140141

141142
/// This is a callback from the driver that is called just after we have populated
142143
/// the list of queries.

src/librustc_interface/passes.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_errors::PResult;
2727
use rustc_expand::base::ExtCtxt;
2828
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2929
use rustc_incremental;
30+
use rustc_lint::LintStore;
3031
use rustc_mir as mir;
3132
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
3233
use rustc_passes::{self, hir_stats, layout_test};
@@ -100,7 +101,7 @@ declare_box_region_type!(
100101
/// Returns `None` if we're aborting after handling -W help.
101102
pub fn configure_and_expand(
102103
sess: Lrc<Session>,
103-
lint_store: Lrc<lint::LintStore>,
104+
lint_store: Lrc<LintStore>,
104105
metadata_loader: Box<MetadataLoaderDyn>,
105106
krate: ast::Crate,
106107
crate_name: &str,
@@ -150,10 +151,10 @@ impl BoxedResolver {
150151
pub fn register_plugins<'a>(
151152
sess: &'a Session,
152153
metadata_loader: &'a dyn MetadataLoader,
153-
register_lints: impl Fn(&Session, &mut lint::LintStore),
154+
register_lints: impl Fn(&Session, &mut LintStore),
154155
mut krate: ast::Crate,
155156
crate_name: &str,
156-
) -> Result<(ast::Crate, Lrc<lint::LintStore>)> {
157+
) -> Result<(ast::Crate, Lrc<LintStore>)> {
157158
krate = sess.time("attributes_injection", || {
158159
rustc_builtin_macros::cmdline_attrs::inject(
159160
krate,
@@ -214,7 +215,7 @@ pub fn register_plugins<'a>(
214215

215216
fn configure_and_expand_inner<'a>(
216217
sess: &'a Session,
217-
lint_store: &'a lint::LintStore,
218+
lint_store: &'a LintStore,
218219
mut krate: ast::Crate,
219220
crate_name: &str,
220221
resolver_arenas: &'a ResolverArenas<'a>,
@@ -420,7 +421,7 @@ fn configure_and_expand_inner<'a>(
420421

421422
pub fn lower_to_hir<'res, 'tcx>(
422423
sess: &'tcx Session,
423-
lint_store: &lint::LintStore,
424+
lint_store: &LintStore,
424425
resolver: &'res mut Resolver<'_>,
425426
dep_graph: &'res DepGraph,
426427
krate: &'res ast::Crate,
@@ -705,7 +706,7 @@ impl<'tcx> QueryContext<'tcx> {
705706

706707
pub fn create_global_ctxt<'tcx>(
707708
compiler: &'tcx Compiler,
708-
lint_store: Lrc<lint::LintStore>,
709+
lint_store: Lrc<LintStore>,
709710
hir_forest: &'tcx map::Forest<'tcx>,
710711
mut resolver_outputs: ResolverOutputs,
711712
outputs: OutputFilenames,

src/librustc_interface/queries.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use crate::passes::{self, BoxedResolver, QueryContext};
44
use rustc::arena::Arena;
55
use rustc::dep_graph::DepGraph;
66
use rustc::hir::map;
7-
use rustc::lint;
8-
use rustc::lint::LintStore;
97
use rustc::session::config::{OutputFilenames, OutputType};
108
use rustc::session::Session;
119
use rustc::ty::steal::Steal;
@@ -15,6 +13,7 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
1513
use rustc_data_structures::sync::{Lrc, Once, WorkerLocal};
1614
use rustc_hir::def_id::LOCAL_CRATE;
1715
use rustc_incremental::DepGraphFuture;
16+
use rustc_lint::LintStore;
1817
use std::any::Any;
1918
use std::cell::{Ref, RefCell, RefMut};
2019
use std::mem;
@@ -133,7 +132,7 @@ impl<'tcx> Queries<'tcx> {
133132
let crate_name = self.crate_name()?.peek().clone();
134133
let krate = self.parse()?.take();
135134

136-
let empty: &(dyn Fn(&Session, &mut lint::LintStore) + Sync + Send) = &|_, _| {};
135+
let empty: &(dyn Fn(&Session, &mut LintStore) + Sync + Send) = &|_, _| {};
137136
let result = passes::register_plugins(
138137
self.session(),
139138
&*self.codegen_backend().metadata_loader(),

src/librustc_lint/array_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc::lint::{LateContext, LateLintPass, LintContext};
1+
use crate::{LateContext, LateLintPass, LintContext};
22
use rustc::ty;
33
use rustc::ty::adjustment::{Adjust, Adjustment};
44
use rustc_errors::Applicability;

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
//! If you define a new `LateLintPass`, you will also need to add it to the
2222
//! `late_lint_methods!` invocation in `lib.rs`.
2323
24+
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2425
use rustc::hir::map::Map;
25-
use rustc::lint::{self, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2626
use rustc::traits::misc::can_type_implement_copy;
2727
use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
2828
use rustc_data_structures::fx::FxHashSet;
@@ -51,7 +51,7 @@ use log::debug;
5151
use std::fmt::Write;
5252

5353
// hardwired lints from librustc
54-
pub use lint::builtin::*;
54+
pub use rustc_session::lint::builtin::*;
5555

5656
declare_lint! {
5757
WHILE_TRUE,

src/librustc/lint/context.rs renamed to src/librustc_lint/context.rs

+9-50
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
1717
use self::TargetLint::*;
1818

19-
use crate::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
20-
use crate::lint::passes::{EarlyLintPassObject, LateLintPassObject};
21-
use crate::lint::LintLevelsBuilder;
22-
use crate::middle::privacy::AccessLevels;
23-
use crate::middle::stability;
24-
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
25-
use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
19+
use crate::levels::LintLevelsBuilder;
20+
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
21+
use rustc::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
22+
use rustc::lint::add_elided_lifetime_in_path_suggestion;
23+
use rustc::middle::privacy::AccessLevels;
24+
use rustc::middle::stability;
25+
use rustc::ty::layout::{LayoutError, LayoutOf, TyLayout};
26+
use rustc::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
2627
use rustc_data_structures::fx::FxHashMap;
2728
use rustc_data_structures::sync;
2829
use rustc_error_codes::*;
29-
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
30+
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
3031
use rustc_hir as hir;
3132
use rustc_hir::def_id::{CrateNum, DefId};
3233
use rustc_session::lint::BuiltinLintDiagnostics;
@@ -467,48 +468,6 @@ impl LintPassObject for EarlyLintPassObject {}
467468

468469
impl LintPassObject for LateLintPassObject {}
469470

470-
pub fn add_elided_lifetime_in_path_suggestion(
471-
sess: &Session,
472-
db: &mut DiagnosticBuilder<'_>,
473-
n: usize,
474-
path_span: Span,
475-
incl_angl_brckt: bool,
476-
insertion_span: Span,
477-
anon_lts: String,
478-
) {
479-
let (replace_span, suggestion) = if incl_angl_brckt {
480-
(insertion_span, anon_lts)
481-
} else {
482-
// When possible, prefer a suggestion that replaces the whole
483-
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
484-
// at a point (which makes for an ugly/confusing label)
485-
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
486-
// But our spans can get out of whack due to macros; if the place we think
487-
// we want to insert `'_` isn't even within the path expression's span, we
488-
// should bail out of making any suggestion rather than panicking on a
489-
// subtract-with-overflow or string-slice-out-out-bounds (!)
490-
// FIXME: can we do better?
491-
if insertion_span.lo().0 < path_span.lo().0 {
492-
return;
493-
}
494-
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
495-
if insertion_index > snippet.len() {
496-
return;
497-
}
498-
let (before, after) = snippet.split_at(insertion_index);
499-
(path_span, format!("{}{}{}", before, anon_lts, after))
500-
} else {
501-
(insertion_span, anon_lts)
502-
}
503-
};
504-
db.span_suggestion(
505-
replace_span,
506-
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
507-
suggestion,
508-
Applicability::MachineApplicable,
509-
);
510-
}
511-
512471
pub trait LintContext: Sized {
513472
type PassObject: LintPassObject;
514473

src/librustc_lint/early.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
//! upon. As the ast is traversed, this keeps track of the current lint level
1515
//! for all lint attributes.
1616
17-
use rustc::lint::{EarlyContext, LintStore};
18-
use rustc::lint::{EarlyLintPass, EarlyLintPassObject};
19-
use rustc::lint::{LintContext, LintPass};
20-
use rustc_session::lint::LintBuffer;
17+
use crate::context::{EarlyContext, LintContext, LintStore};
18+
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
19+
use rustc_session::lint::{LintBuffer, LintPass};
2120
use rustc_session::Session;
2221
use rustc_span::Span;
2322
use syntax::ast;
@@ -291,7 +290,7 @@ macro_rules! early_lint_pass_impl {
291290
)
292291
}
293292

294-
early_lint_methods!(early_lint_pass_impl, []);
293+
crate::early_lint_methods!(early_lint_pass_impl, []);
295294

296295
fn early_lint_crate<T: EarlyLintPass>(
297296
sess: &Session,

src/librustc_lint/internal.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
22
//! Clippy.
33
4-
use crate::lint::{EarlyContext, LateContext, LintContext};
5-
use crate::lint::{EarlyLintPass, LateLintPass};
4+
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
65
use rustc_data_structures::fx::FxHashMap;
76
use rustc_errors::Applicability;
87
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};

src/librustc_lint/late.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
//! upon. As the ast is traversed, this keeps track of the current lint level
1515
//! for all lint attributes.
1616
17+
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
1718
use rustc::hir::map::Map;
18-
use rustc::lint::{LateContext, LateLintPass, LateLintPassObject, LintStore};
1919
use rustc::ty::{self, TyCtxt};
2020
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
2121
use rustc_hir as hir;
@@ -347,7 +347,7 @@ macro_rules! late_lint_pass_impl {
347347
)
348348
}
349349

350-
late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
350+
crate::late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
351351

352352
fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
353353
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)