Auto merge of #85110 - RalfJung:no-rustc_args_required_const, r=oli-obk

Remove rustc_args_required_const attribute

Now that stdarch no longer needs it (thanks `@Amanieu!),` we can kill the `rustc_args_required_const` attribute. This means that lifetime extension of references to temporaries is the only remaining job that promotion is performing. :-)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/69493
This commit is contained in:
bors 2021-05-13 13:37:32 +00:00
commit d2df620789
33 changed files with 111 additions and 613 deletions

View file

@ -11,7 +11,8 @@ extern "platform-intrinsic" {
fn main() {
unsafe {
let _: I32x2 = simd_shuffle2(I32x2(1, 2), I32x2(3, 4), [0, 0]);
let _: I32x2 = simd_shuffle2(I32x2(1, 2), I32x2(3, 4), [0, 0]);
const IDX: [u32; 2] = [0, 0];
let _: I32x2 = simd_shuffle2(I32x2(1, 2), I32x2(3, 4), IDX);
let _: I32x2 = simd_shuffle2(I32x2(1, 2), I32x2(3, 4), IDX);
}
}

View file

@ -1,17 +0,0 @@
// check-pass
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
pub const fn a(value: u8) -> u8 {
value
}
#[rustc_args_required_const(0)]
pub fn b(_: u8) {
unimplemented!()
}
fn main() {
let _ = b(a(0));
}

View file

@ -1,11 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
fn foo(_imm8: i32) {}
fn bar() {
let imm8 = 3;
foo(imm8) //~ ERROR argument 1 is required to be a constant
}
fn main() {}

View file

@ -1,8 +0,0 @@
error: argument 1 is required to be a constant
--> $DIR/const_arg_local.rs:8:5
|
LL | foo(imm8)
| ^^^^^^^^^
error: aborting due to previous error

View file

@ -1,10 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
fn foo(_imm8: i32) {}
fn bar() {
foo(*&mut 42) //~ ERROR argument 1 is required to be a constant
}
fn main() {}

View file

@ -1,8 +0,0 @@
error: argument 1 is required to be a constant
--> $DIR/const_arg_promotable.rs:7:5
|
LL | foo(*&mut 42)
| ^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -1,18 +0,0 @@
// This test is a regression test for a bug where we only checked function calls in no-const
// functions for `rustc_args_required_const` arguments. This meant that even though `bar` needs its
// argument to be const, inside a const fn (callable at runtime), the value for it may come from a
// non-constant (namely an argument to the const fn).
#![feature(rustc_attrs)]
const fn foo(a: i32) {
bar(a); //~ ERROR argument 1 is required to be a constant
}
#[rustc_args_required_const(0)]
const fn bar(_: i32) {}
fn main() {
// this function call will pass a runtime-value (number of program arguments) to `foo`, which
// will in turn forward it to `bar`, which expects a compile-time argument
foo(std::env::args().count() as i32);
}

View file

@ -1,8 +0,0 @@
error: argument 1 is required to be a constant
--> $DIR/const_arg_promotable2.rs:8:5
|
LL | bar(a);
| ^^^^^^
error: aborting due to previous error

View file

@ -1,10 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
fn foo(_imm8: i32) {}
fn bar(imm8: i32) {
foo(imm8) //~ ERROR argument 1 is required to be a constant
}
fn main() {}

View file

@ -1,8 +0,0 @@
error: argument 1 is required to be a constant
--> $DIR/const_arg_wrapper.rs:7:5
|
LL | foo(imm8)
| ^^^^^^^^^
error: aborting due to previous error

View file

@ -1,27 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
fn foo(_a: i32) {
}
#[rustc_args_required_const(1)]
fn bar(_a: i32, _b: i32) {
}
const A: i32 = 3;
const fn baz() -> i32 {
3
}
fn main() {
foo(2);
foo(2 + 3);
const BAZ: i32 = baz();
foo(BAZ);
let a = 4;
foo(A);
foo(a); //~ ERROR: argument 1 is required to be a constant
bar(a, 3);
bar(a, a); //~ ERROR: argument 2 is required to be a constant
}

View file

@ -1,14 +0,0 @@
error: argument 1 is required to be a constant
--> $DIR/rustc-args-required-const.rs:24:5
|
LL | foo(a);
| ^^^^^^
error: argument 2 is required to be a constant
--> $DIR/rustc-args-required-const.rs:26:5
|
LL | bar(a, a);
| ^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -1,32 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)] //~ ERROR index exceeds number of arguments
fn foo1() {}
#[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments
fn foo2(_: u8) {}
#[rustc_args_required_const(a)] //~ ERROR arguments should be non-negative integers
fn foo4() {}
#[rustc_args_required_const(1, a, 2, b)] //~ ERROR arguments should be non-negative integers
fn foo5(_: u8, _: u8, _: u8) {}
#[rustc_args_required_const(0)] //~ ERROR attribute should be applied to a function
struct S;
#[rustc_args_required_const(0usize)] //~ ERROR suffixed literals are not allowed in attributes
fn foo6(_: u8) {}
extern {
#[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments
fn foo7(_: u8);
}
#[rustc_args_required_const] //~ ERROR malformed `rustc_args_required_const` attribute
fn bar1() {}
#[rustc_args_required_const = 1] //~ ERROR malformed `rustc_args_required_const` attribute
fn bar2() {}
fn main() {}

View file

@ -1,60 +0,0 @@
error: suffixed literals are not allowed in attributes
--> $DIR/invalid-rustc_args_required_const-arguments.rs:18:29
|
LL | #[rustc_args_required_const(0usize)]
| ^^^^^^
|
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
error: malformed `rustc_args_required_const` attribute input
--> $DIR/invalid-rustc_args_required_const-arguments.rs:26:1
|
LL | #[rustc_args_required_const]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_args_required_const(N)]`
error: malformed `rustc_args_required_const` attribute input
--> $DIR/invalid-rustc_args_required_const-arguments.rs:29:1
|
LL | #[rustc_args_required_const = 1]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_args_required_const(N)]`
error: index exceeds number of arguments
--> $DIR/invalid-rustc_args_required_const-arguments.rs:3:29
|
LL | #[rustc_args_required_const(0)]
| ^ there are only 0 arguments
error: index exceeds number of arguments
--> $DIR/invalid-rustc_args_required_const-arguments.rs:6:29
|
LL | #[rustc_args_required_const(1)]
| ^ there is only 1 argument
error: arguments should be non-negative integers
--> $DIR/invalid-rustc_args_required_const-arguments.rs:9:29
|
LL | #[rustc_args_required_const(a)]
| ^
error: arguments should be non-negative integers
--> $DIR/invalid-rustc_args_required_const-arguments.rs:12:32
|
LL | #[rustc_args_required_const(1, a, 2, b)]
| ^ ^
error: attribute should be applied to a function
--> $DIR/invalid-rustc_args_required_const-arguments.rs:15:1
|
LL | #[rustc_args_required_const(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | struct S;
| --------- not a function
error: index exceeds number of arguments
--> $DIR/invalid-rustc_args_required_const-arguments.rs:22:33
|
LL | #[rustc_args_required_const(1)]
| ^ there is only 1 argument
error: aborting due to 9 previous errors

View file

@ -1,20 +0,0 @@
// run-pass
// ignore-emscripten FIXME(#45351)
#![feature(platform_intrinsics, repr_simd)]
extern "platform-intrinsic" {
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
}
#[repr(simd)]
#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
struct u64x2(u64, u64);
fn main() {
let a = u64x2(1, 2);
let r: u64x2 = unsafe { simd_shuffle2(a, a, [0-0, 0-0]) };
assert_eq!(r.0, 1);
assert_eq!(r.1, 1);
}

View file

@ -1,10 +0,0 @@
#![feature(rustc_attrs)]
#[rustc_args_required_const(0)]
fn foo(_a: i32) {
}
fn main() {
let a = foo; //~ ERROR: this function can only be invoked directly
a(2);
}

View file

@ -1,8 +0,0 @@
error: this function can only be invoked directly, not through a function pointer
--> $DIR/rustc-args-required-const2.rs:8:13
|
LL | let a = foo;
| ^^^
error: aborting due to previous error

View file

@ -50,25 +50,28 @@ fn main() {
simd_extract::<_, f32>(x, 0);
//~^ ERROR expected return type `i32` (element of input `i32x4`), found `f32`
simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
const IDX2: [u32; 2] = [0; 2];
simd_shuffle2::<i32, i32>(0, 0, IDX2);
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
const IDX4: [u32; 4] = [0; 4];
simd_shuffle4::<i32, i32>(0, 0, IDX4);
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
const IDX8: [u32; 8] = [0; 8];
simd_shuffle8::<i32, i32>(0, 0, IDX8);
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
simd_shuffle2::<_, f32x2>(x, x, IDX2);
//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
simd_shuffle4::<_, f32x4>(x, x, IDX4);
//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32`
simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
simd_shuffle8::<_, f32x8>(x, x, IDX8);
//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32`
simd_shuffle2::<_, i32x8>(x, x, [0; 2]);
simd_shuffle2::<_, i32x8>(x, x, IDX2);
//~^ ERROR expected return type of length 2, found `i32x8` with length 8
simd_shuffle4::<_, i32x8>(x, x, [0; 4]);
simd_shuffle4::<_, i32x8>(x, x, IDX4);
//~^ ERROR expected return type of length 4, found `i32x8` with length 8
simd_shuffle8::<_, i32x2>(x, x, [0; 8]);
simd_shuffle8::<_, i32x2>(x, x, IDX8);
//~^ ERROR expected return type of length 8, found `i32x2` with length 2
}
}

View file

@ -17,58 +17,58 @@ LL | simd_extract::<_, f32>(x, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected SIMD input type, found non-SIMD `i32`
--> $DIR/simd-intrinsic-generic-elements.rs:53:9
--> $DIR/simd-intrinsic-generic-elements.rs:54:9
|
LL | simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle2::<i32, i32>(0, 0, IDX2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected SIMD input type, found non-SIMD `i32`
--> $DIR/simd-intrinsic-generic-elements.rs:55:9
|
LL | simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected SIMD input type, found non-SIMD `i32`
--> $DIR/simd-intrinsic-generic-elements.rs:57:9
|
LL | simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle4::<i32, i32>(0, 0, IDX4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected SIMD input type, found non-SIMD `i32`
--> $DIR/simd-intrinsic-generic-elements.rs:60:9
|
LL | simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle8::<i32, i32>(0, 0, IDX8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
--> $DIR/simd-intrinsic-generic-elements.rs:63:9
|
LL | simd_shuffle2::<_, f32x2>(x, x, IDX2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32`
--> $DIR/simd-intrinsic-generic-elements.rs:62:9
--> $DIR/simd-intrinsic-generic-elements.rs:65:9
|
LL | simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle4::<_, f32x4>(x, x, IDX4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32`
--> $DIR/simd-intrinsic-generic-elements.rs:64:9
|
LL | simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return type of length 2, found `i32x8` with length 8
--> $DIR/simd-intrinsic-generic-elements.rs:67:9
|
LL | simd_shuffle2::<_, i32x8>(x, x, [0; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle8::<_, f32x8>(x, x, IDX8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return type of length 2, found `i32x8` with length 8
--> $DIR/simd-intrinsic-generic-elements.rs:70:9
|
LL | simd_shuffle2::<_, i32x8>(x, x, IDX2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return type of length 4, found `i32x8` with length 8
--> $DIR/simd-intrinsic-generic-elements.rs:69:9
--> $DIR/simd-intrinsic-generic-elements.rs:72:9
|
LL | simd_shuffle4::<_, i32x8>(x, x, [0; 4]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle4::<_, i32x8>(x, x, IDX4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return type of length 8, found `i32x2` with length 2
--> $DIR/simd-intrinsic-generic-elements.rs:71:9
--> $DIR/simd-intrinsic-generic-elements.rs:74:9
|
LL | simd_shuffle8::<_, i32x2>(x, x, [0; 8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_shuffle8::<_, i32x2>(x, x, IDX8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors

View file

@ -21,5 +21,6 @@ fn main() {
#[inline(always)]
unsafe fn inline_me() -> Simd2 {
simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 3])
const IDX: [u32; 2] = [0, 3];
simd_shuffle2(Simd2(10, 11), Simd2(12, 13), IDX)
}

View file

@ -15,7 +15,8 @@ struct Simd2(u8, u8);
fn main() {
unsafe {
let p_res: Simd2 = simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 1]);
const IDX: [u32; 2] = [0, 1];
let p_res: Simd2 = simd_shuffle2(Simd2(10, 11), Simd2(12, 13), IDX);
let a_res: Simd2 = inline_me();
assert_10_11(p_res);
@ -36,5 +37,6 @@ fn assert_10_13(x: Simd2) {
#[inline(always)]
unsafe fn inline_me() -> Simd2 {
simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 3])
const IDX: [u32; 2] = [0, 3];
simd_shuffle2(Simd2(10, 11), Simd2(12, 13), IDX)
}

View file

@ -2,6 +2,8 @@
// ignore-emscripten FIXME(#45351) hits an LLVM assert
#![feature(repr_simd, platform_intrinsics)]
#![allow(incomplete_features)]
#![feature(inline_const)]
#[repr(simd)]
#[derive(Copy, Clone, Debug, PartialEq)]
@ -82,19 +84,19 @@ fn main() {
let y4 = i32x4(140, 141, 142, 143);
let y8 = i32x8(180, 181, 182, 183, 184, 185, 186, 187);
unsafe {
all_eq!(simd_shuffle2(x2, y2, [3, 0]), i32x2(121, 20));
all_eq!(simd_shuffle4(x2, y2, [3, 0, 1, 2]), i32x4(121, 20, 21, 120));
all_eq!(simd_shuffle8(x2, y2, [3, 0, 1, 2, 1, 2, 3, 0]),
all_eq!(simd_shuffle2(x2, y2, const { [3u32, 0] }), i32x2(121, 20));
all_eq!(simd_shuffle4(x2, y2, const { [3u32, 0, 1, 2] }), i32x4(121, 20, 21, 120));
all_eq!(simd_shuffle8(x2, y2, const { [3u32, 0, 1, 2, 1, 2, 3, 0] }),
i32x8(121, 20, 21, 120, 21, 120, 121, 20));
all_eq!(simd_shuffle2(x4, y4, [7, 2]), i32x2(143, 42));
all_eq!(simd_shuffle4(x4, y4, [7, 2, 5, 0]), i32x4(143, 42, 141, 40));
all_eq!(simd_shuffle8(x4, y4, [7, 2, 5, 0, 3, 6, 4, 1]),
all_eq!(simd_shuffle2(x4, y4, const { [7u32, 2] }), i32x2(143, 42));
all_eq!(simd_shuffle4(x4, y4, const { [7u32, 2, 5, 0] }), i32x4(143, 42, 141, 40));
all_eq!(simd_shuffle8(x4, y4, const { [7u32, 2, 5, 0, 3, 6, 4, 1] }),
i32x8(143, 42, 141, 40, 43, 142, 140, 41));
all_eq!(simd_shuffle2(x8, y8, [11, 5]), i32x2(183, 85));
all_eq!(simd_shuffle4(x8, y8, [11, 5, 15, 0]), i32x4(183, 85, 187, 80));
all_eq!(simd_shuffle8(x8, y8, [11, 5, 15, 0, 3, 8, 12, 1]),
all_eq!(simd_shuffle2(x8, y8, const { [11u32, 5] }), i32x2(183, 85));
all_eq!(simd_shuffle4(x8, y8, const { [11u32, 5, 15, 0] }), i32x4(183, 85, 187, 80));
all_eq!(simd_shuffle8(x8, y8, const { [11u32, 5, 15, 0, 3, 8, 12, 1] }),
i32x8(183, 85, 187, 80, 83, 180, 184, 81));
}