Skip to content

Commit

Permalink
Cleanup, handle reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Sep 14, 2024
1 parent b5ac9b5 commit 66b4653
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 133 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
tcx.ensure().check_mod_privacy(module);
});
});
} // { sess.time("mir_checking", || { tcx.hir().mir_for }) }
}
);

// This check has to be run after all lints are done processing. We don't
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ declare_lint! {
UNSAFE_CODE,
Allow,
"usage of `unsafe` code and other potentially unsound constructs",
[loadbearing: true]
[eval_always: true]
}

declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ declare_tool_lint! {
Deny,
"prevent creation of diagnostics which cannot be translated",
report_in_external_macro: true,
[loadbearing: true]
[eval_always: true]
}

declare_tool_lint! {
Expand All @@ -454,7 +454,7 @@ declare_tool_lint! {
Deny,
"prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
report_in_external_macro: true,
[loadbearing: true]
[eval_always: true]
}

declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
if store.late_module_passes.is_empty() {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
} else {
let mut filtered_passes: Vec<_> =
store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
filtered_passes.push(Box::new(builtin_lints));
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
let chained_box = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
let mut binding = store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).chain(std::iter::once(chained_box)).collect::<Vec<_>>();

let pass = RuntimeCombinedLateLintPass { passes: binding.as_mut_slice() };
late_lint_mod_inner(tcx, module_def_id, context, pass);
}
}
Expand Down Expand Up @@ -425,7 +425,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {

let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());

// dbg!(&lints_that_dont_need_to_run);
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
.into_iter()
.filter(|pass| {
Expand Down
69 changes: 7 additions & 62 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::errors::{
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
};
use crate::fluent_generated as fluent;
use crate::late::{unerased_lint_store /*name_without_tool*/};
use crate::late::unerased_lint_store;
use crate::lints::{
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
OverruledAttributeLint, RemovedLint, RemovedLintFromCommandLine, RenamedLint,
Expand Down Expand Up @@ -122,7 +122,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
.get_lints()
.into_iter()
.filter_map(|lint| {
if !lint.loadbearing && lint.default_level(tcx.sess.edition()) == Level::Allow {
if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow {
Some(LintId::of(lint))
} else {
None
Expand All @@ -134,21 +134,6 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
visitor.process_opts();
tcx.hir().walk_attributes(&mut visitor);

// let lint_groups = store.get_lint_groups();
// for group in lint_groups {
// let binding = group.0.to_lowercase();
// let group_name = name_without_tool(&binding).to_string();
// if visitor.lints_that_actually_run.contains(&group_name) {
// for lint in group.1 {
// visitor.lints_that_actually_run.insert(name_without_tool(&lint.to_string()).to_string());
// }
// } else if visitor.lints_allowed.contains(&group_name) {
// for lint in &group.1 {
// visitor.lints_allowed.insert(name_without_tool(&lint.to_string()).to_string());
// }
// }
// }

visitor.dont_need_to_run
}

Expand Down Expand Up @@ -374,22 +359,25 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
self.tcx.hir()
}

/// FIXME(blyxyas): In a future revision, we should also graph #![allow]s,
/// but that is handled with more care
fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) {
match Level::from_attr(attribute) {
if matches!(Level::from_attr(attribute),
Some(
Level::Warn
| Level::Deny
| Level::Forbid
| Level::Expect(..)
| Level::ForceWarn(..),
) => {
)) {
let store = unerased_lint_store(self.tcx.sess);
let Some(meta) = attribute.meta() else { return };
// SAFETY: Lint attributes are always a metalist inside a
// metalist (even with just one lint).
let Some(meta_item_list) = meta.meta_item_list() else { return };

for meta_list in meta_item_list {

// Convert Path to String
let Some(meta_item) = meta_list.meta_item() else { return };
let ident: &str = &meta_item
Expand All @@ -408,50 +396,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
for lint in lints {
self.dont_need_to_run.swap_remove(&lint);
}
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
// if meta_item.path.segments.len() == 1 {
// let Ok(lints) = store.find_lints(
// // SAFETY: Lint attributes can only have literals
// meta_list.ident().unwrap().name.as_str(),
// ) else {
// return;
// };
// for lint in lints {
// dbg!("LINT REMOVED", &lint);
// self.dont_need_to_run.swap_remove(&lint);
// }
// } else {
// let Ok(lints) = store.find_lints(
// // SAFETY: Lint attributes can only have literals
// meta_item.path.segments[1].ident.name.as_str(),
// ) else {
// return;
// };
// for lint in lints {
// dbg!("LINT REMOVED", &lint);
// self.dont_need_to_run.swap_remove(&lint);
// }
// }
}
// We handle #![allow]s differently, as these remove checking rather than adding.
} // Some(Level::Allow) if ast::AttrStyle::Inner == attribute.style => {
// for meta_list in meta.meta_item_list().unwrap() {
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
// if meta_item.path.segments.len() == 1 {
// self.lints_allowed
// .insert(meta_list.name_or_empty().as_str().to_string());
// } else {
// self.lints_allowed
// .insert(meta_item.path.segments[1].ident.name.as_str().to_string());
// }
// }
// }
// }
_ => {
return;
}
}
}
}
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,7 @@ macro_rules! declare_late_lint_pass {
// for all the `check_*` methods.
late_lint_methods!(declare_late_lint_pass, []);

impl LateLintPass<'_> for HardwiredLints {
fn check_fn(
&mut self,
_: &LateContext<'_>,
_: rustc_hir::intravisit::FnKind<'_>,
_: &'_ rustc_hir::FnDecl<'_>,
_: &'_ rustc_hir::Body<'_>,
_: rustc_span::Span,
_: rustc_span::def_id::LocalDefId,
) {
}
}
impl LateLintPass<'_> for HardwiredLints {}

#[macro_export]
macro_rules! expand_combined_late_lint_pass_method {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use rustc_span::edition::Edition;
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};

declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
HardwiredLints => [
// tidy-alphabetical-start
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
Expand Down Expand Up @@ -377,7 +379,7 @@ declare_lint! {
pub ARITHMETIC_OVERFLOW,
Deny,
"arithmetic operation overflows",
[loadbearing: true]
[eval_always: true]
}

declare_lint! {
Expand All @@ -402,7 +404,7 @@ declare_lint! {
pub UNCONDITIONAL_PANIC,
Deny,
"operation will cause a panic at runtime",
[loadbearing: true]
[eval_always: true]
}

declare_lint! {
Expand Down Expand Up @@ -634,7 +636,7 @@ declare_lint! {
pub UNKNOWN_LINTS,
Warn,
"unrecognized lint attribute",
[loadbearing: true]
[eval_always: true]
}

declare_lint! {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub struct Lint {

/// `true` if this lint should not be filtered out under any circustamces
/// (e.g. the unknown_attributes lint)
pub loadbearing: bool,
pub eval_always: bool,
}

/// Extra information for a future incompatibility lint.
Expand Down Expand Up @@ -460,7 +460,7 @@ impl Lint {
future_incompatible: None,
feature_gate: None,
crate_level_only: false,
loadbearing: false,
eval_always: false,
}
}

Expand Down Expand Up @@ -863,7 +863,7 @@ macro_rules! declare_lint {
$(#[$attr])* $vis $NAME, $Level, $desc,
);
);
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr, $([loadbearing: $loadbearing: literal])?
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr, $([eval_always: $eval_always: literal])?
$(@feature_gate = $gate:ident;)?
$(@future_incompatible = FutureIncompatibleInfo {
reason: $reason:expr,
Expand All @@ -885,7 +885,7 @@ macro_rules! declare_lint {
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
}),)?
$(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
$(loadbearing: $loadbearing,)?
$(eval_always: $eval_always,)?
..$crate::Lint::default_fields_for_macro()
};
);
Expand All @@ -896,23 +896,23 @@ macro_rules! declare_tool_lint {
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
$(, @feature_gate = $gate:ident;)?
$(, [loadbearing: $loadbearing: literal])?
$(, [eval_always: $eval_always: literal])?
) => (
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
report_in_external_macro: $rep:expr
$(, @feature_gate = $gate:ident;)?
$(, [loadbearing: $loadbearing: literal])?
$(, [eval_always: $eval_always: literal])?
) => (
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
$external:expr
$(, @feature_gate = $gate:ident;)?
$(, [loadbearing: $loadbearing: literal])?
$(, [eval_always: $eval_always: literal])?
) => (
$(#[$attr])*
$vis static $NAME: &$crate::Lint = &$crate::Lint {
Expand All @@ -925,7 +925,7 @@ macro_rules! declare_tool_lint {
is_externally_loaded: true,
$(feature_gate: Some(rustc_span::symbol::sym::$gate),)?
crate_level_only: false,
$(loadbearing: $loadbearing,)?
$(eval_always: $eval_always,)?
..$crate::Lint::default_fields_for_macro()
};
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ShallowLintLevelMap {
/// This lint level is not usable for diagnostics, it needs to be corrected by
/// `reveal_actual_level` beforehand.
#[instrument(level = "trace", skip(self, tcx), ret)]
pub fn probe_for_lint_level(
fn probe_for_lint_level(
&self,
tcx: TyCtxt<'_>,
id: LintId,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ pub struct Session {
/// errors.
pub ctfe_backtrace: Lock<CtfeBacktrace>,

// pub force_ctfe: bool,
/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
/// const check, optionally with the relevant feature gate. We use this to
/// warn about unleashing, but with a single diagnostic instead of dozens that
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
future_incompatible: None,
is_externally_loaded: true,
crate_level_only: false,
loadbearing: true,
eval_always: true,
..Lint::default_fields_for_macro()
};
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
Expand All @@ -44,7 +44,7 @@ Sometimes it's hard to find a way to reduce the complexity.
### Example
You'll see it when you get the warning.",
version: Some("1.35.0"),
location: "#L0",
location: "clippy_lints/src/cognitive_complexity.rs#L47",
};

pub struct CognitiveComplexity {
Expand Down
Loading

0 comments on commit 66b4653

Please sign in to comment.