Skip to content

Commit ace9e4c

Browse files
Gate checking ~const bounds on const_trait_impl
1 parent 7028d93 commit ace9e4c

13 files changed

+26
-191
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_mir_dataflow::Analysis;
2020
use rustc_mir_dataflow::impls::MaybeStorageLive;
2121
use rustc_mir_dataflow::storage::always_storage_live_locals;
2222
use rustc_span::{Span, Symbol, sym};
23-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2423
use rustc_trait_selection::traits::{
2524
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
2625
};
@@ -419,13 +418,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
419418

420419
let errors = ocx.select_all_or_error();
421420
if !errors.is_empty() {
422-
// FIXME(effects): Soon this should be unconditionally delaying a bug.
423-
if matches!(call_source, CallSource::Normal) && tcx.features().effects() {
424-
tcx.dcx()
425-
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
426-
} else {
427-
infcx.err_ctxt().report_fulfillment_errors(errors);
428-
}
421+
tcx.dcx()
422+
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
429423
}
430424
}
431425
}
@@ -664,7 +658,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
664658
// so we only error if the trait isn't const. We try to resolve the trait
665659
// into the concrete method, and uses that for const stability checks.
666660
// FIXME(effects) we might consider moving const stability checks to typeck as well.
667-
if tcx.features().effects() && trait_is_const {
661+
if tcx.features().const_trait_impl() && trait_is_const {
668662
// This skips the check below that ensures we only call `const fn`.
669663
is_trait = true;
670664

compiler/rustc_hir_typeck/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
847847
// This can be done as soon as we convert the standard library back to
848848
// using const traits, since if we were to enforce these conditions now,
849849
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
850-
if !self.tcx.features().effects() {
850+
if !self.tcx.features().const_trait_impl() {
851851
return;
852852
}
853853

tests/ui/specialization/const_trait_impl.stderr

+1-50
Original file line numberDiff line numberDiff line change
@@ -40,54 +40,5 @@ LL | impl<T: ~const Default + ~const Sub> const A for T {
4040
|
4141
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4242

43-
error[E0015]: cannot call non-const fn `<() as A>::a` in constants
44-
--> $DIR/const_trait_impl.rs:52:23
45-
|
46-
LL | const _: () = assert!(<()>::a() == 42);
47-
| ^^^^^^^^^
48-
|
49-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
50-
help: add `#![feature(effects)]` to the crate attributes to enable
51-
|
52-
LL + #![feature(effects)]
53-
|
54-
55-
error[E0015]: cannot call non-const fn `<u8 as A>::a` in constants
56-
--> $DIR/const_trait_impl.rs:53:23
57-
|
58-
LL | const _: () = assert!(<u8>::a() == 3);
59-
| ^^^^^^^^^
60-
|
61-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
62-
help: add `#![feature(effects)]` to the crate attributes to enable
63-
|
64-
LL + #![feature(effects)]
65-
|
66-
67-
error[E0015]: cannot call non-const fn `<u16 as A>::a` in constants
68-
--> $DIR/const_trait_impl.rs:54:23
69-
|
70-
LL | const _: () = assert!(<u16>::a() == 2);
71-
| ^^^^^^^^^^
72-
|
73-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
74-
help: add `#![feature(effects)]` to the crate attributes to enable
75-
|
76-
LL + #![feature(effects)]
77-
|
78-
79-
error[E0015]: cannot call non-const fn `<T as Sup>::foo` in constant functions
80-
--> $DIR/const_trait_impl.rs:48:9
81-
|
82-
LL | T::foo()
83-
| ^^^^^^^^
84-
|
85-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
86-
help: add `#![feature(effects)]` to the crate attributes to enable
87-
|
88-
LL + #![feature(effects)]
89-
|
90-
91-
error: aborting due to 10 previous errors
43+
error: aborting due to 6 previous errors
9244

93-
For more information about this error, try `rustc --explain E0015`.

tests/ui/traits/const-traits/call-const-trait-method-pass.stderr

+1-25
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ LL | const ADD_INT: Int = Int(1i32) + Int(2i32);
2424
|
2525
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
2626

27-
error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions
28-
--> $DIR/call-const-trait-method-pass.rs:11:20
29-
|
30-
LL | Int(self.0.plus(rhs.0))
31-
| ^^^^^^^^^^^
32-
|
33-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
34-
help: add `#![feature(effects)]` to the crate attributes to enable
35-
|
36-
LL + #![feature(effects)]
37-
|
38-
3927
error[E0015]: cannot call non-const fn `<Int as PartialEq>::eq` in constant functions
4028
--> $DIR/call-const-trait-method-pass.rs:20:15
4129
|
@@ -44,18 +32,6 @@ LL | !self.eq(other)
4432
|
4533
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
4634

47-
error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions
48-
--> $DIR/call-const-trait-method-pass.rs:36:7
49-
|
50-
LL | a.plus(b)
51-
| ^^^^^^^
52-
|
53-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
54-
help: add `#![feature(effects)]` to the crate attributes to enable
55-
|
56-
LL + #![feature(effects)]
57-
|
58-
59-
error: aborting due to 6 previous errors
35+
error: aborting due to 4 previous errors
6036

6137
For more information about this error, try `rustc --explain E0015`.

tests/ui/traits/const-traits/const-drop-fail-2.stderr

+9-21
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,21 @@ LL | const fn check<T: ~const Destruct>(_: T) {}
2121
|
2222
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2323

24-
error[E0493]: destructor of `T` cannot be evaluated at compile-time
25-
--> $DIR/const-drop-fail-2.rs:20:36
26-
|
27-
LL | const fn check<T: ~const Destruct>(_: T) {}
28-
| ^ - value is dropped here
29-
| |
30-
| the destructor for this type cannot be evaluated in constant functions
31-
3224
error[E0277]: the trait bound `T: ~const A` is not satisfied
3325
--> $DIR/const-drop-fail-2.rs:41:9
3426
|
3527
LL | T::a();
3628
| ^^^^^^
3729

38-
error[E0015]: cannot call non-const fn `<T as A>::a` in constant functions
39-
--> $DIR/const-drop-fail-2.rs:41:9
40-
|
41-
LL | T::a();
42-
| ^^^^^^
43-
|
44-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
45-
help: add `#![feature(effects)]` to the crate attributes to enable
46-
|
47-
LL + #![feature(effects)]
30+
error[E0493]: destructor of `T` cannot be evaluated at compile-time
31+
--> $DIR/const-drop-fail-2.rs:20:36
4832
|
33+
LL | const fn check<T: ~const Destruct>(_: T) {}
34+
| ^ - value is dropped here
35+
| |
36+
| the destructor for this type cannot be evaluated in constant functions
4937

50-
error: aborting due to 6 previous errors
38+
error: aborting due to 5 previous errors
5139

52-
Some errors have detailed explanations: E0015, E0277, E0493.
53-
For more information about an error, try `rustc --explain E0015`.
40+
Some errors have detailed explanations: E0277, E0493.
41+
For more information about an error, try `rustc --explain E0277`.

tests/ui/traits/const-traits/const-drop.precise.stderr

+3-15
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
8484
LL | T::foo();
8585
| ^^^^^^^^
8686

87-
error[E0015]: cannot call non-const fn `<T as SomeTrait>::foo` in constant functions
88-
--> $DIR/const-drop.rs:69:13
89-
|
90-
LL | T::foo();
91-
| ^^^^^^^^
92-
|
93-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
94-
help: add `#![feature(effects)]` to the crate attributes to enable
95-
|
96-
LL + #![feature(effects)]
97-
|
98-
99-
error: aborting due to 11 previous errors
87+
error: aborting due to 10 previous errors
10088

101-
Some errors have detailed explanations: E0015, E0277, E0493.
102-
For more information about an error, try `rustc --explain E0015`.
89+
Some errors have detailed explanations: E0277, E0493.
90+
For more information about an error, try `rustc --explain E0277`.

tests/ui/traits/const-traits/const-drop.stock.stderr

+3-15
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
8686
LL | T::foo();
8787
| ^^^^^^^^
8888

89-
error[E0015]: cannot call non-const fn `<T as SomeTrait>::foo` in constant functions
90-
--> $DIR/const-drop.rs:69:13
91-
|
92-
LL | T::foo();
93-
| ^^^^^^^^
94-
|
95-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
96-
help: add `#![feature(effects)]` to the crate attributes to enable
97-
|
98-
LL + #![feature(effects)]
99-
|
100-
101-
error: aborting due to 11 previous errors
89+
error: aborting due to 10 previous errors
10290

103-
Some errors have detailed explanations: E0015, E0277, E0493.
104-
For more information about an error, try `rustc --explain E0015`.
91+
Some errors have detailed explanations: E0277, E0493.
92+
For more information about an error, try `rustc --explain E0277`.

tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied
33
|
44
LL | foo::<()>();
55
| ^^^^^^^^^^^
6-
|
7-
note: required by a bound in `foo`
8-
--> $DIR/default-method-body-is-const-body-checking.rs:7:28
9-
|
10-
LL | const fn foo<T>() where T: ~const Tr {}
11-
| ^^^^^^ required by this bound in `foo`
126

137
error: aborting due to 1 previous error
148

tests/ui/traits/const-traits/specialization/const-default-const-specialized.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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(effects) run-pass
4+
//@ run-pass
65

76
#![feature(const_trait_impl)]
87
#![feature(min_specialization)]
Original file line numberDiff line numberDiff line change
@@ -1,15 +0,0 @@
1-
error[E0015]: cannot call non-const fn `<T as Value>::value` in constant functions
2-
--> $DIR/const-default-const-specialized.rs:16:5
3-
|
4-
LL | T::value()
5-
| ^^^^^^^^^^
6-
|
7-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8-
help: add `#![feature(effects)]` to the crate attributes to enable
9-
|
10-
LL + #![feature(effects)]
11-
|
12-
13-
error: aborting due to 1 previous error
14-
15-
For more information about this error, try `rustc --explain E0015`.

tests/ui/traits/const-traits/specialization/non-const-default-const-specialized.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests that a non-const default impl can be specialized by a const trait impl,
22
// but that the default impl cannot be used in a const context.
3-
//@ known-bug: #110395
4-
// FIXME(effects) run-pass
3+
4+
//@ run-pass
55

66
#![feature(const_trait_impl)]
77
#![feature(min_specialization)]
Original file line numberDiff line numberDiff line change
@@ -1,15 +0,0 @@
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
3-
|
4-
LL | T::value()
5-
| ^^^^^^^^^^
6-
|
7-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8-
help: add `#![feature(effects)]` to the crate attributes to enable
9-
|
10-
LL + #![feature(effects)]
11-
|
12-
13-
error: aborting due to 1 previous error
14-
15-
For more information about this error, try `rustc --explain E0015`.

tests/ui/traits/const-traits/specializing-constness-2.stderr

+2-15
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ error[E0277]: the trait bound `T: ~const A` is not satisfied
44
LL | <T as A>::a();
55
| ^^^^^^^^^^^^^
66

7-
error[E0015]: cannot call non-const fn `<T as A>::a` in constant functions
8-
--> $DIR/specializing-constness-2.rs:27:5
9-
|
10-
LL | <T as A>::a();
11-
| ^^^^^^^^^^^^^
12-
|
13-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
14-
help: add `#![feature(effects)]` to the crate attributes to enable
15-
|
16-
LL + #![feature(effects)]
17-
|
18-
19-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
208

21-
Some errors have detailed explanations: E0015, E0277.
22-
For more information about an error, try `rustc --explain E0015`.
9+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)