1
Fork 0

fix fmt and bless

This commit is contained in:
Deadbeef 2022-12-22 18:15:15 +00:00
parent f6725c0a98
commit b0aa859c24
21 changed files with 46 additions and 10 deletions

View file

@ -8,7 +8,7 @@ use rustc_attr as attr;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::{self, TyCtxt, PolyFnSig}; use rustc_middle::ty::{self, PolyFnSig, TyCtxt};
use rustc_span::Symbol; use rustc_span::Symbol;
pub use self::qualifs::Qualif; pub use self::qualifs::Qualif;

View file

@ -485,7 +485,9 @@ impl<'hir> Map<'hir> {
BodyOwnerKind::Static(mt) => ConstContext::Static(mt), BodyOwnerKind::Static(mt) => ConstContext::Static(mt),
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id.to_def_id()) => return None, BodyOwnerKind::Fn if self.tcx.is_constructor(def_id.to_def_id()) => return None,
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn_raw(def_id.to_def_id()) => { BodyOwnerKind::Fn | BodyOwnerKind::Closure
if self.tcx.is_const_fn_raw(def_id.to_def_id()) =>
{
ConstContext::ConstFn ConstContext::ConstFn
} }
BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id.to_def_id()) => { BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id.to_def_id()) => {

View file

@ -261,16 +261,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Some(closure_kind) => { Some(closure_kind) => {
debug!(?closure_kind, "assemble_unboxed_candidates"); debug!(?closure_kind, "assemble_unboxed_candidates");
if closure_kind.extends(kind) { if closure_kind.extends(kind) {
candidates.vec.push(ClosureCandidate { candidates.vec.push(ClosureCandidate { is_const });
is_const,
});
} }
} }
None => { None => {
debug!("assemble_unboxed_candidates: closure_kind not yet known"); debug!("assemble_unboxed_candidates: closure_kind not yet known");
candidates.vec.push(ClosureCandidate { candidates.vec.push(ClosureCandidate { is_const });
is_const,
});
} }
} }
} }

View file

@ -0,0 +1,11 @@
error[E0015]: cannot call non-const fn `<() as Foo>::foo` in constant functions
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:22
|
LL | (const || { (()).foo() })();
| ^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View file

@ -22,6 +22,7 @@ LL | field2: SafeEnum::Variant4("str".to_string())
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
= note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: calls in statics are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
error[E0010]: allocations are not allowed in statics error[E0010]: allocations are not allowed in statics

View file

@ -6,6 +6,7 @@ LL | (||1usize)()
| |
= note: closures need an RFC before allowed to be called in constants = note: closures need an RFC before allowed to be called in constants
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -22,6 +22,7 @@ LL | for i in 0..x {
note: impl defined here, but it is not `const` note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error[E0658]: mutable references are not allowed in constant functions error[E0658]: mutable references are not allowed in constant functions
--> $DIR/const-fn-error.rs:5:14 --> $DIR/const-fn-error.rs:5:14
@ -39,6 +40,7 @@ LL | for i in 0..x {
| ^^^^ | ^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -7,6 +7,7 @@ LL | for _ in 0..5 {}
note: impl defined here, but it is not `const` note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants
--> $DIR/const-for.rs:5:14 --> $DIR/const-for.rs:5:14
@ -15,6 +16,7 @@ LL | for _ in 0..5 {}
| ^^^^ | ^^^^
| |
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -6,6 +6,7 @@ LL | const { (|| {})() } => {}
| |
= note: closures need an RFC before allowed to be called in constants = note: closures need an RFC before allowed to be called in constants
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -6,6 +6,7 @@ LL | || -> u8 { 5 }()
| |
= note: closures need an RFC before allowed to be called in constants = note: closures need an RFC before allowed to be called in constants
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -6,6 +6,7 @@ LL | const fn foo() { (||{})() }
| |
= note: closures need an RFC before allowed to be called in constant functions = note: closures need an RFC before allowed to be called in constant functions
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: function pointer calls are not allowed in constant functions error: function pointer calls are not allowed in constant functions
--> $DIR/issue-56164.rs:5:5 --> $DIR/issue-56164.rs:5:5

View file

@ -6,6 +6,7 @@ LL | a: [(); (|| { 0 })()]
| |
= note: closures need an RFC before allowed to be called in constants = note: closures need an RFC before allowed to be called in constants
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -8,12 +8,14 @@ const fn f(a: &u8, b: &u8) -> bool {
*a == *b *a == *b
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
} }
const fn g(a: &&&&i64, b: &&&&i64) -> bool { const fn g(a: &&&&i64, b: &&&&i64) -> bool {
****a == ****b ****a == ****b
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
} }
const fn h(mut a: &[u8], mut b: &[u8]) -> bool { const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
@ -21,6 +23,7 @@ const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
if *l == *r { if *l == *r {
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
a = at; a = at;
b = bt; b = bt;
} else { } else {

View file

@ -8,12 +8,14 @@ const fn f(a: &u8, b: &u8) -> bool {
a == b a == b
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
} }
const fn g(a: &&&&i64, b: &&&&i64) -> bool { const fn g(a: &&&&i64, b: &&&&i64) -> bool {
a == b a == b
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
} }
const fn h(mut a: &[u8], mut b: &[u8]) -> bool { const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
@ -21,6 +23,7 @@ const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
if l == r { if l == r {
//~^ ERROR: cannot call non-const operator in constant functions [E0015] //~^ ERROR: cannot call non-const operator in constant functions [E0015]
//~| HELP: consider dereferencing here //~| HELP: consider dereferencing here
//~| HELP: add `#![feature(const_trait_impl)]`
a = at; a = at;
b = bt; b = bt;
} else { } else {

View file

@ -5,30 +5,33 @@ LL | a == b
| ^^^^^^ | ^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
help: consider dereferencing here help: consider dereferencing here
| |
LL | *a == *b LL | *a == *b
| + + | + +
error[E0015]: cannot call non-const operator in constant functions error[E0015]: cannot call non-const operator in constant functions
--> $DIR/issue-90870.rs:14:5 --> $DIR/issue-90870.rs:15:5
| |
LL | a == b LL | a == b
| ^^^^^^ | ^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
help: consider dereferencing here help: consider dereferencing here
| |
LL | ****a == ****b LL | ****a == ****b
| ++++ ++++ | ++++ ++++
error[E0015]: cannot call non-const operator in constant functions error[E0015]: cannot call non-const operator in constant functions
--> $DIR/issue-90870.rs:21:12 --> $DIR/issue-90870.rs:23:12
| |
LL | if l == r { LL | if l == r {
| ^^^^^^ | ^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
help: consider dereferencing here help: consider dereferencing here
| |
LL | if *l == *r { LL | if *l == *r {

View file

@ -47,6 +47,7 @@ LL | [(); { for _ in 0usize.. {}; 0}];
note: impl defined here, but it is not `const` note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error[E0658]: mutable references are not allowed in constants error[E0658]: mutable references are not allowed in constants
--> $DIR/issue-52443.rs:9:21 --> $DIR/issue-52443.rs:9:21
@ -64,6 +65,7 @@ LL | [(); { for _ in 0usize.. {}; 0}];
| ^^^^^^^^ | ^^^^^^^^
| |
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to 6 previous errors; 1 warning emitted error: aborting due to 6 previous errors; 1 warning emitted

View file

@ -5,6 +5,7 @@ LL | let array: [usize; Dim3::dim()]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error[E0015]: cannot call non-const fn `<Dim3 as Dim>::dim` in constants error[E0015]: cannot call non-const fn `<Dim3 as Dim>::dim` in constants
--> $DIR/issue-39559-2.rs:16:15 --> $DIR/issue-39559-2.rs:16:15
@ -13,6 +14,7 @@ LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -7,6 +7,7 @@ LL | pub struct S(A);
| ^ | ^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error error: aborting due to previous error

View file

@ -5,6 +5,7 @@ LL | Const.func();
| ^^^^^^ | ^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -5,6 +5,7 @@ LL | Unstable::func();
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error

View file

@ -5,6 +5,7 @@ LL | Default::default()
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| |
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error