Skip to content

Commit c17fda7

Browse files
committed
Rebased and improved errors
1 parent de2123a commit c17fda7

File tree

9 files changed

+40
-20
lines changed

9 files changed

+40
-20
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
196196
.map(|n| format!("`{}`", n))
197197
.unwrap_or_else(|| "value".to_owned());
198198
match kind {
199-
CallKind::FnCall(once_did) if Some(once_did) == self.infcx.tcx.lang_items().fn_once_trait() => {
199+
CallKind::FnCall(once_did)
200+
if Some(once_did) == self.infcx.tcx.lang_items().fn_once_trait() =>
201+
{
200202
err.span_label(
201203
fn_call_span,
202204
&format!(

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
125125
param_env,
126126
Binder::dummy(TraitPredicate {
127127
trait_ref,
128-
constness: BoundConstness::ConstIfConst,
128+
constness: BoundConstness::NotConst,
129129
polarity: ImplPolarity::Positive,
130130
}),
131131
);

compiler/rustc_const_eval/src/util/call_kind.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ pub fn call_kind<'tcx>(
7171
AssocItemContainer::TraitContainer(trait_did) => Some(trait_did),
7272
});
7373

74-
let fn_call = (!from_hir_call)
75-
.then(|| parent)
76-
.flatten()
74+
let fn_call = parent
7775
.and_then(|p| tcx.lang_items().group(LangItemGroup::Fn).iter().find(|did| **did == p));
7876

7977
let operator = (!from_hir_call)

compiler/rustc_hir/src/lang_items.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum LangItemGroup {
2424
Fn,
2525
}
2626

27-
const NUM_GROUPS: usize = 1;
27+
const NUM_GROUPS: usize = 2;
2828

2929
macro_rules! expand_group {
3030
() => {
@@ -99,11 +99,12 @@ macro_rules! language_item_table {
9999
/// Construct an empty collection of lang items and no missing ones.
100100
pub fn new() -> Self {
101101
fn init_none(_: LangItem) -> Option<DefId> { None }
102+
const EMPTY: Vec<DefId> = Vec::new();
102103

103104
Self {
104105
items: vec![$(init_none(LangItem::$variant)),*],
105106
missing: Vec::new(),
106-
groups: [vec![]; NUM_GROUPS],
107+
groups: [EMPTY; NUM_GROUPS],
107108
}
108109
}
109110

src/test/ui/const-generics/issues/issue-90318.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ fn consume<T: 'static>(_val: T)
1313
where
1414
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
1515
//~^ ERROR: overly complex generic constant
16-
//~| ERROR: calls in constants are limited to constant functions
16+
//~| ERROR: cannot call non-const operator in constants
1717
{
1818
}
1919

2020
fn test<T: 'static>()
2121
where
2222
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
2323
//~^ ERROR: overly complex generic constant
24-
//~| ERROR: calls in constants are limited to constant functions
24+
//~| ERROR: cannot call non-const operator in constants
2525
{
2626
}
2727

src/test/ui/const-generics/issues/issue-90318.stderr

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
99
= help: consider moving this anonymous constant into a `const` function
1010
= note: this operation may be supported in the future
1111

12-
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
12+
error[E0015]: cannot call non-const operator in constants
1313
--> $DIR/issue-90318.rs:14:10
1414
|
1515
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
|
18+
note: impl defined here, but it is not `const`
19+
--> $SRC_DIR/core/src/any.rs:LL:COL
20+
|
21+
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
22+
| ^^^^^^^^^
23+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
24+
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
1725

1826
error: overly complex generic constant
1927
--> $DIR/issue-90318.rs:22:8
@@ -26,11 +34,19 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
2634
= help: consider moving this anonymous constant into a `const` function
2735
= note: this operation may be supported in the future
2836

29-
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
37+
error[E0015]: cannot call non-const operator in constants
3038
--> $DIR/issue-90318.rs:22:10
3139
|
3240
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
3341
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
|
43+
note: impl defined here, but it is not `const`
44+
--> $SRC_DIR/core/src/any.rs:LL:COL
45+
|
46+
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
47+
| ^^^^^^^^^
48+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
49+
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
3450

3551
error: aborting due to 4 previous errors
3652

src/test/ui/consts/issue-90870.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
const fn f(a: &u8, b: &u8) -> bool {
88
*a == *b
9-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
9+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
1010
//~| HELP: consider dereferencing here
1111
}
1212

1313
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
1414
****a == ****b
15-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
15+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
1616
//~| HELP: consider dereferencing here
1717
}
1818

1919
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
2020
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
2121
if *l == *r {
22-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
22+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
2323
//~| HELP: consider dereferencing here
2424
a = at;
2525
b = bt;

src/test/ui/consts/issue-90870.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
const fn f(a: &u8, b: &u8) -> bool {
88
a == b
9-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
9+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
1010
//~| HELP: consider dereferencing here
1111
}
1212

1313
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
1414
a == b
15-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
15+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
1616
//~| HELP: consider dereferencing here
1717
}
1818

1919
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
2020
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
2121
if l == r {
22-
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
22+
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
2323
//~| HELP: consider dereferencing here
2424
a = at;
2525
b = bt;

src/test/ui/consts/issue-90870.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1+
error[E0015]: cannot call non-const operator in constant functions
22
--> $DIR/issue-90870.rs:8:5
33
|
44
LL | a == b
55
| ^^^^^^
66
|
7+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
78
help: consider dereferencing here
89
|
910
LL | *a == *b
1011
| + +
1112

12-
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
13+
error[E0015]: cannot call non-const operator in constant functions
1314
--> $DIR/issue-90870.rs:14:5
1415
|
1516
LL | a == b
1617
| ^^^^^^
1718
|
19+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1820
help: consider dereferencing here
1921
|
2022
LL | ****a == ****b
2123
| ++++ ++++
2224

23-
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
25+
error[E0015]: cannot call non-const operator in constant functions
2426
--> $DIR/issue-90870.rs:21:12
2527
|
2628
LL | if l == r {
2729
| ^^^^^^
2830
|
31+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2932
help: consider dereferencing here
3033
|
3134
LL | if *l == *r {

0 commit comments

Comments
 (0)