Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
callee_did: DefId,
callee_args: GenericArgsRef<'tcx>,
) {
// FIXME(const_trait_impl): We should be enforcing these effects unconditionally.
// 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,
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
if !self.tcx.features().const_trait_impl() {
return;
}

// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) {
return;
Expand Down
7 changes: 2 additions & 5 deletions tests/crashes/137187.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//@ known-bug: #137187
#![feature(const_trait_impl, const_ops)]

use std::ops::Add;

const trait A where
*const Self: const Add,
*const Self: Add,
{
fn b(c: *const Self) -> <*const Self as Add>::Output {
c + c
}
}

fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/coercion/coerce-loop-issue-122561.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ fn for_single_line() -> bool { for i in 0.. { return false; } }
// that it's readable
fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
//~^ ERROR mismatched types
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
true
}

Expand Down Expand Up @@ -88,17 +86,13 @@ fn loop_() -> bool {
const C: i32 = {
for i in 0.. {
//~^ ERROR mismatched types
//~| ERROR `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
}
};

fn main() {
let _ = [10; {
for i in 0..5 {
//~^ ERROR mismatched types
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
}
}];

Expand All @@ -111,6 +105,4 @@ fn main() {

let _ = |a: &[(); for x in 0..2 {}]| {};
//~^ ERROR mismatched types
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
}
105 changes: 14 additions & 91 deletions tests/ui/coercion/coerce-loop-issue-122561.stderr
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
warning: denote infinite loops with `loop { ... }`
--> $DIR/coerce-loop-issue-122561.rs:51:5
--> $DIR/coerce-loop-issue-122561.rs:49:5
|
LL | while true {
| ^^^^^^^^^^ help: use `loop`
|
= note: `#[warn(while_true)]` on by default

warning: denote infinite loops with `loop { ... }`
--> $DIR/coerce-loop-issue-122561.rs:75:5
--> $DIR/coerce-loop-issue-122561.rs:73:5
|
LL | while true {
| ^^^^^^^^^^ help: use `loop`

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:43:33
|
LL | fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
| ^^^^ required by a bound introduced by this call
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:43:33
|
LL | fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:43:24
|
Expand Down Expand Up @@ -131,7 +112,7 @@ LL | fn for_single_line() -> bool { for i in 0.. { return false; } /* `bool` val
| ++++++++++++++++++

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:51:5
--> $DIR/coerce-loop-issue-122561.rs:49:5
|
LL | fn while_inifinite() -> bool {
| ---- expected `bool` because of return type
Expand All @@ -150,7 +131,7 @@ LL + /* `bool` value */
|

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:60:5
--> $DIR/coerce-loop-issue-122561.rs:58:5
|
LL | fn while_finite() -> bool {
| ---- expected `bool` because of return type
Expand All @@ -170,7 +151,7 @@ LL + /* `bool` value */
|

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:68:5
--> $DIR/coerce-loop-issue-122561.rs:66:5
|
LL | fn while_zero_times() -> bool {
| ---- expected `bool` because of return type
Expand All @@ -188,7 +169,7 @@ LL + /* `bool` value */
|

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:75:5
--> $DIR/coerce-loop-issue-122561.rs:73:5
|
LL | fn while_never_type() -> ! {
| - expected `!` because of return type
Expand All @@ -206,30 +187,11 @@ LL ~ }
LL + /* `loop {}` or `panic!("...")` */
|

error[E0277]: the trait bound `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:89:14
|
LL | for i in 0.. {
| ^^^ required by a bound introduced by this call
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::RangeFrom<{integer}>` to implement `const IntoIterator`

error[E0277]: the trait bound `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:89:14
|
LL | for i in 0.. {
| ^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:89:5
--> $DIR/coerce-loop-issue-122561.rs:87:5
|
LL | / for i in 0.. {
... |
LL | |
LL | | }
| |_____^ expected `i32`, found `()`
|
Expand All @@ -240,30 +202,11 @@ LL ~ }
LL + /* `i32` value */
|

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:98:18
|
LL | for i in 0..5 {
| ^^^^ required by a bound introduced by this call
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:98:18
|
LL | for i in 0..5 {
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:98:9
--> $DIR/coerce-loop-issue-122561.rs:94:9
|
LL | / for i in 0..5 {
... |
LL | |
LL | | }
| |_________^ expected `usize`, found `()`
|
Expand All @@ -275,7 +218,7 @@ LL + /* `usize` value */
|

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:106:9
--> $DIR/coerce-loop-issue-122561.rs:100:9
|
LL | / while false {
LL | |
Expand All @@ -289,27 +232,8 @@ LL ~ }
LL + /* `usize` value */
|

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:112:32
|
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
| ^^^^ required by a bound introduced by this call
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
--> $DIR/coerce-loop-issue-122561.rs:112:32
|
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:112:23
--> $DIR/coerce-loop-issue-122561.rs:106:23
|
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
| ^^^^^^^^^^^^^^^^ expected `usize`, found `()`
Expand All @@ -320,7 +244,6 @@ help: consider returning a value here
LL | let _ = |a: &[(); for x in 0..2 {} /* `usize` value */]| {};
| +++++++++++++++++++

error: aborting due to 22 previous errors; 2 warnings emitted
error: aborting due to 14 previous errors; 2 warnings emitted

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0308`.
9 changes: 2 additions & 7 deletions tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
error[E0277]: pointers cannot be reliably compared during const eval
error: pointers cannot be reliably compared during const eval
--> $DIR/const_raw_ptr_ops.rs:7:26
|
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: trait `PartialEq` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

error[E0277]: pointers cannot be reliably compared during const eval
error: pointers cannot be reliably compared during const eval
--> $DIR/const_raw_ptr_ops.rs:9:27
|
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: trait `PartialEq` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
4 changes: 2 additions & 2 deletions tests/ui/consts/const-fn-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const X : usize = 2;
const fn f(x: usize) -> usize {
let mut sum = 0;
for i in 0..x {
//~^ ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
//~| ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
//~^ ERROR cannot use `for`
//~| ERROR cannot use `for`
sum += i;
}
sum
Expand Down
16 changes: 7 additions & 9 deletions tests/ui/consts/const-fn-error.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
--> $DIR/const-fn-error.rs:5:14
|
LL | for i in 0..x {
| ^^^^ required by a bound introduced by this call
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::Range<usize>` to implement `[const] IntoIterator`
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
--> $DIR/const-fn-error.rs:5:14
|
LL | for i in 0..x {
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0015`.
4 changes: 2 additions & 2 deletions tests/ui/consts/const-for-feature-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const _: () = {
for _ in 0..5 {}
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~^ ERROR cannot use `for`
//~| ERROR cannot use `for`
};

fn main() {}
16 changes: 7 additions & 9 deletions tests/ui/consts/const-for-feature-gate.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants
--> $DIR/const-for-feature-gate.rs:4:14
|
LL | for _ in 0..5 {}
| ^^^^ required by a bound introduced by this call
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants
--> $DIR/const-for-feature-gate.rs:4:14
|
LL | for _ in 0..5 {}
| ^^^^
|
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0015`.
4 changes: 2 additions & 2 deletions tests/ui/consts/const-for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const _: () = {
for _ in 0..5 {}
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~^ ERROR cannot use `for`
//~| ERROR cannot use `for`
};

fn main() {}
Loading
Loading