Skip to content

Commit da27a91

Browse files
committed
Rename CLIPPY_CTFE->CTFE and use declare_tool_lint to declare it
1 parent 9c77860 commit da27a91

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

clippy_lints/src/ctfe.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ extern crate clippy_utils;
6565
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
6666
mod utils;
6767

68-
pub mod ctfe; // Very important lint, do not remove (rust#125116)
6968
pub mod declared_lints;
7069
pub mod deprecated_lints;
7170

@@ -607,7 +606,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
607606
store.register_late_pass(|_| Box::new(utils::internal_lints::slow_symbol_comparisons::SlowSymbolComparisons));
608607
}
609608

610-
store.register_late_pass(|_| Box::new(ctfe::ClippyCtfe));
609+
store.register_late_pass(|_| Box::new(utils::ctfe::ClippyCtfe));
611610

612611
store.register_late_pass(move |_| Box::new(operators::arithmetic_side_effects::ArithmeticSideEffects::new(conf)));
613612
store.register_late_pass(|_| Box::new(utils::dump_hir::DumpHir));

clippy_lints/src/utils/ctfe.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use rustc_hir::def_id::LocalDefId;
2+
use rustc_hir::intravisit::FnKind;
3+
use rustc_hir::{Body, FnDecl};
4+
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_session::{declare_lint_pass, declare_tool_lint};
6+
use rustc_span::Span;
7+
8+
// Not using `declare_clippy_lint`, so that no static CLIPPY_CTFE_INFO is created, so this lint
9+
// doesn't show up in the documentation.
10+
declare_tool_lint! {
11+
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
12+
/// As Clippy deactivates codegen, this lint ensures that CTFE (used in hard errors) is still ran.
13+
pub clippy::CTFE,
14+
Allow,
15+
"Ensure CTFE is being made",
16+
report_in_external_macro: true,
17+
@eval_always = true
18+
}
19+
20+
declare_lint_pass! { ClippyCtfe => [CTFE] }
21+
22+
impl<'tcx> LateLintPass<'tcx> for ClippyCtfe {
23+
fn check_fn(
24+
&mut self,
25+
cx: &LateContext<'_>,
26+
_: FnKind<'tcx>,
27+
_: &'tcx FnDecl<'tcx>,
28+
_: &'tcx Body<'tcx>,
29+
_: Span,
30+
defid: LocalDefId,
31+
) {
32+
cx.tcx.ensure().mir_drops_elaborated_and_const_checked(defid); // Lint
33+
}
34+
}

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod author;
2+
pub mod ctfe;
23
pub mod dump_hir;
34
pub mod format_args_collector;
45
#[cfg(feature = "internal")]

0 commit comments

Comments
 (0)