diff options
| author | Ralf Jung <post@ralfj.de> | 2023-07-27 09:29:22 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-07-27 09:29:22 +0200 |
| commit | e5bede18f6b1df9d91e1516a7ac79cacbf1f8a9b (patch) | |
| tree | 413bbb08d04b88e810db6d1423d5a71d1e280fc7 /tests | |
| parent | 3a1a03a1cc56067b54ae198b1426245677954fd7 (diff) | |
| parent | d150dbb067e66f351a0b33a54e7d4b464ef51e47 (diff) | |
| download | rust-e5bede18f6b1df9d91e1516a7ac79cacbf1f8a9b.tar.gz rust-e5bede18f6b1df9d91e1516a7ac79cacbf1f8a9b.zip | |
Merge from rustc
Diffstat (limited to 'tests')
12 files changed, 219 insertions, 2 deletions
diff --git a/tests/codegen/sanitizer-cfi-emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer-cfi-emit-type-metadata-trait-objects.rs index 0f79adab7bd..d24e416b67e 100644 --- a/tests/codegen/sanitizer-cfi-emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer-cfi-emit-type-metadata-trait-objects.rs @@ -53,6 +53,18 @@ impl<'a, T, U> Trait4<'a, U> for T { } } +pub trait Trait5<T, const N: usize> { + fn quux(&self, _: &[T; N]); +} + +#[derive(Copy, Clone)] +pub struct Type5; + +impl<T, U, const N: usize> Trait5<U, N> for T { + fn quux(&self, _: &[U; N]) { + } +} + pub fn foo1(a: &dyn Trait1) { a.foo(); // CHECK-LABEL: define{{.*}}4foo1{{.*}}!type !{{[0-9]+}} @@ -114,7 +126,24 @@ pub fn bar4<'a>() { // CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%[0-9]}}, metadata !"[[TYPE4:[[:print:]]+]]") } +pub fn foo5(a: &dyn Trait5<Type5, 32>) { + let b = &[Type5; 32]; + a.quux(&b); + // CHECK-LABEL: define{{.*}}4foo5{{.*}}!type !{{[0-9]+}} + // CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%[0-9]}}, metadata !"[[TYPE5:[[:print:]]+]]") +} + +pub fn bar5() { + let a = &[Type5; 32]; + foo5(&a); + let b = &a as &dyn Trait5<Type5, 32>; + b.quux(&a); + // CHECK-LABEL: define{{.*}}4bar5{{.*}}!type !{{[0-9]+}} + // CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%[0-9]}}, metadata !"[[TYPE5:[[:print:]]+]]") +} + // CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE1]]"} // CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE2]]"} // CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE3]]"} // CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE4]]"} +// CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE5]]"} diff --git a/tests/codegen/sanitizer-kcfi-emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer-kcfi-emit-type-metadata-trait-objects.rs index 004a67e7df2..78ecc187b8e 100644 --- a/tests/codegen/sanitizer-kcfi-emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer-kcfi-emit-type-metadata-trait-objects.rs @@ -77,6 +77,19 @@ impl<'a, T, U> Trait4<'a, U> for T { } } +pub trait Trait5<T, const N: usize> { + fn quux(&self, _: &[T; N]); +} + +pub struct Type5; + +impl Copy for Type5 {} + +impl<T, U, const N: usize> Trait5<U, N> for T { + fn quux(&self, _: &[U; N]) { + } +} + pub fn foo1(a: &dyn Trait1) { a.foo(); // CHECK-LABEL: define{{.*}}4foo1{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}} @@ -138,7 +151,24 @@ pub fn bar4<'a>() { // CHECK: call align 4 {{ptr|i32\*}} %{{[0-9]}}({{\{\}\*|ptr}} align 1 {{%[a-z]\.0|%_[0-9]}}, {{\{\}\*|ptr|%Type4\*}} align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ] } +pub fn foo5(a: &dyn Trait5<Type5, 32>) { + let b = &[Type5; 32]; + a.quux(&b); + // CHECK-LABEL: define{{.*}}4foo5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}} + // CHECK: call void %{{[0-9]}}({{\{\}\*|ptr}} align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, {{\{\}\*|ptr|\[32 x %Type5\]\*}} align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ] +} + +pub fn bar5() { + let a = &[Type5; 32]; + foo5(&a); + let b = &a as &dyn Trait5<Type5, 32>; + b.quux(&a); + // CHECK-LABEL: define{{.*}}4bar5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}} + // CHECK: call void %{{[0-9]}}({{\{\}\*|ptr}} align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, {{\{\}\*|ptr|\[32 x %Type5\]\*}} align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ] +} + // CHECK: !{{[0-9]+}} = !{i32 [[TYPE1]]} // CHECK: !{{[0-9]+}} = !{i32 [[TYPE2]]} // CHECK: !{{[0-9]+}} = !{i32 [[TYPE3]]} // CHECK: !{{[0-9]+}} = !{i32 [[TYPE4]]} +// CHECK: !{{[0-9]+}} = !{i32 [[TYPE5]]} diff --git a/tests/rustdoc/auxiliary/issue-113982-doc_auto_cfg-reexport-foreign.rs b/tests/rustdoc/auxiliary/issue-113982-doc_auto_cfg-reexport-foreign.rs new file mode 100644 index 00000000000..a1a716f5a41 --- /dev/null +++ b/tests/rustdoc/auxiliary/issue-113982-doc_auto_cfg-reexport-foreign.rs @@ -0,0 +1,3 @@ +#![crate_name = "colors"] + +pub struct Color; diff --git a/tests/rustdoc/issue-113982-doc_auto_cfg-reexport-foreign.rs b/tests/rustdoc/issue-113982-doc_auto_cfg-reexport-foreign.rs new file mode 100644 index 00000000000..88b86d15c56 --- /dev/null +++ b/tests/rustdoc/issue-113982-doc_auto_cfg-reexport-foreign.rs @@ -0,0 +1,19 @@ +// aux-build: issue-113982-doc_auto_cfg-reexport-foreign.rs + +#![feature(no_core, doc_auto_cfg)] +#![no_core] +#![crate_name = "foo"] + +extern crate colors; + +// @has 'foo/index.html' '//*[@class="stab portability"]' 'Non-colors' +// @has 'foo/struct.Color.html' '//*[@class="stab portability"]' \ +// 'Available on non-crate feature colors only.' +#[cfg(not(feature = "colors"))] +pub use colors::*; + +// @has 'foo/index.html' '//*[@class="stab portability"]' 'Non-fruits' +// @has 'foo/struct.Red.html' '//*[@class="stab portability"]' \ +// 'Available on non-crate feature fruits only.' +#[cfg(not(feature = "fruits"))] +pub use colors::Color as Red; diff --git a/tests/ui/const_prop/apfloat-f64-roundtrip.rs b/tests/ui/const_prop/apfloat-f64-roundtrip.rs new file mode 100644 index 00000000000..9fb2ac96beb --- /dev/null +++ b/tests/ui/const_prop/apfloat-f64-roundtrip.rs @@ -0,0 +1,9 @@ +// run-pass +// compile-flags: -O -Zmir-opt-level=3 -Cno-prepopulate-passes +// min-llvm-version: 16.0 (requires APFloat fixes in LLVM) + +// Regression test for a broken MIR optimization (issue #113407). +pub fn main() { + let f = f64::from_bits(0x19873cc2) as f32; + assert_eq!(f.to_bits(), 0); +} diff --git a/tests/ui/const_prop/apfloat-remainder-regression.rs b/tests/ui/const_prop/apfloat-remainder-regression.rs new file mode 100644 index 00000000000..08932c333fd --- /dev/null +++ b/tests/ui/const_prop/apfloat-remainder-regression.rs @@ -0,0 +1,15 @@ +// run-pass +// compile-flags: -O -Zmir-opt-level=3 -Cno-prepopulate-passes + +// Regression test for a broken MIR optimization (issue #102403). +pub fn f() -> f64 { + std::hint::black_box(-1.0) % std::hint::black_box(-1.0) +} + +pub fn g() -> f64 { + -1.0 % -1.0 +} + +pub fn main() { + assert_eq!(f().signum(), g().signum()); +} diff --git a/tests/ui/lint/lint-ctypes-113436-1.rs b/tests/ui/lint/lint-ctypes-113436-1.rs new file mode 100644 index 00000000000..1ca59c6868d --- /dev/null +++ b/tests/ui/lint/lint-ctypes-113436-1.rs @@ -0,0 +1,28 @@ +#![deny(improper_ctypes_definitions)] + +#[repr(C)] +pub struct Foo { + a: u8, + b: (), +} + +extern "C" fn foo(x: Foo) -> Foo { + todo!() +} + +struct NotSafe(u32); + +#[repr(C)] +pub struct Bar { + a: u8, + b: (), + c: NotSafe, +} + +extern "C" fn bar(x: Bar) -> Bar { + //~^ ERROR `extern` fn uses type `NotSafe`, which is not FFI-safe + //~^^ ERROR `extern` fn uses type `NotSafe`, which is not FFI-safe + todo!() +} + +fn main() {} diff --git a/tests/ui/lint/lint-ctypes-113436-1.stderr b/tests/ui/lint/lint-ctypes-113436-1.stderr new file mode 100644 index 00000000000..7b63043f057 --- /dev/null +++ b/tests/ui/lint/lint-ctypes-113436-1.stderr @@ -0,0 +1,35 @@ +error: `extern` fn uses type `NotSafe`, which is not FFI-safe + --> $DIR/lint-ctypes-113436-1.rs:22:22 + | +LL | extern "C" fn bar(x: Bar) -> Bar { + | ^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout +note: the type is defined here + --> $DIR/lint-ctypes-113436-1.rs:13:1 + | +LL | struct NotSafe(u32); + | ^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/lint-ctypes-113436-1.rs:1:9 + | +LL | #![deny(improper_ctypes_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `extern` fn uses type `NotSafe`, which is not FFI-safe + --> $DIR/lint-ctypes-113436-1.rs:22:30 + | +LL | extern "C" fn bar(x: Bar) -> Bar { + | ^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout +note: the type is defined here + --> $DIR/lint-ctypes-113436-1.rs:13:1 + | +LL | struct NotSafe(u32); + | ^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lint/lint-ctypes-113436.rs b/tests/ui/lint/lint-ctypes-113436.rs new file mode 100644 index 00000000000..4f733b5bb16 --- /dev/null +++ b/tests/ui/lint/lint-ctypes-113436.rs @@ -0,0 +1,34 @@ +// check-pass +#![deny(improper_ctypes_definitions)] + +#[repr(C)] +pub struct Wrap<T>(T); + +#[repr(transparent)] +pub struct TransparentWrap<T>(T); + +pub extern "C" fn f() -> Wrap<()> { + todo!() +} + +const _: extern "C" fn() -> Wrap<()> = f; + +pub extern "C" fn ff() -> Wrap<Wrap<()>> { + todo!() +} + +const _: extern "C" fn() -> Wrap<Wrap<()>> = ff; + +pub extern "C" fn g() -> TransparentWrap<()> { + todo!() +} + +const _: extern "C" fn() -> TransparentWrap<()> = g; + +pub extern "C" fn gg() -> TransparentWrap<TransparentWrap<()>> { + todo!() +} + +const _: extern "C" fn() -> TransparentWrap<TransparentWrap<()>> = gg; + +fn main() {} diff --git a/tests/ui/numbers-arithmetic/apfloat-modulo-wrong.rs b/tests/ui/numbers-arithmetic/apfloat-modulo-wrong.rs new file mode 100644 index 00000000000..64ff1f8b1d2 --- /dev/null +++ b/tests/ui/numbers-arithmetic/apfloat-modulo-wrong.rs @@ -0,0 +1,15 @@ +// run-pass +// check-run-results +// regression test for issue #109567 + +fn f() -> f64 { + std::hint::black_box(-1.0) % std::hint::black_box(-1.0) +} + +const G: f64 = -1.0 % -1.0; + +pub fn main() { + assert_eq!(-1, G.signum() as i32); + assert_eq!((-0.0_f64).to_bits(), G.to_bits()); + assert_eq!(f().signum(), G.signum()); +} diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 17b69daa4f0..4a2200091b2 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -18,7 +18,7 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#1 */; -extern crate compiler_builtins /* 442 */ as _ /* 0#1 */; +extern crate compiler_builtins /* 443 */ as _ /* 0#1 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */; diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index 76d54ab2f13..077a728a7a6 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#2 */; -extern crate compiler_builtins /* 442 */ as _ /* 0#2 */; +extern crate compiler_builtins /* 443 */ as _ /* 0#2 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */; |
