Rebased and improved errors
This commit is contained in:
parent
b5235ea732
commit
6d6314f878
9 changed files with 40 additions and 20 deletions
|
@ -196,7 +196,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
.map(|n| format!("`{}`", n))
|
.map(|n| format!("`{}`", n))
|
||||||
.unwrap_or_else(|| "value".to_owned());
|
.unwrap_or_else(|| "value".to_owned());
|
||||||
match kind {
|
match kind {
|
||||||
CallKind::FnCall(once_did) if Some(once_did) == self.infcx.tcx.lang_items().fn_once_trait() => {
|
CallKind::FnCall(once_did)
|
||||||
|
if Some(once_did) == self.infcx.tcx.lang_items().fn_once_trait() =>
|
||||||
|
{
|
||||||
err.span_label(
|
err.span_label(
|
||||||
fn_call_span,
|
fn_call_span,
|
||||||
&format!(
|
&format!(
|
||||||
|
|
|
@ -125,7 +125,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
param_env,
|
param_env,
|
||||||
Binder::dummy(TraitPredicate {
|
Binder::dummy(TraitPredicate {
|
||||||
trait_ref,
|
trait_ref,
|
||||||
constness: BoundConstness::ConstIfConst,
|
constness: BoundConstness::NotConst,
|
||||||
polarity: ImplPolarity::Positive,
|
polarity: ImplPolarity::Positive,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
@ -71,9 +71,7 @@ pub fn call_kind<'tcx>(
|
||||||
AssocItemContainer::TraitContainer(trait_did) => Some(trait_did),
|
AssocItemContainer::TraitContainer(trait_did) => Some(trait_did),
|
||||||
});
|
});
|
||||||
|
|
||||||
let fn_call = (!from_hir_call)
|
let fn_call = parent
|
||||||
.then(|| parent)
|
|
||||||
.flatten()
|
|
||||||
.and_then(|p| tcx.lang_items().group(LangItemGroup::Fn).iter().find(|did| **did == p));
|
.and_then(|p| tcx.lang_items().group(LangItemGroup::Fn).iter().find(|did| **did == p));
|
||||||
|
|
||||||
let operator = (!from_hir_call)
|
let operator = (!from_hir_call)
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub enum LangItemGroup {
|
||||||
Fn,
|
Fn,
|
||||||
}
|
}
|
||||||
|
|
||||||
const NUM_GROUPS: usize = 1;
|
const NUM_GROUPS: usize = 2;
|
||||||
|
|
||||||
macro_rules! expand_group {
|
macro_rules! expand_group {
|
||||||
() => {
|
() => {
|
||||||
|
@ -99,11 +99,12 @@ macro_rules! language_item_table {
|
||||||
/// Construct an empty collection of lang items and no missing ones.
|
/// Construct an empty collection of lang items and no missing ones.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
fn init_none(_: LangItem) -> Option<DefId> { None }
|
fn init_none(_: LangItem) -> Option<DefId> { None }
|
||||||
|
const EMPTY: Vec<DefId> = Vec::new();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
items: vec![$(init_none(LangItem::$variant)),*],
|
items: vec![$(init_none(LangItem::$variant)),*],
|
||||||
missing: Vec::new(),
|
missing: Vec::new(),
|
||||||
groups: [vec![]; NUM_GROUPS],
|
groups: [EMPTY; NUM_GROUPS],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn consume<T: 'static>(_val: T)
|
||||||
where
|
where
|
||||||
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
//~^ ERROR: overly complex generic constant
|
//~^ ERROR: overly complex generic constant
|
||||||
//~| ERROR: calls in constants are limited to constant functions
|
//~| ERROR: cannot call non-const operator in constants
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ fn test<T: 'static>()
|
||||||
where
|
where
|
||||||
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
//~^ ERROR: overly complex generic constant
|
//~^ ERROR: overly complex generic constant
|
||||||
//~| ERROR: calls in constants are limited to constant functions
|
//~| ERROR: cannot call non-const operator in constants
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,19 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
= help: consider moving this anonymous constant into a `const` function
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
= note: this operation may be supported in the future
|
= note: this operation may be supported in the future
|
||||||
|
|
||||||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: cannot call non-const operator in constants
|
||||||
--> $DIR/issue-90318.rs:14:10
|
--> $DIR/issue-90318.rs:14:10
|
||||||
|
|
|
|
||||||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: impl defined here, but it is not `const`
|
||||||
|
--> $SRC_DIR/core/src/any.rs:LL:COL
|
||||||
|
|
|
||||||
|
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||||
|
| ^^^^^^^^^
|
||||||
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||||
|
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: overly complex generic constant
|
error: overly complex generic constant
|
||||||
--> $DIR/issue-90318.rs:22:8
|
--> $DIR/issue-90318.rs:22:8
|
||||||
|
@ -26,11 +34,19 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
= help: consider moving this anonymous constant into a `const` function
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
= note: this operation may be supported in the future
|
= note: this operation may be supported in the future
|
||||||
|
|
||||||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: cannot call non-const operator in constants
|
||||||
--> $DIR/issue-90318.rs:22:10
|
--> $DIR/issue-90318.rs:22:10
|
||||||
|
|
|
|
||||||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: impl defined here, but it is not `const`
|
||||||
|
--> $SRC_DIR/core/src/any.rs:LL:COL
|
||||||
|
|
|
||||||
|
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||||
|
| ^^^^^^^^^
|
||||||
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||||
|
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
|
|
||||||
const fn f(a: &u8, b: &u8) -> bool {
|
const fn f(a: &u8, b: &u8) -> bool {
|
||||||
*a == *b
|
*a == *b
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
||||||
****a == ****b
|
****a == ****b
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
||||||
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
||||||
if *l == *r {
|
if *l == *r {
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
a = at;
|
a = at;
|
||||||
b = bt;
|
b = bt;
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
|
|
||||||
const fn f(a: &u8, b: &u8) -> bool {
|
const fn f(a: &u8, b: &u8) -> bool {
|
||||||
a == b
|
a == b
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
||||||
a == b
|
a == b
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
||||||
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
||||||
if l == r {
|
if l == r {
|
||||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
|
||||||
//~| HELP: consider dereferencing here
|
//~| HELP: consider dereferencing here
|
||||||
a = at;
|
a = at;
|
||||||
b = bt;
|
b = bt;
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: cannot call non-const operator in constant functions
|
||||||
--> $DIR/issue-90870.rs:8:5
|
--> $DIR/issue-90870.rs:8:5
|
||||||
|
|
|
|
||||||
LL | a == b
|
LL | a == b
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
help: consider dereferencing here
|
help: consider dereferencing here
|
||||||
|
|
|
|
||||||
LL | *a == *b
|
LL | *a == *b
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: cannot call non-const operator in constant functions
|
||||||
--> $DIR/issue-90870.rs:14:5
|
--> $DIR/issue-90870.rs:14:5
|
||||||
|
|
|
|
||||||
LL | a == b
|
LL | a == b
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
help: consider dereferencing here
|
help: consider dereferencing here
|
||||||
|
|
|
|
||||||
LL | ****a == ****b
|
LL | ****a == ****b
|
||||||
| ++++ ++++
|
| ++++ ++++
|
||||||
|
|
||||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: cannot call non-const operator in constant functions
|
||||||
--> $DIR/issue-90870.rs:21:12
|
--> $DIR/issue-90870.rs:21:12
|
||||||
|
|
|
|
||||||
LL | if l == r {
|
LL | if l == r {
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
help: consider dereferencing here
|
help: consider dereferencing here
|
||||||
|
|
|
|
||||||
LL | if *l == *r {
|
LL | if *l == *r {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue