Skip to content

Commit f441fa0

Browse files
committed
Remove constness from ImplSource::Param
1 parent 1702d0f commit f441fa0

29 files changed

+119
-186
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,35 +2495,31 @@ impl<'hir> GenericArgsCtor<'hir> {
24952495

24962496
let id = lcx.next_node_id();
24972497
let hir_id = lcx.next_id();
2498+
2499+
let Some(host_param_id) = lcx.host_param_id else {
2500+
lcx.tcx
2501+
.sess
2502+
.delay_span_bug(span, "no host param id for call in const yet no errors reported");
2503+
return;
2504+
};
2505+
24982506
let body = lcx.lower_body(|lcx| {
2499-
(
2500-
&[],
2501-
match constness {
2502-
ast::Const::Yes(_) => {
2503-
let hir_id = lcx.next_id();
2504-
let res =
2505-
Res::Def(DefKind::ConstParam, lcx.host_param_id.unwrap().to_def_id());
2506-
let expr_kind = hir::ExprKind::Path(hir::QPath::Resolved(
2507-
None,
2508-
lcx.arena.alloc(hir::Path {
2509-
span,
2510-
res,
2511-
segments: arena_vec![lcx; hir::PathSegment::new(Ident {
2512-
name: sym::host,
2513-
span,
2514-
}, hir_id, res)],
2515-
}),
2516-
));
2517-
lcx.expr(span, expr_kind)
2518-
}
2519-
ast::Const::No => lcx.expr(
2507+
(&[], {
2508+
let hir_id = lcx.next_id();
2509+
let res = Res::Def(DefKind::ConstParam, host_param_id.to_def_id());
2510+
let expr_kind = hir::ExprKind::Path(hir::QPath::Resolved(
2511+
None,
2512+
lcx.arena.alloc(hir::Path {
25202513
span,
2521-
hir::ExprKind::Lit(
2522-
lcx.arena.alloc(hir::Lit { span, node: ast::LitKind::Bool(true) }),
2523-
),
2524-
),
2525-
},
2526-
)
2514+
res,
2515+
segments: arena_vec![lcx; hir::PathSegment::new(Ident {
2516+
name: sym::host,
2517+
span,
2518+
}, hir_id, res)],
2519+
}),
2520+
));
2521+
lcx.expr(span, expr_kind)
2522+
})
25272523
});
25282524

25292525
let attr_id = lcx.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
772772
};
773773

774774
match implsrc {
775-
Ok(Some(ImplSource::Param(ty::BoundConstness::ConstIfConst, _))) => {
775+
Ok(Some(ImplSource::Param(_))) if tcx.features().effects => {
776776
debug!(
777777
"const_trait_impl: provided {:?} via where-clause in {:?}",
778778
trait_ref, param_env

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ impl Qualif for NeedsNonConstDrop {
174174

175175
if !matches!(
176176
impl_src,
177-
ImplSource::Builtin(BuiltinImplSource::Misc, _)
178-
| ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
177+
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
179178
) {
180179
// If our const destruct candidate is not ConstDestruct or implied by the param env,
181180
// then it's bad

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ pub enum ImplSource<'tcx, N> {
649649
/// for some type parameter. The `Vec<N>` represents the
650650
/// obligations incurred from normalizing the where-clause (if
651651
/// any).
652-
Param(ty::BoundConstness, Vec<N>),
652+
Param(Vec<N>),
653653

654654
/// Successful resolution for a builtin impl.
655655
Builtin(BuiltinImplSource, Vec<N>),
@@ -659,21 +659,21 @@ impl<'tcx, N> ImplSource<'tcx, N> {
659659
pub fn nested_obligations(self) -> Vec<N> {
660660
match self {
661661
ImplSource::UserDefined(i) => i.nested,
662-
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
662+
ImplSource::Param(n) | ImplSource::Builtin(_, n) => n,
663663
}
664664
}
665665

666666
pub fn borrow_nested_obligations(&self) -> &[N] {
667667
match self {
668668
ImplSource::UserDefined(i) => &i.nested,
669-
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => &n,
669+
ImplSource::Param(n) | ImplSource::Builtin(_, n) => &n,
670670
}
671671
}
672672

673673
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
674674
match self {
675675
ImplSource::UserDefined(i) => &mut i.nested,
676-
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
676+
ImplSource::Param(n) | ImplSource::Builtin(_, n) => n,
677677
}
678678
}
679679

@@ -687,7 +687,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
687687
args: i.args,
688688
nested: i.nested.into_iter().map(f).collect(),
689689
}),
690-
ImplSource::Param(ct, n) => ImplSource::Param(ct, n.into_iter().map(f).collect()),
690+
ImplSource::Param(n) => ImplSource::Param(n.into_iter().map(f).collect()),
691691
ImplSource::Builtin(source, n) => {
692692
ImplSource::Builtin(source, n.into_iter().map(f).collect())
693693
}

compiler/rustc_middle/src/traits/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub enum SelectionCandidate<'tcx> {
127127
/// an applicable bound in the trait definition. The `usize` is an index
128128
/// into the list returned by `tcx.item_bounds`. The constness is the
129129
/// constness of the bound in the trait.
130+
// FIXME(effects) do we need this constness
130131
ProjectionCandidate(usize, ty::BoundConstness),
131132

132133
/// Implementation of a `Fn`-family trait by one of the anonymous types

compiler/rustc_middle/src/traits/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
1313
write!(f, "Builtin({source:?}, {d:?})")
1414
}
1515

16-
super::ImplSource::Param(ct, n) => {
17-
write!(f, "ImplSourceParamData({n:?}, {ct:?})")
16+
super::ImplSource::Param(n) => {
17+
write!(f, "ImplSourceParamData({n:?})")
1818
}
1919
}
2020
}

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
123123
// It's fine not to do anything to rematch these, since there are no
124124
// nested obligations.
125125
(Certainty::Yes, CandidateSource::ParamEnv(_) | CandidateSource::AliasBound) => {
126-
Ok(Some(ImplSource::Param(ty::BoundConstness::NotConst, nested_obligations)))
126+
Ok(Some(ImplSource::Param(nested_obligations)))
127127
}
128128

129129
(Certainty::Maybe(_), _) => Ok(None),

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
5959
ParamCandidate(param) => {
6060
let obligations =
6161
self.confirm_param_candidate(obligation, param.map_bound(|t| t.trait_ref));
62-
// FIXME(effects)
63-
ImplSource::Param(ty::BoundConstness::NotConst, obligations)
62+
ImplSource::Param(obligations)
6463
}
6564

6665
ImplCandidate(impl_def_id) => {
@@ -72,9 +71,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
7271
ImplSource::Builtin(BuiltinImplSource::Misc, data)
7372
}
7473

75-
ProjectionCandidate(idx, constness) => {
74+
ProjectionCandidate(idx, _) => {
7675
let obligations = self.confirm_projection_candidate(obligation, idx)?;
77-
ImplSource::Param(constness, obligations)
76+
ImplSource::Param(obligations)
7877
}
7978

8079
ObjectCandidate(idx) => self.confirm_object_candidate(obligation, idx)?,

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
415415

416416
if !matches!(
417417
impl_src,
418-
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
418+
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
419419
) {
420420
return false;
421421
}

tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// known-bug: #110395
22
// FIXME check-pass
3-
#![feature(const_trait_impl)]
3+
#![feature(const_trait_impl, effects)]
44

55
#[const_trait]
66
trait Foo {

0 commit comments

Comments
 (0)