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: 0 additions & 8 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,6 @@ 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 && self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
return;
Expand Down
7 changes: 5 additions & 2 deletions tests/crashes/137187.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//@ known-bug: #137187
use std::ops::Add;
#![feature(const_trait_impl, const_ops)]

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

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/coercion/coerce-loop-issue-122561.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ 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 @@ -86,13 +88,17 @@ 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 @@ -105,4 +111,6 @@ 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: 91 additions & 14 deletions tests/ui/coercion/coerce-loop-issue-122561.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
warning: denote infinite loops with `loop { ... }`
--> $DIR/coerce-loop-issue-122561.rs:49:5
--> $DIR/coerce-loop-issue-122561.rs:51: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:73:5
--> $DIR/coerce-loop-issue-122561.rs:75: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 @@ -112,7 +131,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:49:5
--> $DIR/coerce-loop-issue-122561.rs:51:5
|
LL | fn while_inifinite() -> bool {
| ---- expected `bool` because of return type
Expand All @@ -131,7 +150,7 @@ LL + /* `bool` value */
|

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

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

error[E0308]: mismatched types
--> $DIR/coerce-loop-issue-122561.rs:73:5
--> $DIR/coerce-loop-issue-122561.rs:75:5
|
LL | fn while_never_type() -> ! {
| - expected `!` because of return type
Expand All @@ -187,11 +206,30 @@ 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:87:5
--> $DIR/coerce-loop-issue-122561.rs:89:5
|
LL | / for i in 0.. {
LL | |
... |
LL | | }
| |_____^ expected `i32`, found `()`
|
Expand All @@ -202,11 +240,30 @@ 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:94:9
--> $DIR/coerce-loop-issue-122561.rs:98:9
|
LL | / for i in 0..5 {
LL | |
... |
LL | | }
| |_________^ expected `usize`, found `()`
|
Expand All @@ -218,7 +275,7 @@ LL + /* `usize` value */
|

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

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

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
9 changes: 7 additions & 2 deletions tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
error: pointers cannot be reliably compared during const eval
error[E0277]: 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: pointers cannot be reliably compared during const eval
error[E0277]: 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 cannot use `for`
//~| ERROR cannot use `for`
//~^ ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
//~| ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
sum += i;
}
sum
Expand Down
16 changes: 9 additions & 7 deletions tests/ui/consts/const-fn-error.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
--> $DIR/const-fn-error.rs:5:14
|
LL | for i in 0..x {
| ^^^^
| ^^^^ required by a bound introduced by this call
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
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`

error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
--> $DIR/const-fn-error.rs:5:14
|
LL | for i in 0..x {
| ^^^^
|
= 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`
note: trait `Iterator` is implemented but not `const`
--> $SRC_DIR/core/src/iter/range.rs:LL:COL

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
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 cannot use `for`
//~| ERROR cannot use `for`
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
};

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
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 cannot use `for`
//~| ERROR cannot use `for`
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
};

fn main() {}
Loading
Loading