Gate checking ~const bounds on const_trait_impl
This commit is contained in:
parent
7028d9318f
commit
ace9e4c078
@ -20,7 +20,6 @@
|
|||||||
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
||||||
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
||||||
use rustc_span::{Span, Symbol, sym};
|
use rustc_span::{Span, Symbol, sym};
|
||||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
|
||||||
use rustc_trait_selection::traits::{
|
use rustc_trait_selection::traits::{
|
||||||
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
|
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
|
||||||
};
|
};
|
||||||
@ -419,13 +418,8 @@ fn revalidate_conditional_constness(
|
|||||||
|
|
||||||
let errors = ocx.select_all_or_error();
|
let errors = ocx.select_all_or_error();
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
// FIXME(effects): Soon this should be unconditionally delaying a bug.
|
|
||||||
if matches!(call_source, CallSource::Normal) && tcx.features().effects() {
|
|
||||||
tcx.dcx()
|
tcx.dcx()
|
||||||
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
|
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
|
||||||
} else {
|
|
||||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,7 +658,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
|||||||
// so we only error if the trait isn't const. We try to resolve the trait
|
// so we only error if the trait isn't const. We try to resolve the trait
|
||||||
// into the concrete method, and uses that for const stability checks.
|
// into the concrete method, and uses that for const stability checks.
|
||||||
// FIXME(effects) we might consider moving const stability checks to typeck as well.
|
// FIXME(effects) we might consider moving const stability checks to typeck as well.
|
||||||
if tcx.features().effects() && trait_is_const {
|
if tcx.features().const_trait_impl() && trait_is_const {
|
||||||
// This skips the check below that ensures we only call `const fn`.
|
// This skips the check below that ensures we only call `const fn`.
|
||||||
is_trait = true;
|
is_trait = true;
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ pub(super) fn enforce_context_effects(
|
|||||||
// This can be done as soon as we convert the standard library back to
|
// This can be done as soon as we convert the standard library back to
|
||||||
// using const traits, since if we were to enforce these conditions now,
|
// using const traits, since if we were to enforce these conditions now,
|
||||||
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
|
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
|
||||||
if !self.tcx.features().effects() {
|
if !self.tcx.features().const_trait_impl() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,54 +40,5 @@ LL | impl<T: ~const Default + ~const Sub> const A for T {
|
|||||||
|
|
|
|
||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<() as A>::a` in constants
|
error: aborting due to 6 previous errors
|
||||||
--> $DIR/const_trait_impl.rs:52:23
|
|
||||||
|
|
|
||||||
LL | const _: () = assert!(<()>::a() == 42);
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<u8 as A>::a` in constants
|
|
||||||
--> $DIR/const_trait_impl.rs:53:23
|
|
||||||
|
|
|
||||||
LL | const _: () = assert!(<u8>::a() == 3);
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<u16 as A>::a` in constants
|
|
||||||
--> $DIR/const_trait_impl.rs:54:23
|
|
||||||
|
|
|
||||||
LL | const _: () = assert!(<u16>::a() == 2);
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<T as Sup>::foo` in constant functions
|
|
||||||
--> $DIR/const_trait_impl.rs:48:9
|
|
||||||
|
|
|
||||||
LL | T::foo()
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 10 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
|
||||||
|
@ -24,18 +24,6 @@ LL | const ADD_INT: Int = Int(1i32) + Int(2i32);
|
|||||||
|
|
|
|
||||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions
|
|
||||||
--> $DIR/call-const-trait-method-pass.rs:11:20
|
|
||||||
|
|
|
||||||
LL | Int(self.0.plus(rhs.0))
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<Int as PartialEq>::eq` in constant functions
|
error[E0015]: cannot call non-const fn `<Int as PartialEq>::eq` in constant functions
|
||||||
--> $DIR/call-const-trait-method-pass.rs:20:15
|
--> $DIR/call-const-trait-method-pass.rs:20:15
|
||||||
|
|
|
|
||||||
@ -44,18 +32,6 @@ LL | !self.eq(other)
|
|||||||
|
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions
|
error: aborting due to 4 previous errors
|
||||||
--> $DIR/call-const-trait-method-pass.rs:36:7
|
|
||||||
|
|
|
||||||
LL | a.plus(b)
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
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 E0015`.
|
||||||
|
@ -21,6 +21,12 @@ LL | const fn check<T: ~const Destruct>(_: T) {}
|
|||||||
|
|
|
|
||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `T: ~const A` is not satisfied
|
||||||
|
--> $DIR/const-drop-fail-2.rs:41:9
|
||||||
|
|
|
||||||
|
LL | T::a();
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
||||||
--> $DIR/const-drop-fail-2.rs:20:36
|
--> $DIR/const-drop-fail-2.rs:20:36
|
||||||
|
|
|
|
||||||
@ -29,25 +35,7 @@ LL | const fn check<T: ~const Destruct>(_: T) {}
|
|||||||
| |
|
| |
|
||||||
| the destructor for this type cannot be evaluated in constant functions
|
| the destructor for this type cannot be evaluated in constant functions
|
||||||
|
|
||||||
error[E0277]: the trait bound `T: ~const A` is not satisfied
|
error: aborting due to 5 previous errors
|
||||||
--> $DIR/const-drop-fail-2.rs:41:9
|
|
||||||
|
|
|
||||||
LL | T::a();
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<T as A>::a` in constant functions
|
Some errors have detailed explanations: E0277, E0493.
|
||||||
--> $DIR/const-drop-fail-2.rs:41:9
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
|
|
||||||
LL | T::a();
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0015, E0277, E0493.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
||||||
|
@ -84,19 +84,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
|
|||||||
LL | T::foo();
|
LL | T::foo();
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<T as SomeTrait>::foo` in constant functions
|
error: aborting due to 10 previous errors
|
||||||
--> $DIR/const-drop.rs:69:13
|
|
||||||
|
|
|
||||||
LL | T::foo();
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
Some errors have detailed explanations: E0277, E0493.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
Some errors have detailed explanations: E0015, E0277, E0493.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
||||||
|
@ -86,19 +86,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
|
|||||||
LL | T::foo();
|
LL | T::foo();
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<T as SomeTrait>::foo` in constant functions
|
error: aborting due to 10 previous errors
|
||||||
--> $DIR/const-drop.rs:69:13
|
|
||||||
|
|
|
||||||
LL | T::foo();
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
Some errors have detailed explanations: E0277, E0493.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
Some errors have detailed explanations: E0015, E0277, E0493.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
||||||
|
@ -3,12 +3,6 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied
|
|||||||
|
|
|
|
||||||
LL | foo::<()>();
|
LL | foo::<()>();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
note: required by a bound in `foo`
|
|
||||||
--> $DIR/default-method-body-is-const-body-checking.rs:7:28
|
|
||||||
|
|
|
||||||
LL | const fn foo<T>() where T: ~const Tr {}
|
|
||||||
| ^^^^^^ required by this bound in `foo`
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// Tests that a const default trait impl can be specialized by another const
|
// 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.
|
// trait impl and that the specializing impl will be used during const-eval.
|
||||||
|
|
||||||
//@ known-bug: #110395
|
//@ run-pass
|
||||||
// FIXME(effects) run-pass
|
|
||||||
|
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
|
@ -1,15 +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
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
|
@ -1,7 +1,7 @@
|
|||||||
// Tests that a non-const default impl can be specialized by a const trait impl,
|
// Tests that a non-const default impl can be specialized by a const trait impl,
|
||||||
// but that the default impl cannot be used in a const context.
|
// but that the default impl cannot be used in a const context.
|
||||||
//@ known-bug: #110395
|
|
||||||
// FIXME(effects) run-pass
|
//@ run-pass
|
||||||
|
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
error[E0015]: cannot call non-const fn `<T as Value>::value` in constant functions
|
|
||||||
--> $DIR/non-const-default-const-specialized.rs:15:5
|
|
||||||
|
|
|
||||||
LL | T::value()
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
|
@ -4,19 +4,6 @@ error[E0277]: the trait bound `T: ~const A` is not satisfied
|
|||||||
LL | <T as A>::a();
|
LL | <T as A>::a();
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0015]: cannot call non-const fn `<T as A>::a` in constant functions
|
error: aborting due to 1 previous error
|
||||||
--> $DIR/specializing-constness-2.rs:27:5
|
|
||||||
|
|
|
||||||
LL | <T as A>::a();
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
||||||
|
|
|
||||||
LL + #![feature(effects)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0015, E0277.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user