diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 19f170636dad4..190028457e4b5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -196,7 +196,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .map(|n| format!("`{}`", n)) .unwrap_or_else(|| "value".to_owned()); 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( fn_call_span, &format!( diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index c26b1e550ba23..237201c547822 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -125,7 +125,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { param_env, Binder::dummy(TraitPredicate { trait_ref, - constness: BoundConstness::ConstIfConst, + constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, }), ); diff --git a/compiler/rustc_const_eval/src/util/call_kind.rs b/compiler/rustc_const_eval/src/util/call_kind.rs index 34925692664be..fe35d94234139 100644 --- a/compiler/rustc_const_eval/src/util/call_kind.rs +++ b/compiler/rustc_const_eval/src/util/call_kind.rs @@ -71,9 +71,7 @@ pub fn call_kind<'tcx>( AssocItemContainer::TraitContainer(trait_did) => Some(trait_did), }); - let fn_call = (!from_hir_call) - .then(|| parent) - .flatten() + let fn_call = parent .and_then(|p| tcx.lang_items().group(LangItemGroup::Fn).iter().find(|did| **did == p)); let operator = (!from_hir_call) diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 66a1251276adc..84177cca8f7ab 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -24,7 +24,7 @@ pub enum LangItemGroup { Fn, } -const NUM_GROUPS: usize = 1; +const NUM_GROUPS: usize = 2; macro_rules! expand_group { () => { @@ -99,11 +99,12 @@ macro_rules! language_item_table { /// Construct an empty collection of lang items and no missing ones. pub fn new() -> Self { fn init_none(_: LangItem) -> Option { None } + const EMPTY: Vec = Vec::new(); Self { items: vec![$(init_none(LangItem::$variant)),*], missing: Vec::new(), - groups: [vec![]; NUM_GROUPS], + groups: [EMPTY; NUM_GROUPS], } } diff --git a/src/test/ui/const-generics/issues/issue-90318.rs b/src/test/ui/const-generics/issues/issue-90318.rs index 0c640a5ef7136..bebd0c6ac1202 100644 --- a/src/test/ui/const-generics/issues/issue-90318.rs +++ b/src/test/ui/const-generics/issues/issue-90318.rs @@ -13,7 +13,7 @@ fn consume(_val: T) where If<{ TypeId::of::() != TypeId::of::<()>() }>: True, //~^ 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() where If<{ TypeId::of::() != TypeId::of::<()>() }>: True, //~^ ERROR: overly complex generic constant - //~| ERROR: calls in constants are limited to constant functions + //~| ERROR: cannot call non-const operator in constants { } diff --git a/src/test/ui/const-generics/issues/issue-90318.stderr b/src/test/ui/const-generics/issues/issue-90318.stderr index 2b8afe2ef09ed..c8690ecd0da7e 100644 --- a/src/test/ui/const-generics/issues/issue-90318.stderr +++ b/src/test/ui/const-generics/issues/issue-90318.stderr @@ -9,11 +9,19 @@ LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, = help: consider moving this anonymous constant into a `const` function = 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 | LL | If<{ TypeId::of::() != 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 --> $DIR/issue-90318.rs:22:8 @@ -26,11 +34,19 @@ LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, = help: consider moving this anonymous constant into a `const` function = 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 | LL | If<{ TypeId::of::() != 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 diff --git a/src/test/ui/consts/issue-90870.fixed b/src/test/ui/consts/issue-90870.fixed index e767effcdd06f..0d28e06e53258 100644 --- a/src/test/ui/consts/issue-90870.fixed +++ b/src/test/ui/consts/issue-90870.fixed @@ -6,20 +6,20 @@ const fn f(a: &u8, b: &u8) -> bool { *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 } const fn g(a: &&&&i64, b: &&&&i64) -> bool { ****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 } const fn h(mut a: &[u8], mut b: &[u8]) -> bool { while let ([l, at @ ..], [r, bt @ ..]) = (a, b) { 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 a = at; b = bt; diff --git a/src/test/ui/consts/issue-90870.rs b/src/test/ui/consts/issue-90870.rs index 35b3c8242aa0c..c6bfffd2c5c15 100644 --- a/src/test/ui/consts/issue-90870.rs +++ b/src/test/ui/consts/issue-90870.rs @@ -6,20 +6,20 @@ const fn f(a: &u8, b: &u8) -> bool { 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 } const fn g(a: &&&&i64, b: &&&&i64) -> bool { 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 } const fn h(mut a: &[u8], mut b: &[u8]) -> bool { while let ([l, at @ ..], [r, bt @ ..]) = (a, b) { 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 a = at; b = bt; diff --git a/src/test/ui/consts/issue-90870.stderr b/src/test/ui/consts/issue-90870.stderr index 0e33e6ebe5a59..478445cfb39c5 100644 --- a/src/test/ui/consts/issue-90870.stderr +++ b/src/test/ui/consts/issue-90870.stderr @@ -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 | LL | a == b | ^^^^^^ | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants help: consider dereferencing here | 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 | LL | a == b | ^^^^^^ | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants help: consider dereferencing here | 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 | LL | if l == r { | ^^^^^^ | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants help: consider dereferencing here | LL | if *l == *r {