rustc_lint: Remove some redundant fields from EarlyContext
Use consistent function parameter order for early context construction and early linting Rename some functions to make it clear that they do not necessarily work on the whole crate
This commit is contained in:
@@ -29,12 +29,12 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
|
||||
let store = unerased_lint_store(tcx);
|
||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||
let levels = LintLevelsBuilder::new(tcx.sess, false, &store, crate_attrs);
|
||||
let mut builder = LintLevelMapBuilder { levels, tcx, store };
|
||||
let mut builder = LintLevelMapBuilder { levels, tcx };
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
builder.levels.id_to_set.reserve(krate.owners.len() + 1);
|
||||
|
||||
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true);
|
||||
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), true);
|
||||
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||
tcx.hir().walk_toplevel_module(&mut builder);
|
||||
builder.levels.pop(push);
|
||||
@@ -78,6 +78,14 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
builder
|
||||
}
|
||||
|
||||
pub(crate) fn sess(&self) -> &Session {
|
||||
self.sess
|
||||
}
|
||||
|
||||
pub(crate) fn lint_store(&self) -> &LintStore {
|
||||
self.store
|
||||
}
|
||||
|
||||
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
|
||||
let mut specs = FxHashMap::default();
|
||||
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
|
||||
@@ -217,12 +225,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
/// `#[allow]`
|
||||
///
|
||||
/// Don't forget to call `pop`!
|
||||
pub(crate) fn push(
|
||||
&mut self,
|
||||
attrs: &[ast::Attribute],
|
||||
store: &LintStore,
|
||||
is_crate_node: bool,
|
||||
) -> BuilderPush {
|
||||
pub(crate) fn push(&mut self, attrs: &[ast::Attribute], is_crate_node: bool) -> BuilderPush {
|
||||
let mut specs = FxHashMap::default();
|
||||
let sess = self.sess;
|
||||
let bad_attr = |span| struct_span_err!(sess, span, E0452, "malformed lint attribute input");
|
||||
@@ -310,7 +313,8 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
};
|
||||
let tool_name = tool_ident.map(|ident| ident.name);
|
||||
let name = pprust::path_to_string(&meta_item.path);
|
||||
let lint_result = store.check_lint_name(sess, &name, tool_name, self.crate_attrs);
|
||||
let lint_result =
|
||||
self.store.check_lint_name(sess, &name, tool_name, self.crate_attrs);
|
||||
match &lint_result {
|
||||
CheckLintNameResult::Ok(ids) => {
|
||||
let src = LintLevelSource::Node(
|
||||
@@ -459,7 +463,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
// Ignore any errors or warnings that happen because the new name is inaccurate
|
||||
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
||||
if let CheckLintNameResult::Ok(ids) =
|
||||
store.check_lint_name(sess, &new_name, None, self.crate_attrs)
|
||||
self.store.check_lint_name(sess, &new_name, None, self.crate_attrs)
|
||||
{
|
||||
let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason);
|
||||
for &id in ids {
|
||||
@@ -576,20 +580,19 @@ pub fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribut
|
||||
.any(|name| name == m_item)
|
||||
}
|
||||
|
||||
struct LintLevelMapBuilder<'a, 'tcx> {
|
||||
struct LintLevelMapBuilder<'tcx> {
|
||||
levels: LintLevelsBuilder<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
store: &'a LintStore,
|
||||
}
|
||||
|
||||
impl LintLevelMapBuilder<'_, '_> {
|
||||
impl LintLevelMapBuilder<'_> {
|
||||
fn with_lint_attrs<F>(&mut self, id: hir::HirId, f: F)
|
||||
where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let is_crate_hir = id == hir::CRATE_HIR_ID;
|
||||
let attrs = self.tcx.hir().attrs(id);
|
||||
let push = self.levels.push(attrs, self.store, is_crate_hir);
|
||||
let push = self.levels.push(attrs, is_crate_hir);
|
||||
if push.changed {
|
||||
self.levels.register_id(id);
|
||||
}
|
||||
@@ -598,7 +601,7 @@ impl LintLevelMapBuilder<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> {
|
||||
type NestedFilter = nested_filter::All;
|
||||
|
||||
fn nested_visit_map(&mut self) -> Self::Map {
|
||||
|
||||
Reference in New Issue
Block a user