Skip to content

use correct feature flag for impl-block-level trait bounds on const fn #84556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2021
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
13 changes: 2 additions & 11 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Validator<'mir, 'tcx> {
ty::PredicateKind::Subtype(_) => {
bug!("subtype predicate on function: {:#?}", predicate)
}
ty::PredicateKind::Trait(pred, constness) => {
ty::PredicateKind::Trait(pred, _constness) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}
Expand All @@ -440,16 +440,7 @@ impl Validator<'mir, 'tcx> {
// arguments when determining importance.
let kind = LocalKind::Arg;

if constness == hir::Constness::Const {
self.check_op_spanned(ops::ty::TraitBound(kind), span);
} else if !tcx.features().const_fn
|| self.ccx.is_const_stable_const_fn()
{
// HACK: We shouldn't need the conditional above, but trait
// bounds on containing impl blocks are wrongly being marked as
// "not-const".
self.check_op_spanned(ops::ty::TraitBound(kind), span);
}
self.check_op_spanned(ops::ty::TraitBound(kind), span);
}
// other kinds of bounds are either tautologies
// or cause errors in other passes
Expand Down
3 changes: 2 additions & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#![feature(rustc_allow_const_fn_unstable)]
#![feature(nll)]
#![feature(staged_api)]
#![feature(const_fn)]
#![cfg_attr(bootstrap, feature(const_fn))]
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
#![feature(const_fn_fn_ptr_basics)]
#![feature(allow_internal_unstable)]
#![feature(decl_macro)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

// run-pass

#![feature(const_fn)]

#[derive(PartialEq, Debug, Clone)]
struct N(u8);

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-consts/associated-const-in-trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #29924

#![feature(const_fn, associated_consts)]
#![feature(associated_consts)]

trait Trait {
const N: usize;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/auxiliary/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![crate_type="rlib"]
#![stable(feature = "rust1", since = "1.0.0")]

#![feature(const_fn)]
#![feature(staged_api)]

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const_fn_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(const_fn)]

fn double(x: usize) -> usize { x * 2 }
const fn double_const(x: usize) -> usize { x * 2 }
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/consts/const-eval/const_fn_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr.rs:12:5
--> $DIR/const_fn_ptr.rs:11:5
|
LL | X(x)
| ^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr.rs:16:5
--> $DIR/const_fn_ptr.rs:15:5
|
LL | X_CONST(x)
| ^^^^^^^^^^
help: skipping check for `const_fn_fn_ptr_basics` feature
--> $DIR/const_fn_ptr.rs:19:14
--> $DIR/const_fn_ptr.rs:18:14
|
LL | const fn foo(x: fn(usize) -> usize, y: usize) -> usize {
| ^
help: skipping check for `const_fn_fn_ptr_basics` feature
--> $DIR/const_fn_ptr.rs:20:5
--> $DIR/const_fn_ptr.rs:19:5
|
LL | x(y)
| ^
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr.rs:20:5
--> $DIR/const_fn_ptr.rs:19:5
|
LL | x(y)
| ^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const_fn_ptr_fail.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(const_fn)]
#![allow(unused)]

fn double(x: usize) -> usize { x * 2 }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/const_fn_ptr_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr_fail.rs:10:5
--> $DIR/const_fn_ptr_fail.rs:9:5
|
LL | X(x) // FIXME: this should error someday
| ^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// build-fail
// compile-flags: -Zunleash-the-miri-inside-of-you

#![feature(const_fn)]
#![allow(const_err)]

fn double(x: usize) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0080]: evaluation of constant value failed
--> $DIR/const_fn_ptr_fail2.rs:20:16
--> $DIR/const_fn_ptr_fail2.rs:19:16
|
LL | assert_eq!(Y, 4);
| ^ referenced constant has errors

error[E0080]: evaluation of constant value failed
--> $DIR/const_fn_ptr_fail2.rs:22:16
--> $DIR/const_fn_ptr_fail2.rs:21:16
|
LL | assert_eq!(Z, 4);
| ^ referenced constant has errors

warning: skipping const checks
|
help: skipping check for `const_fn_fn_ptr_basics` feature
--> $DIR/const_fn_ptr_fail2.rs:12:14
--> $DIR/const_fn_ptr_fail2.rs:11:14
|
LL | const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
| ^
help: skipping check for `const_fn_fn_ptr_basics` feature
--> $DIR/const_fn_ptr_fail2.rs:13:5
--> $DIR/const_fn_ptr_fail2.rs:12:5
|
LL | x(y)
| ^
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr_fail2.rs:13:5
--> $DIR/const_fn_ptr_fail2.rs:12:5
|
LL | x(y)
| ^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
we're apparently really bad at it",
issue = "none")]

#![feature(const_fn)]
#![feature(staged_api)]

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: `foo` is not yet stable as a const fn
--> $DIR/dont_promote_unstable_const_fn.rs:15:25
--> $DIR/dont_promote_unstable_const_fn.rs:14:25
|
LL | const fn bar() -> u32 { foo() }
| ^^^^^
|
= help: add `#![feature(foo)]` to the crate attributes to enable

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:18:28
--> $DIR/dont_promote_unstable_const_fn.rs:17:28
|
LL | let _: &'static u32 = &foo();
| ------------ ^^^^^ creates a temporary which is freed while still in use
Expand All @@ -17,7 +17,7 @@ LL | }
| - temporary value is freed at the end of this statement

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:22:28
--> $DIR/dont_promote_unstable_const_fn.rs:21:28
|
LL | let _: &'static u32 = &meh();
| ------------ ^^^^^ creates a temporary which is freed while still in use
Expand All @@ -28,7 +28,7 @@ LL | }
| - temporary value is freed at the end of this statement

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:23:26
--> $DIR/dont_promote_unstable_const_fn.rs:22:26
|
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/double_promotion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass

#![feature(const_fn, rustc_attrs)]
#![feature(rustc_attrs)]

#[rustc_args_required_const(0)]
pub const fn a(value: u8) -> u8 {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/consts/const-eval/feature-gate-const_fn_union.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_fn)]

fn main() {}

#[repr(C)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: unions in const fn are unstable
--> $DIR/feature-gate-const_fn_union.rs:12:5
--> $DIR/feature-gate-const_fn_union.rs:10:5
|
LL | Foo { u }.i
| ^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/promoted_const_fn_fail.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_fn, const_fn_union)]
#![feature(const_fn_union)]

#![allow(const_err)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_fn, const_fn_union)]
#![feature(const_fn_union)]

#![deny(const_err)]

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/simd/insert_extract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// run-pass
#![feature(const_fn)]
#![feature(repr_simd)]
#![feature(platform_intrinsics)]
#![feature(staged_api)]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/union-const-eval-field.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// only-x86_64
#![feature(const_fn)]

type Field1 = i32;
type Field2 = f32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/union-const-eval-field.rs:29:5
--> $DIR/union-const-eval-field.rs:28:5
|
LL | const FIELD3: Field3 = unsafe { UNION.field3 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/union-ice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// only-x86_64
#![feature(const_fn)]

type Field1 = i32;
type Field3 = i64;
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/consts/const-eval/union-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/union-ice.rs:15:1
--> $DIR/union-ice.rs:14:1
|
LL | const FIELD3: Field3 = unsafe { UNION.field3 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
Expand All @@ -10,7 +10,7 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 };
}

error[E0080]: it is undefined behavior to use this value
--> $DIR/union-ice.rs:17:1
--> $DIR/union-ice.rs:16:1
|
LL | / const FIELD_PATH: Struct = Struct {
LL | | a: 42,
Expand All @@ -24,7 +24,7 @@ LL | | };
}

error[E0080]: it is undefined behavior to use this value
--> $DIR/union-ice.rs:27:1
--> $DIR/union-ice.rs:26:1
|
LL | / const FIELD_PATH2: Struct2 = Struct2 {
LL | | b: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
warning: any use of this value will cause an error
--> $DIR/validate_uninhabited_zsts.rs:6:14
--> $DIR/validate_uninhabited_zsts.rs:5:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| transmuting to uninhabited type
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:6:14
| inside `FOO` at $DIR/validate_uninhabited_zsts.rs:16:26
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:5:14
| inside `FOO` at $DIR/validate_uninhabited_zsts.rs:15:26
...
LL | const FOO: [Empty; 3] = [foo(); 3];
| -----------------------------------
|
note: the lint level is defined here
--> $DIR/validate_uninhabited_zsts.rs:15:8
--> $DIR/validate_uninhabited_zsts.rs:14:8
|
LL | #[warn(const_err)]
| ^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error[E0080]: it is undefined behavior to use this value
--> $DIR/validate_uninhabited_zsts.rs:19:1
--> $DIR/validate_uninhabited_zsts.rs:18:1
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Empty at [0]
Expand All @@ -29,7 +29,7 @@ LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}

warning: the type `!` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:6:14
--> $DIR/validate_uninhabited_zsts.rs:5:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -41,7 +41,7 @@ LL | unsafe { std::mem::transmute(()) }
= note: the `!` type has no valid value

warning: the type `Empty` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:19:35
--> $DIR/validate_uninhabited_zsts.rs:18:35
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
warning: any use of this value will cause an error
--> $DIR/validate_uninhabited_zsts.rs:6:14
--> $DIR/validate_uninhabited_zsts.rs:5:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| transmuting to uninhabited type
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:6:14
| inside `FOO` at $DIR/validate_uninhabited_zsts.rs:16:26
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:5:14
| inside `FOO` at $DIR/validate_uninhabited_zsts.rs:15:26
...
LL | const FOO: [Empty; 3] = [foo(); 3];
| -----------------------------------
|
note: the lint level is defined here
--> $DIR/validate_uninhabited_zsts.rs:15:8
--> $DIR/validate_uninhabited_zsts.rs:14:8
|
LL | #[warn(const_err)]
| ^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error[E0080]: it is undefined behavior to use this value
--> $DIR/validate_uninhabited_zsts.rs:19:1
--> $DIR/validate_uninhabited_zsts.rs:18:1
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Empty at [0]
Expand All @@ -29,7 +29,7 @@ LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}

warning: the type `!` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:6:14
--> $DIR/validate_uninhabited_zsts.rs:5:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -41,7 +41,7 @@ LL | unsafe { std::mem::transmute(()) }
= note: the `!` type has no valid value

warning: the type `Empty` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:19:35
--> $DIR/validate_uninhabited_zsts.rs:18:35
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
#![feature(const_fn)]
#![feature(const_fn_transmute)]

const fn foo() -> ! {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/consts/const-fn-error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_fn)]

const X : usize = 2;

const fn f(x: usize) -> usize {
Expand Down
Loading