Skip to content

Commit 1b84389

Browse files
committed
Move qualify_min_const_fn out of rustc into clippy
1 parent 6f9a8a7 commit 1b84389

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

compiler/rustc_mir/src/transform/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub mod match_branches;
3636
pub mod no_landing_pads;
3737
pub mod nrvo;
3838
pub mod promote_consts;
39-
pub mod qualify_min_const_fn;
4039
pub mod remove_noop_landing_pads;
4140
pub mod remove_unneeded_drops;
4241
pub mod required_consts;

src/tools/clippy/clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(concat_idents)]
77
#![feature(crate_visibility_modifier)]
88
#![feature(drain_filter)]
9+
#![feature(in_band_lifetimes)]
910
#![feature(or_patterns)]
1011
#![feature(rustc_private)]
1112
#![feature(stmt_expr_attributes)]

src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::lint::in_external_macro;
7-
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
7+
use crate::utils::qualify_min_const_fn::is_min_const_fn;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::Span;
1010
use rustc_typeck::hir_ty_to_ty;

src/tools/clippy/clippy_lints/src/utils/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod paths;
2020
pub mod ptr;
2121
pub mod sugg;
2222
pub mod usage;
23+
pub mod qualify_min_const_fn;
2324

2425
pub use self::attrs::*;
2526
pub use self::diagnostics::*;

compiler/rustc_mir/src/transform/qualify_min_const_fn.rs renamed to src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
1414
// Prevent const trait methods from being annotated as `stable`.
1515
if tcx.features().staged_api {
1616
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
17-
if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
17+
if rustc_mir::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
1818
return Err((body.span, "trait methods cannot be stable const fn".into()));
1919
}
2020
}
@@ -32,13 +32,13 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
3232
| ty::PredicateAtom::ConstEquate(..)
3333
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
3434
ty::PredicateAtom::ObjectSafe(_) => {
35-
bug!("object safe predicate on function: {:#?}", predicate)
35+
panic!("object safe predicate on function: {:#?}", predicate)
3636
}
3737
ty::PredicateAtom::ClosureKind(..) => {
38-
bug!("closure kind predicate on function: {:#?}", predicate)
38+
panic!("closure kind predicate on function: {:#?}", predicate)
3939
}
4040
ty::PredicateAtom::Subtype(_) => {
41-
bug!("subtype predicate on function: {:#?}", predicate)
41+
panic!("subtype predicate on function: {:#?}", predicate)
4242
}
4343
ty::PredicateAtom::Trait(pred, constness) => {
4444
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
@@ -343,7 +343,7 @@ fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bo
343343

344344
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
345345
// opt-in via `allow_internal_unstable`.
346-
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
346+
rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
347347
}
348348

349349
/// Returns `true` if the given library feature gate is allowed within the function with the given `DefId`.
@@ -362,7 +362,7 @@ pub fn lib_feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbo
362362

363363
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
364364
// opt-in via `allow_internal_unstable`.
365-
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
365+
rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
366366
}
367367

368368
fn check_terminator(
@@ -407,8 +407,8 @@ fn check_terminator(
407407
if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() {
408408
// Allow unstable const if we opt in by using #[allow_internal_unstable]
409409
// on function or macro declaration.
410-
if !crate::const_eval::is_min_const_fn(tcx, fn_def_id)
411-
&& !crate::const_eval::is_unstable_const_fn(tcx, fn_def_id)
410+
if !rustc_mir::const_eval::is_min_const_fn(tcx, fn_def_id)
411+
&& !rustc_mir::const_eval::is_unstable_const_fn(tcx, fn_def_id)
412412
.map(|feature| {
413413
span.allows_unstable(feature)
414414
|| lib_feature_allowed(tcx, def_id, feature)

0 commit comments

Comments
 (0)