Skip to content

Commit 32bc4a5

Browse files
committed
Make more lints incremental
1 parent 7e156c2 commit 32bc4a5

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

src/librustc/hir/map/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<'hir> Map<'hir> {
10131013
/// corresponding to the Node ID
10141014
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
10151015
self.read(id); // reveals attributes on the node
1016-
let attrs = match self.find(id) {
1016+
let attrs = match self.find_entry(id).map(|entry| entry.node) {
10171017
Some(Node::Local(l)) => Some(&l.attrs[..]),
10181018
Some(Node::Item(i)) => Some(&i.attrs[..]),
10191019
Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]),
@@ -1027,6 +1027,7 @@ impl<'hir> Map<'hir> {
10271027
// Unit/tuple structs/variants take the attributes straight from
10281028
// the struct/variant definition.
10291029
Some(Node::Ctor(..)) => return self.attrs(self.get_parent(id)),
1030+
Some(Node::Crate) => Some(&self.forest.krate.attrs[..]),
10301031
_ => None
10311032
};
10321033
attrs.unwrap_or(&[])

src/librustc/lint/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use errors::DiagnosticBuilder;
3939
use crate::hir;
4040
use crate::hir::def_id::{DefId, LOCAL_CRATE};
4141
use crate::hir::intravisit as hir_visit;
42+
use crate::hir::intravisit::Visitor;
4243
use syntax::util::lev_distance::find_best_match_for_name;
4344
use syntax::visit as ast_visit;
4445

@@ -1244,6 +1245,11 @@ pub fn lint_mod<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) {
12441245
let (module, span, hir_id) = tcx.hir().get_module(module_def_id);
12451246
cx.process_mod(module, span, hir_id);
12461247

1248+
// Visit the crate attributes
1249+
if hir_id == hir::CRATE_HIR_ID {
1250+
walk_list!(cx, visit_attribute, cx.tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID));
1251+
}
1252+
12471253
// Put the lint store levels and passes back in the session.
12481254
let passes = cx.lint_sess.passes;
12491255
drop(cx.lint_sess.lints);

src/librustc_lint/lib.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
125125
store.register_early_pass(sess, false, true, box BuiltinCombinedEarlyLintPass::new());
126126
}
127127

128-
// FIXME: Make a separate lint type which do not require typeck tables
129-
130128
late_lint_methods!(declare_combined_late_lint_pass, [BuiltinCombinedModuleLateLintPass, [
131129
HardwiredLints: HardwiredLints,
132130
WhileTrue: WhileTrue,
133131
ImproperCTypes: ImproperCTypes,
134132
VariantSizeDifferences: VariantSizeDifferences,
135133
BoxPointers: BoxPointers,
136134
PathStatements: PathStatements,
135+
136+
// Depends on referenced function signatures in expressions
137137
UnusedResults: UnusedResults,
138+
138139
NonUpperCaseGlobals: NonUpperCaseGlobals,
139140
NonShorthandFieldPatterns: NonShorthandFieldPatterns,
140141
UnusedAllocation: UnusedAllocation,
@@ -157,39 +158,35 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
157158

158159
TrivialConstraints: TrivialConstraints,
159160
TypeLimits: TypeLimits::new(),
161+
162+
NonSnakeCase: NonSnakeCase,
163+
InvalidNoMangleItems: InvalidNoMangleItems,
164+
165+
// Depends on access levels
166+
UnreachablePub: UnreachablePub,
167+
168+
ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
160169
]], ['tcx]);
161170

162171
store.register_late_pass(sess, false, true, box BuiltinCombinedModuleLateLintPass::new());
163172

164173
late_lint_methods!(declare_combined_late_lint_pass, [BuiltinCombinedLateLintPass, [
165-
166174
// Uses attr::is_used which is untracked, can't be an incremental module pass.
167-
// Doesn't require type tables. Make a separate combined pass for that?
168175
UnusedAttributes: UnusedAttributes,
169176

170-
171-
// Checks crate attributes. Find out how that would work.
172-
NonSnakeCase: NonSnakeCase,
173-
174-
175-
// Needs to look at crate attributes. Make sure that works
177+
// Needs to run after UnusedAttributes as it marks all `feature` attributes as used.
176178
UnstableFeatures: UnstableFeatures,
177179

178-
// Depends on access levels
179-
InvalidNoMangleItems: InvalidNoMangleItems,
180-
181-
// Depends on access levels
182-
UnreachablePub: UnreachablePub,
183-
180+
// Tracks state across modules
184181
UnnameableTestItems: UnnameableTestItems::new(),
185182

186183
// Tracks attributes of parents
187184
MissingDoc: MissingDoc::new(),
188185

189186
// Depends on access levels
187+
// FIXME: Turn the computation of types which implement Debug into a query
188+
// and change this to a module lint pass
190189
MissingDebugImplementations: MissingDebugImplementations::new(),
191-
192-
ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
193190
]], ['tcx]);
194191

195192
store.register_late_pass(sess, false, false, box BuiltinCombinedLateLintPass::new());

src/librustc_lint/nonstandard_style.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,15 @@ impl LintPass for NonSnakeCase {
267267
}
268268

269269
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
270-
fn check_crate(&mut self, cx: &LateContext<'_, '_>, cr: &hir::Crate) {
270+
fn check_mod(&mut self, cx: &LateContext<'_, '_>, _: &'tcx hir::Mod, _: Span, id: hir::HirId) {
271+
if id != hir::CRATE_HIR_ID {
272+
return;
273+
}
274+
271275
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
272276
Some(Ident::from_str(name))
273277
} else {
274-
attr::find_by_name(&cr.attrs, "crate_name")
278+
attr::find_by_name(&cx.tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID), "crate_name")
275279
.and_then(|attr| attr.meta())
276280
.and_then(|meta| {
277281
meta.name_value_literal().and_then(|lit| {

0 commit comments

Comments
 (0)