1
Fork 0

Move qualify_min_const_fn out of rustc into clippy

This commit is contained in:
Oliver Scherer 2020-09-26 16:08:24 +02:00
parent 6f9a8a7f9b
commit 1b843896c8
5 changed files with 11 additions and 10 deletions

View file

@ -36,7 +36,6 @@ pub mod match_branches;
pub mod no_landing_pads; pub mod no_landing_pads;
pub mod nrvo; pub mod nrvo;
pub mod promote_consts; pub mod promote_consts;
pub mod qualify_min_const_fn;
pub mod remove_noop_landing_pads; pub mod remove_noop_landing_pads;
pub mod remove_unneeded_drops; pub mod remove_unneeded_drops;
pub mod required_consts; pub mod required_consts;

View file

@ -6,6 +6,7 @@
#![feature(concat_idents)] #![feature(concat_idents)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(or_patterns)] #![feature(or_patterns)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]

View file

@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro; 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_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Span; use rustc_span::Span;
use rustc_typeck::hir_ty_to_ty; use rustc_typeck::hir_ty_to_ty;

View file

@ -20,6 +20,7 @@ pub mod paths;
pub mod ptr; pub mod ptr;
pub mod sugg; pub mod sugg;
pub mod usage; pub mod usage;
pub mod qualify_min_const_fn;
pub use self::attrs::*; pub use self::attrs::*;
pub use self::diagnostics::*; pub use self::diagnostics::*;

View file

@ -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`. // Prevent const trait methods from being annotated as `stable`.
if tcx.features().staged_api { if tcx.features().staged_api {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); 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())); 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::ConstEquate(..)
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
ty::PredicateAtom::ObjectSafe(_) => { ty::PredicateAtom::ObjectSafe(_) => {
bug!("object safe predicate on function: {:#?}", predicate) panic!("object safe predicate on function: {:#?}", predicate)
} }
ty::PredicateAtom::ClosureKind(..) => { ty::PredicateAtom::ClosureKind(..) => {
bug!("closure kind predicate on function: {:#?}", predicate) panic!("closure kind predicate on function: {:#?}", predicate)
} }
ty::PredicateAtom::Subtype(_) => { ty::PredicateAtom::Subtype(_) => {
bug!("subtype predicate on function: {:#?}", predicate) panic!("subtype predicate on function: {:#?}", predicate)
} }
ty::PredicateAtom::Trait(pred, constness) => { ty::PredicateAtom::Trait(pred, constness) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() { 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 // However, we cannot allow stable `const fn`s to use unstable features without an explicit
// opt-in via `allow_internal_unstable`. // 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`. /// 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 // However, we cannot allow stable `const fn`s to use unstable features without an explicit
// opt-in via `allow_internal_unstable`. // 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( fn check_terminator(
@ -407,8 +407,8 @@ fn check_terminator(
if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() {
// Allow unstable const if we opt in by using #[allow_internal_unstable] // Allow unstable const if we opt in by using #[allow_internal_unstable]
// on function or macro declaration. // on function or macro declaration.
if !crate::const_eval::is_min_const_fn(tcx, fn_def_id) if !rustc_mir::const_eval::is_min_const_fn(tcx, fn_def_id)
&& !crate::const_eval::is_unstable_const_fn(tcx, fn_def_id) && !rustc_mir::const_eval::is_unstable_const_fn(tcx, fn_def_id)
.map(|feature| { .map(|feature| {
span.allows_unstable(feature) span.allows_unstable(feature)
|| lib_feature_allowed(tcx, def_id, feature) || lib_feature_allowed(tcx, def_id, feature)