Skip to content
Permalink
Browse files

move rustc::lint::{context, passes} to rustc_lint.

Also do some cleanup of the interface.
  • Loading branch information
Centril committed Jan 9, 2020
1 parent 8c12c42 commit f58db203623b89e6c9e68d4b9ccb000031825cc4
@@ -3789,6 +3789,7 @@ dependencies = [
"rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_lint",
"rustc_metadata",
"rustc_span",
"syntax",
@@ -72,8 +72,6 @@ extern crate rustc_data_structures;
#[macro_use]
extern crate log;
#[macro_use]
extern crate syntax;
#[macro_use]
extern crate smallvec;

#[cfg(test)]

Large diffs are not rendered by default.

@@ -37,7 +37,6 @@ use rustc::arena::Arena;
use rustc::dep_graph::DepGraph;
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
use rustc::hir::map::Map;
use rustc::lint::builtin;
use rustc::{bug, span_bug};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
@@ -51,7 +50,7 @@ use rustc_hir::intravisit;
use rustc_hir::{ConstArg, GenericArg, ParamName};
use rustc_index::vec::IndexVec;
use rustc_session::config::nightly_options;
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
use rustc_session::lint::{builtin, BuiltinLintDiagnostics, LintBuffer};
use rustc_session::node_id::NodeMap;
use rustc_session::Session;
use rustc_span::hygiene::ExpnId;
@@ -23,9 +23,7 @@ extern crate lazy_static;

pub extern crate rustc_plugin_impl as plugin;

//use rustc_resolve as resolve;
use rustc::lint;
use rustc::lint::Lint;
use rustc::lint::{Lint, LintId};
use rustc::middle::cstore::MetadataLoader;
use rustc::session::config::nightly_options;
use rustc::session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
@@ -41,6 +39,7 @@ use rustc_feature::{find_gated_cfg, UnstableFeatures};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_interface::util::get_builtin_codegen_backend;
use rustc_interface::{interface, Queries};
use rustc_lint::LintStore;
use rustc_metadata::locator;
use rustc_save_analysis as save;
use rustc_save_analysis::DumpHandler;
@@ -811,7 +810,7 @@ the command line flag directly.
);
}

fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins: bool) {
fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
println!(
"
Available lint options:
@@ -832,8 +831,8 @@ Available lint options:
}

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

let print_lint_groups = |lints: Vec<(&'static str, Vec<lint::LintId>)>| {
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
for (name, to) in lints {
let name = name.to_lowercase().replace("_", "-");
let desc = to
@@ -12,6 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::OnDrop;
use rustc_errors::registry::Registry;
use rustc_lint::LintStore;
use rustc_parse::new_parser_from_source_str;
use rustc_span::edition;
use rustc_span::source_map::{FileLoader, FileName, SourceMap};
@@ -36,7 +37,7 @@ pub struct Compiler {
pub(crate) output_dir: Option<PathBuf>,
pub(crate) output_file: Option<PathBuf>,
pub(crate) crate_name: Option<String>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries:
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
}
@@ -136,7 +137,7 @@ pub struct Config {
///
/// Note that if you find a Some here you probably want to call that function in the new
/// function being registered.
pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
pub register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,

/// This is a callback from the driver that is called just after we have populated
/// the list of queries.
@@ -27,6 +27,7 @@ use rustc_errors::PResult;
use rustc_expand::base::ExtCtxt;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_incremental;
use rustc_lint::LintStore;
use rustc_mir as mir;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
use rustc_passes::{self, hir_stats, layout_test};
@@ -100,7 +101,7 @@ declare_box_region_type!(
/// Returns `None` if we're aborting after handling -W help.
pub fn configure_and_expand(
sess: Lrc<Session>,
lint_store: Lrc<lint::LintStore>,
lint_store: Lrc<LintStore>,
metadata_loader: Box<MetadataLoaderDyn>,
krate: ast::Crate,
crate_name: &str,
@@ -150,10 +151,10 @@ impl BoxedResolver {
pub fn register_plugins<'a>(
sess: &'a Session,
metadata_loader: &'a dyn MetadataLoader,
register_lints: impl Fn(&Session, &mut lint::LintStore),
register_lints: impl Fn(&Session, &mut LintStore),
mut krate: ast::Crate,
crate_name: &str,
) -> Result<(ast::Crate, Lrc<lint::LintStore>)> {
) -> Result<(ast::Crate, Lrc<LintStore>)> {
krate = sess.time("attributes_injection", || {
rustc_builtin_macros::cmdline_attrs::inject(
krate,
@@ -214,7 +215,7 @@ pub fn register_plugins<'a>(

fn configure_and_expand_inner<'a>(
sess: &'a Session,
lint_store: &'a lint::LintStore,
lint_store: &'a LintStore,
mut krate: ast::Crate,
crate_name: &str,
resolver_arenas: &'a ResolverArenas<'a>,
@@ -420,7 +421,7 @@ fn configure_and_expand_inner<'a>(

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

pub fn create_global_ctxt<'tcx>(
compiler: &'tcx Compiler,
lint_store: Lrc<lint::LintStore>,
lint_store: Lrc<LintStore>,
hir_forest: &'tcx map::Forest<'tcx>,
mut resolver_outputs: ResolverOutputs,
outputs: OutputFilenames,
@@ -4,8 +4,6 @@ use crate::passes::{self, BoxedResolver, QueryContext};
use rustc::arena::Arena;
use rustc::dep_graph::DepGraph;
use rustc::hir::map;
use rustc::lint;
use rustc::lint::LintStore;
use rustc::session::config::{OutputFilenames, OutputType};
use rustc::session::Session;
use rustc::ty::steal::Steal;
@@ -15,6 +13,7 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::sync::{Lrc, Once, WorkerLocal};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_incremental::DepGraphFuture;
use rustc_lint::LintStore;
use std::any::Any;
use std::cell::{Ref, RefCell, RefMut};
use std::mem;
@@ -133,7 +132,7 @@ impl<'tcx> Queries<'tcx> {
let crate_name = self.crate_name()?.peek().clone();
let krate = self.parse()?.take();

let empty: &(dyn Fn(&Session, &mut lint::LintStore) + Sync + Send) = &|_, _| {};
let empty: &(dyn Fn(&Session, &mut LintStore) + Sync + Send) = &|_, _| {};
let result = passes::register_plugins(
self.session(),
&*self.codegen_backend().metadata_loader(),
@@ -1,4 +1,4 @@
use rustc::lint::{LateContext, LateLintPass, LintContext};
use crate::{LateContext, LateLintPass, LintContext};
use rustc::ty;
use rustc::ty::adjustment::{Adjust, Adjustment};
use rustc_errors::Applicability;
@@ -21,8 +21,8 @@
//! If you define a new `LateLintPass`, you will also need to add it to the
//! `late_lint_methods!` invocation in `lib.rs`.

use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc::hir::map::Map;
use rustc::lint::{self, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc::traits::misc::can_type_implement_copy;
use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashSet;
@@ -51,7 +51,7 @@ use log::debug;
use std::fmt::Write;

// hardwired lints from librustc
pub use lint::builtin::*;
pub use rustc_session::lint::builtin::*;

declare_lint! {
WHILE_TRUE,
@@ -16,17 +16,18 @@

use self::TargetLint::*;

use crate::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
use crate::lint::passes::{EarlyLintPassObject, LateLintPassObject};
use crate::lint::LintLevelsBuilder;
use crate::middle::privacy::AccessLevels;
use crate::middle::stability;
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
use crate::levels::LintLevelsBuilder;
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
use rustc::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc::lint::add_elided_lifetime_in_path_suggestion;
use rustc::middle::privacy::AccessLevels;
use rustc::middle::stability;
use rustc::ty::layout::{LayoutError, LayoutOf, TyLayout};
use rustc::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync;
use rustc_error_codes::*;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_session::lint::BuiltinLintDiagnostics;
@@ -467,48 +468,6 @@ impl LintPassObject for EarlyLintPassObject {}

impl LintPassObject for LateLintPassObject {}

pub fn add_elided_lifetime_in_path_suggestion(
sess: &Session,
db: &mut DiagnosticBuilder<'_>,
n: usize,
path_span: Span,
incl_angl_brckt: bool,
insertion_span: Span,
anon_lts: String,
) {
let (replace_span, suggestion) = if incl_angl_brckt {
(insertion_span, anon_lts)
} else {
// When possible, prefer a suggestion that replaces the whole
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
// at a point (which makes for an ugly/confusing label)
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
// But our spans can get out of whack due to macros; if the place we think
// we want to insert `'_` isn't even within the path expression's span, we
// should bail out of making any suggestion rather than panicking on a
// subtract-with-overflow or string-slice-out-out-bounds (!)
// FIXME: can we do better?
if insertion_span.lo().0 < path_span.lo().0 {
return;
}
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
if insertion_index > snippet.len() {
return;
}
let (before, after) = snippet.split_at(insertion_index);
(path_span, format!("{}{}{}", before, anon_lts, after))
} else {
(insertion_span, anon_lts)
}
};
db.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
suggestion,
Applicability::MachineApplicable,
);
}

pub trait LintContext: Sized {
type PassObject: LintPassObject;

@@ -14,10 +14,9 @@
//! upon. As the ast is traversed, this keeps track of the current lint level
//! for all lint attributes.

use rustc::lint::{EarlyContext, LintStore};
use rustc::lint::{EarlyLintPass, EarlyLintPassObject};
use rustc::lint::{LintContext, LintPass};
use rustc_session::lint::LintBuffer;
use crate::context::{EarlyContext, LintContext, LintStore};
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
use rustc_session::lint::{LintBuffer, LintPass};
use rustc_session::Session;
use rustc_span::Span;
use syntax::ast;
@@ -291,7 +290,7 @@ macro_rules! early_lint_pass_impl {
)
}

early_lint_methods!(early_lint_pass_impl, []);
crate::early_lint_methods!(early_lint_pass_impl, []);

fn early_lint_crate<T: EarlyLintPass>(
sess: &Session,
@@ -1,8 +1,7 @@
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
//! Clippy.

use crate::lint::{EarlyContext, LateContext, LintContext};
use crate::lint::{EarlyLintPass, LateLintPass};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
@@ -14,8 +14,8 @@
//! upon. As the ast is traversed, this keeps track of the current lint level
//! for all lint attributes.

use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
use rustc::hir::map::Map;
use rustc::lint::{LateContext, LateLintPass, LateLintPassObject, LintStore};
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
use rustc_hir as hir;
@@ -347,7 +347,7 @@ macro_rules! late_lint_pass_impl {
)
}

late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
crate::late_lint_methods!(late_lint_pass_impl, [], ['tcx]);

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

0 comments on commit f58db20

Please sign in to comment.
You can’t perform that action at this time.