Skip to content

Commit 475be26

Browse files
committed
Auto merge of rust-lang#114781 - fee1-dead-contrib:param-impl-source, r=davidtwco
Remove constness from `ImplSource::Param`
2 parents e845910 + f441fa0 commit 475be26

29 files changed

+119
-186
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+23-27
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

+1-1
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

+1-2
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

+5-5
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

+1
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

+2-2
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

+1-1
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

+3-4
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

+1-1
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

+1-1
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 {
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
error[E0015]: cannot call non-const fn `<<T as Foo>::Assoc as Foo>::foo` in constant functions
1+
error[E0277]: the trait bound `T: Foo` is not satisfied
22
--> $DIR/assoc-type-const-bound-usage.rs:12:5
33
|
44
LL | <T as Foo>::Assoc::foo();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
66
|
7-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
7+
help: consider further restricting this bound
8+
|
9+
LL | const fn foo<T: ~const Foo + Foo>() {
10+
| +++++
811

912
error: aborting due to previous error
1013

11-
For more information about this error, try `rustc --explain E0015`.
14+
For more information about this error, try `rustc --explain E0277`.

tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-fail.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// known-bug: #110395
2-
#![feature(const_trait_impl)]
1+
// FIXME(effects)
2+
// check-pass
3+
#![feature(const_trait_impl, effects)]
34

45
pub const fn equals_self<T: PartialEq>(t: &T) -> bool {
56
*t == *t

tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-fail.stderr

-15
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/specialization/const-default-const-specialized.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Tests that a const default trait impl can be specialized by another const
22
// trait impl and that the specializing impl will be used during const-eval.
33

4-
// known-bug: #110395
5-
// FIXME run-pass
4+
// run-pass
65

7-
#![feature(const_trait_impl)]
6+
#![feature(const_trait_impl, effects)]
87
#![feature(min_specialization)]
98

109
#[const_trait]

tests/ui/rfcs/rfc-2632-const-trait-impl/specialization/const-default-const-specialized.stderr

-11
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/specialization/non-const-default-const-specialized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// known-bug: #110395
44
// FIXME run-pass
55

6-
#![feature(const_trait_impl)]
6+
#![feature(const_trait_impl, effects)]
77
#![feature(min_specialization)]
88

99
#[const_trait]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
error[E0015]: cannot call non-const fn `<T as Value>::value` in constant functions
2-
--> $DIR/non-const-default-const-specialized.rs:15:5
1+
error[E0119]: conflicting implementations of trait `Value` for type `FortyTwo`
2+
--> $DIR/non-const-default-const-specialized.rs:27:1
33
|
4-
LL | T::value()
5-
| ^^^^^^^^^^
6-
|
7-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
4+
LL | impl<T> Value for T {
5+
| ------------------- first implementation here
6+
...
7+
LL | impl const Value for FortyTwo {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `FortyTwo`
89

910
error: aborting due to previous error
1011

11-
For more information about this error, try `rustc --explain E0015`.
12+
For more information about this error, try `rustc --explain E0119`.

tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// known-bug: #110395
2-
// FIXME check-pass
3-
#![feature(const_trait_impl)]
1+
// check-pass
2+
#![feature(const_trait_impl, effects)]
43

54
#[const_trait]
65
trait Foo {

tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits.stderr

-11
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#![feature(const_trait_impl)]
1+
#![feature(const_trait_impl, effects)]
22
#![feature(generic_arg_infer)]
33
#![feature(generic_const_exprs)]
44
#![allow(incomplete_features)]
55

66
struct Foo<const N: usize>;
77

88
impl<const N: usize> Foo<N> {
9-
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
10-
Foo
11-
}
9+
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
10+
//~^ ERROR mismatched types
11+
Foo
12+
}
1213
}
1314

1415
#[const_trait]
@@ -24,7 +25,7 @@ impl const Add42 for () {
2425

2526
fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
2627
//~^ ERROR `~const` is not allowed here
27-
//~| ERROR cannot call
28+
//~| ERROR mismatched types
2829
Foo
2930
}
3031

Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
error: `~const` is not allowed here
2-
--> $DIR/tilde-const-and-const-params.rs:25:11
2+
--> $DIR/tilde-const-and-const-params.rs:26:11
33
|
44
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
55
| ^^^^^^^^^^^^
66
|
77
note: this function is not `const`, so it cannot have `~const` trait bounds
8-
--> $DIR/tilde-const-and-const-params.rs:25:4
8+
--> $DIR/tilde-const-and-const-params.rs:26:4
99
|
1010
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
1111
| ^^^
1212

13-
error[E0015]: cannot call non-const fn `<A as Add42>::add` in constants
14-
--> $DIR/tilde-const-and-const-params.rs:25:61
13+
error[E0308]: mismatched types
14+
--> $DIR/tilde-const-and-const-params.rs:26:61
1515
|
1616
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
17-
| ^^^^^^^^^
17+
| ^^^^^^^^^ expected `false`, found `true`
1818
|
19-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
19+
= note: expected constant `false`
20+
found constant `true`
2021

21-
error: aborting due to 2 previous errors
22+
error[E0308]: mismatched types
23+
--> $DIR/tilde-const-and-const-params.rs:9:44
24+
|
25+
LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
26+
| ^^^^^^^^^ expected `false`, found `true`
27+
|
28+
= note: expected constant `false`
29+
found constant `true`
30+
31+
error: aborting due to 3 previous errors
2232

23-
For more information about this error, try `rustc --explain E0015`.
33+
For more information about this error, try `rustc --explain E0308`.

tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs

+1-1
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)