Auto merge of #114781 - fee1-dead-contrib:param-impl-source, r=davidtwco

Remove constness from `ImplSource::Param`
This commit is contained in:
bors 2023-08-14 15:24:41 +00:00
commit 475be26d99
29 changed files with 122 additions and 189 deletions

View File

@ -2495,35 +2495,31 @@ impl<'hir> GenericArgsCtor<'hir> {
let id = lcx.next_node_id();
let hir_id = lcx.next_id();
let Some(host_param_id) = lcx.host_param_id else {
lcx.tcx
.sess
.delay_span_bug(span, "no host param id for call in const yet no errors reported");
return;
};
let body = lcx.lower_body(|lcx| {
(
&[],
match constness {
ast::Const::Yes(_) => {
let hir_id = lcx.next_id();
let res =
Res::Def(DefKind::ConstParam, lcx.host_param_id.unwrap().to_def_id());
let expr_kind = hir::ExprKind::Path(hir::QPath::Resolved(
None,
lcx.arena.alloc(hir::Path {
span,
res,
segments: arena_vec![lcx; hir::PathSegment::new(Ident {
name: sym::host,
span,
}, hir_id, res)],
}),
));
lcx.expr(span, expr_kind)
}
ast::Const::No => lcx.expr(
(&[], {
let hir_id = lcx.next_id();
let res = Res::Def(DefKind::ConstParam, host_param_id.to_def_id());
let expr_kind = hir::ExprKind::Path(hir::QPath::Resolved(
None,
lcx.arena.alloc(hir::Path {
span,
hir::ExprKind::Lit(
lcx.arena.alloc(hir::Lit { span, node: ast::LitKind::Bool(true) }),
),
),
},
)
res,
segments: arena_vec![lcx; hir::PathSegment::new(Ident {
name: sym::host,
span,
}, hir_id, res)],
}),
));
lcx.expr(span, expr_kind)
})
});
let attr_id = lcx.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();

View File

@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
};
match implsrc {
Ok(Some(ImplSource::Param(ty::BoundConstness::ConstIfConst, _))) => {
Ok(Some(ImplSource::Param(_))) if tcx.features().effects => {
debug!(
"const_trait_impl: provided {:?} via where-clause in {:?}",
trait_ref, param_env

View File

@ -174,8 +174,7 @@ impl Qualif for NeedsNonConstDrop {
if !matches!(
impl_src,
ImplSource::Builtin(BuiltinImplSource::Misc, _)
| ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
) {
// If our const destruct candidate is not ConstDestruct or implied by the param env,
// then it's bad

View File

@ -649,7 +649,7 @@ pub enum ImplSource<'tcx, N> {
/// for some type parameter. The `Vec<N>` represents the
/// obligations incurred from normalizing the where-clause (if
/// any).
Param(ty::BoundConstness, Vec<N>),
Param(Vec<N>),
/// Successful resolution for a builtin impl.
Builtin(BuiltinImplSource, Vec<N>),
@ -659,21 +659,21 @@ impl<'tcx, N> ImplSource<'tcx, N> {
pub fn nested_obligations(self) -> Vec<N> {
match self {
ImplSource::UserDefined(i) => i.nested,
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
ImplSource::Param(n) | ImplSource::Builtin(_, n) => n,
}
}
pub fn borrow_nested_obligations(&self) -> &[N] {
match self {
ImplSource::UserDefined(i) => &i.nested,
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => &n,
ImplSource::Param(n) | ImplSource::Builtin(_, n) => &n,
}
}
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
match self {
ImplSource::UserDefined(i) => &mut i.nested,
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
ImplSource::Param(n) | ImplSource::Builtin(_, n) => n,
}
}
@ -687,7 +687,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
args: i.args,
nested: i.nested.into_iter().map(f).collect(),
}),
ImplSource::Param(ct, n) => ImplSource::Param(ct, n.into_iter().map(f).collect()),
ImplSource::Param(n) => ImplSource::Param(n.into_iter().map(f).collect()),
ImplSource::Builtin(source, n) => {
ImplSource::Builtin(source, n.into_iter().map(f).collect())
}

View File

@ -127,6 +127,7 @@ pub enum SelectionCandidate<'tcx> {
/// an applicable bound in the trait definition. The `usize` is an index
/// into the list returned by `tcx.item_bounds`. The constness is the
/// constness of the bound in the trait.
// FIXME(effects) do we need this constness
ProjectionCandidate(usize, ty::BoundConstness),
/// Implementation of a `Fn`-family trait by one of the anonymous types

View File

@ -13,8 +13,8 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
write!(f, "Builtin({source:?}, {d:?})")
}
super::ImplSource::Param(ct, n) => {
write!(f, "ImplSourceParamData({n:?}, {ct:?})")
super::ImplSource::Param(n) => {
write!(f, "ImplSourceParamData({n:?})")
}
}
}

View File

@ -123,7 +123,7 @@ impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
// It's fine not to do anything to rematch these, since there are no
// nested obligations.
(Certainty::Yes, CandidateSource::ParamEnv(_) | CandidateSource::AliasBound) => {
Ok(Some(ImplSource::Param(ty::BoundConstness::NotConst, nested_obligations)))
Ok(Some(ImplSource::Param(nested_obligations)))
}
(Certainty::Maybe(_), _) => Ok(None),

View File

@ -59,8 +59,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ParamCandidate(param) => {
let obligations =
self.confirm_param_candidate(obligation, param.map_bound(|t| t.trait_ref));
// FIXME(effects)
ImplSource::Param(ty::BoundConstness::NotConst, obligations)
ImplSource::Param(obligations)
}
ImplCandidate(impl_def_id) => {
@ -72,9 +71,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
ProjectionCandidate(idx, constness) => {
ProjectionCandidate(idx, _) => {
let obligations = self.confirm_projection_candidate(obligation, idx)?;
ImplSource::Param(constness, obligations)
ImplSource::Param(obligations)
}
ObjectCandidate(idx) => self.confirm_object_candidate(obligation, idx)?,

View File

@ -415,7 +415,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
if !matches!(
impl_src,
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
) {
return false;
}

View File

@ -1,6 +1,6 @@
// known-bug: #110395
// FIXME check-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#[const_trait]
trait Foo {

View File

@ -1,11 +1,14 @@
error[E0015]: cannot call non-const fn `<<T as Foo>::Assoc as Foo>::foo` in constant functions
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/assoc-type-const-bound-usage.rs:12:5
|
LL | <T as Foo>::Assoc::foo();
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider further restricting this bound
|
LL | const fn foo<T: ~const Foo + Foo>() {
| +++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.

View File

@ -1,5 +1,6 @@
// known-bug: #110395
#![feature(const_trait_impl)]
// FIXME(effects)
// check-pass
#![feature(const_trait_impl, effects)]
pub const fn equals_self<T: PartialEq>(t: &T) -> bool {
*t == *t

View File

@ -1,15 +0,0 @@
error[E0015]: cannot call non-const operator in constant functions
--> $DIR/call-generic-method-fail.rs:5:5
|
LL | *t == *t
| ^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider further restricting this bound
|
LL | pub const fn equals_self<T: PartialEq + ~const std::cmp::PartialEq>(t: &T) -> bool {
| ++++++++++++++++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View File

@ -1,10 +1,9 @@
// Tests that a const default trait impl can be specialized by another const
// trait impl and that the specializing impl will be used during const-eval.
// known-bug: #110395
// FIXME run-pass
// run-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![feature(min_specialization)]
#[const_trait]

View File

@ -1,11 +0,0 @@
error[E0015]: cannot call non-const fn `<T as Value>::value` in constant functions
--> $DIR/const-default-const-specialized.rs:16:5
|
LL | T::value()
| ^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View File

@ -3,7 +3,7 @@
// known-bug: #110395
// FIXME run-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![feature(min_specialization)]
#[const_trait]

View File

@ -1,11 +1,12 @@
error[E0015]: cannot call non-const fn `<T as Value>::value` in constant functions
--> $DIR/non-const-default-const-specialized.rs:15:5
error[E0119]: conflicting implementations of trait `Value` for type `FortyTwo`
--> $DIR/non-const-default-const-specialized.rs:27:1
|
LL | T::value()
| ^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | impl<T> Value for T {
| ------------------- first implementation here
...
LL | impl const Value for FortyTwo {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `FortyTwo`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0119`.

View File

@ -1,6 +1,5 @@
// known-bug: #110395
// FIXME check-pass
#![feature(const_trait_impl)]
// check-pass
#![feature(const_trait_impl, effects)]
#[const_trait]
trait Foo {

View File

@ -1,11 +0,0 @@
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
--> $DIR/super-traits.rs:21:7
|
LL | t.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View File

@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![feature(generic_arg_infer)]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
@ -6,9 +6,10 @@
struct Foo<const N: usize>;
impl<const N: usize> Foo<N> {
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
Foo
}
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
//~^ ERROR mismatched types
Foo
}
}
#[const_trait]
@ -24,7 +25,7 @@ impl const Add42 for () {
fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
//~^ ERROR `~const` is not allowed here
//~| ERROR cannot call
//~| ERROR mismatched types
Foo
}

View File

@ -1,23 +1,33 @@
error: `~const` is not allowed here
--> $DIR/tilde-const-and-const-params.rs:25:11
--> $DIR/tilde-const-and-const-params.rs:26:11
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/tilde-const-and-const-params.rs:25:4
--> $DIR/tilde-const-and-const-params.rs:26:4
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^
error[E0015]: cannot call non-const fn `<A as Add42>::add` in constants
--> $DIR/tilde-const-and-const-params.rs:25:61
error[E0308]: mismatched types
--> $DIR/tilde-const-and-const-params.rs:26:61
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^
| ^^^^^^^^^ expected `false`, found `true`
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: expected constant `false`
found constant `true`
error: aborting due to 2 previous errors
error[E0308]: mismatched types
--> $DIR/tilde-const-and-const-params.rs:9:44
|
LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^ expected `false`, found `true`
|
= note: expected constant `false`
found constant `true`
For more information about this error, try `rustc --explain E0015`.
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,6 +1,6 @@
// known-bug: #110395
// FIXME check-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#[const_trait]
trait Foo {

View File

@ -1,11 +1,12 @@
error[E0015]: cannot call non-const fn `<T as Foo>::foo` in constant functions
--> $DIR/tilde_const_on_impl_bound.rs:14:16
error[E0308]: mismatched types
--> $DIR/tilde_const_on_impl_bound.rs:14:9
|
LL | self.0.foo()
| ^^^^^
| ^^^^^^^^^^^^ expected `host`, found `true`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: expected constant `host`
found constant `true`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0308`.

View File

@ -4,7 +4,7 @@
// test is not enough.
// known-bug: #110395
// FIXME check-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#[const_trait]
trait Bar {}

View File

@ -1,51 +1,35 @@
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
--> $DIR/trait-where-clause-const.rs:20:5
|
LL | T::a();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<T as Foo>::b` in constant functions
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
--> $DIR/trait-where-clause-const.rs:21:5
|
LL | T::b();
| ^^^^^^
| ^^^^ the trait `Bar` is not implemented for `T`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
note: required by a bound in `Foo::b`
--> $DIR/trait-where-clause-const.rs:15:24
|
LL | fn b() where Self: ~const Bar;
| ^^^^^^^^^^ required by this bound in `Foo::b`
help: consider further restricting this bound
|
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
| +++++
error[E0015]: cannot call non-const fn `<T as Foo>::c::<T>` in constant functions
--> $DIR/trait-where-clause-const.rs:23:5
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
--> $DIR/trait-where-clause-const.rs:23:12
|
LL | T::c::<T>();
| ^^^^^^^^^^^
| ^ the trait `Bar` is not implemented for `T`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
note: required by a bound in `Foo::c`
--> $DIR/trait-where-clause-const.rs:16:13
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^ required by this bound in `Foo::c`
help: consider further restricting this bound
|
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
| +++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
--> $DIR/trait-where-clause-const.rs:28:5
|
LL | T::a();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors
error[E0015]: cannot call non-const fn `<T as Foo>::b` in constant functions
--> $DIR/trait-where-clause-const.rs:29:5
|
LL | T::b();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<T as Foo>::c::<T>` in constant functions
--> $DIR/trait-where-clause-const.rs:30:5
|
LL | T::c::<T>();
| ^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.

View File

@ -1,5 +1,4 @@
// known-bug: #110395
// FIXME run-pass
// run-pass
#![feature(const_trait_impl, effects)]

View File

@ -1,11 +0,0 @@
error[E0015]: cannot call non-const fn `<Self as Bar>::bar` in constant functions
--> $DIR/trait-where-clause-run.rs:14:9
|
LL | <Self as Bar>::bar() * 6
| ^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View File

@ -1,7 +1,6 @@
// known-bug: #110395
// FIXME check-pass
// check-pass
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#[const_trait]
trait Foo {

View File

@ -1,11 +0,0 @@
error[E0015]: cannot call non-const fn `<T as Foo>::bar` in constant functions
--> $DIR/trait-where-clause-self-referential.rs:22:5
|
LL | T::bar();
| ^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.