Move qualify_min_const_fn
out of rustc into clippy
This commit is contained in:
parent
6f9a8a7f9b
commit
1b843896c8
compiler/rustc_mir/src/transform
src/tools/clippy/clippy_lints/src
@ -36,7 +36,6 @@ pub mod match_branches;
|
||||
pub mod no_landing_pads;
|
||||
pub mod nrvo;
|
||||
pub mod promote_consts;
|
||||
pub mod qualify_min_const_fn;
|
||||
pub mod remove_noop_landing_pads;
|
||||
pub mod remove_unneeded_drops;
|
||||
pub mod required_consts;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#![feature(concat_idents)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(or_patterns)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
|
||||
use crate::utils::qualify_min_const_fn::is_min_const_fn;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::Span;
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
|
@ -20,6 +20,7 @@ pub mod paths;
|
||||
pub mod ptr;
|
||||
pub mod sugg;
|
||||
pub mod usage;
|
||||
pub mod qualify_min_const_fn;
|
||||
|
||||
pub use self::attrs::*;
|
||||
pub use self::diagnostics::*;
|
||||
|
@ -14,7 +14,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
|
||||
// Prevent const trait methods from being annotated as `stable`.
|
||||
if tcx.features().staged_api {
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
|
||||
if rustc_mir::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
|
||||
return Err((body.span, "trait methods cannot be stable const fn".into()));
|
||||
}
|
||||
}
|
||||
@ -32,13 +32,13 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
|
||||
| ty::PredicateAtom::ConstEquate(..)
|
||||
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
|
||||
ty::PredicateAtom::ObjectSafe(_) => {
|
||||
bug!("object safe predicate on function: {:#?}", predicate)
|
||||
panic!("object safe predicate on function: {:#?}", predicate)
|
||||
}
|
||||
ty::PredicateAtom::ClosureKind(..) => {
|
||||
bug!("closure kind predicate on function: {:#?}", predicate)
|
||||
panic!("closure kind predicate on function: {:#?}", predicate)
|
||||
}
|
||||
ty::PredicateAtom::Subtype(_) => {
|
||||
bug!("subtype predicate on function: {:#?}", predicate)
|
||||
panic!("subtype predicate on function: {:#?}", predicate)
|
||||
}
|
||||
ty::PredicateAtom::Trait(pred, constness) => {
|
||||
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
|
||||
|
||||
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
|
||||
// opt-in via `allow_internal_unstable`.
|
||||
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
|
||||
rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
|
||||
// opt-in via `allow_internal_unstable`.
|
||||
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
|
||||
rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
|
||||
}
|
||||
|
||||
fn check_terminator(
|
||||
@ -407,8 +407,8 @@ fn check_terminator(
|
||||
if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() {
|
||||
// Allow unstable const if we opt in by using #[allow_internal_unstable]
|
||||
// on function or macro declaration.
|
||||
if !crate::const_eval::is_min_const_fn(tcx, fn_def_id)
|
||||
&& !crate::const_eval::is_unstable_const_fn(tcx, fn_def_id)
|
||||
if !rustc_mir::const_eval::is_min_const_fn(tcx, fn_def_id)
|
||||
&& !rustc_mir::const_eval::is_unstable_const_fn(tcx, fn_def_id)
|
||||
.map(|feature| {
|
||||
span.allows_unstable(feature)
|
||||
|| lib_feature_allowed(tcx, def_id, feature)
|
Loading…
x
Reference in New Issue
Block a user