Skip to content

Commit b29f8bd

Browse files
committed
Remove possibly footgunny is_const method
1 parent b35fa64 commit b29f8bd

7 files changed

Lines changed: 11 additions & 15 deletions

File tree

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,10 +4593,6 @@ impl FnHeader {
45934593
matches!(self.asyncness, IsAsync::Async(_))
45944594
}
45954595

4596-
pub fn is_const(&self) -> bool {
4597-
matches!(self.constness, Constness::Const { .. })
4598-
}
4599-
46004596
pub fn is_unsafe(&self) -> bool {
46014597
self.safety().is_unsafe()
46024598
}

compiler/rustc_passes/src/stability.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use rustc_hir::def::{DefKind, Res};
1212
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalModDefId};
1313
use rustc_hir::intravisit::{self, Visitor, VisitorExt};
1414
use rustc_hir::{
15-
self as hir, AmbigArg, ConstStability, DefaultBodyStability, FieldDef, HirId, Item, ItemKind,
16-
Path, Stability, StabilityLevel, StableSince, TraitRef, Ty, TyKind, UnstableReason, UsePath,
17-
VERSION_PLACEHOLDER, Variant, find_attr,
15+
self as hir, AmbigArg, ConstStability, Constness, DefaultBodyStability, FieldDef, HirId, Item,
16+
ItemKind, Path, Stability, StabilityLevel, StableSince, TraitRef, Ty, TyKind, UnstableReason,
17+
UsePath, VERSION_PLACEHOLDER, Variant, find_attr,
1818
};
1919
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::middle::lib_features::{FeatureStability, LibFeatures};
@@ -207,7 +207,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
207207
let parent_stab = tcx.lookup_stability(parent)?;
208208
if parent_stab.is_unstable()
209209
&& let Some(fn_sig) = tcx.hir_node_by_def_id(def_id).fn_sig()
210-
&& fn_sig.header.is_const()
210+
&& matches!(fn_sig.header.constness, Constness::Const { .. })
211211
{
212212
let const_stable_indirect = find_attr!(tcx, def_id, RustcConstStableIndirect);
213213
return Some(ConstStability::unmarked(const_stable_indirect, parent_stab));
@@ -229,7 +229,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
229229
// If this is a const fn but not annotated with stability markers, see if we can inherit
230230
// regular stability.
231231
if let Some(fn_sig) = tcx.hir_node_by_def_id(def_id).fn_sig()
232-
&& fn_sig.header.is_const()
232+
&& matches!(fn_sig.header.constness, Constness::Const { .. })
233233
&& const_stab.is_none()
234234
// We only ever inherit unstable features.
235235
&& let Some(inherit_regular_stab) = tcx.lookup_stability(def_id)
@@ -385,7 +385,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
385385
// implied), check if the function/method is const or the parent impl block is const.
386386
let fn_sig = self.tcx.hir_node_by_def_id(def_id).fn_sig();
387387
if let Some(fn_sig) = fn_sig
388-
&& !fn_sig.header.is_const()
388+
&& !matches!(fn_sig.header.constness, Constness::Const { .. })
389389
&& const_stab.is_some()
390390
&& find_attr_span!(RustcConstStability).is_some()
391391
{

src/librustdoc/json/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl FromClean<rustc_hir::FnHeader> for FunctionHeader {
409409
};
410410
FunctionHeader {
411411
is_async: header.is_async(),
412-
is_const: header.is_const(),
412+
is_const: matches!(header.constness, rustc_hir::Constness::Const { .. }),
413413
is_unsafe,
414414
abi: header.abi.into_json(renderer),
415415
}

src/tools/clippy/clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
253253
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
254254
&& cx.tcx.hir_attrs(impl_item_hir).is_empty()
255255
{
256-
let is_const = constness == hir::Constness::Const;
256+
let is_const = matches!(constness, hir::Constness::Const { always: false });
257257
if adt_def.is_struct() {
258258
check_struct(
259259
cx,

src/tools/clippy/clippy_lints/src/methods/should_implement_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn check_impl_item<'tcx>(
2929
&& first_arg_ty_opt
3030
.is_none_or(|first_arg_ty| method_config.self_kind.matches(cx, self_ty, first_arg_ty))
3131
&& sig.header.is_safe()
32-
&& !sig.header.is_const()
32+
&& matches!(sig.header.constness, hir::Constness::NotConst)
3333
&& !sig.header.is_async()
3434
&& sig.header.abi == ExternAbi::Rust
3535
&& method_config.lifetime_param_cond(impl_item)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
187187
// We don't have to lint on something that's already `const`
188188
#[must_use]
189189
fn already_const(header: hir::FnHeader) -> bool {
190-
header.constness == Constness::Const
190+
matches!(header.constness, Constness::Const { .. })
191191
}
192192

193193
fn could_be_const_with_abi(cx: &LateContext<'_>, msrv: Msrv, abi: ExternAbi) -> bool {

src/tools/clippy/clippy_utils/src/check_proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
242242
fn fn_header_search_pat(header: FnHeader) -> Pat {
243243
if header.is_async() {
244244
Pat::Str("async")
245-
} else if header.is_const() {
245+
} else if matches!(header.constness, rustc_hir::Constness::Const { always: false }) {
246246
Pat::Str("const")
247247
} else if header.is_unsafe() {
248248
Pat::Str("unsafe")

0 commit comments

Comments
 (0)