Skip to content

Commit e97a770

Browse files
committed
Auto merge of rust-lang#114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obk
Remove `constness` from `ParamEnv` This should be replaced by keyword generics/effects. cc rust-lang#110395 r? `@oli-obk`
2 parents 42d3370 + 39fb315 commit e97a770

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

clippy_lints/src/derive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::def_id::DefId;
77
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
88
use rustc_hir::{
9-
self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource,
9+
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource,
1010
Unsafety,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
@@ -526,6 +526,5 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
526526
}),
527527
)),
528528
Reveal::UserFacing,
529-
Constness::NotConst,
530529
)
531530
}

clippy_lints/src/manual_float_methods.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::snippet_opt;
44
use clippy_utils::{is_from_proc_macro, path_to_local};
55
use rustc_errors::Applicability;
6-
use rustc_hir::{BinOpKind, Expr, ExprKind};
6+
use rustc_hir::{BinOpKind, Constness, Expr, ExprKind};
77
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
88
use rustc_middle::lint::in_external_macro;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -83,8 +83,10 @@ impl Variant {
8383
impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
8484
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
8585
if !in_external_macro(cx.sess(), expr.span)
86-
&& (!cx.param_env.is_const() || cx.tcx.features().active(sym!(const_float_classify)))
87-
&& let ExprKind::Binary(kind, lhs, rhs) = expr.kind
86+
&& (
87+
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
88+
|| cx.tcx.features().active(sym!(const_float_classify))
89+
) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind
8890
&& let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind
8991
&& let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind
9092
// Checking all possible scenarios using a function would be a hopeless task, as we have

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -391,32 +391,38 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
391391

392392
#[expect(clippy::similar_names)] // bit too pedantic
393393
fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool {
394-
// Avoid selecting for simple cases, such as builtin types.
395-
if ty::util::is_trivially_const_drop(ty) {
396-
return true;
397-
}
394+
// FIXME(effects, fee1-dead) revert to const destruct once it works again
395+
#[expect(unused)]
396+
fn is_ty_const_destruct_unused<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool {
397+
// Avoid selecting for simple cases, such as builtin types.
398+
if ty::util::is_trivially_const_drop(ty) {
399+
return true;
400+
}
398401

399-
let obligation = Obligation::new(
400-
tcx,
401-
ObligationCause::dummy_with_span(body.span),
402-
ConstCx::new(tcx, body).param_env.with_const(),
403-
TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst),
404-
);
402+
let obligation = Obligation::new(
403+
tcx,
404+
ObligationCause::dummy_with_span(body.span),
405+
ConstCx::new(tcx, body).param_env,
406+
TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst),
407+
);
405408

406-
let infcx = tcx.infer_ctxt().build();
407-
let mut selcx = SelectionContext::new(&infcx);
408-
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
409-
return false;
410-
};
409+
let infcx = tcx.infer_ctxt().build();
410+
let mut selcx = SelectionContext::new(&infcx);
411+
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
412+
return false;
413+
};
414+
415+
if !matches!(
416+
impl_src,
417+
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
418+
) {
419+
return false;
420+
}
411421

412-
if !matches!(
413-
impl_src,
414-
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
415-
) {
416-
return false;
422+
let ocx = ObligationCtxt::new(&infcx);
423+
ocx.register_obligations(impl_src.nested_obligations());
424+
ocx.select_all_or_error().is_empty()
417425
}
418426

419-
let ocx = ObligationCtxt::new(&infcx);
420-
ocx.register_obligations(impl_src.nested_obligations());
421-
ocx.select_all_or_error().is_empty()
427+
!ty.needs_drop(tcx, ConstCx::new(tcx, body).param_env)
422428
}

tests/ui/missing_const_for_fn/could_be_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ impl const Drop for D {
9999
}
100100

101101
// Lint this, since it can be dropped in const contexts
102+
// FIXME(effects)
102103
fn d(this: D) {}

tests/ui/missing_const_for_fn/could_be_const.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,5 @@ LL | | 46
8989
LL | | }
9090
| |_^
9191

92-
error: this could be a `const fn`
93-
--> $DIR/could_be_const.rs:102:1
94-
|
95-
LL | fn d(this: D) {}
96-
| ^^^^^^^^^^^^^^^^
97-
98-
error: aborting due to 12 previous errors
92+
error: aborting due to 11 previous errors
9993

0 commit comments

Comments
 (0)