diff options
Diffstat (limited to 'tests')
342 files changed, 4230 insertions, 1090 deletions
diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 32cce3839dc..762df40a44b 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -576,6 +576,42 @@ //@ revisions: x86_64_wrs_vxworks //@ [x86_64_wrs_vxworks] compile-flags: --target x86_64-wrs-vxworks //@ [x86_64_wrs_vxworks] needs-llvm-components: x86 +//@ revisions: thumbv6m_nuttx_eabi +//@ [thumbv6m_nuttx_eabi] compile-flags: --target thumbv6m-nuttx-eabi +//@ [thumbv6m_nuttx_eabi] needs-llvm-components: arm +//@ revisions: thumbv7m_nuttx_eabi +//@ [thumbv7m_nuttx_eabi] compile-flags: --target thumbv7m-nuttx-eabi +//@ [thumbv7m_nuttx_eabi] needs-llvm-components: arm +//@ revisions: thumbv7em_nuttx_eabi +//@ [thumbv7em_nuttx_eabi] compile-flags: --target thumbv7em-nuttx-eabi +//@ [thumbv7em_nuttx_eabi] needs-llvm-components: arm +//@ revisions: thumbv7em_nuttx_eabihf +//@ [thumbv7em_nuttx_eabihf] compile-flags: --target thumbv7em-nuttx-eabihf +//@ [thumbv7em_nuttx_eabihf] needs-llvm-components: arm +//@ revisions: thumbv8m_base_nuttx_eabi +//@ [thumbv8m_base_nuttx_eabi] compile-flags: --target thumbv8m.base-nuttx-eabi +//@ [thumbv8m_base_nuttx_eabi] needs-llvm-components: arm +//@ revisions: thumbv8m_main_nuttx_eabi +//@ [thumbv8m_main_nuttx_eabi] compile-flags: --target thumbv8m.main-nuttx-eabi +//@ [thumbv8m_main_nuttx_eabi] needs-llvm-components: arm +//@ revisions: thumbv8m_main_nuttx_eabihf +//@ [thumbv8m_main_nuttx_eabihf] compile-flags: --target thumbv8m.main-nuttx-eabihf +//@ [thumbv8m_main_nuttx_eabihf] needs-llvm-components: arm +//@ revisions: riscv32imc_unknown_nuttx_elf +//@ [riscv32imc_unknown_nuttx_elf] compile-flags: --target riscv32imc-unknown-nuttx-elf +//@ [riscv32imc_unknown_nuttx_elf] needs-llvm-components: riscv +//@ revisions: riscv32imac_unknown_nuttx_elf +//@ [riscv32imac_unknown_nuttx_elf] compile-flags: --target riscv32imac-unknown-nuttx-elf +//@ [riscv32imac_unknown_nuttx_elf] needs-llvm-components: riscv +//@ revisions: riscv32imafc_unknown_nuttx_elf +//@ [riscv32imafc_unknown_nuttx_elf] compile-flags: --target riscv32imafc-unknown-nuttx-elf +//@ [riscv32imafc_unknown_nuttx_elf] needs-llvm-components: riscv +//@ revisions: riscv64imac_unknown_nuttx_elf +//@ [riscv64imac_unknown_nuttx_elf] compile-flags: --target riscv64imac-unknown-nuttx-elf +//@ [riscv64imac_unknown_nuttx_elf] needs-llvm-components: riscv +//@ revisions: riscv64gc_unknown_nuttx_elf +//@ [riscv64gc_unknown_nuttx_elf] compile-flags: --target riscv64gc-unknown-nuttx-elf +//@ [riscv64gc_unknown_nuttx_elf] needs-llvm-components: riscv // FIXME: disabled since it requires a custom LLVM until the upstream LLVM adds support for the target (https://github.com/espressif/llvm-project/issues/4) /* revisions: xtensa_esp32_none_elf diff --git a/tests/codegen/generic-debug.rs b/tests/codegen/generic-debug.rs index 3423abe7187..0ad0b074657 100644 --- a/tests/codegen/generic-debug.rs +++ b/tests/codegen/generic-debug.rs @@ -1,4 +1,3 @@ -//@ ignore-windows //@ ignore-wasi wasi codegens the main symbol differently //@ compile-flags: -g -C no-prepopulate-passes diff --git a/tests/codegen/issues/issue-58881.rs b/tests/codegen/issues/issue-58881.rs index 759e3b70baa..ba6285f3972 100644 --- a/tests/codegen/issues/issue-58881.rs +++ b/tests/codegen/issues/issue-58881.rs @@ -1,7 +1,6 @@ //@ compile-flags: -C no-prepopulate-passes -Copt-level=0 // //@ only-x86_64 -//@ ignore-windows #![crate_type = "lib"] diff --git a/tests/codegen/mainsubprogram.rs b/tests/codegen/mainsubprogram.rs index 12b24c90229..ce3fe3c8608 100644 --- a/tests/codegen/mainsubprogram.rs +++ b/tests/codegen/mainsubprogram.rs @@ -1,7 +1,6 @@ // This test depends on a patch that was committed to upstream LLVM // before 4.0, formerly backported to the Rust LLVM fork. -//@ ignore-windows //@ ignore-apple //@ ignore-wasi diff --git a/tests/codegen/mainsubprogramstart.rs b/tests/codegen/mainsubprogramstart.rs index 20741791db5..0bcb311644d 100644 --- a/tests/codegen/mainsubprogramstart.rs +++ b/tests/codegen/mainsubprogramstart.rs @@ -1,4 +1,3 @@ -//@ ignore-windows //@ ignore-apple //@ ignore-wasi wasi codegens the main symbol differently diff --git a/tests/codegen/nounwind.rs b/tests/codegen/nounwind.rs index 464bc2535c2..c910644458a 100644 --- a/tests/codegen/nounwind.rs +++ b/tests/codegen/nounwind.rs @@ -1,6 +1,5 @@ //@ aux-build:nounwind.rs //@ compile-flags: -C no-prepopulate-passes -C panic=abort -C metadata=a -//@ ignore-windows //@ ignore-android #![crate_type = "lib"] diff --git a/tests/crashes/119299.rs b/tests/crashes/119299.rs deleted file mode 100644 index c8c10546d94..00000000000 --- a/tests/crashes/119299.rs +++ /dev/null @@ -1,25 +0,0 @@ -//@ known-bug: #119299 -#![feature(adt_const_params)] -#![allow(incomplete_features)] - -use std::marker::ConstParamTy; - -#[derive(Eq, PartialEq)] -struct ConstStrU(*const u8, usize); - -impl ConstParamTy for &'static ConstStrU {} - -impl ConstStrU { - const fn from_bytes(bytes: &'static [u8]) -> Self { - Self(bytes.as_ptr(), bytes.len()) - } -} - -const fn chars_s<const S: &'static ConstStrU>() -> [char; 3] { - ['a','b','c'] -} - -fn main() { - const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc"); - chars_s::<A>(); -} diff --git a/tests/crashes/127009.rs b/tests/crashes/127009.rs deleted file mode 100644 index 74ca14393e4..00000000000 --- a/tests/crashes/127009.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ known-bug: #127009 - -#![feature(non_lifetime_binders)] - -fn b() -where - for<const C: usize> [(); C]: Copy, -{ -} - -fn main() {} diff --git a/tests/crashes/127351.rs b/tests/crashes/127351.rs new file mode 100644 index 00000000000..e3f41594885 --- /dev/null +++ b/tests/crashes/127351.rs @@ -0,0 +1,17 @@ +//@ known-bug: #127351 +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +struct Outer0<'a, T>(ExplicitTypeOutlives<'a, T>); +type ExplicitTypeOutlives<'a, T: 'a> = (&'a (), T); + +pub struct Warns { + _significant_drop: ExplicitTypeOutlives, + field: String, +} + +pub fn test(w: Warns) { + _ = || drop(w.field); +} + +fn main() {} diff --git a/tests/crashes/127353.rs b/tests/crashes/127353.rs new file mode 100644 index 00000000000..9bcb90b5c57 --- /dev/null +++ b/tests/crashes/127353.rs @@ -0,0 +1,18 @@ +//@ known-bug: #127353 +#![feature(type_alias_impl_trait)] +trait Trait<T> {} +type Alias<'a, U> = impl Trait<U>; + +fn f<'a>() -> Alias<'a, ()> {} + +pub enum UninhabitedVariants { + Tuple(Alias), +} + +struct A; + +fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything(x: UninhabitedVariants) -> A { + match x {} +} + +fn main() {} diff --git a/tests/crashes/127628.rs b/tests/crashes/127628.rs new file mode 100644 index 00000000000..f11ab3f7e8d --- /dev/null +++ b/tests/crashes/127628.rs @@ -0,0 +1,14 @@ +//@ known-bug: #127628 +//@ compile-flags: -Zpolonius=next + +use std::io::{self, Read}; + +pub struct Container<'a> { + reader: &'a mut dyn Read, +} + +impl<'a> Container { + pub fn wrap<'s>(reader: &'s mut dyn io::Read) -> Container<'s> { + Container { reader: reader } + } +} diff --git a/tests/crashes/127643.rs b/tests/crashes/127643.rs new file mode 100644 index 00000000000..a4db9397bde --- /dev/null +++ b/tests/crashes/127643.rs @@ -0,0 +1,18 @@ +//@ known-bug: #127643 + +#![feature(associated_const_equality)] + +fn user() -> impl Owner<dyn Sized, C = 0> {} + +trait Owner<K> { + const C: K; +} +impl<K: ConstDefault> Owner<K> for () { + const C: K = K::DEFAULT; +} + +trait ConstDefault { + const DEFAULT: Self; +} + +fn main() {} diff --git a/tests/crashes/127676.rs b/tests/crashes/127676.rs new file mode 100644 index 00000000000..81149c2ef84 --- /dev/null +++ b/tests/crashes/127676.rs @@ -0,0 +1,8 @@ +//@ known-bug: #127676 +//@ edition:2018 + +#![feature(dyn_star,const_async_blocks)] + +static S: dyn* Send + Sync = async { 42 }; + +pub fn main() {} diff --git a/tests/crashes/127737.rs b/tests/crashes/127737.rs new file mode 100644 index 00000000000..2ee8c769858 --- /dev/null +++ b/tests/crashes/127737.rs @@ -0,0 +1,21 @@ +//@ known-bug: #127737 +//@ compile-flags: -Zmir-opt-level=5 --crate-type lib + +pub trait TestTrait { + type MyType; + fn func() -> Option<Self> + where + Self: Sized; +} + +impl<T> dyn TestTrait<MyType = T> +where + Self: Sized, +{ + pub fn other_func() -> Option<Self> { + match Self::func() { + Some(me) => Some(me), + None => None, + } + } +} diff --git a/tests/crashes/127742.rs b/tests/crashes/127742.rs new file mode 100644 index 00000000000..24add454135 --- /dev/null +++ b/tests/crashes/127742.rs @@ -0,0 +1,11 @@ +//@ known-bug: #127742 +struct Vtable(dyn Cap); // missing lifetime + +trait Cap<'a> {} + +union Transmute { + t: u64, // ICEs with u64, u128, or usize. Correctly errors with u32. + u: &'static Vtable, +} + +const G: &'static Vtable = unsafe { Transmute { t: 1 }.u }; diff --git a/tests/crashes/127880.rs b/tests/crashes/127880.rs new file mode 100644 index 00000000000..6c625eac691 --- /dev/null +++ b/tests/crashes/127880.rs @@ -0,0 +1,5 @@ +//@ known-bug: #127880 +//@ compile-flags: -Cinstrument-coverage + +#[coverage] +fn main() {} diff --git a/tests/crashes/127916.rs b/tests/crashes/127916.rs new file mode 100644 index 00000000000..295c88df857 --- /dev/null +++ b/tests/crashes/127916.rs @@ -0,0 +1,16 @@ +//@ known-bug: #127916 + +trait Trait { + fn foo(&self) -> u32 { 0 } +} + +struct F; +struct S; + +mod to_reuse { + pub fn foo(&self) -> u32 {} +} + +impl Trait S { + reuse to_reuse::foo { self } +} diff --git a/tests/crashes/127972.rs b/tests/crashes/127972.rs new file mode 100644 index 00000000000..d0764f875db --- /dev/null +++ b/tests/crashes/127972.rs @@ -0,0 +1,6 @@ +//@ known-bug: #127962 +#![feature(generic_const_exprs)] + +fn zero_init<const usize: usize>() -> Substs1<{ (N) }> { + Substs1([0; { (usize) }]) +} diff --git a/tests/crashes/128016.rs b/tests/crashes/128016.rs new file mode 100644 index 00000000000..d23721ae14e --- /dev/null +++ b/tests/crashes/128016.rs @@ -0,0 +1,10 @@ +//@ known-bug: #128016 +macro_rules! len { + () => { + target + }; +} + +fn main() { + let val: [str; len!()] = []; +} diff --git a/tests/mir-opt/const_prop/invalid_constant.rs b/tests/mir-opt/const_prop/invalid_constant.rs index 91ee36ae2c5..b59103792bf 100644 --- a/tests/mir-opt/const_prop/invalid_constant.rs +++ b/tests/mir-opt/const_prop/invalid_constant.rs @@ -3,7 +3,7 @@ //@ compile-flags: -Zmir-enable-passes=+RemoveZsts // Verify that we can pretty print invalid constants. -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] #[derive(Copy, Clone)] diff --git a/tests/mir-opt/dataflow-const-prop/aggregate_copy.foo.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/aggregate_copy.foo.DataflowConstProp.diff index 1aeaaff21dc..3b739a25cb8 100644 --- a/tests/mir-opt/dataflow-const-prop/aggregate_copy.foo.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/aggregate_copy.foo.DataflowConstProp.diff @@ -57,9 +57,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 05 00 00 00 03 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/aggregate_copy.rs b/tests/mir-opt/dataflow-const-prop/aggregate_copy.rs index aca5f047222..9cd485813bc 100644 --- a/tests/mir-opt/dataflow-const-prop/aggregate_copy.rs +++ b/tests/mir-opt/dataflow-const-prop/aggregate_copy.rs @@ -1,6 +1,7 @@ //! Verify that we manage to propagate the value of aggregate `a` even without directly mentioning //! the contained scalars. //@ test-mir-pass: DataflowConstProp +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes const Foo: (u32, u32) = (5, 3); diff --git a/tests/mir-opt/issue_99325.rs b/tests/mir-opt/issue_99325.rs index 2638b69e2ee..4cee4f20b31 100644 --- a/tests/mir-opt/issue_99325.rs +++ b/tests/mir-opt/issue_99325.rs @@ -1,7 +1,7 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_BIT_WIDTH -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] { diff --git a/tests/run-make/c-static-dylib/Makefile b/tests/run-make/c-static-dylib/Makefile deleted file mode 100644 index 05da1743c83..00000000000 --- a/tests/run-make/c-static-dylib/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# This test checks that static Rust linking with C does not encounter any errors, with dynamic dependencies given preference over static. -# See https://github.com/rust-lang/rust/issues/10434 - -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,cfoo) - $(RUSTC) foo.rs -C prefer-dynamic - $(RUSTC) bar.rs - rm $(call NATIVE_STATICLIB,cfoo) - $(call RUN,bar) - $(call REMOVE_DYLIBS,foo) - $(call FAIL,bar) diff --git a/tests/run-make/c-static-dylib/rmake.rs b/tests/run-make/c-static-dylib/rmake.rs new file mode 100644 index 00000000000..12ec06c8199 --- /dev/null +++ b/tests/run-make/c-static-dylib/rmake.rs @@ -0,0 +1,20 @@ +// This test checks that static Rust linking with C does not encounter any errors, +// with dynamic dependencies given preference over static. +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{ + build_native_static_lib, dynamic_lib_name, rfs, run, run_fail, rustc, static_lib_name, +}; + +fn main() { + build_native_static_lib("cfoo"); + rustc().input("foo.rs").arg("-Cprefer-dynamic").run(); + rustc().input("bar.rs").run(); + rfs::remove_file(static_lib_name("cfoo")); + run("bar"); + rfs::remove_file(dynamic_lib_name("foo")); + run_fail("bar"); +} diff --git a/tests/run-make/c-static-rlib/Makefile b/tests/run-make/c-static-rlib/Makefile deleted file mode 100644 index 298e432cdb8..00000000000 --- a/tests/run-make/c-static-rlib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# This test checks that static Rust linking with C does not encounter any errors, with static dependencies given preference over dynamic. (This is the default behaviour.) -# See https://github.com/rust-lang/rust/issues/10434 - -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,cfoo) - $(RUSTC) foo.rs - $(RUSTC) bar.rs - $(call REMOVE_RLIBS,foo) - rm $(call NATIVE_STATICLIB,cfoo) - $(call RUN,bar) diff --git a/tests/run-make/c-static-rlib/rmake.rs b/tests/run-make/c-static-rlib/rmake.rs new file mode 100644 index 00000000000..447e29a14f6 --- /dev/null +++ b/tests/run-make/c-static-rlib/rmake.rs @@ -0,0 +1,17 @@ +// This test checks that static Rust linking with C does not encounter any errors, +// with static dependencies given preference over dynamic. (This is the default behaviour.) +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, rfs, run, rust_lib_name, rustc, static_lib_name}; + +fn main() { + build_native_static_lib("cfoo"); + rustc().input("foo.rs").run(); + rustc().input("bar.rs").run(); + rfs::remove_file(rust_lib_name("foo")); + rfs::remove_file(static_lib_name("cfoo")); + run("bar"); +} diff --git a/tests/run-make/c-unwind-abi-catch-panic/Makefile b/tests/run-make/c-unwind-abi-catch-panic/Makefile deleted file mode 100644 index 0a38d838e32..00000000000 --- a/tests/run-make/c-unwind-abi-catch-panic/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# Exercise unwinding a panic. This catches a panic across an FFI boundary and downcasts it into an integer. The Rust code that panics is in the same directory. -# See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb - -# ignore-cross-compile -# needs-unwind -include ../tools.mk - -all: $(call NATIVE_STATICLIB,add) - $(RUSTC) main.rs - $(call RUN,main) || exit 1 diff --git a/tests/run-make/c-unwind-abi-catch-panic/rmake.rs b/tests/run-make/c-unwind-abi-catch-panic/rmake.rs new file mode 100644 index 00000000000..a99dbd18ec6 --- /dev/null +++ b/tests/run-make/c-unwind-abi-catch-panic/rmake.rs @@ -0,0 +1,18 @@ +// A test for calling `C-unwind` functions across foreign function boundaries (FFI). +// This test triggers a panic when calling a foreign function that calls *back* into Rust. +// This catches a panic across an FFI boundary and downcasts it into an integer. +// The Rust code that panics is in the same directory, unlike `c-unwind-abi-catch-lib-panic`. +// See https://github.com/rust-lang/rust/pull/76570 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ needs-unwind +// Reason: this test exercises panic unwinding + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("add"); + rustc().input("main.rs").run(); + run("main"); +} diff --git a/tests/run-make/compiler-lookup-paths-2/Makefile b/tests/run-make/compiler-lookup-paths-2/Makefile deleted file mode 100644 index ecc0577384a..00000000000 --- a/tests/run-make/compiler-lookup-paths-2/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# This test checks that extern crate declarations in Cargo without a corresponding declaration in the manifest of a dependency are NOT allowed. -# See https://github.com/rust-lang/rust/pull/21113 - -include ../tools.mk - -all: - mkdir -p $(TMPDIR)/a $(TMPDIR)/b - $(RUSTC) a.rs && mv $(TMPDIR)/liba.rlib $(TMPDIR)/a - $(RUSTC) b.rs -L $(TMPDIR)/a && mv $(TMPDIR)/libb.rlib $(TMPDIR)/b - $(RUSTC) c.rs -L crate=$(TMPDIR)/b -L dependency=$(TMPDIR)/a \ - && exit 1 || exit 0 diff --git a/tests/run-make/compiler-lookup-paths-2/rmake.rs b/tests/run-make/compiler-lookup-paths-2/rmake.rs new file mode 100644 index 00000000000..99efb157b53 --- /dev/null +++ b/tests/run-make/compiler-lookup-paths-2/rmake.rs @@ -0,0 +1,20 @@ +// This test checks that extern crate declarations in Cargo without a corresponding declaration +// in the manifest of a dependency are NOT allowed. The last rustc call does it anyways, which +// should result in a compilation failure. +// See https://github.com/rust-lang/rust/pull/21113 + +use run_make_support::{path, rfs, rust_lib_name, rustc}; + +fn main() { + rfs::create_dir("a"); + rfs::create_dir("b"); + rustc().input("a.rs").run(); + rfs::rename(rust_lib_name("a"), path("a").join(rust_lib_name("a"))); + rustc().input("b.rs").library_search_path("a").run(); + rfs::rename(rust_lib_name("b"), path("b").join(rust_lib_name("b"))); + rustc() + .input("c.rs") + .library_search_path("crate=b") + .library_search_path("dependency=a") + .run_fail(); +} diff --git a/tests/run-make/crate-hash-rustc-version/Makefile b/tests/run-make/crate-hash-rustc-version/Makefile deleted file mode 100644 index 6bf504bf01b..00000000000 --- a/tests/run-make/crate-hash-rustc-version/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Ensure that crates compiled with different rustc versions cannot -# be dynamically linked. - -FLAGS := -Cprefer-dynamic -Csymbol-mangling-version=v0 -UNAME := $(shell uname) -ifeq ($(UNAME),Linux) - EXT=".so" - NM_CMD := nm -D -endif -ifeq ($(UNAME),Darwin) - EXT=".dylib" - NM_CMD := nm -endif - -ifndef NM_CMD -all: - exit 0 -else -all: - # a.rs is a dylib - $(RUSTC) a.rs --crate-type=dylib $(FLAGS) - # Write symbols to disk. - $(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsbefore - # b.rs is a binary - $(RUSTC) b.rs --extern a=$(TMPDIR)/liba$(EXT) --crate-type=bin -Crpath $(FLAGS) - $(call RUN,b) - # Now re-compile a.rs with another rustc version - RUSTC_FORCE_RUSTC_VERSION=deadfeed $(RUSTC) a.rs --crate-type=dylib $(FLAGS) - # After compiling with a different rustc version, write symbols to disk again. - $(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsafter - # As a sanity check, test if the symbols changed: - # If the symbols are identical, there's been an error. - if diff $(TMPDIR)/symbolsbefore $(TMPDIR)/symbolsafter; then exit 1; fi - $(call FAIL,b) -endif diff --git a/tests/run-make/crate-hash-rustc-version/rmake.rs b/tests/run-make/crate-hash-rustc-version/rmake.rs new file mode 100644 index 00000000000..97b3dd3931e --- /dev/null +++ b/tests/run-make/crate-hash-rustc-version/rmake.rs @@ -0,0 +1,57 @@ +// Ensure that crates compiled with different rustc versions cannot +// be dynamically linked. + +//@ ignore-cross-compile +//@ only-unix + +use run_make_support::llvm; +use run_make_support::{diff, dynamic_lib_name, is_darwin, run, run_fail, rustc}; + +fn llvm_readobj() -> llvm::LlvmReadobj { + let mut cmd = llvm::llvm_readobj(); + if is_darwin() { + cmd.symbols(); + } else { + cmd.dynamic_table(); + } + cmd +} + +fn main() { + let flags = ["-Cprefer-dynamic", "-Csymbol-mangling-version=v0"]; + + // a.rs is compiled to a dylib + rustc().input("a.rs").crate_type("dylib").args(&flags).run(); + + // Store symbols + let symbols_before = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8(); + + // b.rs is compiled to a binary + rustc() + .input("b.rs") + .extern_("a", dynamic_lib_name("a")) + .crate_type("bin") + .arg("-Crpath") + .args(&flags) + .run(); + run("b"); + + // Now re-compile a.rs with another rustc version + rustc() + .env("RUSTC_FORCE_RUSTC_VERSION", "deadfeed") + .input("a.rs") + .crate_type("dylib") + .args(&flags) + .run(); + + // After compiling with a different rustc version, store symbols again. + let symbols_after = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8(); + + // As a sanity check, test if the symbols changed: + // If the symbols are identical, there's been an error. + diff() + .expected_text("symbols_before", symbols_before) + .actual_text("symbols_after", symbols_after) + .run_fail(); + run_fail("b"); +} diff --git a/tests/run-make/extern-fn-generic/Makefile b/tests/run-make/extern-fn-generic/Makefile deleted file mode 100644 index 7dceea6cb88..00000000000 --- a/tests/run-make/extern-fn-generic/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,test) - $(RUSTC) testcrate.rs - $(RUSTC) test.rs - $(call RUN,test) || exit 1 diff --git a/tests/run-make/extern-fn-generic/rmake.rs b/tests/run-make/extern-fn-generic/rmake.rs new file mode 100644 index 00000000000..05de839a1b0 --- /dev/null +++ b/tests/run-make/extern-fn-generic/rmake.rs @@ -0,0 +1,16 @@ +// Generic types in foreign-function interfaces were introduced in #15831 - this +// test simply runs a Rust program containing generics that is also reliant on +// a C library, and checks that compilation and execution are successful. +// See https://github.com/rust-lang/rust/pull/15831 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("test"); + rustc().input("testcrate.rs").run(); + rustc().input("test.rs").run(); + run("test"); +} diff --git a/tests/run-make/extern-fn-with-union/Makefile b/tests/run-make/extern-fn-with-union/Makefile deleted file mode 100644 index e6c8c993679..00000000000 --- a/tests/run-make/extern-fn-with-union/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,ctest) - $(RUSTC) testcrate.rs - $(RUSTC) test.rs - $(call RUN,test) || exit 1 diff --git a/tests/run-make/extern-fn-with-union/rmake.rs b/tests/run-make/extern-fn-with-union/rmake.rs new file mode 100644 index 00000000000..200602eabeb --- /dev/null +++ b/tests/run-make/extern-fn-with-union/rmake.rs @@ -0,0 +1,16 @@ +// If an external function from foreign-function interface was called upon, +// its attributes would only be passed to LLVM if and only if it was called in the same crate. +// This caused passing around unions to be incorrect. +// See https://github.com/rust-lang/rust/pull/14191 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("ctest"); + rustc().input("testcrate.rs").run(); + rustc().input("test.rs").run(); + run("test"); +} diff --git a/tests/run-make/issue-14698/foo.rs b/tests/run-make/invalid-tmpdir-env-var/foo.rs index f328e4d9d04..f328e4d9d04 100644 --- a/tests/run-make/issue-14698/foo.rs +++ b/tests/run-make/invalid-tmpdir-env-var/foo.rs diff --git a/tests/run-make/invalid-tmpdir-env-var/rmake.rs b/tests/run-make/invalid-tmpdir-env-var/rmake.rs new file mode 100644 index 00000000000..db44debb319 --- /dev/null +++ b/tests/run-make/invalid-tmpdir-env-var/rmake.rs @@ -0,0 +1,20 @@ +// When the TMP (on Windows) or TMPDIR (on Unix) variable is set to an invalid +// or non-existing directory, this used to cause an internal compiler error (ICE). After the +// addition of proper error handling in #28430, this test checks that the expected message is +// printed. +// See https://github.com/rust-lang/rust/issues/14698 + +use run_make_support::{is_windows, rustc}; + +// NOTE: This is not a UI test despite its simplicity, as the error message contains a path +// with some variability that is difficult to normalize + +fn main() { + let mut rustc = rustc(); + if is_windows() { + rustc.env("TMP", "fake"); + } else { + rustc.env("TMPDIR", "fake"); + } + rustc.input("foo.rs").run_fail().assert_stderr_contains("couldn't create a temp dir"); +} diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile deleted file mode 100644 index d614e3e1055..00000000000 --- a/tests/run-make/issue-107094/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# needs-git-hash - -include ../tools.mk - -all: - $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" - $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" diff --git a/tests/run-make/issue-14698/Makefile b/tests/run-make/issue-14698/Makefile deleted file mode 100644 index a1cfb5abab5..00000000000 --- a/tests/run-make/issue-14698/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include ../tools.mk - -all: - TMP=fake TMPDIR=fake $(RUSTC) foo.rs 2>&1 | $(CGREP) "couldn't create a temp dir:" diff --git a/tests/run-make/issue-15460/Makefile b/tests/run-make/issue-15460/Makefile deleted file mode 100644 index a36a085fa6f..00000000000 --- a/tests/run-make/issue-15460/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,foo) - $(RUSTC) foo.rs -C extra-filename=-383hf8 -C prefer-dynamic - $(RUSTC) bar.rs - $(call RUN,bar) diff --git a/tests/run-make/issue-28595/Makefile b/tests/run-make/issue-28595/Makefile deleted file mode 100644 index 258f9788aaf..00000000000 --- a/tests/run-make/issue-28595/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,a) $(call NATIVE_STATICLIB,b) - $(RUSTC) a.rs - $(RUSTC) b.rs - $(call RUN,b) diff --git a/tests/run-make/issue-33329/Makefile b/tests/run-make/issue-33329/Makefile deleted file mode 100644 index 9c149440d8e..00000000000 --- a/tests/run-make/issue-33329/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) --target x86_64_unknown-linux-musl main.rs 2>&1 | $(CGREP) \ - "error: Error loading target specification: Could not find specification for target" diff --git a/tests/run-make/issue-33329/main.rs b/tests/run-make/issue-33329/main.rs deleted file mode 100644 index f328e4d9d04..00000000000 --- a/tests/run-make/issue-33329/main.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/tests/run-make/issue-97463-abi-param-passing/Makefile b/tests/run-make/issue-97463-abi-param-passing/Makefile deleted file mode 100644 index 7ce7aaeec57..00000000000 --- a/tests/run-make/issue-97463-abi-param-passing/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# ignore-msvc - -# The issue exercised by this test, rust-lang/rust#97463, explicitly needs `-O` -# flags (like `-O3`) to reproduce. Thus, we call $(CC) instead of nicer -# alternatives provided by tools.mk like using `COMPILE_OBJ` or using a -# `NATIVE_STATICLIB` dependency. - -all: - $(CC) -c -O3 -o $(TMPDIR)/bad.o bad.c - $(AR) rcs $(TMPDIR)/libbad.a $(TMPDIR)/bad.o - $(RUSTC) param_passing.rs -L$(TMPDIR) -lbad -C opt-level=3 - $(call RUN,param_passing) diff --git a/tests/run-make/link-framework/Makefile b/tests/run-make/link-framework/Makefile deleted file mode 100644 index 96d832ad4a8..00000000000 --- a/tests/run-make/link-framework/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# only-apple -# -# Check that linking to a framework actually makes it to the linker. - -include ../tools.mk - -all: - $(RUSTC) dep-link-framework.rs - $(RUSTC) dep-link-weak-framework.rs - - $(RUSTC) empty.rs - otool -L $(TMPDIR)/no-link | $(CGREP) -v CoreFoundation - - $(RUSTC) link-framework.rs - otool -L $(TMPDIR)/link-framework | $(CGREP) CoreFoundation | $(CGREP) -v weak - - $(RUSTC) link-weak-framework.rs - otool -L $(TMPDIR)/link-weak-framework | $(CGREP) CoreFoundation | $(CGREP) weak - -# When linking the framework both normally, and weakly, the weak linking takes preference - - $(RUSTC) link-both.rs - otool -L $(TMPDIR)/link-both | $(CGREP) CoreFoundation | $(CGREP) weak diff --git a/tests/run-make/link-framework/rmake.rs b/tests/run-make/link-framework/rmake.rs new file mode 100644 index 00000000000..e5df93b181a --- /dev/null +++ b/tests/run-make/link-framework/rmake.rs @@ -0,0 +1,38 @@ +// Check that linking to a framework actually makes it to the linker. + +//@ only-apple + +use run_make_support::{cmd, rustc}; + +fn main() { + rustc().input("dep-link-framework.rs").run(); + rustc().input("dep-link-weak-framework.rs").run(); + + rustc().input("empty.rs").run(); + cmd("otool").arg("-L").arg("no-link").run_fail().assert_stdout_not_contains("CoreFoundation"); + + rustc().input("link-framework.rs").run(); + cmd("otool") + .arg("-L") + .arg("link-framework") + .run() + .assert_stdout_contains("CoreFoundation") + .assert_stdout_not_contains("weak"); + + rustc().input("link-weak-framework.rs").run(); + cmd("otool") + .arg("-L") + .arg("link-weak-framework") + .run() + .assert_stdout_contains("CoreFoundation") + .assert_stdout_contains("weak"); + + // When linking the framework both normally, and weakly, the weak linking takes preference. + rustc().input("link-both.rs").run(); + cmd("otool") + .arg("-L") + .arg("link-both") + .run() + .assert_stdout_contains("CoreFoundation") + .assert_stdout_contains("weak"); +} diff --git a/tests/run-make/issue-15460/bar.rs b/tests/run-make/link-native-static-lib-to-dylib/bar.rs index e66aeb6bd39..e66aeb6bd39 100644 --- a/tests/run-make/issue-15460/bar.rs +++ b/tests/run-make/link-native-static-lib-to-dylib/bar.rs diff --git a/tests/run-make/issue-15460/foo.c b/tests/run-make/link-native-static-lib-to-dylib/foo.c index fdf595b574e..fdf595b574e 100644 --- a/tests/run-make/issue-15460/foo.c +++ b/tests/run-make/link-native-static-lib-to-dylib/foo.c diff --git a/tests/run-make/issue-15460/foo.rs b/tests/run-make/link-native-static-lib-to-dylib/foo.rs index b4eaa0b31c5..b4eaa0b31c5 100644 --- a/tests/run-make/issue-15460/foo.rs +++ b/tests/run-make/link-native-static-lib-to-dylib/foo.rs diff --git a/tests/run-make/link-native-static-lib-to-dylib/rmake.rs b/tests/run-make/link-native-static-lib-to-dylib/rmake.rs new file mode 100644 index 00000000000..0746c396314 --- /dev/null +++ b/tests/run-make/link-native-static-lib-to-dylib/rmake.rs @@ -0,0 +1,14 @@ +// Regression test for <https://github.com/rust-lang/rust/issues/15460>. + +//@ ignore-cross-compile + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("foo"); + + rustc().input("foo.rs").extra_filename("-383hf8").arg("-Cprefer-dynamic").run(); + rustc().input("bar.rs").run(); + + run("bar"); +} diff --git a/tests/run-make/linkage-attr-on-static/Makefile b/tests/run-make/linkage-attr-on-static/Makefile deleted file mode 100644 index ef50a7ef9f1..00000000000 --- a/tests/run-make/linkage-attr-on-static/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,foo) - $(RUSTC) bar.rs - $(call RUN,bar) || exit 1 diff --git a/tests/run-make/linkage-attr-on-static/rmake.rs b/tests/run-make/linkage-attr-on-static/rmake.rs new file mode 100644 index 00000000000..cd85542e958 --- /dev/null +++ b/tests/run-make/linkage-attr-on-static/rmake.rs @@ -0,0 +1,15 @@ +// #[linkage] is a useful attribute which can be applied to statics to allow +// external linkage, something which was not possible before #18890. This test +// checks that using this new feature results in successful compilation and execution. +// See https://github.com/rust-lang/rust/pull/18890 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("foo"); + rustc().input("bar.rs").run(); + run("bar"); +} diff --git a/tests/run-make/lto-linkage-used-attr/Makefile b/tests/run-make/lto-linkage-used-attr/Makefile deleted file mode 100644 index fed41a00f84..00000000000 --- a/tests/run-make/lto-linkage-used-attr/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include ../tools.mk - -# Verify that the impl_* symbols are preserved. #108030 -# only-x86_64-unknown-linux-gnu - -all: - $(RUSTC) -Cdebuginfo=0 -Copt-level=3 lib.rs - $(RUSTC) -Clto=fat -Cdebuginfo=0 -Copt-level=3 main.rs diff --git a/tests/run-make/lto-linkage-used-attr/rmake.rs b/tests/run-make/lto-linkage-used-attr/rmake.rs new file mode 100644 index 00000000000..12463b79a75 --- /dev/null +++ b/tests/run-make/lto-linkage-used-attr/rmake.rs @@ -0,0 +1,15 @@ +// Link time optimizations (LTO) used to snip away some important symbols +// when setting optimization level to 3 or higher. +// This is an LLVM, not a rustc bug, fixed here: https://reviews.llvm.org/D145293 +// This test checks that the impl_* symbols are preserved as they should. +// See https://github.com/rust-lang/rust/issues/108030 + +//@ only-x86_64-unknown-linux-gnu +// Reason: some of the inline assembly directives are architecture-specific. + +use run_make_support::rustc; + +fn main() { + rustc().arg("-Cdebuginfo=0").opt_level("3").input("lib.rs").run(); + rustc().arg("-Clto=fat").arg("-Cdebuginfo=0").opt_level("3").input("main.rs").run(); +} diff --git a/tests/run-make/lto-no-link-whole-rlib/Makefile b/tests/run-make/lto-no-link-whole-rlib/Makefile deleted file mode 100644 index 3e82322e72d..00000000000 --- a/tests/run-make/lto-no-link-whole-rlib/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar) - $(RUSTC) lib1.rs - $(RUSTC) lib2.rs - $(RUSTC) main.rs -Clto - $(call RUN,main) - diff --git a/tests/run-make/lto-no-link-whole-rlib/rmake.rs b/tests/run-make/lto-no-link-whole-rlib/rmake.rs new file mode 100644 index 00000000000..8cd653d5f08 --- /dev/null +++ b/tests/run-make/lto-no-link-whole-rlib/rmake.rs @@ -0,0 +1,18 @@ +// In order to improve linking performance, entire rlibs will only be linked if a dylib is being +// created. Otherwise, an executable will only link one rlib as usual. Linking will fail in this +// test should this optimization be reverted. +// See https://github.com/rust-lang/rust/pull/31460 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("foo"); + build_native_static_lib("bar"); + rustc().input("lib1.rs").run(); + rustc().input("lib2.rs").run(); + rustc().input("main.rs").arg("-Clto").run(); + run("main"); +} diff --git a/tests/run-make/issue-28595/a.c b/tests/run-make/native-lib-load-order/a.c index 7bfd83cca21..7bfd83cca21 100644 --- a/tests/run-make/issue-28595/a.c +++ b/tests/run-make/native-lib-load-order/a.c diff --git a/tests/run-make/issue-28595/a.rs b/tests/run-make/native-lib-load-order/a.rs index 07863cf64d6..07863cf64d6 100644 --- a/tests/run-make/issue-28595/a.rs +++ b/tests/run-make/native-lib-load-order/a.rs diff --git a/tests/run-make/issue-28595/b.c b/tests/run-make/native-lib-load-order/b.c index 6aecb5f9e04..6aecb5f9e04 100644 --- a/tests/run-make/issue-28595/b.c +++ b/tests/run-make/native-lib-load-order/b.c diff --git a/tests/run-make/issue-28595/b.rs b/tests/run-make/native-lib-load-order/b.rs index 1f389859fad..1f389859fad 100644 --- a/tests/run-make/issue-28595/b.rs +++ b/tests/run-make/native-lib-load-order/b.rs diff --git a/tests/run-make/native-lib-load-order/rmake.rs b/tests/run-make/native-lib-load-order/rmake.rs new file mode 100644 index 00000000000..ffe20a64168 --- /dev/null +++ b/tests/run-make/native-lib-load-order/rmake.rs @@ -0,0 +1,16 @@ +// An old compiler bug from 2015 caused native libraries to be loaded in the +// wrong order, causing `b` to be loaded before `a` in this test. If the compilation +// is successful, the libraries were loaded in the correct order. + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("a"); + build_native_static_lib("b"); + rustc().input("a.rs").run(); + rustc().input("b.rs").run(); + run("b"); +} diff --git a/tests/run-make/no-duplicate-libs/Makefile b/tests/run-make/no-duplicate-libs/Makefile deleted file mode 100644 index 4be8c026294..00000000000 --- a/tests/run-make/no-duplicate-libs/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -ifdef IS_MSVC -# FIXME(#27979) -all: -else -all: $(call STATICLIB,foo) $(call STATICLIB,bar) - $(RUSTC) main.rs - $(call RUN,main) -endif diff --git a/tests/run-make/no-duplicate-libs/rmake.rs b/tests/run-make/no-duplicate-libs/rmake.rs new file mode 100644 index 00000000000..469348e266c --- /dev/null +++ b/tests/run-make/no-duplicate-libs/rmake.rs @@ -0,0 +1,22 @@ +// The rust compiler used to try to detect duplicated libraries in +// the linking order and remove the duplicates... but certain edge cases, +// such as the one presented in `foo` and `bar` in this test, demand precise +// control over the link order, including duplicates. As the anti-duplication +// filter was removed, this test should now successfully see main be compiled +// and executed. +// See https://github.com/rust-lang/rust/pull/12688 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +//@ ignore-msvc +// Reason: native compilation results in an unresolved external symbol + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("foo"); + build_native_static_lib("bar"); + rustc().input("main.rs").run(); + run("main"); +} diff --git a/tests/run-make/pass-non-c-like-enum-to-c/Makefile b/tests/run-make/pass-non-c-like-enum-to-c/Makefile deleted file mode 100644 index bd441d321bf..00000000000 --- a/tests/run-make/pass-non-c-like-enum-to-c/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,test) - $(RUSTC) nonclike.rs -L$(TMPDIR) -ltest - $(call RUN,nonclike) diff --git a/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs b/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs new file mode 100644 index 00000000000..c706e82f4a0 --- /dev/null +++ b/tests/run-make/pass-non-c-like-enum-to-c/rmake.rs @@ -0,0 +1,19 @@ +// Similar to the `return-non-c-like-enum-from-c` test, where +// the C code is the library, and the Rust code compiles +// into the executable. Once again, enum variants should be treated +// like an union of structs, which should prevent segfaults or +// unexpected results. The only difference with the aforementioned +// test is that the structs are passed into C directly through the +// `tt_add` and `t_add` function calls. +// See https://github.com/rust-lang/rust/issues/68190 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("test"); + rustc().input("nonclike.rs").arg("-ltest").run(); + run("nonclike"); +} diff --git a/tests/run-make/pgo-gen-no-imp-symbols/Makefile b/tests/run-make/pgo-gen-no-imp-symbols/Makefile deleted file mode 100644 index d2baa145ba5..00000000000 --- a/tests/run-make/pgo-gen-no-imp-symbols/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../tools.mk - -COMPILE_FLAGS=-O -Ccodegen-units=1 -Cprofile-generate="$(TMPDIR)" -Zno-profiler-runtime - -all: - $(RUSTC) $(COMPILE_FLAGS) --emit=llvm-ir test.rs - # We expect symbols starting with "__llvm_profile_". - $(CGREP) "__llvm_profile_" < $(TMPDIR)/test.ll - # We do NOT expect the "__imp_" version of these symbols. - $(CGREP) -v "__imp___llvm_profile_" < $(TMPDIR)/test.ll # 64 bit - $(CGREP) -v "__imp____llvm_profile_" < $(TMPDIR)/test.ll # 32 bit diff --git a/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs new file mode 100644 index 00000000000..85ade7885ce --- /dev/null +++ b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs @@ -0,0 +1,27 @@ +// LLVM's profiling instrumentation adds a few symbols that are used by the profiler runtime. +// Since these show up as globals in the LLVM IR, the compiler generates dllimport-related +// __imp_ stubs for them. This can lead to linker errors because the instrumentation +// symbols have weak linkage or are in a comdat section, but the __imp_ stubs aren't. +// Since profiler-related symbols were excluded from stub-generation in #59812, this has +// been fixed, and this test checks that the llvm profile symbol appear, but without the +// anomalous __imp_ stubs. +// See https://github.com/rust-lang/rust/pull/59812 + +use run_make_support::{cwd, rfs, rustc}; + +fn main() { + rustc() + .input("test.rs") + .emit("llvm-ir") + .opt() + .codegen_units(1) + .profile_generate(cwd()) + .arg("-Zno-profiler-runtime") + .run(); + let out = rfs::read_to_string("test.ll"); + // We expect symbols starting with "__llvm_profile_". + assert!(out.contains("__llvm_profile_")); + // We do NOT expect the "__imp_" version of these symbols. + assert!(!out.contains("__imp___llvm_profile_")); // 64 bit + assert!(!out.contains("__imp____llvm_profile_")); // 32 bit +} diff --git a/tests/run-make/return-non-c-like-enum-from-c/Makefile b/tests/run-make/return-non-c-like-enum-from-c/Makefile deleted file mode 100644 index bd441d321bf..00000000000 --- a/tests/run-make/return-non-c-like-enum-from-c/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: $(call NATIVE_STATICLIB,test) - $(RUSTC) nonclike.rs -L$(TMPDIR) -ltest - $(call RUN,nonclike) diff --git a/tests/run-make/return-non-c-like-enum-from-c/rmake.rs b/tests/run-make/return-non-c-like-enum-from-c/rmake.rs new file mode 100644 index 00000000000..f24bd6d5fc7 --- /dev/null +++ b/tests/run-make/return-non-c-like-enum-from-c/rmake.rs @@ -0,0 +1,17 @@ +// A reversed version of the `return-non-c-like-enum` test, though +// this time, the C code is the library, and the Rust code compiles +// into the executable. Once again, enum variants should be treated +// like an union of structs, which should prevent segfaults or +// unexpected results. +// See https://github.com/rust-lang/rust/issues/68190 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("test"); + rustc().input("nonclike.rs").arg("-ltest").run(); + run("nonclike"); +} diff --git a/tests/run-make/rlib-format-packed-bundled-libs-3/Makefile b/tests/run-make/rlib-format-packed-bundled-libs-3/Makefile deleted file mode 100644 index 9ba077b1854..00000000000 --- a/tests/run-make/rlib-format-packed-bundled-libs-3/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -include ../tools.mk - -# ignore-cross-compile -# only-linux - -# Make sure -Zpacked_bundled_libs-like behavior activates with +bundle,+whole-archive. - -# We're using the llvm-nm instead of the system nm to ensure it is compatible -# with the LLVM bitcode generated by rustc. -NM = "$(LLVM_BIN_DIR)"/llvm-nm - -all: $(call NATIVE_STATICLIB,native_dep_1) $(call NATIVE_STATICLIB,native_dep_2) $(call NATIVE_STATICLIB,native_dep_3) $(call NATIVE_STATICLIB,native_dep_4) - # test cfg with packed bundle - $(RUSTC) rust_dep_cfg.rs --crate-type=rlib - $(RUSTC) main.rs --extern rust_dep=$(TMPDIR)/librust_dep_cfg.rlib --crate-type=staticlib --cfg should_add - $(AR) t $(TMPDIR)/librust_dep_cfg.rlib | $(CGREP) -e "libnative_dep_1.a" - $(AR) t $(TMPDIR)/librust_dep_cfg.rlib | $(CGREP) -e "libnative_dep_2.a" - $(AR) t $(TMPDIR)/libmain.a | $(CGREP) -e "libnative_dep_1.o" - $(AR) t $(TMPDIR)/libmain.a | $(CGREP) -ev "libnative_dep_2.o" - - - # test bundle with whole_archive - $(RUSTC) rust_dep.rs --crate-type=rlib - $(AR) t $(TMPDIR)/librust_dep.rlib | $(CGREP) -e "native_dep_1" - $(AR) t $(TMPDIR)/librust_dep.rlib | $(CGREP) -e "native_dep_3" - $(AR) t $(TMPDIR)/librust_dep.rlib | $(CGREP) -ev "native_dep_2" - $(AR) t $(TMPDIR)/librust_dep.rlib | $(CGREP) -ev "native_dep_4" - - # Make sure compiler doesn't use files, that it shouldn't know about. - rm $(TMPDIR)/libnative_dep_1.a - rm $(TMPDIR)/libnative_dep_3.a - - $(RUSTC) main.rs --extern rust_dep=$(TMPDIR)/librust_dep.rlib --print link-args > $(TMPDIR)/link_args - cat $(TMPDIR)/link_args | $(CGREP) -ev "native_dep_3" - cat $(TMPDIR)/link_args | $(CGREP) -e "--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4" diff --git a/tests/run-make/rlib-format-packed-bundled-libs-3/rmake.rs b/tests/run-make/rlib-format-packed-bundled-libs-3/rmake.rs new file mode 100644 index 00000000000..d152047600f --- /dev/null +++ b/tests/run-make/rlib-format-packed-bundled-libs-3/rmake.rs @@ -0,0 +1,84 @@ +// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler +// only require a native library and no supplementary object files to compile. +// #105601 made it possible to have this behaviour without an unstable flag by +// passing +bundle in modifiers, and this test checks that this feature successfully +// compiles and includes only the static libraries, with no object files. +// See https://github.com/rust-lang/rust/pull/105601 + +use run_make_support::{ + build_native_static_lib, is_msvc, llvm_ar, regex, rfs, rust_lib_name, rustc, static_lib_name, +}; + +//@ ignore-cross-compile +// Reason: Invalid library format (not ELF) causes compilation failure +// in the final `rustc` call. + +//@ only-linux +// Reason: differences in the native lib compilation process causes differences +// in the --print link-args output + +fn main() { + build_native_static_lib("native_dep_1"); + build_native_static_lib("native_dep_2"); + build_native_static_lib("native_dep_3"); + build_native_static_lib("native_dep_4"); + // Test cfg with packed bundle. + rustc().input("rust_dep_cfg.rs").crate_type("rlib").run(); + rustc() + .input("main.rs") + .extern_("rust_dep", rust_lib_name("rust_dep_cfg")) + .crate_type("staticlib") + .cfg("should_add") + .run(); + // Only static libraries should appear, no object files at all. + llvm_ar() + .arg("t") + .arg(rust_lib_name("rust_dep_cfg")) + .run() + .assert_stdout_contains(static_lib_name("native_dep_1")); + llvm_ar() + .arg("t") + .arg(rust_lib_name("rust_dep_cfg")) + .run() + .assert_stdout_contains(static_lib_name("native_dep_2")); + llvm_ar().arg("t").arg(static_lib_name("main")).run().assert_stdout_contains("native_dep_1.o"); + llvm_ar() + .arg("t") + .arg(static_lib_name("main")) + .run() + .assert_stdout_not_contains("native_dep_2.o"); + + // Test bundle with whole archive. + rustc().input("rust_dep.rs").crate_type("rlib").run(); + // Only deps with `+bundle` should appear. + llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1"); + llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3"); + llvm_ar() + .arg("t") + .arg(rust_lib_name("rust_dep")) + .run() + .assert_stdout_not_contains("native_dep_2"); + llvm_ar() + .arg("t") + .arg(rust_lib_name("rust_dep")) + .run() + .assert_stdout_not_contains("native_dep_4"); + + // The compiler shouldn't use files which it doesn't know about. + rfs::remove_file(static_lib_name("native_dep_1")); + rfs::remove_file(static_lib_name("native_dep_3")); + + let out = rustc() + .input("main.rs") + .extern_("rust_dep", rust_lib_name("rust_dep")) + .print("link-args") + .run() + .assert_stdout_not_contains("native_dep_3") + .stdout_utf8(); + + let re = regex::Regex::new( +"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4" + ).unwrap(); + + assert!(re.is_match(&out)); +} diff --git a/tests/run-make/staticlib-blank-lib/Makefile b/tests/run-make/staticlib-blank-lib/Makefile deleted file mode 100644 index fcbf87758fb..00000000000 --- a/tests/run-make/staticlib-blank-lib/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -include ../tools.mk - -all: - $(AR) crus $(TMPDIR)/libfoo.a foo.rs - $(AR) d $(TMPDIR)/libfoo.a foo.rs - $(RUSTC) foo.rs diff --git a/tests/run-make/staticlib-blank-lib/rmake.rs b/tests/run-make/staticlib-blank-lib/rmake.rs new file mode 100644 index 00000000000..11a85d102aa --- /dev/null +++ b/tests/run-make/staticlib-blank-lib/rmake.rs @@ -0,0 +1,13 @@ +// In this test, the static library foo is made blank, which used to cause +// a compilation error. As the compiler now returns Ok upon encountering a blank +// staticlib as of #12379, this test checks that compilation is successful despite +// the blank staticlib. +// See https://github.com/rust-lang/rust/pull/12379 + +use run_make_support::{llvm_ar, rustc, static_lib_name}; + +fn main() { + llvm_ar().obj_to_ar().output_input(static_lib_name("foo"), "foo.rs").run(); + llvm_ar().arg("d").output_input(static_lib_name("foo"), "foo.rs").run(); + rustc().input("foo.rs").run(); +} diff --git a/tests/run-make/test-benches/Makefile b/tests/run-make/test-benches/Makefile deleted file mode 100644 index 11aed2e4c79..00000000000 --- a/tests/run-make/test-benches/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# ignore-cross-compile -# needs-unwind #[bench] and -Zpanic-abort-tests can't be combined - -all: - # Smoke-test that `#[bench]` isn't entirely broken. - $(RUSTC) --test smokebench.rs -O - $(call RUN,smokebench --bench) - $(call RUN,smokebench --bench noiter) - $(call RUN,smokebench --bench yesiter) - $(call RUN,smokebench) diff --git a/tests/run-make/test-benches/rmake.rs b/tests/run-make/test-benches/rmake.rs new file mode 100644 index 00000000000..1458fb8c990 --- /dev/null +++ b/tests/run-make/test-benches/rmake.rs @@ -0,0 +1,22 @@ +// #[bench] is a Rust feature to run benchmarks on performance-critical +// code, which previously experienced a runtime panic bug in #103794. +// In order to ensure future breakages of this feature are detected, this +// smoke test was created, using the benchmarking feature with various +// runtime flags. +// See https://github.com/rust-lang/rust/issues/103794 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ needs-unwind +// Reason: #[bench] and -Zpanic-abort-tests can't be combined + +use run_make_support::{run, run_with_args, rustc}; + +fn main() { + // Smoke-test that #[bench] isn't entirely broken. + rustc().arg("--test").input("smokebench.rs").opt().run(); + run_with_args("smokebench", &["--bench"]); + run_with_args("smokebench", &["--bench", "noiter"]); + run_with_args("smokebench", &["--bench", "yesiter"]); + run("smokebench"); +} diff --git a/tests/run-make/version-verbose-commit-hash/rmake.rs b/tests/run-make/version-verbose-commit-hash/rmake.rs new file mode 100644 index 00000000000..733c0e2cdb1 --- /dev/null +++ b/tests/run-make/version-verbose-commit-hash/rmake.rs @@ -0,0 +1,20 @@ +// `--version --verbose` should display the git-commit hashes of rustc and rustdoc, but this +// functionality was lost due to #104184. After this feature was returned by #109981, this +// test ensures it will not be broken again. +// See https://github.com/rust-lang/rust/issues/107094 + +//@ needs-git-hash + +use run_make_support::{bare_rustc, bare_rustdoc, regex}; + +fn main() { + let out_rustc = + bare_rustc().arg("--version").arg("--verbose").run().stdout_utf8().to_lowercase(); + let out_rustdoc = + bare_rustdoc().arg("--version").arg("--verbose").run().stdout_utf8().to_lowercase(); + let re = + regex::Regex::new(r#"commit-hash: [0-9a-f]{40}\ncommit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}"#) + .unwrap(); + assert!(re.is_match(&out_rustc)); + assert!(re.is_match(&out_rustdoc)); +} diff --git a/tests/run-make/wasm-panic-small/rmake.rs b/tests/run-make/wasm-panic-small/rmake.rs index 8d0944ed98d..e69fbac9635 100644 --- a/tests/run-make/wasm-panic-small/rmake.rs +++ b/tests/run-make/wasm-panic-small/rmake.rs @@ -13,7 +13,14 @@ fn main() { fn test(cfg: &str) { eprintln!("running cfg {cfg:?}"); - rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run(); + rustc() + .input("foo.rs") + .target("wasm32-wasip1") + .arg("-Clto") + .arg("-Cstrip=debuginfo") + .opt() + .cfg(cfg) + .run(); let bytes = rfs::read("foo.wasm"); println!("{}", bytes.len()); diff --git a/tests/run-make/wasm-stringify-ints-small/rmake.rs b/tests/run-make/wasm-stringify-ints-small/rmake.rs index 93eb38b0987..c0448c59c03 100644 --- a/tests/run-make/wasm-stringify-ints-small/rmake.rs +++ b/tests/run-make/wasm-stringify-ints-small/rmake.rs @@ -4,7 +4,13 @@ use run_make_support::{rfs, rustc}; fn main() { - rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); + rustc() + .input("foo.rs") + .target("wasm32-wasip1") + .arg("-Clto") + .arg("-Cstrip=debuginfo") + .opt() + .run(); let bytes = rfs::read("foo.wasm"); println!("{}", bytes.len()); diff --git a/tests/run-make/issue-97463-abi-param-passing/bad.c b/tests/run-make/zero-extend-abi-param-passing/bad.c index 013314ab20d..013314ab20d 100644 --- a/tests/run-make/issue-97463-abi-param-passing/bad.c +++ b/tests/run-make/zero-extend-abi-param-passing/bad.c diff --git a/tests/run-make/issue-97463-abi-param-passing/param_passing.rs b/tests/run-make/zero-extend-abi-param-passing/param_passing.rs index c11f3cc72bd..c11f3cc72bd 100644 --- a/tests/run-make/issue-97463-abi-param-passing/param_passing.rs +++ b/tests/run-make/zero-extend-abi-param-passing/param_passing.rs diff --git a/tests/run-make/zero-extend-abi-param-passing/rmake.rs b/tests/run-make/zero-extend-abi-param-passing/rmake.rs new file mode 100644 index 00000000000..aed27f7f5ab --- /dev/null +++ b/tests/run-make/zero-extend-abi-param-passing/rmake.rs @@ -0,0 +1,25 @@ +// This test was created in response to an obscure miscompilation bug, only +// visible with the -O3 flag passed to the cc compiler when trying to obtain +// a native static library for the sake of foreign function interface. This +// flag could cause certain integer types to fail to be zero-extended, resulting +// in type casting errors. After the fix in #97800, this test attempts integer casting +// while simultaneously interfacing with a C library and using the -O3 flag. +// See https://github.com/rust-lang/rust/issues/97463 + +//@ ignore-msvc +// Reason: the rustc compilation fails due to an unresolved external symbol + +//@ ignore-cross-compile +// Reason: The compiled binary is executed. + +use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name}; + +fn main() { + // The issue exercised by this test specifically needs needs `-O` + // flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of + // the nicer `build_native_static_lib`. + cc().arg("-c").arg("-O3").out_exe("bad.o").input("bad.c").run(); + llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), "bad.o").run(); + rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run(); + run("param_passing"); +} diff --git a/tests/rustdoc-gui/item-name-wrap.goml b/tests/rustdoc-gui/item-name-wrap.goml new file mode 100644 index 00000000000..825c16ac5b8 --- /dev/null +++ b/tests/rustdoc-gui/item-name-wrap.goml @@ -0,0 +1,23 @@ +// This test ensures that the item name's width is not wrapped. +go-to: "file://" + |DOC_PATH| + "/test_docs/short_docs/index.html" +set-window-size: (1000, 600) + +// First we ensure that there is only one `item-table`... +assert-count: ("ul.item-table", 1) +// And only two items in it. +assert-count: ("ul.item-table li", 2) + +// If they don't have the same height, then it means one of the two is on two lines whereas it +// shouldn't! +compare-elements-size: ( + ".item-table .item-name a[href='fn.mult_vec_num.html']", + ".item-table .item-name a[href='fn.subt_vec_num.html']", + ["height"], +) + +// We also check that the `item-table` is taking the full width. +compare-elements-size: ( + "#functions", + "ul.item-table", + ["width"], +) diff --git a/tests/rustdoc-gui/source-code-page-code-scroll.goml b/tests/rustdoc-gui/source-code-page-code-scroll.goml index 35f338ea328..31ab281d6ce 100644 --- a/tests/rustdoc-gui/source-code-page-code-scroll.goml +++ b/tests/rustdoc-gui/source-code-page-code-scroll.goml @@ -2,7 +2,7 @@ go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" set-window-size: (800, 1000) // "scrollWidth" should be superior than "clientWidth". -assert-property: ("body", {"scrollWidth": 1047, "clientWidth": 800}) +assert-property: ("body", {"scrollWidth": 1114, "clientWidth": 800}) // Both properties should be equal (ie, no scroll on the code block). -assert-property: (".example-wrap .rust", {"scrollWidth": 933, "clientWidth": 933}) +assert-property: (".example-wrap .rust", {"scrollWidth": 1000, "clientWidth": 1000}) diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs index 7e34178e56f..7397992c0ab 100644 --- a/tests/rustdoc-gui/src/test_docs/lib.rs +++ b/tests/rustdoc-gui/src/test_docs/lib.rs @@ -20,10 +20,10 @@ Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>. Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>. -Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code> -</span>. -Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code> -</span>. +Finally, you can use `quz` only on <span class="stab portability" data-span="1"><code>Unix or x86-64 +</code></span>. +Finally, you can use `quz` only on <span class="stab portability" data-span="2"><code>Unix or x86-64 +</code></span>. */ use std::convert::AsRef; @@ -614,3 +614,17 @@ pub mod private { B, } } + +pub mod trait_bounds { + pub trait OneBound: Sized {} + pub trait TwoBounds: Sized + Copy {} + pub trait ThreeBounds: Sized + Copy + Eq {} +} + +pub mod short_docs { + /// mult_vec_num(x: &[f64], y: f64) + pub fn mult_vec_num() {} + + /// subt_vec_num(x: &[f64], y: f64) + pub fn subt_vec_num() {} +} diff --git a/tests/rustdoc-gui/stab-in-doc.goml b/tests/rustdoc-gui/stab-in-doc.goml new file mode 100644 index 00000000000..6a03a51fe9f --- /dev/null +++ b/tests/rustdoc-gui/stab-in-doc.goml @@ -0,0 +1,9 @@ +// This test ensure that `stab` elements if used in doc blocks are not breaking the text layout. +go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" +// We make the window wide enough for the two stabs who are looking into to be on the same line. +set-window-size: (1100, 600) +compare-elements-position: ( + ".top-doc .docblock span[data-span='1']", + ".top-doc .docblock span[data-span='2']", + ["y"], +) diff --git a/tests/rustdoc-gui/trait-with-bounds.goml b/tests/rustdoc-gui/trait-with-bounds.goml new file mode 100644 index 00000000000..f076bdd4707 --- /dev/null +++ b/tests/rustdoc-gui/trait-with-bounds.goml @@ -0,0 +1,35 @@ +// Check that if a trait has more than 2 bounds, they are displayed on different lines. + +// It tries to load a JS for each trait but there are none since they're not implemented. +fail-on-request-error: false +go-to: "file://" + |DOC_PATH| + "/test_docs/trait_bounds/trait.OneBound.html" +// They should have the same Y position. +compare-elements-position: ( + ".item-decl code", + ".item-decl a.trait[title='trait core::marker::Sized']", + ["y"], +) +go-to: "file://" + |DOC_PATH| + "/test_docs/trait_bounds/trait.TwoBounds.html" +// They should have the same Y position. +compare-elements-position: ( + ".item-decl code", + ".item-decl a.trait[title='trait core::marker::Copy']", + ["y"], +) +go-to: "file://" + |DOC_PATH| + "/test_docs/trait_bounds/trait.ThreeBounds.html" +// All on their own line. +compare-elements-position-false: ( + ".item-decl code", + ".item-decl a.trait[title='trait core::marker::Sized']", + ["y"], +) +compare-elements-position-false: ( + ".item-decl a.trait[title='trait core::marker::Sized']", + ".item-decl a.trait[title='trait core::marker::Copy']", + ["y"], +) +compare-elements-position-false: ( + ".item-decl a.trait[title='trait core::marker::Copy']", + ".item-decl a.trait[title='trait core::cmp::Eq']", + ["y"], +) diff --git a/tests/rustdoc-gui/type-declation-overflow.goml b/tests/rustdoc-gui/type-declation-overflow.goml index fdf84c3fd29..8df946c6f39 100644 --- a/tests/rustdoc-gui/type-declation-overflow.goml +++ b/tests/rustdoc-gui/type-declation-overflow.goml @@ -8,34 +8,38 @@ fail-on-request-error: false go-to: "file://" + |DOC_PATH| + "/lib2/long_trait/trait.ALongNameBecauseItHelpsTestingTheCurrentProblem.html" // We set a fixed size so there is no chance of "random" resize. -set-window-size: (1100, 800) +set-window-size: (710, 800) // Logically, the <body> scroll width should be the width of the window. -assert-property: ("body", {"scrollWidth": "1100"}) -// However, since there is overflow in the type declaration, its scroll width is bigger. -assert-property: ("pre.item-decl", {"scrollWidth": "1324"}) +assert-property: ("body", {"scrollWidth": "710"}) +// We now check that the section width hasn't grown because of it. +assert-property: ("#main-content", {"scrollWidth": "450"}) +// However, since there is overflow in the type declaration, its scroll width is bigger that "#main-content". +assert-property: ("pre.item-decl", {"scrollWidth": "585"}) // In the table-ish view on the module index, the name should not be wrapped more than necessary. go-to: "file://" + |DOC_PATH| + "/lib2/too_long/index.html" // We'll ensure that items with short documentation have the same width. store-property: ("//*[@class='item-table']//*[@class='struct']/..", {"offsetWidth": offset_width}) -assert: |offset_width| == "277" +assert: |offset_width| == "149" assert-property: ("//*[@class='item-table']//*[@class='constant']/..", {"offsetWidth": |offset_width|}) // We now make the same check on type declaration... go-to: "file://" + |DOC_PATH| + "/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html" -assert-property: ("body", {"scrollWidth": "1100"}) +assert-property: ("body", {"scrollWidth": "710"}) +// Getting the width of the "<main>" element. +assert-property: ("main", {"scrollWidth": "510"}) // We now check that the section width hasn't grown because of it. -assert-property: ("#main-content", {"scrollWidth": "840"}) +assert-property: ("#main-content", {"scrollWidth": "450"}) // And now checking that it has scrollable content. assert-property: ("pre.item-decl", {"scrollWidth": "1103"}) // ... and constant. // On a sidenote, it also checks that the (very) long title isn't changing the docblock width. go-to: "file://" + |DOC_PATH| + "/lib2/too_long/constant.ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong.html" -assert-property: ("body", {"scrollWidth": "1100"}) +assert-property: ("body", {"scrollWidth": "710"}) // We now check that the section width hasn't grown because of it. -assert-property: ("#main-content", {"scrollWidth": "840"}) +assert-property: ("#main-content", {"scrollWidth": "450"}) // And now checking that it has scrollable content. assert-property: ("pre.item-decl", {"scrollWidth": "950"}) diff --git a/tests/rustdoc-ui/track-diagnostics.stderr b/tests/rustdoc-ui/track-diagnostics.stderr index f7f3e368a3c..3d17570a7a2 100644 --- a/tests/rustdoc-ui/track-diagnostics.stderr +++ b/tests/rustdoc-ui/track-diagnostics.stderr @@ -3,7 +3,7 @@ error[E0308]: mismatched types | LL | const S: A = B; | ^ expected `A`, found `B` --Ztrack-diagnostics: created at compiler/rustc_infer/src/error_reporting/infer/mod.rs:LL:CC +-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs:LL:CC error: aborting due to 1 previous error diff --git a/tests/rustdoc/anchor-id-duplicate-method-name-25001.rs b/tests/rustdoc/anchor-id-duplicate-method-name-25001.rs index 5fa6891b23d..e1f19e7e017 100644 --- a/tests/rustdoc/anchor-id-duplicate-method-name-25001.rs +++ b/tests/rustdoc/anchor-id-duplicate-method-name-25001.rs @@ -24,14 +24,14 @@ impl Foo<u32> { } impl<T> Bar for Foo<T> { - //@ has - '//*[@id="associatedtype.Item-1"]//h4[@class="code-header"]' 'type Item = T' + // @has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' 'type Item = T' type Item=T; //@ has - '//*[@id="method.quux"]//h4[@class="code-header"]' 'fn quux(self)' fn quux(self) {} } impl<'a, T> Bar for &'a Foo<T> { - //@ has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item = &'a T" + // @has - '//*[@id="associatedtype.Item-1"]//h4[@class="code-header"]' "type Item = &'a T" type Item=&'a T; //@ has - '//*[@id="method.quux-1"]//h4[@class="code-header"]' 'fn quux(self)' diff --git a/tests/rustdoc/auxiliary/precise-capturing.rs b/tests/rustdoc/auxiliary/precise-capturing.rs new file mode 100644 index 00000000000..531d4dfdccc --- /dev/null +++ b/tests/rustdoc/auxiliary/precise-capturing.rs @@ -0,0 +1,7 @@ +#![feature(precise_capturing)] + +pub fn cross_crate_empty() -> impl Sized + use<> {} + +pub fn cross_crate_missing() -> impl Sized {} + +pub fn cross_crate_args<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {} diff --git a/tests/rustdoc/const-generics/const-impl.rs b/tests/rustdoc/const-generics/const-impl.rs index ce536291290..279a7842254 100644 --- a/tests/rustdoc/const-generics/const-impl.rs +++ b/tests/rustdoc/const-generics/const-impl.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![crate_name = "foo"] use std::marker::ConstParamTy; diff --git a/tests/rustdoc/impl-trait-precise-capturing.rs b/tests/rustdoc/impl-trait-precise-capturing.rs index d1987a555c1..a964a1f8518 100644 --- a/tests/rustdoc/impl-trait-precise-capturing.rs +++ b/tests/rustdoc/impl-trait-precise-capturing.rs @@ -1,6 +1,10 @@ +//@ aux-build:precise-capturing.rs + #![crate_name = "foo"] #![feature(precise_capturing)] +extern crate precise_capturing; + //@ has foo/fn.two.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'b, 'a>" pub fn two<'a, 'b, 'c>() -> impl Sized + use<'b, 'a /* no 'c */> {} @@ -12,3 +16,12 @@ pub fn none() -> impl Sized + use<> {} //@ has foo/fn.first.html '//section[@id="main-content"]//pre' "-> impl use<> + Sized" pub fn first() -> impl use<> + Sized {} + +//@ has foo/fn.cross_crate_empty.html '//section[@id="main-content"]//pre' "-> impl Sized + use<>" +pub use precise_capturing::cross_crate_empty; + +//@ matches foo/fn.cross_crate_missing.html '//section[@id="main-content"]//pre' "-> impl Sized$" +pub use precise_capturing::cross_crate_missing; + +//@ has foo/fn.cross_crate_args.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'a, T, N>" +pub use precise_capturing::cross_crate_args; diff --git a/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.rs b/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.rs new file mode 100644 index 00000000000..e422026ca4a --- /dev/null +++ b/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.rs @@ -0,0 +1,15 @@ +#![allow(dead_code)] + +extern "C" { + fn rust_interesting_average(_: i64, ...) -> f64; +} + +fn test<T, U>(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { + unsafe { + rust_interesting_average( + 6, a as f64, b, b as f64, f, c as f64, d, d as f64, e, e as f64, f, g, //~ ERROR use of moved value: `f` [E0382] + ) as i64 + } +} + +fn main() {} diff --git a/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.stderr b/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.stderr new file mode 100644 index 00000000000..6997710ec89 --- /dev/null +++ b/tests/ui/borrowck/move-error-suggest-clone-panic-issue-127915.stderr @@ -0,0 +1,25 @@ +error[E0382]: use of moved value: `f` + --> $DIR/move-error-suggest-clone-panic-issue-127915.rs:10:78 + | +LL | fn test<T, U>(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { + | - move occurs because `f` has type `T`, which does not implement the `Copy` trait +... +LL | 6, a as f64, b, b as f64, f, c as f64, d, d as f64, e, e as f64, f, g, + | - value moved here ^ value used here after move + | +help: if `T` implemented `Clone`, you could clone the value + --> $DIR/move-error-suggest-clone-panic-issue-127915.rs:7:9 + | +LL | fn test<T, U>(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { + | ^ consider constraining this type parameter with `Clone` +... +LL | 6, a as f64, b, b as f64, f, c as f64, d, d as f64, e, e as f64, f, g, + | - you could clone this value +help: consider restricting type parameter `T` + | +LL | fn test<T: Copy, U>(a: i64, b: i64, c: i64, d: i64, e: i64, f: T, g: U) -> i64 { + | ++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr index 00a97ca1488..57cbe173c78 100644 --- a/tests/ui/check-cfg/mix.stderr +++ b/tests/ui/check-cfg/mix.stderr @@ -251,7 +251,7 @@ warning: unexpected `cfg` condition value: `zebra` LL | cfg!(target_feature = "zebra"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 197 more + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 199 more = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration warning: 27 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 78b7f0f5d99..00abb5f5e5c 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -165,7 +165,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_feature = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `fcma`, `fdivdu`, `fhm`, `flagm`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lsx`, `lvz`, `lzcnt`, `m`, `mclass`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sign-ext`, `simd128`, `sm4`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `sve`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `fcma`, `fdivdu`, `fhm`, `flagm`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lsx`, `lvz`, `lzcnt`, `m`, `mclass`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sign-ext`, `simd128`, `sm4`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `sve`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` @@ -201,7 +201,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_os = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` @@ -285,7 +285,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux` | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration warning: 29 warnings emitted diff --git a/tests/ui/closures/binder/const-bound.rs b/tests/ui/closures/binder/const-bound.rs index b1c79db1375..10d869fcc85 100644 --- a/tests/ui/closures/binder/const-bound.rs +++ b/tests/ui/closures/binder/const-bound.rs @@ -3,5 +3,6 @@ fn main() { for<const N: i32> || -> () {}; - //~^ ERROR late-bound const parameter not allowed on closures + //~^ ERROR late-bound const parameters cannot be used currently + //~| ERROR late-bound const parameter not allowed on closures } diff --git a/tests/ui/closures/binder/const-bound.stderr b/tests/ui/closures/binder/const-bound.stderr index 9c4fd95ed76..b805879f7fa 100644 --- a/tests/ui/closures/binder/const-bound.stderr +++ b/tests/ui/closures/binder/const-bound.stderr @@ -1,3 +1,9 @@ +error: late-bound const parameters cannot be used currently + --> $DIR/const-bound.rs:5:15 + | +LL | for<const N: i32> || -> () {}; + | ^ + warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/const-bound.rs:1:37 | @@ -13,5 +19,5 @@ error: late-bound const parameter not allowed on closures LL | for<const N: i32> || -> () {}; | ^^^^^^^^^^^^ -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/closures/closure-no-fn-3.stderr b/tests/ui/closures/closure-no-fn-3.stderr index bbf3677fb72..7711347c568 100644 --- a/tests/ui/closures/closure-no-fn-3.stderr +++ b/tests/ui/closures/closure-no-fn-3.stderr @@ -3,6 +3,12 @@ error[E0605]: non-primitive cast: `{closure@$DIR/closure-no-fn-3.rs:6:28: 6:30}` | LL | let baz: fn() -> u8 = (|| { b }) as fn() -> u8; | ^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast + | +note: closures can only be coerced to `fn` types if they do not capture any variables + --> $DIR/closure-no-fn-3.rs:6:33 + | +LL | let baz: fn() -> u8 = (|| { b }) as fn() -> u8; + | ^ `b` captured here error: aborting due to 1 previous error diff --git a/tests/ui/codegen/equal-pointers-unequal/README.md b/tests/ui/codegen/equal-pointers-unequal/README.md new file mode 100644 index 00000000000..343f9646a32 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/README.md @@ -0,0 +1,22 @@ +See https://github.com/rust-lang/rust/issues/107975 + +Basically, if you have two pointers with the same address but from two different allocations, +the compiler gets confused whether their addresses are equal or not, +resulting in some self-contradictory behavior of the compiled code. + +This folder contains some examples. +They all boil down to allocating a variable on the stack, taking its address, +getting rid of the variable, and then doing it all again. +This way we end up with two addresses stored in two `usize`s (`a` and `b`). +The addresses are (probably) equal but (definitely) come from two different allocations. +Logically, we would expect that exactly one of the following options holds true: +1. `a == b` +2. `a != b` +Sadly, the compiler does not always agree. + +Due to Rust having at least three meaningfully different ways +to get a variable's address as an `usize`, +each example is provided in three versions, each in the corresponding subfolder: +1. `./as-cast/` for `&v as *const _ as usize`, +2. `./strict-provenance/` for `addr_of!(v).addr()`, +2. `./exposed-provenance/` for `addr_of!(v).expose_provenance()`. diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.rs new file mode 100644 index 00000000000..e2a00ce173d --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.rs @@ -0,0 +1,21 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +fn main() { + let a: usize = { + let v = 0u8; + &v as *const _ as usize + }; + let b: usize = { + let v = 0u8; + &v as *const _ as usize + }; + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/function.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/function.rs new file mode 100644 index 00000000000..15434de50f7 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/function.rs @@ -0,0 +1,22 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1434203908 + +fn f() -> usize { + let v = 0; + &v as *const _ as usize +} + +fn main() { + let a = f(); + let b = f(); + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.rs new file mode 100644 index 00000000000..d13fd4b63b3 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.rs @@ -0,0 +1,30 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a = { + let v = 0; + &v as *const _ as usize + }; + let b = { + let v = 0; + &v as *const _ as usize + }; + assert_eq!(format!("{}", a == b), "false"); + assert_eq!(format!("{}", cmp_in(a, b)), "false"); + assert_eq!(format!("{}", cmp(a, b)), "true"); + assert_eq!(a.to_string(), b.to_string()); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.rs new file mode 100644 index 00000000000..9a1ace86e4d --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.rs @@ -0,0 +1,30 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a = { + let v = 0; + &v as *const _ as usize + }; + let b = { + let v = 0; + &v as *const _ as usize + }; + assert_eq!(a.to_string(), b.to_string()); + assert_eq!(format!("{}", a == b), "true"); + assert_eq!(format!("{}", cmp_in(a, b)), "true"); + assert_eq!(format!("{}", cmp(a, b)), "true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/print.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/print.rs new file mode 100644 index 00000000000..f33a9e511b6 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/print.rs @@ -0,0 +1,20 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +fn main() { + let a = { + let v = 0; + &v as *const _ as usize + }; + let b = { + let v = 0; + &v as *const _ as usize + }; + + assert_ne!(a, b); + println!("{a}"); // or b + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.rs new file mode 100644 index 00000000000..eda83e999a5 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.rs @@ -0,0 +1,23 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +fn main() { + let a = { + let v = 0; + &v as *const _ as usize + }; + let b = { + let v = 0; + &v as *const _ as usize + }; + + assert_ne!(a, b); + assert_ne!(a, b); + let c = a; + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "false true false"); + println!("{a} {b}"); + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "true true true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.rs new file mode 100644 index 00000000000..97a875f15bc --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.rs @@ -0,0 +1,63 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +use std::cell::{Ref, RefCell}; + +fn main() { + let a: usize = { + let v = 0u8; + &v as *const _ as usize + }; + let b: usize = { + let v = 0u8; + &v as *const _ as usize + }; + let i: usize = b - a; + + // A surprise tool that will help us later. + let arr = [ + RefCell::new(Some(Box::new(1u8))), + RefCell::new(None), + RefCell::new(None), + RefCell::new(None), + ]; + + // `i` is not 0 + assert_ne!(i, 0); + + // Let's borrow the `i`-th element. + // If `i` is out of bounds, indexing will panic. + let r: Ref<Option<Box<u8>>> = arr[i].borrow(); + + // If we got here, it means `i` was in bounds. + // Now, two options are possible: + // EITHER `i` is not 0 (as we have asserted above), + // so the unwrap will panic, because only the 0-th element is `Some` + // OR the assert lied, `i` *is* 0, and the `unwrap` will not panic. + let r: &Box<u8> = r.as_ref().unwrap(); + + // If we got here, it means `i` *was* actually 0. + // Let's ignore the fact that the assert has lied + // and try to take a mutable reference to the 0-th element. + // `borrow_mut` should panic, because we are sill holding on + // to a shared `Ref` for the same `RefCell`. + *arr[0].borrow_mut() = None; + + // But it doesn't panic! + // We have successfully replaced `Some(Box)` with `None`, + // while holding a shared reference to it. + // No unsafe involved. + + // The `Box` has been deallocated by now, so this is a dangling reference! + let r: &u8 = &*r; + println!("{:p}", r); + + // The following might segfault. Or it might not. + // Depends on the platform semantics + // and whatever happened to the pointed-to memory after deallocation. + // let u: u8 = *r; + // println!("{u}"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.rs b/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.rs new file mode 100644 index 00000000000..d1aa95a9a56 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.rs @@ -0,0 +1,28 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Derived from https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +fn main() { + let a: usize = { + let v = 0u8; + &v as *const _ as usize + }; + let b: usize = { + let v = 0u8; + &v as *const _ as usize + }; + + // So, are `a` and `b` equal? + + // Let's check their difference. + let i: usize = a - b; + // It's not zero, which means `a` and `b` are not equal. + assert_ne!(i, 0); + // But it looks like zero... + assert_eq!(i.to_string(), "0"); + // ...and now it *is* zero? + assert_eq!(i, 0); + // So `a` and `b` are equal after all? +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/basic.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/basic.rs new file mode 100644 index 00000000000..0c9df7ecd78 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/basic.rs @@ -0,0 +1,25 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +#![feature(exposed_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/function.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/function.rs new file mode 100644 index 00000000000..b188b794d1f --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/function.rs @@ -0,0 +1,26 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1434203908 + +#![feature(exposed_provenance)] + +use std::ptr; + +fn f() -> usize { + let v = 0; + ptr::from_ref(&v).expose_provenance() +} + +fn main() { + let a = f(); + let b = f(); + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline1.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline1.rs new file mode 100644 index 00000000000..7f64e23b9c1 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline1.rs @@ -0,0 +1,34 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#![feature(exposed_provenance)] + +use std::ptr; + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + assert_eq!(format!("{}", a == b), "false"); + assert_eq!(format!("{}", cmp_in(a, b)), "false"); + assert_eq!(format!("{}", cmp(a, b)), "true"); + assert_eq!(a.to_string(), b.to_string()); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline2.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline2.rs new file mode 100644 index 00000000000..3417296ce12 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline2.rs @@ -0,0 +1,34 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#![feature(exposed_provenance)] + +use std::ptr; + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + assert_eq!(a.to_string(), b.to_string()); + assert_eq!(format!("{}", a == b), "true"); + assert_eq!(format!("{}", cmp_in(a, b)), "true"); + assert_eq!(format!("{}", cmp(a, b)), "true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print.rs new file mode 100644 index 00000000000..e1e9e3f46b8 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print.rs @@ -0,0 +1,24 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +#![feature(exposed_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + + assert_ne!(a, b); + println!("{a}"); // or b + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print3.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print3.rs new file mode 100644 index 00000000000..8d581e8c9e9 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print3.rs @@ -0,0 +1,27 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +#![feature(exposed_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).expose_provenance() + }; + + assert_ne!(a, b); + assert_ne!(a, b); + let c = a; + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "false true false"); + println!("{a} {b}"); + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "true true true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/segfault.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/segfault.rs new file mode 100644 index 00000000000..506f114cd2a --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/segfault.rs @@ -0,0 +1,68 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +#![feature(exposed_provenance)] + +use std::{ + cell::{Ref, RefCell}, + ptr, +}; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + let i: usize = b - a; + + // A surprise tool that will help us later. + let arr = [ + RefCell::new(Some(Box::new(1u8))), + RefCell::new(None), + RefCell::new(None), + RefCell::new(None), + ]; + + // `i` is not 0 + assert_ne!(i, 0); + + // Let's borrow the `i`-th element. + // If `i` is out of bounds, indexing will panic. + let r: Ref<Option<Box<u8>>> = arr[i].borrow(); + + // If we got here, it means `i` was in bounds. + // Now, two options are possible: + // EITHER `i` is not 0 (as we have asserted above), + // so the unwrap will panic, because only the 0-th element is `Some` + // OR the assert lied, `i` *is* 0, and the `unwrap` will not panic. + let r: &Box<u8> = r.as_ref().unwrap(); + + // If we got here, it means `i` *was* actually 0. + // Let's ignore the fact that the assert has lied + // and try to take a mutable reference to the 0-th element. + // `borrow_mut` should panic, because we are sill holding on + // to a shared `Ref` for the same `RefCell`. + *arr[0].borrow_mut() = None; + + // But it doesn't panic! + // We have successfully replaced `Some(Box)` with `None`, + // while holding a shared reference to it. + // No unsafe involved. + + // The `Box` has been deallocated by now, so this is a dangling reference! + let r: &u8 = &*r; + println!("{:p}", r); + + // The following might segfault. Or it might not. + // Depends on the platform semantics + // and whatever happened to the pointed-to memory after deallocation. + // let u: u8 = *r; + // println!("{u}"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/zero.rs b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/zero.rs new file mode 100644 index 00000000000..603db5e08f4 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/exposed-provenance/zero.rs @@ -0,0 +1,32 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Derived from https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +#![feature(exposed_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).expose_provenance() + }; + + // So, are `a` and `b` equal? + + // Let's check their difference. + let i: usize = a - b; + // It's not zero, which means `a` and `b` are not equal. + assert_ne!(i, 0); + // But it looks like zero... + assert_eq!(i.to_string(), "0"); + // ...and now it *is* zero? + assert_eq!(i, 0); + // So `a` and `b` are equal after all? +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/basic.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/basic.rs new file mode 100644 index 00000000000..0243c2bfe95 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/basic.rs @@ -0,0 +1,25 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +#![feature(strict_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/function.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/function.rs new file mode 100644 index 00000000000..29758036a21 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/function.rs @@ -0,0 +1,26 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1434203908 + +#![feature(strict_provenance)] + +use std::ptr; + +fn f() -> usize { + let v = 0; + ptr::from_ref(&v).addr() +} + +fn main() { + let a = f(); + let b = f(); + + // `a` and `b` are not equal. + assert_ne!(a, b); + // But they are the same number. + assert_eq!(format!("{a}"), format!("{b}")); + // And they are equal. + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline1.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline1.rs new file mode 100644 index 00000000000..11925261a65 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline1.rs @@ -0,0 +1,34 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#![feature(strict_provenance)] + +use std::ptr; + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + assert_eq!(format!("{}", a == b), "false"); + assert_eq!(format!("{}", cmp_in(a, b)), "false"); + assert_eq!(format!("{}", cmp(a, b)), "true"); + assert_eq!(a.to_string(), b.to_string()); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline2.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline2.rs new file mode 100644 index 00000000000..e628bb90faa --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline2.rs @@ -0,0 +1,34 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Based on https://github.com/rust-lang/rust/issues/107975#issuecomment-1432161340 + +#![feature(strict_provenance)] + +use std::ptr; + +#[inline(never)] +fn cmp(a: usize, b: usize) -> bool { + a == b +} + +#[inline(always)] +fn cmp_in(a: usize, b: usize) -> bool { + a == b +} + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + assert_eq!(a.to_string(), b.to_string()); + assert_eq!(format!("{}", a == b), "true"); + assert_eq!(format!("{}", cmp_in(a, b)), "true"); + assert_eq!(format!("{}", cmp(a, b)), "true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print.rs new file mode 100644 index 00000000000..075e3475a32 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print.rs @@ -0,0 +1,24 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +#![feature(strict_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + + assert_ne!(a, b); + println!("{a}"); // or b + assert_eq!(a, b); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print3.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print3.rs new file mode 100644 index 00000000000..6d7b6fa33e0 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/print3.rs @@ -0,0 +1,27 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1430704499 + +#![feature(strict_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0; + ptr::from_ref(&v).addr() + }; + + assert_ne!(a, b); + assert_ne!(a, b); + let c = a; + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "false true false"); + println!("{a} {b}"); + assert_eq!(format!("{} {} {}", a == b, a == c, b == c), "true true true"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/segfault.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/segfault.rs new file mode 100644 index 00000000000..67660d285a4 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/segfault.rs @@ -0,0 +1,68 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +#![feature(strict_provenance)] + +use std::{ + cell::{Ref, RefCell}, + ptr, +}; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + let i: usize = b - a; + + // A surprise tool that will help us later. + let arr = [ + RefCell::new(Some(Box::new(1u8))), + RefCell::new(None), + RefCell::new(None), + RefCell::new(None), + ]; + + // `i` is not 0 + assert_ne!(i, 0); + + // Let's borrow the `i`-th element. + // If `i` is out of bounds, indexing will panic. + let r: Ref<Option<Box<u8>>> = arr[i].borrow(); + + // If we got here, it means `i` was in bounds. + // Now, two options are possible: + // EITHER `i` is not 0 (as we have asserted above), + // so the unwrap will panic, because only the 0-th element is `Some` + // OR the assert lied, `i` *is* 0, and the `unwrap` will not panic. + let r: &Box<u8> = r.as_ref().unwrap(); + + // If we got here, it means `i` *was* actually 0. + // Let's ignore the fact that the assert has lied + // and try to take a mutable reference to the 0-th element. + // `borrow_mut` should panic, because we are sill holding on + // to a shared `Ref` for the same `RefCell`. + *arr[0].borrow_mut() = None; + + // But it doesn't panic! + // We have successfully replaced `Some(Box)` with `None`, + // while holding a shared reference to it. + // No unsafe involved. + + // The `Box` has been deallocated by now, so this is a dangling reference! + let r: &u8 = &*r; + println!("{:p}", r); + + // The following might segfault. Or it might not. + // Depends on the platform semantics + // and whatever happened to the pointed-to memory after deallocation. + // let u: u8 = *r; + // println!("{u}"); +} diff --git a/tests/ui/codegen/equal-pointers-unequal/strict-provenance/zero.rs b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/zero.rs new file mode 100644 index 00000000000..a89310f9930 --- /dev/null +++ b/tests/ui/codegen/equal-pointers-unequal/strict-provenance/zero.rs @@ -0,0 +1,32 @@ +//@ known-bug: #107975 +//@ compile-flags: -Copt-level=2 +//@ run-pass + +// Derived from https://github.com/rust-lang/rust/issues/107975#issuecomment-1431758601 + +#![feature(strict_provenance)] + +use std::ptr; + +fn main() { + let a: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + let b: usize = { + let v = 0u8; + ptr::from_ref(&v).addr() + }; + + // So, are `a` and `b` equal? + + // Let's check their difference. + let i: usize = a - b; + // It's not zero, which means `a` and `b` are not equal. + assert_ne!(i, 0); + // But it looks like zero... + assert_eq!(i.to_string(), "0"); + // ...and now it *is* zero? + assert_eq!(i, 0); + // So `a` and `b` are equal after all? +} diff --git a/tests/ui/coherence/negative-coherence/regions-in-canonical.rs b/tests/ui/coherence/negative-coherence/regions-in-canonical.rs index 6c2a11e0135..f0424e72434 100644 --- a/tests/ui/coherence/negative-coherence/regions-in-canonical.rs +++ b/tests/ui/coherence/negative-coherence/regions-in-canonical.rs @@ -1,13 +1,12 @@ //@ check-pass -#![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARN the feature `unsized_const_params` is incomplete #![feature(with_negative_coherence, negative_impls)] pub trait A<const K: &'static str> {} pub trait C {} - struct W<T>(T); // Negative coherence: diff --git a/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr b/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr index dc8c926f182..72044915294 100644 --- a/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr +++ b/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr @@ -1,8 +1,8 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/regions-in-canonical.rs:3:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/regions-in-canonical.rs:3:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information = note: `#[warn(incomplete_features)]` on by default diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs index 8035fce0914..e90426ec0c7 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs @@ -1,7 +1,6 @@ //@ check-pass #![feature(adt_const_params, lazy_type_alias)] -//~^ WARN: the feature `adt_const_params` is incomplete -//~| WARN: the feature `lazy_type_alias` is incomplete +//~^ WARN: the feature `lazy_type_alias` is incomplete pub type Matrix = [usize; 1]; const EMPTY_MATRIX: Matrix = [0; 1]; diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr index 5c6981077b2..4f5133474c6 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr @@ -1,12 +1,3 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/alias_const_param_ty-1.rs:2:12 - | -LL | #![feature(adt_const_params, lazy_type_alias)] - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information - = note: `#[warn(incomplete_features)]` on by default - warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/alias_const_param_ty-1.rs:2:30 | @@ -14,6 +5,7 @@ LL | #![feature(adt_const_params, lazy_type_alias)] | ^^^^^^^^^^^^^^^ | = note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information + = note: `#[warn(incomplete_features)]` on by default -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs index a576b75341c..961e1a9cfbf 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs @@ -1,6 +1,5 @@ //@ check-pass #![feature(adt_const_params)] -//~^ WARN: the feature `adt_const_params` is incomplete const EMPTY_MATRIX: <Type as Trait>::Matrix = [0; 1]; diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr deleted file mode 100644 index dbc8ab71636..00000000000 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/alias_const_param_ty-2.rs:2:12 - | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs b/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs new file mode 100644 index 00000000000..e2ba459f8dd --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs @@ -0,0 +1,7 @@ +#![feature(adt_const_params, unsized_const_params)] + +#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] +pub struct Foo([u8]); + +#[derive(std::marker::ConstParamTy, Eq, PartialEq)] +pub struct GenericNotUnsizedParam<T>(T); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs index c4d2d02ba70..35539193a27 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs @@ -1,13 +1,13 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] -fn check(_: impl std::marker::ConstParamTy) {} +fn check(_: impl std::marker::UnsizedConstParamTy) {} fn main() { - check(main); //~ error: `fn() {main}` can't be used as a const parameter type - check(|| {}); //~ error: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as a const parameter type - check(main as fn()); //~ error: `fn()` can't be used as a const parameter type - check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type + check(main); //~ error: `fn() {main}` can't be used as a const parameter type + check(|| {}); //~ error: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as a const parameter type + check(main as fn()); //~ error: `fn()` can't be used as a const parameter type + check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type - check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type + check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type } diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr index d96491f4f20..694f5a5c1a9 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr @@ -2,15 +2,15 @@ error[E0277]: `fn() {main}` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:7:11 | LL | check(main); - | ----- ^^^^ the trait `ConstParamTy` is not implemented for fn item `fn() {main}` + | ----- ^^^^ the trait `UnsizedConstParamTy` is not implemented for fn item `fn() {main}` | | | required by a bound introduced by this call | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this function | LL | check(main()); @@ -20,15 +20,15 @@ error[E0277]: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as --> $DIR/const_param_ty_bad.rs:8:11 | LL | check(|| {}); - | ----- ^^^^^ the trait `ConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` + | ----- ^^^^^ the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` | | | required by a bound introduced by this call | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this closure | LL | check(|| {}()); @@ -38,15 +38,15 @@ error[E0277]: `fn()` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:9:11 | LL | check(main as fn()); - | ----- ^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `fn()` + | ----- ^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `fn()` | | | required by a bound introduced by this call | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this function pointer | LL | check(main as fn()()); @@ -56,16 +56,16 @@ error[E0277]: `&mut ()` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:10:11 | LL | check(&mut ()); - | ----- ^^^^^^^ the trait `ConstParamTy` is not implemented for `&mut ()` + | ----- ^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `&mut ()` | | | required by a bound introduced by this call | - = note: `ConstParamTy` is implemented for `&()`, but not for `&mut ()` + = note: `UnsizedConstParamTy` is implemented for `&()`, but not for `&mut ()` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: consider removing the leading `&`-reference | LL - check(&mut ()); @@ -76,31 +76,31 @@ error[E0277]: `*mut ()` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:11:11 | LL | check(&mut () as *mut ()); - | ----- ^^^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*mut ()` + | ----- ^^^^^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `*mut ()` | | | required by a bound introduced by this call | - = help: the trait `ConstParamTy` is implemented for `()` + = help: the trait `UnsizedConstParamTy` is implemented for `()` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `*const ()` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:12:11 | LL | check(&() as *const ()); - | ----- ^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*const ()` + | ----- ^^^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `*const ()` | | | required by a bound introduced by this call | - = help: the trait `ConstParamTy` is implemented for `()` + = help: the trait `UnsizedConstParamTy` is implemented for `()` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs index b0e3b13cc1e..2008a96310a 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs @@ -1,10 +1,10 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; -fn check<T: std::marker::ConstParamTy>() {} +fn check<T: std::marker::ConstParamTy_>() {} fn main() { check::<[NotParam; 0]>(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr index 771d661f615..9852e181b9a 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr @@ -2,14 +2,14 @@ error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_bad_empty_array.rs:10:13 | LL | check::<[NotParam; 0]>(); - | ^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 0]: ConstParamTy` + | ^^^^^^^^^^^^^ the trait `ConstParamTy_` is not implemented for `NotParam`, which is required by `[NotParam; 0]: ConstParamTy_` | - = note: required for `[NotParam; 0]` to implement `ConstParamTy` + = note: required for `[NotParam; 0]` to implement `ConstParamTy_` note: required by a bound in `check` --> $DIR/const_param_ty_bad_empty_array.rs:7:13 | -LL | fn check<T: std::marker::ConstParamTy>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check<T: std::marker::ConstParamTy_>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs index e4dc76703a2..7ffdafa33e9 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs @@ -1,13 +1,13 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; -fn check<T: std::marker::ConstParamTy + ?Sized>() {} +fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {} fn main() { - check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type - check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type + check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type + check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type } diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr index 83c34c41f10..e63ae582fd5 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr @@ -2,40 +2,40 @@ error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13 | LL | check::<&NotParam>(); - | ^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `&NotParam: ConstParamTy` + | ^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `&NotParam: UnsizedConstParamTy` | - = note: required for `&NotParam` to implement `ConstParamTy` + = note: required for `&NotParam` to implement `UnsizedConstParamTy` note: required by a bound in `check` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13 | LL | check::<[NotParam]>(); - | ^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam]: ConstParamTy` + | ^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam]: UnsizedConstParamTy` | - = note: required for `[NotParam]` to implement `ConstParamTy` + = note: required for `[NotParam]` to implement `UnsizedConstParamTy` note: required by a bound in `check` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13 | LL | check::<[NotParam; 17]>(); - | ^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 17]: ConstParamTy` + | ^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 17]: UnsizedConstParamTy` | - = note: required for `[NotParam; 17]` to implement `ConstParamTy` + = note: required for `[NotParam; 17]` to implement `UnsizedConstParamTy` note: required by a bound in `check` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs index bce24059de8..98a8eb6ee95 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs @@ -1,7 +1,9 @@ //@ check-pass + +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -#![feature(adt_const_params)] -use std::marker::ConstParamTy; + +use std::marker::UnsizedConstParamTy; #[derive(PartialEq, Eq)] struct S<T> { @@ -9,16 +11,15 @@ struct S<T> { gen: T, } -impl<T: ConstParamTy> ConstParamTy for S<T> {} +impl<T: UnsizedConstParamTy> UnsizedConstParamTy for S<T> {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] struct D<T> { field: u8, gen: T, } - -fn check<T: ConstParamTy + ?Sized>() {} +fn check<T: UnsizedConstParamTy + ?Sized>() {} fn main() { check::<u8>(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs index 74283a37afc..8b3d0546010 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; @@ -7,11 +7,11 @@ struct NotParam; #[derive(PartialEq, Eq)] struct CantParam(NotParam); -impl std::marker::ConstParamTy for CantParam {} -//~^ error: the trait `ConstParamTy` cannot be implemented for this type +impl std::marker::UnsizedConstParamTy for CantParam {} +//~^ error: the trait `ConstParamTy_` cannot be implemented for this type -#[derive(std::marker::ConstParamTy, Eq, PartialEq)] -//~^ error: the trait `ConstParamTy` cannot be implemented for this type +#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] +//~^ error: the trait `ConstParamTy_` cannot be implemented for this type struct CantParamDerive(NotParam); fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr index 52b65d6061a..808a569fcad 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr @@ -1,22 +1,22 @@ -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type - --> $DIR/const_param_ty_impl_bad_field.rs:10:36 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/const_param_ty_impl_bad_field.rs:10:43 | LL | struct CantParam(NotParam); - | -------- this field does not implement `ConstParamTy` + | -------- this field does not implement `ConstParamTy_` LL | -LL | impl std::marker::ConstParamTy for CantParam {} - | ^^^^^^^^^ +LL | impl std::marker::UnsizedConstParamTy for CantParam {} + | ^^^^^^^^^ -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type --> $DIR/const_param_ty_impl_bad_field.rs:13:10 | -LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | struct CantParamDerive(NotParam); - | -------- this field does not implement `ConstParamTy` + | -------- this field does not implement `ConstParamTy_` | - = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs index dfb8a36ec53..761a6387a24 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs @@ -1,22 +1,22 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct ImplementsConstParamTy; -impl std::marker::ConstParamTy for ImplementsConstParamTy {} +impl std::marker::UnsizedConstParamTy for ImplementsConstParamTy {} struct CantParam(ImplementsConstParamTy); -impl std::marker::ConstParamTy for CantParam {} +impl std::marker::UnsizedConstParamTy for CantParam {} //~^ error: the type `CantParam` does not `#[derive(PartialEq)]` //~| the trait bound `CantParam: Eq` is not satisfied -#[derive(std::marker::ConstParamTy)] +#[derive(std::marker::UnsizedConstParamTy)] //~^ error: the type `CantParamDerive` does not `#[derive(PartialEq)]` //~| the trait bound `CantParamDerive: Eq` is not satisfied struct CantParamDerive(ImplementsConstParamTy); -fn check<T: std::marker::ConstParamTy>() {} +fn check<T: std::marker::UnsizedConstParamTy>() {} fn main() { check::<ImplementsConstParamTy>(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr index e213808cf7b..80d9942c591 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr @@ -1,10 +1,10 @@ error[E0277]: the trait bound `CantParam: Eq` is not satisfied - --> $DIR/const_param_ty_impl_no_structural_eq.rs:10:36 + --> $DIR/const_param_ty_impl_no_structural_eq.rs:10:43 | -LL | impl std::marker::ConstParamTy for CantParam {} - | ^^^^^^^^^ the trait `Eq` is not implemented for `CantParam` +LL | impl std::marker::UnsizedConstParamTy for CantParam {} + | ^^^^^^^^^ the trait `Eq` is not implemented for `CantParam` | -note: required by a bound in `ConstParamTy` +note: required by a bound in `UnsizedConstParamTy` --> $SRC_DIR/core/src/marker.rs:LL:COL help: consider annotating `CantParam` with `#[derive(Eq)]` | @@ -13,23 +13,23 @@ LL | struct CantParam(ImplementsConstParamTy); | error[E0277]: the type `CantParam` does not `#[derive(PartialEq)]` - --> $DIR/const_param_ty_impl_no_structural_eq.rs:10:36 + --> $DIR/const_param_ty_impl_no_structural_eq.rs:10:43 | -LL | impl std::marker::ConstParamTy for CantParam {} - | ^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParam` +LL | impl std::marker::UnsizedConstParamTy for CantParam {} + | ^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParam` | -note: required by a bound in `ConstParamTy` +note: required by a bound in `UnsizedConstParamTy` --> $SRC_DIR/core/src/marker.rs:LL:COL error[E0277]: the trait bound `CantParamDerive: Eq` is not satisfied --> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10 | -LL | #[derive(std::marker::ConstParamTy)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `CantParamDerive` +LL | #[derive(std::marker::UnsizedConstParamTy)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `CantParamDerive` | -note: required by a bound in `ConstParamTy` +note: required by a bound in `UnsizedConstParamTy` --> $SRC_DIR/core/src/marker.rs:LL:COL - = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `CantParamDerive` with `#[derive(Eq)]` | LL + #[derive(Eq)] @@ -39,12 +39,12 @@ LL | struct CantParamDerive(ImplementsConstParamTy); error[E0277]: the type `CantParamDerive` does not `#[derive(PartialEq)]` --> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10 | -LL | #[derive(std::marker::ConstParamTy)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParamDerive` +LL | #[derive(std::marker::UnsizedConstParamTy)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParamDerive` | -note: required by a bound in `ConstParamTy` +note: required by a bound in `UnsizedConstParamTy` --> $SRC_DIR/core/src/marker.rs:LL:COL - = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs index f2986f9cc60..236b3bc162a 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] union Union { a: u8, @@ -12,10 +12,10 @@ impl PartialEq for Union { } impl Eq for Union {} -impl std::marker::ConstParamTy for Union {} -//~^ ERROR the type `Union` does not `#[derive(PartialEq)]` +impl std::marker::UnsizedConstParamTy for Union {} +//~^ ERROR the trait `ConstParamTy` may not be implemented for this type -#[derive(std::marker::ConstParamTy)] +#[derive(std::marker::UnsizedConstParamTy)] //~^ ERROR this trait cannot be derived for unions union UnionDerive { a: u8, @@ -28,5 +28,4 @@ impl PartialEq for UnionDerive { } impl Eq for UnionDerive {} - fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr index 4c937db6c3a..837c289c924 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr @@ -1,18 +1,14 @@ error: this trait cannot be derived for unions --> $DIR/const_param_ty_impl_union.rs:18:10 | -LL | #[derive(std::marker::ConstParamTy)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[derive(std::marker::UnsizedConstParamTy)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0277]: the type `Union` does not `#[derive(PartialEq)]` - --> $DIR/const_param_ty_impl_union.rs:15:36 +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/const_param_ty_impl_union.rs:15:43 | -LL | impl std::marker::ConstParamTy for Union {} - | ^^^^^ the trait `StructuralPartialEq` is not implemented for `Union` - | -note: required by a bound in `ConstParamTy` - --> $SRC_DIR/core/src/marker.rs:LL:COL +LL | impl std::marker::UnsizedConstParamTy for Union {} + | ^^^^^ type is not a structure or enumeration error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs new file mode 100644 index 00000000000..6a553c2e085 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs @@ -0,0 +1,12 @@ +#![feature(adt_const_params, unsized_const_params)] +#![allow(incomplete_features)] + +use std::marker::{ConstParamTy_, UnsizedConstParamTy}; + +fn foo(a: &dyn ConstParamTy_) {} +//~^ ERROR: the trait `ConstParamTy_` + +fn bar(a: &dyn UnsizedConstParamTy) {} +//~^ ERROR: the trait `UnsizedConstParamTy` + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr new file mode 100644 index 00000000000..ba38f63d5df --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr @@ -0,0 +1,33 @@ +error[E0038]: the trait `ConstParamTy_` cannot be made into an object + --> $DIR/const_param_ty_object_safety.rs:6:12 + | +LL | fn foo(a: &dyn ConstParamTy_) {} + | ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: the trait cannot be made into an object because it uses `Self` as a type parameter +help: consider using an opaque type instead + | +LL | fn foo(a: &impl ConstParamTy_) {} + | ~~~~ + +error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object + --> $DIR/const_param_ty_object_safety.rs:9:12 + | +LL | fn bar(a: &dyn UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: the trait cannot be made into an object because it uses `Self` as a type parameter +help: consider using an opaque type instead + | +LL | fn bar(a: &impl UnsizedConstParamTy) {} + | ~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs index 0d1f023d565..7a4970c2e3c 100644 --- a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs @@ -1,18 +1,30 @@ // issue: rust-lang/rust/#83993 #![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + fn bug<'a>() where for<'b> [(); { let x: &'b (); //~^ ERROR generic parameters may not be used in const operations 0 - }]: -{} + }]:, +{ +} -fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { } -//~^ ERROR generic parameters may not be used in const operations -fn good() where for<'b> [();{0}]: Sized { } +fn bad() +where + for<'b> [(); { + let _: &'b (); + //~^ ERROR generic parameters may not be used in const operations + 0 + }]: Sized, +{ +} +fn good() +where + for<'b> [(); { 0 }]: Sized, +{ +} pub fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr index a49dfc31916..b7e459511f1 100644 --- a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr @@ -8,22 +8,13 @@ LL | let x: &'b (); = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/index-oob-ice-83993.rs:14:36 + --> $DIR/index-oob-ice-83993.rs:18:17 | -LL | fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { } - | ^^ cannot perform const operation using `'b` +LL | let _: &'b (); + | ^^ cannot perform const operation using `'b` | = note: lifetime parameters may not be used in const expressions = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/index-oob-ice-83993.rs:3:12 - | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information - = note: `#[warn(incomplete_features)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs index 9f05c53eef0..3a283442a0b 100644 --- a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs +++ b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs @@ -4,15 +4,18 @@ use std::marker::ConstParamTy; #[derive(ConstParamTy)] -//~^ the trait `ConstParamTy` cannot be implemented for this ty +//~^ the trait `ConstParamTy_` cannot be implemented for this ty +//~| the trait `ConstParamTy_` cannot be implemented for this ty struct Foo([*const u8; 1]); #[derive(ConstParamTy)] -//~^ the trait `ConstParamTy` cannot be implemented for this ty +//~^ the trait `ConstParamTy_` cannot be implemented for this ty +//~| the trait `ConstParamTy_` cannot be implemented for this ty struct Foo2([*mut u8; 1]); #[derive(ConstParamTy)] -//~^ the trait `ConstParamTy` cannot be implemented for this ty +//~^ the trait `ConstParamTy_` cannot be implemented for this ty +//~| the trait `ConstParamTy_` cannot be implemented for this ty struct Foo3([fn(); 1]); fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr index 9e772e8d55d..c2520f1d103 100644 --- a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr +++ b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr @@ -1,51 +1,99 @@ -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type --> $DIR/nested_bad_const_param_ty.rs:6:10 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... LL | struct Foo([*const u8; 1]); - | -------------- this field does not implement `ConstParamTy` + | -------------- this field does not implement `ConstParamTy_` | -note: the `ConstParamTy` impl for `[*const u8; 1]` requires that `*const u8: ConstParamTy` - --> $DIR/nested_bad_const_param_ty.rs:8:12 +note: the `ConstParamTy_` impl for `[*const u8; 1]` requires that `*const u8: ConstParamTy_` + --> $DIR/nested_bad_const_param_ty.rs:9:12 | LL | struct Foo([*const u8; 1]); | ^^^^^^^^^^^^^^ = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type - --> $DIR/nested_bad_const_param_ty.rs:10:10 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:11:10 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... LL | struct Foo2([*mut u8; 1]); - | ------------ this field does not implement `ConstParamTy` + | ------------ this field does not implement `ConstParamTy_` | -note: the `ConstParamTy` impl for `[*mut u8; 1]` requires that `*mut u8: ConstParamTy` - --> $DIR/nested_bad_const_param_ty.rs:12:13 +note: the `ConstParamTy_` impl for `[*mut u8; 1]` requires that `*mut u8: ConstParamTy_` + --> $DIR/nested_bad_const_param_ty.rs:14:13 | LL | struct Foo2([*mut u8; 1]); | ^^^^^^^^^^^^ = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type - --> $DIR/nested_bad_const_param_ty.rs:14:10 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:16:10 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... LL | struct Foo3([fn(); 1]); - | --------- this field does not implement `ConstParamTy` + | --------- this field does not implement `ConstParamTy_` | -note: the `ConstParamTy` impl for `[fn(); 1]` requires that `fn(): ConstParamTy` - --> $DIR/nested_bad_const_param_ty.rs:16:13 +note: the `ConstParamTy_` impl for `[fn(); 1]` requires that `fn(): ConstParamTy_` + --> $DIR/nested_bad_const_param_ty.rs:19:13 | LL | struct Foo3([fn(); 1]); | ^^^^^^^^^ = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 3 previous errors +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:6:10 + | +LL | #[derive(ConstParamTy)] + | ^^^^^^^^^^^^ +... +LL | struct Foo([*const u8; 1]); + | -------------- this field does not implement `ConstParamTy_` + | +note: the `ConstParamTy_` impl for `[*const u8; 1]` requires that `*const u8: UnsizedConstParamTy` + --> $DIR/nested_bad_const_param_ty.rs:9:12 + | +LL | struct Foo([*const u8; 1]); + | ^^^^^^^^^^^^^^ + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:11:10 + | +LL | #[derive(ConstParamTy)] + | ^^^^^^^^^^^^ +... +LL | struct Foo2([*mut u8; 1]); + | ------------ this field does not implement `ConstParamTy_` + | +note: the `ConstParamTy_` impl for `[*mut u8; 1]` requires that `*mut u8: UnsizedConstParamTy` + --> $DIR/nested_bad_const_param_ty.rs:14:13 + | +LL | struct Foo2([*mut u8; 1]); + | ^^^^^^^^^^^^ + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:16:10 + | +LL | #[derive(ConstParamTy)] + | ^^^^^^^^^^^^ +... +LL | struct Foo3([fn(); 1]); + | --------- this field does not implement `ConstParamTy_` + | +note: the `ConstParamTy_` impl for `[fn(); 1]` requires that `fn(): UnsizedConstParamTy` + --> $DIR/nested_bad_const_param_ty.rs:19:13 + | +LL | struct Foo3([fn(); 1]); + | ^^^^^^^^^ + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs b/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs index c55f3dcec68..f28bebf85db 100644 --- a/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs +++ b/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs @@ -3,7 +3,7 @@ // issues rust-lang/rust#111911 // test for ICE opaque type with non-universal region substs -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub async fn foo<const X: &'static str>() {} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs new file mode 100644 index 00000000000..a1ee1c4cdd5 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs @@ -0,0 +1,11 @@ +#![feature(adt_const_params, unsized_const_params)] +#![allow(incomplete_features)] + +use std::marker::UnsizedConstParamTy; + +struct Foo; + +impl UnsizedConstParamTy for &'static Foo {} +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr new file mode 100644 index 00000000000..5ca8e6c7516 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr @@ -0,0 +1,9 @@ +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/reference_pointee_is_const_param-1.rs:8:30 + | +LL | impl UnsizedConstParamTy for &'static Foo {} + | ^^^^^^^^^^^^ this field does not implement `ConstParamTy_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs new file mode 100644 index 00000000000..ac1b522f469 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs @@ -0,0 +1,27 @@ +#![feature(adt_const_params, unsized_const_params)] +#![allow(incomplete_features)] + +// Regression test for #119299 + +use std::marker::UnsizedConstParamTy; + +#[derive(Eq, PartialEq)] +struct ConstStrU(*const u8, usize); + +impl UnsizedConstParamTy for &'static ConstStrU {} +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type + +impl ConstStrU { + const fn from_bytes(bytes: &'static [u8]) -> Self { + Self(bytes.as_ptr(), bytes.len()) + } +} + +const fn chars_s<const S: &'static ConstStrU>() -> [char; 3] { + ['a', 'b', 'c'] +} + +fn main() { + const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc"); + chars_s::<A>(); +} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr new file mode 100644 index 00000000000..5e5f6cc642d --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr @@ -0,0 +1,9 @@ +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/reference_pointee_is_const_param-2.rs:11:30 + | +LL | impl UnsizedConstParamTy for &'static ConstStrU {} + | ^^^^^^^^^^^^^^^^^^ this field does not implement `ConstParamTy_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs index 0d2e65c45ea..33988bc0678 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs @@ -8,9 +8,8 @@ fn uwu_0<const N: &'static mut ()>() {} //~| HELP: add `#![feature(adt_const_params)]` //~| HELP: add `#![feature(adt_const_params)]` //~| HELP: add `#![feature(adt_const_params)]` -//~| HELP: add `#![feature(adt_const_params)]` -//~| HELP: add `#![feature(adt_const_params)]` -//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(unsized_const_params)]` +//~| HELP: add `#![feature(unsized_const_params)]` // Needs the feature but can be used, so suggest adding the feature. fn owo_0<const N: &'static u32>() {} diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr index cd4349623d7..aafc0640dd2 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr @@ -7,7 +7,7 @@ LL | fn uwu_0<const N: &'static mut ()>() {} = note: the only supported types are integers, `bool` and `char` error: `&'static u32` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:16:19 + --> $DIR/suggest_feature_only_when_possible.rs:15:19 | LL | fn owo_0<const N: &'static u32>() {} | ^^^^^^^^^^^^ @@ -17,9 +17,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `Meow` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:24:20 + --> $DIR/suggest_feature_only_when_possible.rs:23:20 | LL | fn meow_0<const N: Meow>() {} | ^^^^ @@ -31,7 +35,7 @@ LL + #![feature(adt_const_params)] | error: `&'static Meow` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:26:20 + --> $DIR/suggest_feature_only_when_possible.rs:25:20 | LL | fn meow_1<const N: &'static Meow>() {} | ^^^^^^^^^^^^^ @@ -41,45 +45,37 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `[Meow; 100]` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:28:20 + --> $DIR/suggest_feature_only_when_possible.rs:27:20 | LL | fn meow_2<const N: [Meow; 100]>() {} | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` -help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types - | -LL + #![feature(adt_const_params)] - | error: `(Meow, u8)` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:30:20 + --> $DIR/suggest_feature_only_when_possible.rs:29:20 | LL | fn meow_3<const N: (Meow, u8)>() {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` -help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types - | -LL + #![feature(adt_const_params)] - | error: `(Meow, String)` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:35:20 + --> $DIR/suggest_feature_only_when_possible.rs:34:20 | LL | fn meow_4<const N: (Meow, String)>() {} | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` -help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types - | -LL + #![feature(adt_const_params)] - | error: `String` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:39:19 + --> $DIR/suggest_feature_only_when_possible.rs:38:19 | LL | fn nya_0<const N: String>() {} | ^^^^^^ @@ -87,7 +83,7 @@ LL | fn nya_0<const N: String>() {} = note: the only supported types are integers, `bool` and `char` error: `Vec<u32>` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:41:19 + --> $DIR/suggest_feature_only_when_possible.rs:40:19 | LL | fn nya_1<const N: Vec<u32>>() {} | ^^^^^^^^ diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs new file mode 100644 index 00000000000..b0934508399 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs @@ -0,0 +1,13 @@ +#![feature(adt_const_params, unsized_const_params)] +#![allow(incomplete_features)] + +use std::marker::UnsizedConstParamTy; + +trait Trait {} + +impl UnsizedConstParamTy for dyn Trait {} +//~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + +fn foo<const N: dyn Trait>() {} + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr new file mode 100644 index 00000000000..9933ba6e335 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr @@ -0,0 +1,8 @@ +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/trait_objects_as_a_const_generic.rs:8:30 + | +LL | impl UnsizedConstParamTy for dyn Trait {} + | ^^^^^^^^^ type is not a structure or enumeration + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-1.rs b/tests/ui/const-generics/adt_const_params/unsized_field-1.rs new file mode 100644 index 00000000000..f6e5bd6e355 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-1.rs @@ -0,0 +1,20 @@ +//@ aux-build:unsized_const_param.rs +#![feature(adt_const_params)] + +extern crate unsized_const_param; + +use std::marker::ConstParamTy; + +#[derive(ConstParamTy, Eq, PartialEq)] +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type +struct A([u8]); + +#[derive(ConstParamTy, Eq, PartialEq)] +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type +struct B(&'static [u8]); + +#[derive(ConstParamTy, Eq, PartialEq)] +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type +struct C(unsized_const_param::Foo); + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr b/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr new file mode 100644 index 00000000000..7a4f9b99c63 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr @@ -0,0 +1,36 @@ +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/unsized_field-1.rs:8:10 + | +LL | #[derive(ConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^ +LL | +LL | struct A([u8]); + | ---- this field does not implement `ConstParamTy_` + | + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/unsized_field-1.rs:12:10 + | +LL | #[derive(ConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^ +LL | +LL | struct B(&'static [u8]); + | ------------- this field does not implement `ConstParamTy_` + | + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/unsized_field-1.rs:16:10 + | +LL | #[derive(ConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^ +LL | +LL | struct C(unsized_const_param::Foo); + | ------------------------ this field does not implement `ConstParamTy_` + | + = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-2.rs b/tests/ui/const-generics/adt_const_params/unsized_field-2.rs new file mode 100644 index 00000000000..e4a3a481b4e --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-2.rs @@ -0,0 +1,14 @@ +//@ aux-build:unsized_const_param.rs +#![feature(adt_const_params, unsized_const_params)] +//~^ WARN: the feature `unsized_const_params` is incomplete + +extern crate unsized_const_param; + +#[derive(std::marker::ConstParamTy, Eq, PartialEq)] +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type +struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>); + +#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] +struct B(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>); + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr b/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr new file mode 100644 index 00000000000..15acece538f --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr @@ -0,0 +1,28 @@ +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unsized_field-2.rs:2:30 + | +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/unsized_field-2.rs:7:10 + | +LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>); + | ---------------------------------------------------------- this field does not implement `ConstParamTy_` + | +note: the `ConstParamTy_` impl for `GenericNotUnsizedParam<&'static [u8]>` requires that `&'static [u8]: ConstParamTy_` + --> $DIR/unsized_field-2.rs:9:10 + | +LL | struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr index 1c81b14f8f5..62267224738 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -39,6 +39,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:14:15 @@ -51,6 +55,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:22:15 @@ -63,6 +71,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:26:17 @@ -75,6 +87,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:17:21 @@ -87,6 +103,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 10 previous errors diff --git a/tests/ui/const-generics/const-param-elided-lifetime.rs b/tests/ui/const-generics/const-param-elided-lifetime.rs index ef1eecb59be..e75073de98d 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.rs +++ b/tests/ui/const-generics/const-param-elided-lifetime.rs @@ -3,7 +3,7 @@ // elided lifetimes within the type of a const generic parameters to be 'static, like elided // lifetimes within const/static items. //@ revisions: full min -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct A<const N: &u8>; @@ -12,8 +12,8 @@ struct A<const N: &u8>; trait B {} impl<const N: &u8> A<N> { -//~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&u8` is forbidden + //~^ ERROR `&` without an explicit lifetime name cannot be used here + //[min]~^^ ERROR `&u8` is forbidden fn foo<const M: &u8>(&self) {} //~^ ERROR `&` without an explicit lifetime name cannot be used here //[min]~^^ ERROR `&u8` is forbidden diff --git a/tests/ui/const-generics/const-param-with-additional-obligations.rs b/tests/ui/const-generics/const-param-with-additional-obligations.rs index f53cf85cdd3..98097e86c7d 100644 --- a/tests/ui/const-generics/const-param-with-additional-obligations.rs +++ b/tests/ui/const-generics/const-param-with-additional-obligations.rs @@ -1,14 +1,14 @@ -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; #[derive(Eq, PartialEq)] struct Foo<T>(T); trait Other {} -impl<T> ConstParamTy for Foo<T> where T: Other + ConstParamTy {} +impl<T> UnsizedConstParamTy for Foo<T> where T: Other + UnsizedConstParamTy {} fn foo<const N: Foo<u8>>() {} //~^ ERROR `Foo<u8>` must implement `ConstParamTy` to be used as the type of a const generic parameter diff --git a/tests/ui/const-generics/float-generic.adt_const_params.stderr b/tests/ui/const-generics/float-generic.adt_const_params.stderr index cae4806368a..1a7c19ba4be 100644 --- a/tests/ui/const-generics/float-generic.adt_const_params.stderr +++ b/tests/ui/const-generics/float-generic.adt_const_params.stderr @@ -1,5 +1,5 @@ error[E0741]: `f32` is forbidden as the type of a const generic parameter - --> $DIR/float-generic.rs:5:17 + --> $DIR/float-generic.rs:7:17 | LL | fn foo<const F: f32>() {} | ^^^ diff --git a/tests/ui/const-generics/float-generic.full.stderr b/tests/ui/const-generics/float-generic.full.stderr new file mode 100644 index 00000000000..1a7c19ba4be --- /dev/null +++ b/tests/ui/const-generics/float-generic.full.stderr @@ -0,0 +1,9 @@ +error[E0741]: `f32` is forbidden as the type of a const generic parameter + --> $DIR/float-generic.rs:7:17 + | +LL | fn foo<const F: f32>() {} + | ^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/float-generic.rs b/tests/ui/const-generics/float-generic.rs index aaf63a93d70..f92e1667701 100644 --- a/tests/ui/const-generics/float-generic.rs +++ b/tests/ui/const-generics/float-generic.rs @@ -1,4 +1,6 @@ -//@ revisions: simple adt_const_params +//@ revisions: simple adt_const_params full +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] +#![cfg_attr(full, allow(incomplete_features))] #![cfg_attr(adt_const_params, feature(adt_const_params))] #![cfg_attr(adt_const_params, allow(incomplete_features))] diff --git a/tests/ui/const-generics/float-generic.simple.stderr b/tests/ui/const-generics/float-generic.simple.stderr index eccf9059ee3..2999bce32d6 100644 --- a/tests/ui/const-generics/float-generic.simple.stderr +++ b/tests/ui/const-generics/float-generic.simple.stderr @@ -1,5 +1,5 @@ error: `f32` is forbidden as the type of a const generic parameter - --> $DIR/float-generic.rs:5:17 + --> $DIR/float-generic.rs:7:17 | LL | fn foo<const F: f32>() {} | ^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr b/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr new file mode 100644 index 00000000000..fd9346a533e --- /dev/null +++ b/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr @@ -0,0 +1,15 @@ +error[E0741]: using function pointers as const generic parameters is forbidden + --> $DIR/fn-const-param-call.rs:13:25 + | +LL | struct Wrapper<const F: fn() -> u32>; + | ^^^^^^^^^^^ + +error[E0741]: using function pointers as const generic parameters is forbidden + --> $DIR/fn-const-param-call.rs:15:15 + | +LL | impl<const F: fn() -> u32> Wrapper<F> { + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/fn-const-param-call.full.stderr b/tests/ui/const-generics/fn-const-param-call.full.stderr index b55c2449858..fd9346a533e 100644 --- a/tests/ui/const-generics/fn-const-param-call.full.stderr +++ b/tests/ui/const-generics/fn-const-param-call.full.stderr @@ -1,11 +1,11 @@ error[E0741]: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-call.rs:11:25 + --> $DIR/fn-const-param-call.rs:13:25 | LL | struct Wrapper<const F: fn() -> u32>; | ^^^^^^^^^^^ error[E0741]: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-call.rs:13:15 + --> $DIR/fn-const-param-call.rs:15:15 | LL | impl<const F: fn() -> u32> Wrapper<F> { | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.min.stderr b/tests/ui/const-generics/fn-const-param-call.min.stderr index 2d316fba1e9..d37766b28c9 100644 --- a/tests/ui/const-generics/fn-const-param-call.min.stderr +++ b/tests/ui/const-generics/fn-const-param-call.min.stderr @@ -1,5 +1,5 @@ error: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-call.rs:11:25 + --> $DIR/fn-const-param-call.rs:13:25 | LL | struct Wrapper<const F: fn() -> u32>; | ^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Wrapper<const F: fn() -> u32>; = note: the only supported types are integers, `bool` and `char` error: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-call.rs:13:15 + --> $DIR/fn-const-param-call.rs:15:15 | LL | impl<const F: fn() -> u32> Wrapper<F> { | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.rs b/tests/ui/const-generics/fn-const-param-call.rs index ce780143178..d536c240239 100644 --- a/tests/ui/const-generics/fn-const-param-call.rs +++ b/tests/ui/const-generics/fn-const-param-call.rs @@ -1,8 +1,10 @@ // Check that functions cannot be used as const parameters. -//@ revisions: full min +//@ revisions: min adt_const_params full -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] fn function() -> u32 { 17 @@ -11,7 +13,7 @@ fn function() -> u32 { struct Wrapper<const F: fn() -> u32>; //~ ERROR: using function pointers as const generic parameters impl<const F: fn() -> u32> Wrapper<F> { -//~^ ERROR: using function pointers as const generic parameters + //~^ ERROR: using function pointers as const generic parameters fn call() -> u32 { F() } diff --git a/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr new file mode 100644 index 00000000000..54f3bff172a --- /dev/null +++ b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr @@ -0,0 +1,30 @@ +error[E0741]: using function pointers as const generic parameters is forbidden + --> $DIR/fn-const-param-infer.rs:8:25 + | +LL | struct Checked<const F: fn(usize) -> bool>; + | ^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/fn-const-param-infer.rs:33:25 + | +LL | let _ = Checked::<{ generic_arg::<u32> }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item + | + = note: expected fn pointer `fn(usize) -> _` + found fn item `fn(u32) -> _ {generic_arg::<u32>}` + +error[E0282]: type annotations needed + --> $DIR/fn-const-param-infer.rs:35:23 + | +LL | let _ = Checked::<generic>; + | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` + | +help: consider specifying the generic argument + | +LL | let _ = Checked::<generic::<T>>; + | +++++ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0282, E0308, E0741. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/fn-const-param-infer.full.stderr b/tests/ui/const-generics/fn-const-param-infer.full.stderr index 753558636e1..54f3bff172a 100644 --- a/tests/ui/const-generics/fn-const-param-infer.full.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.full.stderr @@ -1,20 +1,20 @@ error[E0741]: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-infer.rs:6:25 + --> $DIR/fn-const-param-infer.rs:8:25 | LL | struct Checked<const F: fn(usize) -> bool>; | ^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/fn-const-param-infer.rs:23:24 + --> $DIR/fn-const-param-infer.rs:33:25 | -LL | let _ = Checked::<{generic_arg::<u32>}>; - | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item +LL | let _ = Checked::<{ generic_arg::<u32> }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item | = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::<u32>}` error[E0282]: type annotations needed - --> $DIR/fn-const-param-infer.rs:25:23 + --> $DIR/fn-const-param-infer.rs:35:23 | LL | let _ = Checked::<generic>; | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` diff --git a/tests/ui/const-generics/fn-const-param-infer.min.stderr b/tests/ui/const-generics/fn-const-param-infer.min.stderr index 01e224f8d9c..4da503d344a 100644 --- a/tests/ui/const-generics/fn-const-param-infer.min.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.min.stderr @@ -1,5 +1,5 @@ error: using function pointers as const generic parameters is forbidden - --> $DIR/fn-const-param-infer.rs:6:25 + --> $DIR/fn-const-param-infer.rs:8:25 | LL | struct Checked<const F: fn(usize) -> bool>; | ^^^^^^^^^^^^^^^^^ @@ -7,16 +7,16 @@ LL | struct Checked<const F: fn(usize) -> bool>; = note: the only supported types are integers, `bool` and `char` error[E0308]: mismatched types - --> $DIR/fn-const-param-infer.rs:23:24 + --> $DIR/fn-const-param-infer.rs:33:25 | -LL | let _ = Checked::<{generic_arg::<u32>}>; - | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item +LL | let _ = Checked::<{ generic_arg::<u32> }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item | = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::<u32>}` error[E0282]: type annotations needed - --> $DIR/fn-const-param-infer.rs:25:23 + --> $DIR/fn-const-param-infer.rs:35:23 | LL | let _ = Checked::<generic>; | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` diff --git a/tests/ui/const-generics/fn-const-param-infer.rs b/tests/ui/const-generics/fn-const-param-infer.rs index ed0bb9f7217..5f1958df26e 100644 --- a/tests/ui/const-generics/fn-const-param-infer.rs +++ b/tests/ui/const-generics/fn-const-param-infer.rs @@ -1,17 +1,27 @@ -//@ revisions: full min +//@ revisions: min adt_const_params full -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Checked<const F: fn(usize) -> bool>; //~^ ERROR: using function pointers as const generic parameters -fn not_one(val: usize) -> bool { val != 1 } -fn not_two(val: usize) -> bool { val != 2 } +fn not_one(val: usize) -> bool { + val != 1 +} +fn not_two(val: usize) -> bool { + val != 2 +} -fn generic_arg<T>(val: T) -> bool { true } +fn generic_arg<T>(val: T) -> bool { + true +} -fn generic<T>(val: usize) -> bool { val != 1 } +fn generic<T>(val: usize) -> bool { + val != 1 +} fn main() { let _: Option<Checked<not_one>> = None; @@ -19,11 +29,11 @@ fn main() { let _: Checked<not_one> = Checked::<not_two>; let _ = Checked::<generic_arg>; - let _ = Checked::<{generic_arg::<usize>}>; - let _ = Checked::<{generic_arg::<u32>}>; //~ ERROR: mismatched types + let _ = Checked::<{ generic_arg::<usize> }>; + let _ = Checked::<{ generic_arg::<u32> }>; //~ ERROR: mismatched types let _ = Checked::<generic>; //~ ERROR: type annotations needed - let _ = Checked::<{generic::<u16>}>; - let _: Checked<{generic::<u16>}> = Checked::<{generic::<u16>}>; - let _: Checked<{generic::<u32>}> = Checked::<{generic::<u16>}>; + let _ = Checked::<{ generic::<u16> }>; + let _: Checked<{ generic::<u16> }> = Checked::<{ generic::<u16> }>; + let _: Checked<{ generic::<u32> }> = Checked::<{ generic::<u16> }>; } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-100360.rs b/tests/ui/const-generics/generic_const_exprs/issue-100360.rs index b7e677a4a1e..37f015d5e0f 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-100360.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-100360.rs @@ -1,7 +1,7 @@ //@ check-pass // (this requires debug assertions) -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] fn foo<const B: &'static bool>(arg: &'static bool) -> bool { diff --git a/tests/ui/const-generics/generic_const_exprs/issue-89851.rs b/tests/ui/const-generics/generic_const_exprs/issue-89851.rs index 78189c5225c..f93ba30856d 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-89851.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-89851.rs @@ -1,7 +1,7 @@ //@ check-pass // (this requires debug assertions) -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub const BAR: () = ice::<"">(); diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs index 5a6565fe2f1..443d0a2fe87 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs @@ -1,7 +1,7 @@ //@ check-pass -#![feature(adt_const_params, generic_const_exprs)] -//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] +//~^ WARN the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] //~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] pub struct Changes<const CHANGES: &'static [&'static str]> @@ -16,9 +16,7 @@ where [(); CHANGES.len()]:, { pub const fn new() -> Self { - Self { - changes: [0; CHANGES.len()], - } + Self { changes: [0; CHANGES.len()] } } } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr index 1cceaece715..b6b297593a2 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr @@ -1,17 +1,17 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-1.rs:3:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-97047-ice-1.rs:3:30 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information = note: `#[warn(incomplete_features)]` on by default warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-1.rs:3:30 + --> $DIR/issue-97047-ice-1.rs:3:52 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs index 1338f40208c..6a91b522567 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs @@ -1,7 +1,7 @@ //@ check-pass -#![feature(adt_const_params, generic_const_exprs)] -//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] +//~^ WARN the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] //~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] pub struct Changes<const CHANGES: &'static [&'static str]> diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr index 774e842bcbe..c0c7dcc79dc 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr @@ -1,17 +1,17 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-2.rs:3:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-97047-ice-2.rs:3:30 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information = note: `#[warn(incomplete_features)]` on by default warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-2.rs:3:30 + --> $DIR/issue-97047-ice-2.rs:3:52 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information diff --git a/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs b/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs index 5673f1dd073..ffa9d960e04 100644 --- a/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs +++ b/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs @@ -7,7 +7,8 @@ pub fn foo() where for<const N: usize = { const fn bar() {} bar(); 1 }> ():, - //~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~^ ERROR late-bound const parameters cannot be used currently + //~| ERROR defaults for generic parameters are not allowed in `for<...>` binders {} fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.stderr b/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.stderr index 5924a673da9..814022f26b9 100644 --- a/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.stderr +++ b/tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.stderr @@ -1,8 +1,14 @@ +error: late-bound const parameters cannot be used currently + --> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:15 + | +LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():, + | ^ + error: defaults for generic parameters are not allowed in `for<...>` binders --> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:9 | LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index 5e4acd80e93..2a6d9f53317 100644 --- a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -1,14 +1,14 @@ error: generic parameters may not be used in const operations - --> $DIR/intrinsics-type_name-as-const-argument.rs:15:44 + --> $DIR/intrinsics-type_name-as-const-argument.rs:14:45 | -LL | T: Trait<{std::intrinsics::type_name::<T>()}> - | ^ cannot perform const operation using `T` +LL | T: Trait<{ std::intrinsics::type_name::<T>() }>, + | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/intrinsics-type_name-as-const-argument.rs:10:22 + --> $DIR/intrinsics-type_name-as-const-argument.rs:9:22 | LL | trait Trait<const S: &'static str> {} | ^^^^^^^^^^^^ @@ -18,6 +18,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs index 02e6d27a27e..79c20fe81e3 100644 --- a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs +++ b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs @@ -2,8 +2,7 @@ //@ revisions: full min #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(adt_const_params, generic_const_exprs))] - +#![cfg_attr(full, feature(adt_const_params, unsized_const_params, generic_const_exprs))] #![feature(core_intrinsics)] #![feature(const_type_name)] @@ -12,10 +11,10 @@ trait Trait<const S: &'static str> {} struct Bug<T> where - T: Trait<{std::intrinsics::type_name::<T>()}> + T: Trait<{ std::intrinsics::type_name::<T>() }>, //[min]~^ ERROR generic parameters may not be used in const operations { - t: T + t: T, } fn main() {} diff --git a/tests/ui/const-generics/issue-66451.rs b/tests/ui/const-generics/issue-66451.rs index c8d5515e987..0b8693e0e67 100644 --- a/tests/ui/const-generics/issue-66451.rs +++ b/tests/ui/const-generics/issue-66451.rs @@ -1,30 +1,20 @@ -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; -#[derive(Debug, PartialEq, Eq, ConstParamTy)] +#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)] struct Foo { value: i32, nested: &'static Bar<i32>, } -#[derive(Debug, PartialEq, Eq, ConstParamTy)] +#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)] struct Bar<T>(T); struct Test<const F: Foo>; fn main() { - let x: Test<{ - Foo { - value: 3, - nested: &Bar(4), - } - }> = Test; - let y: Test<{ - Foo { - value: 3, - nested: &Bar(5), - } - }> = x; //~ ERROR mismatched types + let x: Test<{ Foo { value: 3, nested: &Bar(4) } }> = Test; + let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x; //~ ERROR mismatched types } diff --git a/tests/ui/const-generics/issue-66451.stderr b/tests/ui/const-generics/issue-66451.stderr index 404e3839bca..63d193e1bca 100644 --- a/tests/ui/const-generics/issue-66451.stderr +++ b/tests/ui/const-generics/issue-66451.stderr @@ -1,16 +1,10 @@ error[E0308]: mismatched types - --> $DIR/issue-66451.rs:29:10 + --> $DIR/issue-66451.rs:19:58 | -LL | let y: Test<{ - | ____________- -LL | | Foo { -LL | | value: 3, -LL | | nested: &Bar(5), -LL | | } -LL | | }> = x; - | | - ^ expected `Foo { value: 3, nested: &Bar::<i32>(5) }`, found `Foo { value: 3, nested: &Bar::<i32>(4) }` - | |______| - | expected due to this +LL | let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x; + | ------------------------------------------- ^ expected `Foo { value: 3, nested: &Bar::<i32>(5) }`, found `Foo { value: 3, nested: &Bar::<i32>(4) }` + | | + | expected due to this | = note: expected struct `Test<Foo { value: 3, nested: &Bar::<i32>(5) }>` found struct `Test<Foo { value: 3, nested: &Bar::<i32>(4) }>` diff --git a/tests/ui/const-generics/issue-70408.rs b/tests/ui/const-generics/issue-70408.rs index e74bcf945a5..ea7a57d3b2f 100644 --- a/tests/ui/const-generics/issue-70408.rs +++ b/tests/ui/const-generics/issue-70408.rs @@ -1,6 +1,6 @@ //@ build-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] { diff --git a/tests/ui/const-generics/issue-80471.rs b/tests/ui/const-generics/issue-80471.rs index fa6f1fde435..20d92092b9f 100644 --- a/tests/ui/const-generics/issue-80471.rs +++ b/tests/ui/const-generics/issue-80471.rs @@ -1,5 +1,4 @@ #![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] #[derive(PartialEq, Eq)] enum Nat { diff --git a/tests/ui/const-generics/issue-80471.stderr b/tests/ui/const-generics/issue-80471.stderr index b21ad3aec79..a8514c5cc07 100644 --- a/tests/ui/const-generics/issue-80471.stderr +++ b/tests/ui/const-generics/issue-80471.stderr @@ -1,14 +1,5 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-80471.rs:1:12 - | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information - = note: `#[warn(incomplete_features)]` on by default - error[E0741]: `Nat` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/issue-80471.rs:10:17 + --> $DIR/issue-80471.rs:9:17 | LL | fn foo<const N: Nat>() {} | ^^^ @@ -19,6 +10,6 @@ LL + #[derive(ConstParamTy)] LL | enum Nat { | -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/issues/issue-100313.rs b/tests/ui/const-generics/issues/issue-100313.rs index 4e9d3626aa8..e07fde76a4a 100644 --- a/tests/ui/const-generics/issues/issue-100313.rs +++ b/tests/ui/const-generics/issues/issue-100313.rs @@ -1,10 +1,10 @@ #![allow(incomplete_features)] #![feature(const_mut_refs)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] struct T<const B: &'static bool>; -impl <const B: &'static bool> T<B> { +impl<const B: &'static bool> T<B> { const fn set_false(&self) { unsafe { *(B as *const bool as *mut bool) = false; @@ -14,7 +14,7 @@ impl <const B: &'static bool> T<B> { } const _: () = { - let x = T::<{&true}>; + let x = T::<{ &true }>; x.set_false(); }; diff --git a/tests/ui/const-generics/issues/issue-105821.rs b/tests/ui/const-generics/issues/issue-105821.rs index ecbae4d9f35..3092893837a 100644 --- a/tests/ui/const-generics/issues/issue-105821.rs +++ b/tests/ui/const-generics/issues/issue-105821.rs @@ -4,7 +4,7 @@ // a failing test, we just started masking the bug. #![allow(incomplete_features)] -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(dead_code)] const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1] diff --git a/tests/ui/const-generics/issues/issue-56445-1.min.stderr b/tests/ui/const-generics/issues/issue-56445-1.min.stderr index 580542bb6da..ff0a1bfc0b5 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.min.stderr +++ b/tests/ui/const-generics/issues/issue-56445-1.min.stderr @@ -17,6 +17,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-56445-1.rs b/tests/ui/const-generics/issues/issue-56445-1.rs index 35126b3f55a..53aab40b0ad 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.rs +++ b/tests/ui/const-generics/issues/issue-56445-1.rs @@ -1,6 +1,6 @@ // Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995. //@ revisions: full min -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] #![crate_type = "lib"] diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr index 5082705927e..8ea96428deb 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr @@ -4,7 +4,7 @@ error[E0741]: `&'static (dyn A + 'static)` can't be used as a const parameter ty LL | fn test<const T: &'static dyn A>() { | ^^^^^^^^^^^^^^ | - = note: `(dyn A + 'static)` must implement `ConstParamTy`, but it does not + = note: `(dyn A + 'static)` must implement `UnsizedConstParamTy`, but it does not error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr index 7f387cbd5a1..101ca456cd9 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs index c5b83e9d529..9b15a8a7013 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs @@ -1,5 +1,5 @@ //@ revisions: full min -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] trait A {} diff --git a/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs b/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs index 113bf94b5cb..41c5eaa0cd9 100644 --- a/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs +++ b/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs @@ -1,8 +1,7 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] - trait Trait<const NAME: &'static str> { type Assoc; } diff --git a/tests/ui/const-generics/issues/issue-71547.rs b/tests/ui/const-generics/issues/issue-71547.rs index a2cea433a44..bb9ca63bd32 100644 --- a/tests/ui/const-generics/issues/issue-71547.rs +++ b/tests/ui/const-generics/issues/issue-71547.rs @@ -1,6 +1,6 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub trait GetType<const N: &'static str> { diff --git a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr index e9363d42148..cba03b1cb1f 100644 --- a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr +++ b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs index 701b3423f31..fcab1f70507 100644 --- a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs +++ b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs @@ -3,12 +3,12 @@ //@ revisions: full min //@[full]check-pass -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] fn a<const X: &'static [u32]>() {} //[min]~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter fn main() { - a::<{&[]}>(); + a::<{ &[] }>(); } diff --git a/tests/ui/const-generics/issues/issue-86535-2.rs b/tests/ui/const-generics/issues/issue-86535-2.rs index bd9431dbc85..ab68c6b78df 100644 --- a/tests/ui/const-generics/issues/issue-86535-2.rs +++ b/tests/ui/const-generics/issues/issue-86535-2.rs @@ -1,10 +1,12 @@ //@ run-pass -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(incomplete_features)] pub trait Foo { const ASSOC_C: usize; - fn foo() where [(); Self::ASSOC_C]:; + fn foo() + where + [(); Self::ASSOC_C]:; } #[allow(dead_code)] @@ -12,7 +14,10 @@ struct Bar<const N: &'static ()>; impl<const N: &'static ()> Foo for Bar<N> { const ASSOC_C: usize = 3; - fn foo() where [u8; Self::ASSOC_C]: { + fn foo() + where + [u8; Self::ASSOC_C]:, + { let _: [u8; Self::ASSOC_C] = loop {}; } } diff --git a/tests/ui/const-generics/issues/issue-86535.rs b/tests/ui/const-generics/issues/issue-86535.rs index cd9934a4a99..9aaf7ddc9e8 100644 --- a/tests/ui/const-generics/issues/issue-86535.rs +++ b/tests/ui/const-generics/issues/issue-86535.rs @@ -1,5 +1,5 @@ //@ run-pass -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(incomplete_features, unused_variables)] #[allow(dead_code)] diff --git a/tests/ui/const-generics/issues/issue-90455.fixed b/tests/ui/const-generics/issues/issue-90455.fixed index 2502d47eb46..423a1fbd765 100644 --- a/tests/ui/const-generics/issues/issue-90455.fixed +++ b/tests/ui/const-generics/issues/issue-90455.fixed @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(generic_const_exprs, adt_const_params)] +#![feature(generic_const_exprs, unsized_const_params, adt_const_params)] #![allow(incomplete_features, dead_code)] struct FieldElement<const N: &'static str> where [(); num_limbs(N)]: { diff --git a/tests/ui/const-generics/issues/issue-90455.rs b/tests/ui/const-generics/issues/issue-90455.rs index 794c7d76cb1..be4f27ec689 100644 --- a/tests/ui/const-generics/issues/issue-90455.rs +++ b/tests/ui/const-generics/issues/issue-90455.rs @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(generic_const_exprs, adt_const_params)] +#![feature(generic_const_exprs, unsized_const_params, adt_const_params)] #![allow(incomplete_features, dead_code)] struct FieldElement<const N: &'static str> { diff --git a/tests/ui/const-generics/issues/issue-99641.stderr b/tests/ui/const-generics/issues/issue-99641.stderr index 800aec3ef2c..3365012a038 100644 --- a/tests/ui/const-generics/issues/issue-99641.stderr +++ b/tests/ui/const-generics/issues/issue-99641.stderr @@ -4,7 +4,7 @@ error[E0741]: `(fn(),)` can't be used as a const parameter type LL | pub struct Color<const WHITE: (fn(),)>; | ^^^^^^^ | - = note: `fn()` must implement `ConstParamTy`, but it does not + = note: `fn()` must implement `ConstParamTy_`, but it does not error[E0741]: `(fn(),)` can't be used as a const parameter type --> $DIR/issue-99641.rs:8:23 @@ -12,7 +12,7 @@ error[E0741]: `(fn(),)` can't be used as a const parameter type LL | impl<const WHITE: (fn(),)> Color<WHITE> { | ^^^^^^^ | - = note: `fn()` must implement `ConstParamTy`, but it does not + = note: `fn()` must implement `ConstParamTy_`, but it does not error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/min_const_generics/complex-types.stderr b/tests/ui/const-generics/min_const_generics/complex-types.stderr index 8e83ea58194..0211770f9e5 100644 --- a/tests/ui/const-generics/min_const_generics/complex-types.stderr +++ b/tests/ui/const-generics/min_const_generics/complex-types.stderr @@ -45,6 +45,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `!` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:17:21 diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr new file mode 100644 index 00000000000..18f47f7dc23 --- /dev/null +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr @@ -0,0 +1,15 @@ +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param-deref.rs:11:23 + | +LL | struct Const<const P: *const u32>; + | ^^^^^^^^^^ + +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param-deref.rs:13:15 + | +LL | impl<const P: *const u32> Const<P> { + | ^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr index 657eee2be24..18f47f7dc23 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr @@ -1,11 +1,11 @@ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:9:23 + --> $DIR/raw-ptr-const-param-deref.rs:11:23 | LL | struct Const<const P: *const u32>; | ^^^^^^^^^^ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:11:15 + --> $DIR/raw-ptr-const-param-deref.rs:13:15 | LL | impl<const P: *const u32> Const<P> { | ^^^^^^^^^^ diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr index 1eb238255ab..6027dbb01cd 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr @@ -1,5 +1,5 @@ error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:9:23 + --> $DIR/raw-ptr-const-param-deref.rs:11:23 | LL | struct Const<const P: *const u32>; | ^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Const<const P: *const u32>; = note: the only supported types are integers, `bool` and `char` error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:11:15 + --> $DIR/raw-ptr-const-param-deref.rs:13:15 | LL | impl<const P: *const u32> Const<P> { | ^^^^^^^^^^ diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.rs b/tests/ui/const-generics/raw-ptr-const-param-deref.rs index b7fcbb3447a..bf077acd4fa 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.rs +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.rs @@ -1,21 +1,22 @@ // Checks that pointers must not be used as the type of const params. -//@ revisions: full min +//@ revisions: min adt_const_params full -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] const A: u32 = 3; struct Const<const P: *const u32>; //~ ERROR: using raw pointers as const generic parameters -impl<const P: *const u32> Const<P> { //~ ERROR: using raw pointers as const generic parameters +impl<const P: *const u32> Const<P> { + //~^ ERROR: using raw pointers as const generic parameters fn get() -> u32 { - unsafe { - *P - } + unsafe { *P } } } fn main() { - assert_eq!(Const::<{&A as *const _}>::get(), 3) + assert_eq!(Const::<{ &A as *const _ }>::get(), 3) } diff --git a/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr b/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr new file mode 100644 index 00000000000..f040d3cc36a --- /dev/null +++ b/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr @@ -0,0 +1,21 @@ +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param.rs:8:23 + | +LL | struct Const<const P: *const u32>; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/raw-ptr-const-param.rs:11:40 + | +LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; + | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` + | | + | expected due to this + | + = note: expected struct `Const<{0xf as *const u32}>` + found struct `Const<{0xa as *const u32}>` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0741. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/raw-ptr-const-param.full.stderr b/tests/ui/const-generics/raw-ptr-const-param.full.stderr index 7ba9ac15bf3..f040d3cc36a 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.full.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param.full.stderr @@ -1,11 +1,11 @@ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param.rs:6:23 + --> $DIR/raw-ptr-const-param.rs:8:23 | LL | struct Const<const P: *const u32>; | ^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/raw-ptr-const-param.rs:9:40 + --> $DIR/raw-ptr-const-param.rs:11:40 | LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` diff --git a/tests/ui/const-generics/raw-ptr-const-param.min.stderr b/tests/ui/const-generics/raw-ptr-const-param.min.stderr index 18bbcc33c4d..c48eea069e0 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.min.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param.min.stderr @@ -1,5 +1,5 @@ error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param.rs:6:23 + --> $DIR/raw-ptr-const-param.rs:8:23 | LL | struct Const<const P: *const u32>; | ^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Const<const P: *const u32>; = note: the only supported types are integers, `bool` and `char` error[E0308]: mismatched types - --> $DIR/raw-ptr-const-param.rs:9:40 + --> $DIR/raw-ptr-const-param.rs:11:40 | LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` diff --git a/tests/ui/const-generics/raw-ptr-const-param.rs b/tests/ui/const-generics/raw-ptr-const-param.rs index 19d18a2f9d2..49e48d9905f 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.rs +++ b/tests/ui/const-generics/raw-ptr-const-param.rs @@ -1,7 +1,9 @@ -//@ revisions: full min +//@ revisions: min adt_const_params full -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Const<const P: *const u32>; //~ ERROR: using raw pointers as const generic parameters diff --git a/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr b/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr new file mode 100644 index 00000000000..bcb2bd255da --- /dev/null +++ b/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr @@ -0,0 +1,49 @@ +error[E0741]: `&'static str` can't be used as a const parameter type + --> $DIR/slice-const-param-mismatch.rs:8:29 + | +LL | struct ConstString<const T: &'static str>; + | ^^^^^^^^^^^^ + +error[E0741]: `&'static [u8]` can't be used as a const parameter type + --> $DIR/slice-const-param-mismatch.rs:11:28 + | +LL | struct ConstBytes<const T: &'static [u8]>; + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:17:35 + | +LL | let _: ConstString<"Hello"> = ConstString::<"World">; + | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` + | | + | expected due to this + | + = note: expected struct `ConstString<"Hello">` + found struct `ConstString<"World">` + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:19:33 + | +LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; + | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` + | | + | expected due to this + | + = note: expected struct `ConstString<"ℇ㇈↦">` + found struct `ConstString<"ℇ㇈↥">` + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:21:33 + | +LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; + | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` + | | + | expected due to this + | + = note: expected struct `ConstBytes<b"AAA">` + found struct `ConstBytes<b"BBB">` + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0308, E0741. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/slice-const-param-mismatch.full.stderr b/tests/ui/const-generics/slice-const-param-mismatch.full.stderr index 80dd1be33c2..883ba988be7 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.full.stderr +++ b/tests/ui/const-generics/slice-const-param-mismatch.full.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:14:35 + --> $DIR/slice-const-param-mismatch.rs:17:35 | LL | let _: ConstString<"Hello"> = ConstString::<"World">; | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` @@ -10,7 +10,7 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">; found struct `ConstString<"World">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:16:33 + --> $DIR/slice-const-param-mismatch.rs:19:33 | LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` @@ -21,7 +21,7 @@ LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; found struct `ConstString<"ℇ㇈↥">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:18:33 + --> $DIR/slice-const-param-mismatch.rs:21:33 | LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` diff --git a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr index 0650dafc685..3b2410c9894 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr +++ b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr @@ -1,5 +1,5 @@ error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param-mismatch.rs:7:29 + --> $DIR/slice-const-param-mismatch.rs:8:29 | LL | struct ConstString<const T: &'static str>; | ^^^^^^^^^^^^ @@ -9,9 +9,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&'static [u8]` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param-mismatch.rs:9:28 + --> $DIR/slice-const-param-mismatch.rs:11:28 | LL | struct ConstBytes<const T: &'static [u8]>; | ^^^^^^^^^^^^^ @@ -21,9 +25,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:14:35 + --> $DIR/slice-const-param-mismatch.rs:17:35 | LL | let _: ConstString<"Hello"> = ConstString::<"World">; | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` @@ -34,7 +42,7 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">; found struct `ConstString<"World">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:16:33 + --> $DIR/slice-const-param-mismatch.rs:19:33 | LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` @@ -45,7 +53,7 @@ LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; found struct `ConstString<"ℇ㇈↥">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:18:33 + --> $DIR/slice-const-param-mismatch.rs:21:33 | LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` diff --git a/tests/ui/const-generics/slice-const-param-mismatch.rs b/tests/ui/const-generics/slice-const-param-mismatch.rs index 733eeb69fa9..feee39e602d 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.rs +++ b/tests/ui/const-generics/slice-const-param-mismatch.rs @@ -1,19 +1,22 @@ -//@ revisions: full min +//@ revisions: min adt_const_params full -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] - +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct ConstString<const T: &'static str>; //[min]~^ ERROR +//[adt_const_params]~^^ ERROR struct ConstBytes<const T: &'static [u8]>; //[min]~^ ERROR +//[adt_const_params]~^^ ERROR pub fn main() { let _: ConstString<"Hello"> = ConstString::<"Hello">; let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">; let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types - let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>; + let _: ConstBytes<b"AAA"> = ConstBytes::<{ &[0x41, 0x41, 0x41] }>; let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types } diff --git a/tests/ui/const-generics/slice-const-param.rs b/tests/ui/const-generics/slice-const-param.rs index c6c0047c929..1c5088b5283 100644 --- a/tests/ui/const-generics/slice-const-param.rs +++ b/tests/ui/const-generics/slice-const-param.rs @@ -1,6 +1,6 @@ //@ run-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_str<const STRING: &'static str>() -> &'static str { @@ -12,9 +12,8 @@ pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] { } // Also check the codepaths for custom DST -#[derive(PartialEq, Eq)] +#[derive(std::marker::UnsizedConstParamTy, PartialEq, Eq)] struct MyStr(str); -impl std::marker::ConstParamTy for MyStr {} fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr { S @@ -34,7 +33,7 @@ pub fn main() { assert_eq!(function_with_str::<"Rust">(), "Rust"); assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦"); assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]); - assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA"); + assert_eq!(function_with_bytes::<{ &[0x41, 0x41, 0x41, 0x41] }>(), b"AAAA"); assert_eq!(function_with_my_str::<{ MyStr::new("hello") }>().as_str(), "hello"); } diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr b/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr new file mode 100644 index 00000000000..7a936ced030 --- /dev/null +++ b/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr @@ -0,0 +1,9 @@ +error[E0741]: `&'static ()` can't be used as a const parameter type + --> $DIR/transmute-const-param-static-reference.rs:9:23 + | +LL | struct Const<const P: &'static ()>; + | ^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr index fdb6ddeb578..cf236487cf0 100644 --- a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr +++ b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr @@ -1,5 +1,5 @@ error: `&'static ()` is forbidden as the type of a const generic parameter - --> $DIR/transmute-const-param-static-reference.rs:7:23 + --> $DIR/transmute-const-param-static-reference.rs:9:23 | LL | struct Const<const P: &'static ()>; | ^^^^^^^^^^^ @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.rs b/tests/ui/const-generics/transmute-const-param-static-reference.rs index 49541233ed1..0b47fd31eaf 100644 --- a/tests/ui/const-generics/transmute-const-param-static-reference.rs +++ b/tests/ui/const-generics/transmute-const-param-static-reference.rs @@ -1,16 +1,17 @@ -//@ revisions: full min +//@ revisions: full adt_const_params min //@[full] check-pass -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Const<const P: &'static ()>; //[min]~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter +//[adt_const_params]~^^ ERROR `&'static ()` can't be used as a const parameter type fn main() { - const A: &'static () = unsafe { - std::mem::transmute(10 as *const ()) - }; + const A: &'static () = unsafe { std::mem::transmute(10 as *const ()) }; - let _ = Const::<{A}>; + let _ = Const::<{ A }>; } diff --git a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr index f42a331a8a4..858900a500d 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:18:25 @@ -21,6 +25,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/type-dependent/issue-71348.rs b/tests/ui/const-generics/type-dependent/issue-71348.rs index f349a88d124..2ffbd015485 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.rs +++ b/tests/ui/const-generics/type-dependent/issue-71348.rs @@ -1,6 +1,6 @@ //@ [full] run-pass //@ revisions: full min -#![cfg_attr(full, feature(adt_const_params))] +#![cfg_attr(full, feature(adt_const_params, unsized_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Foo { diff --git a/tests/ui/consts/const_refs_to_static.rs b/tests/ui/consts/const_refs_to_static.rs index 1baa8535b2c..f41725b786e 100644 --- a/tests/ui/consts/const_refs_to_static.rs +++ b/tests/ui/consts/const_refs_to_static.rs @@ -9,7 +9,7 @@ const C1: &i32 = &S; const C1_READ: () = { assert!(*C1 == 0); }; -const C2: *const i32 = unsafe { std::ptr::addr_of!(S_MUT) }; +const C2: *const i32 = std::ptr::addr_of!(S_MUT); fn main() { assert_eq!(*C1, 0); diff --git a/tests/ui/consts/mut-ptr-to-static.rs b/tests/ui/consts/mut-ptr-to-static.rs index d8a788bb37d..e921365c7d4 100644 --- a/tests/ui/consts/mut-ptr-to-static.rs +++ b/tests/ui/consts/mut-ptr-to-static.rs @@ -16,12 +16,9 @@ static mut STATIC: u32 = 42; static INTERIOR_MUTABLE_STATIC: SyncUnsafeCell<u32> = SyncUnsafeCell::new(42); // A static that mutably points to STATIC. -static PTR: SyncPtr = SyncPtr { - foo: unsafe { ptr::addr_of_mut!(STATIC) }, -}; -static INTERIOR_MUTABLE_PTR: SyncPtr = SyncPtr { - foo: ptr::addr_of!(INTERIOR_MUTABLE_STATIC) as *mut u32, -}; +static PTR: SyncPtr = SyncPtr { foo: ptr::addr_of_mut!(STATIC) }; +static INTERIOR_MUTABLE_PTR: SyncPtr = + SyncPtr { foo: ptr::addr_of!(INTERIOR_MUTABLE_STATIC) as *mut u32 }; fn main() { let ptr = PTR.foo; diff --git a/tests/ui/consts/packed_pattern.stderr b/tests/ui/consts/packed_pattern.stderr index 9ca50a95e4e..a0b434b2d78 100644 --- a/tests/ui/consts/packed_pattern.stderr +++ b/tests/ui/consts/packed_pattern.stderr @@ -1,8 +1,10 @@ warning: unreachable pattern --> $DIR/packed_pattern.rs:16:9 | +LL | Foo { field: (5, 6, 7, 8) } => {}, + | --------------------------- matches all the values already LL | FOO => unreachable!(), - | ^^^ + | ^^^ unreachable pattern | = note: `#[warn(unreachable_patterns)]` on by default diff --git a/tests/ui/consts/packed_pattern2.stderr b/tests/ui/consts/packed_pattern2.stderr index 4dc54461eeb..4785f4d0297 100644 --- a/tests/ui/consts/packed_pattern2.stderr +++ b/tests/ui/consts/packed_pattern2.stderr @@ -1,8 +1,10 @@ warning: unreachable pattern --> $DIR/packed_pattern2.rs:24:9 | +LL | Bar { a: Foo { field: (5, 6) } } => {}, + | -------------------------------- matches all the values already LL | FOO => unreachable!(), - | ^^^ + | ^^^ unreachable pattern | = note: `#[warn(unreachable_patterns)]` on by default diff --git a/tests/ui/consts/refs_check_const_eq-issue-88384.rs b/tests/ui/consts/refs_check_const_eq-issue-88384.rs index fb0405b651c..46cb6275171 100644 --- a/tests/ui/consts/refs_check_const_eq-issue-88384.rs +++ b/tests/ui/consts/refs_check_const_eq-issue-88384.rs @@ -1,10 +1,10 @@ #![feature(fn_traits)] -#![feature(adt_const_params)] -//~^ WARNING the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARNING the feature `unsized_const_params` is incomplete #[derive(PartialEq, Eq)] -struct CompileTimeSettings{ - hooks: &'static[fn()], +struct CompileTimeSettings { + hooks: &'static [fn()], } struct Foo<const T: CompileTimeSettings>; @@ -12,14 +12,11 @@ struct Foo<const T: CompileTimeSettings>; impl<const T: CompileTimeSettings> Foo<T> { //~^ ERROR `CompileTimeSettings` must implement `ConstParamTy` to be used as the type of a const generic parameter - fn call_hooks(){ - } + fn call_hooks() {} } -fn main(){ - const SETTINGS: CompileTimeSettings = CompileTimeSettings{ - hooks: &[], - }; +fn main() { + const SETTINGS: CompileTimeSettings = CompileTimeSettings { hooks: &[] }; Foo::<SETTINGS>::call_hooks(); } diff --git a/tests/ui/consts/refs_check_const_eq-issue-88384.stderr b/tests/ui/consts/refs_check_const_eq-issue-88384.stderr index c490cd053e7..62c5c527641 100644 --- a/tests/ui/consts/refs_check_const_eq-issue-88384.stderr +++ b/tests/ui/consts/refs_check_const_eq-issue-88384.stderr @@ -1,8 +1,8 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/refs_check_const_eq-issue-88384.rs:2:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/refs_check_const_eq-issue-88384.rs:2:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information = note: `#[warn(incomplete_features)]` on by default @@ -16,7 +16,7 @@ LL | struct Foo<const T: CompileTimeSettings>; help: add `#[derive(ConstParamTy)]` to the struct | LL + #[derive(ConstParamTy)] -LL | struct CompileTimeSettings{ +LL | struct CompileTimeSettings { | error[E0741]: `CompileTimeSettings` must implement `ConstParamTy` to be used as the type of a const generic parameter @@ -28,7 +28,7 @@ LL | impl<const T: CompileTimeSettings> Foo<T> { help: add `#[derive(ConstParamTy)]` to the struct | LL + #[derive(ConstParamTy)] -LL | struct CompileTimeSettings{ +LL | struct CompileTimeSettings { | error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs index 446fdc75514..33b6b7f52ca 100644 --- a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs +++ b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs @@ -1,7 +1,7 @@ //@ check-pass #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] struct FooConst<const ARRAY: &'static [&'static str]> {} diff --git a/tests/ui/coroutine/coroutine-with-nll.stderr b/tests/ui/coroutine/coroutine-with-nll.stderr index 3f3d51da311..ee3a8f45f44 100644 --- a/tests/ui/coroutine/coroutine-with-nll.stderr +++ b/tests/ui/coroutine/coroutine-with-nll.stderr @@ -1,11 +1,19 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/coroutine-with-nll.rs:8:17 | +LL | || { + | -- within this coroutine +... LL | let b = &mut true; | ^^^^^^^^^ LL | LL | yield (); | -------- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | static || { + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/issue-48048.stderr b/tests/ui/coroutine/issue-48048.stderr index 199ecf4ca6a..8231dbef7f6 100644 --- a/tests/ui/coroutine/issue-48048.stderr +++ b/tests/ui/coroutine/issue-48048.stderr @@ -1,10 +1,18 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/issue-48048.rs:9:9 | +LL | #[coroutine] || { + | -- within this coroutine +... LL | x.0({ | ^^^ LL | yield; | ----- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | #[coroutine] static || { + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/pattern-borrow.stderr b/tests/ui/coroutine/pattern-borrow.stderr index 9e7b330d79d..a3954b0b8ad 100644 --- a/tests/ui/coroutine/pattern-borrow.stderr +++ b/tests/ui/coroutine/pattern-borrow.stderr @@ -1,10 +1,17 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/pattern-borrow.rs:9:24 | +LL | #[coroutine] move || { + | ------- within this coroutine LL | if let Test::A(ref _a) = test { | ^^^^^^ LL | yield (); | -------- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | #[coroutine] static move || { + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/self_referential_gen_block.stderr b/tests/ui/coroutine/self_referential_gen_block.stderr index e23d653d0d4..2f53e7c84a1 100644 --- a/tests/ui/coroutine/self_referential_gen_block.stderr +++ b/tests/ui/coroutine/self_referential_gen_block.stderr @@ -1,6 +1,9 @@ error[E0626]: borrow may still be in use when `gen` block yields --> $DIR/self_referential_gen_block.rs:9:21 | +LL | let mut x = gen { + | --- within this `gen` block +LL | let y = 42; LL | let z = &y; | ^^ LL | yield 43; diff --git a/tests/ui/coroutine/yield-in-args.stderr b/tests/ui/coroutine/yield-in-args.stderr index 1d2c54f9bdb..1cc3c83deb3 100644 --- a/tests/ui/coroutine/yield-in-args.stderr +++ b/tests/ui/coroutine/yield-in-args.stderr @@ -1,8 +1,16 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-in-args.rs:9:13 | +LL | || { + | -- within this coroutine +LL | let b = true; LL | foo(&b, yield); | ^^ ----- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | static || { + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/yield-while-iterating.stderr b/tests/ui/coroutine/yield-while-iterating.stderr index f81c914c4bd..a92237e44c1 100644 --- a/tests/ui/coroutine/yield-while-iterating.stderr +++ b/tests/ui/coroutine/yield-while-iterating.stderr @@ -1,10 +1,17 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-iterating.rs:13:18 | +LL | let _b =#[coroutine] move || { + | ------- within this coroutine LL | for p in &x { | ^^ LL | yield(); | ------- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | let _b =#[coroutine] static move || { + | ++++++ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable --> $DIR/yield-while-iterating.rs:58:20 diff --git a/tests/ui/coroutine/yield-while-local-borrowed.stderr b/tests/ui/coroutine/yield-while-local-borrowed.stderr index 8fe981de929..b42ca3ba461 100644 --- a/tests/ui/coroutine/yield-while-local-borrowed.stderr +++ b/tests/ui/coroutine/yield-while-local-borrowed.stderr @@ -1,20 +1,35 @@ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-local-borrowed.rs:13:17 | +LL | let mut b = #[coroutine] move || { + | ------- within this coroutine LL | let a = &mut 3; | ^^^^^^ LL | LL | yield (); | -------- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | let mut b = #[coroutine] static move || { + | ++++++ error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-local-borrowed.rs:40:21 | +LL | let mut b = #[coroutine] move || { + | ------- within this coroutine +... LL | let b = &a; | ^^ LL | LL | yield (); | -------- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | let mut b = #[coroutine] static move || { + | ++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/error-codes/E0001.stderr b/tests/ui/error-codes/E0001.stderr index 49bb73e7ba8..40008230ec8 100644 --- a/tests/ui/error-codes/E0001.stderr +++ b/tests/ui/error-codes/E0001.stderr @@ -2,8 +2,17 @@ error: unreachable pattern --> $DIR/E0001.rs:8:9 | LL | _ => {/* ... */} - | ^ + | ^ unreachable pattern | +note: these patterns collectively make the last one unreachable + --> $DIR/E0001.rs:8:9 + | +LL | Some(_) => {/* ... */} + | ------- matches some of the same values +LL | None => {/* ... */} + | ---- matches some of the same values +LL | _ => {/* ... */} + | ^ collectively making this unreachable note: the lint level is defined here --> $DIR/E0001.rs:1:9 | diff --git a/tests/ui/error-codes/E0746.stderr b/tests/ui/error-codes/E0746.stderr index 9fe90ab7bec..cfc747cb1e2 100644 --- a/tests/ui/error-codes/E0746.stderr +++ b/tests/ui/error-codes/E0746.stderr @@ -4,11 +4,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn foo() -> dyn Trait { Struct } | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn foo() -> impl Trait { Struct } | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL | fn foo() -> Box<dyn Trait> { Box::new(Struct) } | ++++ + +++++++++ + @@ -19,10 +19,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bar() -> dyn Trait { | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn bar() -> impl Trait { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn bar() -> Box<dyn Trait> { diff --git a/tests/ui/error-codes/E0771.rs b/tests/ui/error-codes/E0771.rs index c0a2e98a7df..a932c5ef981 100644 --- a/tests/ui/error-codes/E0771.rs +++ b/tests/ui/error-codes/E0771.rs @@ -1,5 +1,5 @@ -#![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARN the feature `unsized_const_params` is incomplete fn function_with_str<'a, const STRING: &'a str>() {} //~ ERROR E0770 diff --git a/tests/ui/error-codes/E0771.stderr b/tests/ui/error-codes/E0771.stderr index e1384effe37..5e829e6f6d2 100644 --- a/tests/ui/error-codes/E0771.stderr +++ b/tests/ui/error-codes/E0771.stderr @@ -6,11 +6,11 @@ LL | fn function_with_str<'a, const STRING: &'a str>() {} | = note: lifetime parameters may not be used in the type of const parameters -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/E0771.rs:1:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/E0771.rs:1:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information = note: `#[warn(incomplete_features)]` on by default diff --git a/tests/ui/errors/wrong-target-spec.rs b/tests/ui/errors/wrong-target-spec.rs new file mode 100644 index 00000000000..bc9038c1fab --- /dev/null +++ b/tests/ui/errors/wrong-target-spec.rs @@ -0,0 +1,8 @@ +// The attentive may note the underscores in the target triple, making it invalid. This test +// checks that such invalid target specs are rejected by the compiler. +// See https://github.com/rust-lang/rust/issues/33329 + +//@ needs-llvm-components: x86 +//@ compile-flags: --target x86_64_unknown-linux-musl + +fn main() {} diff --git a/tests/ui/errors/wrong-target-spec.stderr b/tests/ui/errors/wrong-target-spec.stderr new file mode 100644 index 00000000000..8b06f404078 --- /dev/null +++ b/tests/ui/errors/wrong-target-spec.stderr @@ -0,0 +1,2 @@ +error: Error loading target specification: Could not find specification for target "x86_64_unknown-linux-musl". Run `rustc --print target-list` for a list of built-in targets + diff --git a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr index fcb9b8a6fc5..649e936888b 100644 --- a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr +++ b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/feature-gates/feature-gate-unsized-const-params.rs b/tests/ui/feature-gates/feature-gate-unsized-const-params.rs new file mode 100644 index 00000000000..d088d382377 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-unsized-const-params.rs @@ -0,0 +1,6 @@ +struct Foo<const N: [u8]>; +//~^ ERROR: `[u8]` is forbidden as the type of a const generic parameter +//~| HELP: add `#![feature(adt_const_params)]` to the crate +//~| HELP: add `#![feature(unsized_const_params)]` to the crate + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr b/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr new file mode 100644 index 00000000000..0a87f34f4f5 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr @@ -0,0 +1,18 @@ +error: `[u8]` is forbidden as the type of a const generic parameter + --> $DIR/feature-gate-unsized-const-params.rs:1:21 + | +LL | struct Foo<const N: [u8]>; + | ^^^^ + | + = note: the only supported types are integers, `bool` and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | + +error: aborting due to 1 previous error + diff --git a/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr b/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr index 4205c5c5ef7..d1decc0c3f1 100644 --- a/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr +++ b/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr @@ -13,8 +13,8 @@ LL | type A<'a> where Self: 'a; | ^ ...because it contains the generic associated type `A` = help: consider moving `A` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead: - Fooer<T> Fooy + Fooer<T> error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/gat-in-trait-path.rs:32:5 @@ -31,8 +31,8 @@ LL | type A<'a> where Self: 'a; | ^ ...because it contains the generic associated type `A` = help: consider moving `A` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead: - Fooer<T> Fooy + Fooer<T> error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/gat-in-trait-path.rs:32:5 @@ -49,8 +49,8 @@ LL | type A<'a> where Self: 'a; | ^ ...because it contains the generic associated type `A` = help: consider moving `A` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead: - Fooer<T> Fooy + Fooer<T> = note: required for the cast from `Box<Fooer<{integer}>>` to `Box<(dyn Foo<A = &'a ()> + 'static)>` error: aborting due to 3 previous errors diff --git a/tests/ui/generic-associated-types/issue-79422.base.stderr b/tests/ui/generic-associated-types/issue-79422.base.stderr index 7f58f825702..bcc6382cf7c 100644 --- a/tests/ui/generic-associated-types/issue-79422.base.stderr +++ b/tests/ui/generic-associated-types/issue-79422.base.stderr @@ -29,8 +29,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; | ^^^^^^^^ ...because it contains the generic associated type `VRefCont` = help: consider moving `VRefCont` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `MapLike` for this new enum and using it instead: - Source std::collections::BTreeMap<K, V> + Source error[E0038]: the trait `MapLike` cannot be made into an object --> $DIR/issue-79422.rs:44:13 @@ -47,8 +47,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; | ^^^^^^^^ ...because it contains the generic associated type `VRefCont` = help: consider moving `VRefCont` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `MapLike` for this new enum and using it instead: - Source std::collections::BTreeMap<K, V> + Source = note: required for the cast from `Box<BTreeMap<u8, u8>>` to `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>` error: aborting due to 3 previous errors diff --git a/tests/ui/generic-const-items/elided-lifetimes.stderr b/tests/ui/generic-const-items/elided-lifetimes.stderr index 1d4a997ff60..85807a1b631 100644 --- a/tests/ui/generic-const-items/elided-lifetimes.stderr +++ b/tests/ui/generic-const-items/elided-lifetimes.stderr @@ -32,6 +32,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs b/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs index a6dcad3face..00034fb9f44 100644 --- a/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs +++ b/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs @@ -1,6 +1,6 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] trait Bar<const FOO: &'static str> {} diff --git a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr index f25269ca032..9c546659564 100644 --- a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr +++ b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr @@ -48,10 +48,14 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bap() -> Trait { Struct } | ^^^^^ doesn't have a size known at compile-time | -help: box the return type, and wrap all of the returned values in `Box::new` +help: consider returning an `impl Trait` instead of a `dyn Trait` + | +LL | fn bap() -> impl Trait { Struct } + | ++++ +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | -LL | fn bap() -> Box<Trait> { Box::new(Struct) } - | ++++ + +++++++++ + +LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) } + | +++++++ + +++++++++ + error[E0746]: return type cannot have an unboxed trait object --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13 @@ -59,11 +63,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn ban() -> dyn Trait { Struct } | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn ban() -> impl Trait { Struct } | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) } | ++++ + +++++++++ + @@ -74,11 +78,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bak() -> dyn Trait { unimplemented!() } | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn bak() -> impl Trait { unimplemented!() } | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) } | ++++ + +++++++++ + @@ -89,10 +93,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bal() -> dyn Trait { | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn bal() -> impl Trait { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn bal() -> Box<dyn Trait> { @@ -108,10 +109,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bax() -> dyn Trait { | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn bax() -> impl Trait { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn bax() -> Box<dyn Trait> { @@ -263,10 +261,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bat() -> dyn Trait { | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn bat() -> impl Trait { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn bat() -> Box<dyn Trait> { @@ -282,10 +277,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn bay() -> dyn Trait { | ^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn bay() -> impl Trait { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn bay() -> Box<dyn Trait> { diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr b/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr index fc9c30abf13..09a689e6396 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr +++ b/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr @@ -54,10 +54,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn car() -> dyn NotObjectSafe { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn car() -> impl NotObjectSafe { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn car() -> Box<dyn NotObjectSafe> { diff --git a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr index 9205d74504f..54849c112f5 100644 --- a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr +++ b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr @@ -171,11 +171,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn hat() -> dyn std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn hat() -> impl std::fmt::Display { | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn hat() -> Box<dyn std::fmt::Display> { LL | match 13 { @@ -192,11 +192,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn pug() -> dyn std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn pug() -> impl std::fmt::Display { | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn pug() -> Box<dyn std::fmt::Display> { LL | match 13 { @@ -211,10 +211,7 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn man() -> dyn std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type - | -LL | fn man() -> impl std::fmt::Display { - | ~~~~ + = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn man() -> Box<dyn std::fmt::Display> { diff --git a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs index b6395258c89..9205f1e1632 100644 --- a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs +++ b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs @@ -1,7 +1,7 @@ //@ check-pass #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] pub struct Element; diff --git a/tests/ui/inference/ice-cannot-relate-region-109178.rs b/tests/ui/inference/ice-cannot-relate-region-109178.rs index 3282f95a992..2e3953646ff 100644 --- a/tests/ui/inference/ice-cannot-relate-region-109178.rs +++ b/tests/ui/inference/ice-cannot-relate-region-109178.rs @@ -2,7 +2,7 @@ #![allow(incomplete_features)] #![crate_type = "lib"] -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] struct Changes<const CHANGES: &[&'static str]> //~^ ERROR `&` without an explicit lifetime name cannot be used here diff --git a/tests/ui/issues/issue-18107.stderr b/tests/ui/issues/issue-18107.stderr index 702207c30f7..705f7d0df12 100644 --- a/tests/ui/issues/issue-18107.stderr +++ b/tests/ui/issues/issue-18107.stderr @@ -4,11 +4,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | dyn AbstractRenderer | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | impl AbstractRenderer | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL ~ Box<dyn AbstractRenderer> LL | diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 70f06b4be60..e446345aedc 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -63,6 +63,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: aborting due to 8 previous errors diff --git a/tests/ui/lto/debuginfo-lto-alloc.rs b/tests/ui/lto/debuginfo-lto-alloc.rs index 459103c354c..89043275329 100644 --- a/tests/ui/lto/debuginfo-lto-alloc.rs +++ b/tests/ui/lto/debuginfo-lto-alloc.rs @@ -9,7 +9,8 @@ // that compilation is successful. //@ check-pass -//@ compile-flags: --test -C debuginfo=2 -C lto=fat -C incremental=inc-fat +//@ compile-flags: --test -C debuginfo=2 -C lto=fat +//@ incremental extern crate alloc; diff --git a/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs b/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs new file mode 100644 index 00000000000..781443207ac --- /dev/null +++ b/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs @@ -0,0 +1,18 @@ +//@ run-pass + +#![feature(macro_metavar_expr_concat)] + +macro_rules! one_rep { + ( $($a:ident)* ) => { + $( + const ${concat($a, Z)}: i32 = 3; + )* + }; +} + +fn main() { + one_rep!(A B C); + assert_eq!(AZ, 3); + assert_eq!(BZ, 3); + assert_eq!(CZ, 3); +} diff --git a/tests/ui/mir/ice-mir-const-qualif-125837.rs b/tests/ui/mir/ice-mir-const-qualif-125837.rs new file mode 100644 index 00000000000..a0f57caaba4 --- /dev/null +++ b/tests/ui/mir/ice-mir-const-qualif-125837.rs @@ -0,0 +1,17 @@ +// Test for ICE: mir_const_qualif: index out of bounds: the len is 0 but the index is 0 +// https://github.com/rust-lang/rust/issues/125837 + +use std::fmt::Debug; + +trait Foo<Item> {} + +impl<Item, D: Debug + Clone> Foo for D { +//~^ ERROR missing generics for trait `Foo` + fn foo<'a>(&'a self) -> impl Debug { + //~^ ERROR method `foo` is not a member of trait `Foo` + const { return } +//~^ ERROR return statement outside of function body + } +} + +pub fn main() {} diff --git a/tests/ui/mir/ice-mir-const-qualif-125837.stderr b/tests/ui/mir/ice-mir-const-qualif-125837.stderr new file mode 100644 index 00000000000..003b327210b --- /dev/null +++ b/tests/ui/mir/ice-mir-const-qualif-125837.stderr @@ -0,0 +1,41 @@ +error[E0407]: method `foo` is not a member of trait `Foo` + --> $DIR/ice-mir-const-qualif-125837.rs:10:5 + | +LL | / fn foo<'a>(&'a self) -> impl Debug { +LL | | +LL | | const { return } +LL | | +LL | | } + | |_____^ not a member of trait `Foo` + +error[E0107]: missing generics for trait `Foo` + --> $DIR/ice-mir-const-qualif-125837.rs:8:30 + | +LL | impl<Item, D: Debug + Clone> Foo for D { + | ^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `Item` + --> $DIR/ice-mir-const-qualif-125837.rs:6:7 + | +LL | trait Foo<Item> {} + | ^^^ ---- +help: add missing generic argument + | +LL | impl<Item, D: Debug + Clone> Foo<Item> for D { + | ++++++ + +error[E0572]: return statement outside of function body + --> $DIR/ice-mir-const-qualif-125837.rs:12:17 + | +LL | / fn foo<'a>(&'a self) -> impl Debug { +LL | | +LL | | const { return } + | | --^^^^^^-- the return is part of this body... +LL | | +LL | | } + | |_____- ...not the enclosing function body + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0107, E0407, E0572. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/nll/issue-55850.stderr b/tests/ui/nll/issue-55850.stderr index 3d43817f4d8..5a9c7799197 100644 --- a/tests/ui/nll/issue-55850.stderr +++ b/tests/ui/nll/issue-55850.stderr @@ -10,8 +10,16 @@ LL | yield &s[..] error[E0626]: borrow may still be in use when coroutine yields --> $DIR/issue-55850.rs:28:16 | +LL | GenIter(#[coroutine] move || { + | ------- within this coroutine +LL | let mut s = String::new(); LL | yield &s[..] | -------^---- possible yield occurs here + | +help: add `static` to mark this coroutine as unmovable + | +LL | GenIter(#[coroutine] static move || { + | ++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.rs b/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.rs index 1ad335bf394..afdcff0346b 100644 --- a/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.rs +++ b/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.rs @@ -29,6 +29,11 @@ fn main() { (1, 4 | 5) => {} //~ ERROR unreachable pattern _ => {} } + match (0u8, 0u8, 0u8) { + (0, 0, 0) => {} + (0, 0 | 1, 0) => {} //~ ERROR unreachable pattern + _ => {} + } match (true, true) { (false | true, false | true) => (), } diff --git a/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index 336530d1b32..5570390b21c 100644 --- a/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/tests/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:8:9 | +LL | (1 | 2,) => {} + | -------- matches all the values already LL | (1,) => {} - | ^^^^ + | ^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/exhaustiveness-unreachable-pattern.rs:1:9 @@ -13,212 +15,354 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:13:9 | +LL | (1 | 2,) => {} + | -------- matches all the values already LL | (2,) => {} - | ^^^^ + | ^^^^ unreachable pattern error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:19:9 | LL | (1 | 2,) => {} - | ^^^^^^^^ + | ^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:19:9 + | +LL | (1,) => {} + | ---- matches some of the same values +LL | (2,) => {} + | ---- matches some of the same values +LL | (1 | 2,) => {} + | ^^^^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:24:9 | +LL | (1 | 2, 3 | 4) => {} + | -------------- matches all the values already LL | (1, 3) => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:25:9 | +LL | (1 | 2, 3 | 4) => {} + | -------------- matches all the values already +LL | (1, 3) => {} LL | (1, 4) => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:26:9 | +LL | (1 | 2, 3 | 4) => {} + | -------------- matches all the values already +... LL | (2, 4) => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:27:9 | +LL | (1 | 2, 3 | 4) => {} + | -------------- matches all the values already +... LL | (2 | 1, 4) => {} - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:29:9 | LL | (1, 4 | 5) => {} - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:29:9 + | +LL | (1 | 2, 3 | 4) => {} + | -------------- matches some of the same values +... +LL | (1, 5 | 6) => {} + | ---------- matches some of the same values +LL | (1, 4 | 5) => {} + | ^^^^^^^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:37:9 + --> $DIR/exhaustiveness-unreachable-pattern.rs:34:13 | +LL | (0, 0, 0) => {} + | - matches all the values already +LL | (0, 0 | 1, 0) => {} + | ^ unreachable pattern + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:42:9 + | +LL | (None | Some(1 | 2),) => {} + | --------------------- matches all the values already LL | (Some(1),) => {} - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:38:9 + --> $DIR/exhaustiveness-unreachable-pattern.rs:43:9 | +LL | (None | Some(1 | 2),) => {} + | --------------------- matches all the values already +LL | (Some(1),) => {} LL | (None,) => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:43:9 + --> $DIR/exhaustiveness-unreachable-pattern.rs:48:9 | +LL | ((1 | 2,) | (3 | 4,),) => {} + | ---------------------- matches all the values already LL | ((1..=4,),) => {} - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:48:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:53:14 | LL | (1 | 1,) => {} - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:52:19 + --> $DIR/exhaustiveness-unreachable-pattern.rs:57:19 | LL | (0 | 1) | 1 => {} - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:58:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:63:14 | LL | 0 | (0 | 0) => {} - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:58:18 + --> $DIR/exhaustiveness-unreachable-pattern.rs:63:18 | LL | 0 | (0 | 0) => {} - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:66:13 + --> $DIR/exhaustiveness-unreachable-pattern.rs:71:13 | +LL | Some(0) | + | ------- matches all the values already LL | / Some( LL | | 0 | 0) => {} - | |______________________^ + | |______________________^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:72:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:77:15 | +LL | [0 + | - matches all the values already LL | | 0 - | ^ + | ^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:74:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:79:15 | +LL | , 0 + | - matches all the values already LL | | 0] => {} - | ^ + | ^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:78:20 + --> $DIR/exhaustiveness-unreachable-pattern.rs:83:20 | LL | (true, 0 | 0) => {} - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:79:17 + --> $DIR/exhaustiveness-unreachable-pattern.rs:84:17 | LL | (_, 0 | 0) => {} - | ^ + | ^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:84:17 + | +LL | (true, 0 | 0) => {} + | - matches some of the same values +LL | (_, 0 | 0) => {} + | - ^ collectively making this unreachable + | | + | matches some of the same values error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:87:10 + --> $DIR/exhaustiveness-unreachable-pattern.rs:92:10 | +LL | [1, ..] => {} + | - matches all the values already LL | [1 - | ^ + | ^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:99:10 + --> $DIR/exhaustiveness-unreachable-pattern.rs:104:10 | +LL | [true, ..] => {} + | ---- matches all the values already LL | [true - | ^^^^ + | ^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:106:36 + --> $DIR/exhaustiveness-unreachable-pattern.rs:111:36 | LL | (true | false, None | Some(true - | ^^^^ + | ^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:111:36 + | +LL | (true, Some(_)) => {} + | - matches some of the same values +LL | (false, Some(true)) => {} + | ---- matches some of the same values +LL | (true | false, None | Some(true + | ^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:111:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:116:14 | LL | (true - | ^^^^ + | ^^^^ unreachable pattern ... LL | (true | false, None | Some(t_or_f!())) => {} | --------- in this macro invocation | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:116:14 + | +LL | (true + | ^^^^ collectively making this unreachable +... +LL | (true, Some(_)) => {} + | - matches some of the same values +LL | (false, Some(true)) => {} + | ---- matches some of the same values +LL | (true | false, None | Some(t_or_f!())) => {} + | --------- in this macro invocation = note: this error originates in the macro `t_or_f` (in Nightly builds, run with -Z macro-backtrace for more info) error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:122:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:127:14 | +LL | Some(0) => {} + | - matches all the values already LL | Some(0 - | ^ + | ^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:141:19 + --> $DIR/exhaustiveness-unreachable-pattern.rs:146:19 | +LL | Some(false) => {} + | ----- matches all the values already +LL | None | Some(true LL | | false) => {} - | ^^^^^ + | ^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:149:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:154:15 | LL | | true) => {} - | ^^^^ + | ^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:154:15 + | +LL | (false, true) => {} + | ---- matches some of the same values +LL | (true, true) => {} + | ---- matches some of the same values +LL | (false | true, false +LL | | true) => {} + | ^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:155:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:160:15 | LL | | true, - | ^^^^ + | ^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/exhaustiveness-unreachable-pattern.rs:160:15 + | +LL | (true, false) => {} + | ---- matches some of the same values +LL | (true, true) => {} + | ---- matches some of the same values +LL | (false +LL | | true, + | ^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:160:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:165:15 | +LL | (x, y) + | ------ matches any value LL | | (y, x) => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:164:30 + --> $DIR/exhaustiveness-unreachable-pattern.rs:169:30 | LL | fn unreachable_in_param((_ | (_, _)): (bool, bool)) {} - | ^^^^^^ + | - ^^^^^^ unreachable pattern + | | + | matches any value error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:171:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:176:14 | LL | let (_ | (_, _)) = bool_pair; - | ^^^^^^ + | - ^^^^^^ unreachable pattern + | | + | matches any value error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:173:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:178:14 | LL | for (_ | (_, _)) in [bool_pair] {} - | ^^^^^^ + | - ^^^^^^ unreachable pattern + | | + | matches any value error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:176:20 + --> $DIR/exhaustiveness-unreachable-pattern.rs:181:20 | LL | let (Some(_) | Some(true)) = bool_option else { return }; - | ^^^^^^^^^^ + | ------- ^^^^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:178:22 + --> $DIR/exhaustiveness-unreachable-pattern.rs:183:22 | LL | if let Some(_) | Some(true) = bool_option {} - | ^^^^^^^^^^ + | ------- ^^^^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:180:25 + --> $DIR/exhaustiveness-unreachable-pattern.rs:185:25 | LL | while let Some(_) | Some(true) = bool_option {} - | ^^^^^^^^^^ + | ------- ^^^^^^^^^^ unreachable pattern + | | + | matches all the values already -error: aborting due to 35 previous errors +error: aborting due to 36 previous errors diff --git a/tests/ui/pattern/usefulness/consts-opaque.stderr b/tests/ui/pattern/usefulness/consts-opaque.stderr index d057309e420..9d3a35321ca 100644 --- a/tests/ui/pattern/usefulness/consts-opaque.stderr +++ b/tests/ui/pattern/usefulness/consts-opaque.stderr @@ -106,20 +106,34 @@ LL | _ => {} // should not be emitting unreachable warning error: unreachable pattern --> $DIR/consts-opaque.rs:72:9 | +LL | BAZ => {} + | --- matches all the values already LL | Baz::Baz1 => {} // should not be emitting unreachable warning - | ^^^^^^^^^ + | ^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/consts-opaque.rs:79:9 | +LL | Baz::Baz1 => {} + | --------- matches all the values already LL | BAZ => {} - | ^^^ + | ^^^ unreachable pattern error: unreachable pattern --> $DIR/consts-opaque.rs:87:9 | LL | _ => {} // should not be emitting unreachable warning - | ^ + | ^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/consts-opaque.rs:87:9 + | +LL | BAZ => {} + | --- matches some of the same values +LL | Baz::Baz2 => {} + | --------- matches some of the same values +LL | _ => {} // should not be emitting unreachable warning + | ^ collectively making this unreachable error: aborting due to 17 previous errors diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr index 4c434192431..9e700ee55ef 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `EmptyEnum` is uninhabited note: the lint level is defined here --> $DIR/empty-match-check-notes.rs:7:9 | @@ -11,25 +12,31 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:20:9 + --> $DIR/empty-match-check-notes.rs:21:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `EmptyEnum` is uninhabited error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:27:9 + --> $DIR/empty-match-check-notes.rs:29:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `EmptyForeignEnum` is uninhabited error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:30:9 + --> $DIR/empty-match-check-notes.rs:33:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `EmptyForeignEnum` is uninhabited error[E0005]: refutable pattern in local binding - --> $DIR/empty-match-check-notes.rs:35:9 + --> $DIR/empty-match-check-notes.rs:39:9 | LL | let None = x; | ^^^^ pattern `Some(_)` not covered @@ -44,7 +51,7 @@ LL | if let None = x { todo!() }; | ++ +++++++++++ error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered - --> $DIR/empty-match-check-notes.rs:45:11 + --> $DIR/empty-match-check-notes.rs:49:11 | LL | match 0u8 { | ^^^ pattern `0_u8..=u8::MAX` not covered diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr index 45f715dc7b2..480ae7095a6 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `EmptyEnum` is uninhabited note: the lint level is defined here --> $DIR/empty-match-check-notes.rs:7:9 | @@ -11,25 +12,31 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:20:9 + --> $DIR/empty-match-check-notes.rs:21:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `EmptyEnum` is uninhabited error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:27:9 + --> $DIR/empty-match-check-notes.rs:29:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `EmptyForeignEnum` is uninhabited error: unreachable pattern - --> $DIR/empty-match-check-notes.rs:30:9 + --> $DIR/empty-match-check-notes.rs:33:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `EmptyForeignEnum` is uninhabited error[E0005]: refutable pattern in local binding - --> $DIR/empty-match-check-notes.rs:35:9 + --> $DIR/empty-match-check-notes.rs:39:9 | LL | let None = x; | ^^^^ pattern `Some(_)` not covered @@ -43,7 +50,7 @@ LL | if let None = x { todo!() }; | ++ +++++++++++ error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered - --> $DIR/empty-match-check-notes.rs:45:11 + --> $DIR/empty-match-check-notes.rs:49:11 | LL | match 0u8 { | ^^^ pattern `0_u8..=u8::MAX` not covered diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.rs b/tests/ui/pattern/usefulness/empty-match-check-notes.rs index ea797bc7dd5..2eef283a21e 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.rs +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.rs @@ -15,9 +15,11 @@ fn empty_enum(x: EmptyEnum) { match x {} // ok match x { _ => {} //~ ERROR unreachable pattern + //~^ NOTE matches no values } match x { _ if false => {} //~ ERROR unreachable pattern + //~^ NOTE matches no values } } @@ -25,9 +27,11 @@ fn empty_foreign_enum(x: empty::EmptyForeignEnum) { match x {} // ok match x { _ => {} //~ ERROR unreachable pattern + //~^ NOTE matches no values } match x { _ if false => {} //~ ERROR unreachable pattern + //~^ NOTE matches no values } } diff --git a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr index 45bdba94d78..416a50b87b5 100644 --- a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here --> $DIR/empty-types.rs:17:9 | @@ -15,6 +16,8 @@ error: unreachable pattern | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty --> $DIR/empty-types.rs:58:11 @@ -36,24 +39,32 @@ error: unreachable pattern | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(u32, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:80:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:83:9 | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:87:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(_)` not covered --> $DIR/empty-types.rs:91:11 @@ -79,12 +90,16 @@ error: unreachable pattern | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:104:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered --> $DIR/empty-types.rs:101:11 @@ -123,114 +138,152 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:123:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:126:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:127:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:130:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:131:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:140:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:152:13 | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:156:13 | +LL | None => {} + | ---- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/empty-types.rs:208:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:291:9 | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:294:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:295:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty --> $DIR/empty-types.rs:327:11 @@ -292,18 +345,24 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:372:9 | LL | [_, _, _] => {} | ^^^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:375:9 | LL | [_, ..] => {} | ^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty --> $DIR/empty-types.rs:389:11 @@ -322,8 +381,10 @@ LL + } error: unreachable pattern --> $DIR/empty-types.rs:396:9 | +LL | [] => {} + | -- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered --> $DIR/empty-types.rs:398:11 @@ -344,48 +405,66 @@ error: unreachable pattern | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:422:9 | LL | Some(_a) => {} | ^^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:427:9 | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/empty-types.rs:432:9 | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable LL | _a => {} - | ^^ + | ^^ unreachable pattern error: unreachable pattern --> $DIR/empty-types.rs:604:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error: aborting due to 49 previous errors diff --git a/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr index 6e50dfe6a26..2e5511527d5 100644 --- a/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr +++ b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here --> $DIR/empty-types.rs:17:9 | @@ -15,6 +16,8 @@ error: unreachable pattern | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty --> $DIR/empty-types.rs:58:11 @@ -36,24 +39,32 @@ error: unreachable pattern | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(u32, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:80:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:83:9 | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:87:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(_)` not covered --> $DIR/empty-types.rs:91:11 @@ -79,12 +90,16 @@ error: unreachable pattern | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:104:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered --> $DIR/empty-types.rs:101:11 @@ -137,60 +152,80 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:123:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:126:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:127:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:130:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:131:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:140:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:152:13 | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:156:13 | +LL | None => {} + | ---- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `Some(_)` not covered --> $DIR/empty-types.rs:165:15 @@ -204,6 +239,7 @@ note: `Option<Void>` defined here | = note: not covered = note: the matched value is of type `Option<Void>` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -215,54 +251,72 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:291:9 | LL | (_, _) => {} | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:294:9 | LL | Ok(_) => {} | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:295:9 | LL | Err(_) => {} | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty --> $DIR/empty-types.rs:316:11 @@ -349,6 +403,7 @@ LL | match slice_never { | ^^^^^^^^^^^ pattern `&[_, ..]` not covered | = note: the matched value is of type `&[!]` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ [] => {}, @@ -401,18 +456,24 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:372:9 | LL | [_, _, _] => {} | ^^^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:375:9 | LL | [_, ..] => {} | ^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty --> $DIR/empty-types.rs:389:11 @@ -431,8 +492,10 @@ LL + } error: unreachable pattern --> $DIR/empty-types.rs:396:9 | +LL | [] => {} + | -- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered --> $DIR/empty-types.rs:398:11 @@ -453,24 +516,34 @@ error: unreachable pattern | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:422:9 | LL | Some(_a) => {} | ^^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:427:9 | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/empty-types.rs:432:9 | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable LL | _a => {} - | ^^ + | ^^ unreachable pattern error[E0004]: non-exhaustive patterns: `&Some(_)` not covered --> $DIR/empty-types.rs:452:11 @@ -484,6 +557,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `&Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ &None => {}, @@ -502,6 +576,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -520,6 +595,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_) => {}, @@ -538,6 +614,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_a) => {}, @@ -563,24 +640,32 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `&_` not covered --> $DIR/empty-types.rs:638:11 @@ -589,6 +674,7 @@ LL | match ref_never { | ^^^^^^^^^ pattern `&_` not covered | = note: the matched value is of type `&!` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required = note: references are always considered inhabited = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -609,6 +695,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Err(_) => {}, @@ -627,6 +714,7 @@ note: `Option<Result<!, !>>` defined here | = note: not covered = note: the matched value is of type `Option<Result<!, !>>` + = note: `Result<!, !>` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, diff --git a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr index 0ff2472922e..4856a2f8e08 100644 --- a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr +++ b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr @@ -13,6 +13,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here --> $DIR/empty-types.rs:17:9 | @@ -24,6 +25,8 @@ error: unreachable pattern | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty --> $DIR/empty-types.rs:58:11 @@ -73,6 +76,8 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(!)` not covered --> $DIR/empty-types.rs:91:11 @@ -218,12 +223,16 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error[E0004]: non-exhaustive patterns: `Some(!)` not covered --> $DIR/empty-types.rs:146:15 @@ -266,36 +275,48 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty --> $DIR/empty-types.rs:316:11 @@ -460,8 +481,10 @@ LL + } error: unreachable pattern --> $DIR/empty-types.rs:396:9 | +LL | [] => {} + | -- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered --> $DIR/empty-types.rs:398:11 @@ -568,24 +591,32 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `&!` not covered --> $DIR/empty-types.rs:638:11 diff --git a/tests/ui/pattern/usefulness/empty-types.normal.stderr b/tests/ui/pattern/usefulness/empty-types.normal.stderr index 1d13802a2bd..78db9ee349b 100644 --- a/tests/ui/pattern/usefulness/empty-types.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-types.normal.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here --> $DIR/empty-types.rs:17:9 | @@ -15,6 +16,8 @@ error: unreachable pattern | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty --> $DIR/empty-types.rs:58:11 @@ -64,6 +67,8 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered --> $DIR/empty-types.rs:91:11 @@ -209,12 +214,16 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error[E0004]: non-exhaustive patterns: `Some(_)` not covered --> $DIR/empty-types.rs:146:15 @@ -257,36 +266,48 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty --> $DIR/empty-types.rs:316:11 @@ -451,8 +472,10 @@ LL + } error: unreachable pattern --> $DIR/empty-types.rs:396:9 | +LL | [] => {} + | -- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered --> $DIR/empty-types.rs:398:11 @@ -559,24 +582,32 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ + | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `&_` not covered --> $DIR/empty-types.rs:638:11 diff --git a/tests/ui/pattern/usefulness/explain-unreachable-pats.rs b/tests/ui/pattern/usefulness/explain-unreachable-pats.rs new file mode 100644 index 00000000000..98f781b6a09 --- /dev/null +++ b/tests/ui/pattern/usefulness/explain-unreachable-pats.rs @@ -0,0 +1,101 @@ +#![feature(never_type)] +#![feature(min_exhaustive_patterns)] +#![deny(unreachable_patterns)] +//~^ NOTE lint level is defined here + +#[rustfmt::skip] +fn main() { + match (0u8,) { + (1 | 2,) => {} + //~^ NOTE matches all the values already + (2,) => {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + _ => {} + } + + match (0u8,) { + (1,) => {} + //~^ NOTE matches some of the same values + (2,) => {} + //~^ NOTE matches some of the same values + (1 | 2,) => {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + //~| NOTE these patterns collectively make the last one unreachable + //~| NOTE collectively making this unreachable + _ => {} + } + + let res: Result<(),!> = Ok(()); + match res { + Ok(_) => {} + Err(_) => {} + //~^ ERROR unreachable pattern + //~| NOTE this pattern matches no values because `!` is uninhabited + } + + #[derive(Copy, Clone)] + enum Void1 {} + #[derive(Copy, Clone)] + enum Void2 {} + // Only an empty type matched _by value_ can make an arm unreachable. We must get the right one. + let res1: Result<(), Void1> = Ok(()); + let res2: Result<(), Void2> = Ok(()); + match (&res1, res2) { + (Err(_), Err(_)) => {} + //~^ ERROR unreachable pattern + //~| NOTE this pattern matches no values because `Void2` is uninhabited + _ => {} + } + match (res1, &res2) { + (Err(_), Err(_)) => {} + //~^ ERROR unreachable pattern + //~| NOTE this pattern matches no values because `Void1` is uninhabited + _ => {} + } + + + if let (0 + //~^ NOTE matches all the values already + | 0, _) = (0, 0) {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + + match (true, true) { + (_, true) if false => {} // Guarded patterns don't cover others + (true, _) => {} + //~^ NOTE matches some of the same values + (false, _) => {} + //~^ NOTE matches some of the same values + (_, true) => {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + //~| NOTE these patterns collectively make the last one unreachable + //~| NOTE collectively making this unreachable + } + + match (true, true) { + (true, _) => {} + //~^ NOTE matches all the values already + (false, _) => {} + #[allow(unreachable_patterns)] + (_, true) => {} // Doesn't cover below because it's already unreachable. + (true, true) => {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + } + + // Despite skipping some irrelevant cases, we still report a set of rows that covers the + // unreachable one. + match (true, true, 0) { + (true, _, _) => {} + (_, true, 0..10) => {} + //~^ NOTE matches all the values already + (_, true, 10..) => {} + (_, true, 3) => {} + //~^ ERROR unreachable pattern + //~| NOTE unreachable pattern + _ => {} + } +} diff --git a/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr new file mode 100644 index 00000000000..e2eecf4a9f3 --- /dev/null +++ b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr @@ -0,0 +1,104 @@ +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:11:9 + | +LL | (1 | 2,) => {} + | -------- matches all the values already +LL | +LL | (2,) => {} + | ^^^^ unreachable pattern + | +note: the lint level is defined here + --> $DIR/explain-unreachable-pats.rs:3:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:22:9 + | +LL | (1 | 2,) => {} + | ^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/explain-unreachable-pats.rs:22:9 + | +LL | (1,) => {} + | ---- matches some of the same values +LL | +LL | (2,) => {} + | ---- matches some of the same values +LL | +LL | (1 | 2,) => {} + | ^^^^^^^^ collectively making this unreachable + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:33:9 + | +LL | Err(_) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:46:9 + | +LL | (Err(_), Err(_)) => {} + | ^^^^^^^^^^^^^^^^ + | + = note: this pattern matches no values because `Void2` is uninhabited + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:52:9 + | +LL | (Err(_), Err(_)) => {} + | ^^^^^^^^^^^^^^^^ + | + = note: this pattern matches no values because `Void1` is uninhabited + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:61:11 + | +LL | if let (0 + | - matches all the values already +LL | +LL | | 0, _) = (0, 0) {} + | ^ unreachable pattern + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:71:9 + | +LL | (_, true) => {} + | ^^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/explain-unreachable-pats.rs:71:9 + | +LL | (true, _) => {} + | --------- matches some of the same values +LL | +LL | (false, _) => {} + | ---------- matches some of the same values +LL | +LL | (_, true) => {} + | ^^^^^^^^^ collectively making this unreachable + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:84:9 + | +LL | (true, _) => {} + | --------- matches all the values already +... +LL | (true, true) => {} + | ^^^^^^^^^^^^ unreachable pattern + +error: unreachable pattern + --> $DIR/explain-unreachable-pats.rs:96:9 + | +LL | (_, true, 0..10) => {} + | ---------------- matches all the values already +... +LL | (_, true, 3) => {} + | ^^^^^^^^^^^^ unreachable pattern + +error: aborting due to 9 previous errors + diff --git a/tests/ui/pattern/usefulness/floats.stderr b/tests/ui/pattern/usefulness/floats.stderr index 684f6c93a16..d0a8841d6a8 100644 --- a/tests/ui/pattern/usefulness/floats.stderr +++ b/tests/ui/pattern/usefulness/floats.stderr @@ -14,8 +14,10 @@ LL + _ => todo!() error: unreachable pattern --> $DIR/floats.rs:18:9 | +LL | 0.01f16..=6.5f16 => {} + | ---------------- matches all the values already LL | 0.01f16 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/floats.rs:1:9 @@ -26,80 +28,118 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/floats.rs:19:9 | +LL | 0.01f16..=6.5f16 => {} + | ---------------- matches all the values already +LL | 0.01f16 => {} LL | 0.02f16 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:20:9 | +LL | 0.01f16..=6.5f16 => {} + | ---------------- matches all the values already +... LL | 6.5f16 => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:31:9 | +LL | 0.01f32..=6.5f32 => {} + | ---------------- matches all the values already LL | 0.01f32 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:32:9 | +LL | 0.01f32..=6.5f32 => {} + | ---------------- matches all the values already +LL | 0.01f32 => {} LL | 0.02f32 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:33:9 | +LL | 0.01f32..=6.5f32 => {} + | ---------------- matches all the values already +... LL | 6.5f32 => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:45:9 | +LL | 0.01f64..=6.5f64 => {} + | ---------------- matches all the values already +LL | 0.005f64 => {} LL | 0.01f64 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:46:9 | +LL | 0.01f64..=6.5f64 => {} + | ---------------- matches all the values already +... LL | 0.02f64 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:47:9 | +LL | 0.01f64..=6.5f64 => {} + | ---------------- matches all the values already +... LL | 6.5f64 => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:49:9 | +LL | 0.01f64..=6.5f64 => {} + | ---------------- matches all the values already +... LL | 1.0f64..=4.0f64 => {} - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:62:9 | +LL | 0.01f128..=6.5f128 => {} + | ------------------ matches all the values already +LL | 0.005f128 => {} LL | 0.01f128 => {} - | ^^^^^^^^ + | ^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:63:9 | +LL | 0.01f128..=6.5f128 => {} + | ------------------ matches all the values already +... LL | 0.02f128 => {} - | ^^^^^^^^ + | ^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:64:9 | +LL | 0.01f128..=6.5f128 => {} + | ------------------ matches all the values already +... LL | 6.5f128 => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/floats.rs:66:9 | +LL | 0.01f128..=6.5f128 => {} + | ------------------ matches all the values already +... LL | 1.0f128..=4.0f128 => {} - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ unreachable pattern error: aborting due to 15 previous errors diff --git a/tests/ui/pattern/usefulness/impl-trait.stderr b/tests/ui/pattern/usefulness/impl-trait.stderr index ba8b12f9f66..c079f5a259d 100644 --- a/tests/ui/pattern/usefulness/impl-trait.stderr +++ b/tests/ui/pattern/usefulness/impl-trait.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here --> $DIR/impl-trait.rs:5:9 | @@ -15,36 +16,48 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:45:13 | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:49:13 | +LL | None => {} + | ---- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/impl-trait.rs:59:13 | LL | Some(_) => {} | ^^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:63:13 | +LL | None => {} + | ---- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/impl-trait.rs:76:9 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:86:9 @@ -59,12 +72,16 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:105:9 | +LL | Some((a, b)) => {} + | ------------ matches all the values already LL | Some((mut x, mut y)) => { - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/impl-trait.rs:124:13 @@ -79,12 +96,16 @@ error: unreachable pattern | LL | _ => {} | ^ + | + = note: this pattern matches no values because `SecretelyVoid` is uninhabited error: unreachable pattern --> $DIR/impl-trait.rs:151:13 | LL | _ => {} | ^ + | + = note: this pattern matches no values because `SecretelyDoubleVoid` is uninhabited error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty --> $DIR/impl-trait.rs:23:11 diff --git a/tests/ui/pattern/usefulness/integer-ranges/reachability.stderr b/tests/ui/pattern/usefulness/integer-ranges/reachability.stderr index c5b028d2038..5d86007a853 100644 --- a/tests/ui/pattern/usefulness/integer-ranges/reachability.stderr +++ b/tests/ui/pattern/usefulness/integer-ranges/reachability.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/reachability.rs:18:17 | LL | m!(0u8, 42, 42); - | ^^ + | -- ^^ unreachable pattern + | | + | matches all the values already | note: the lint level is defined here --> $DIR/reachability.rs:3:9 @@ -14,121 +16,211 @@ error: unreachable pattern --> $DIR/reachability.rs:22:22 | LL | m!(0u8, 20..=30, 20); - | ^^ + | ------- ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:23:22 | LL | m!(0u8, 20..=30, 21); - | ^^ + | ------- ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:24:22 | LL | m!(0u8, 20..=30, 25); - | ^^ + | ------- ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:25:22 | LL | m!(0u8, 20..=30, 29); - | ^^ + | ------- ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:26:22 | LL | m!(0u8, 20..=30, 30); - | ^^ + | ------- ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:29:21 | LL | m!(0u8, 20..30, 20); - | ^^ + | ------ ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:30:21 | LL | m!(0u8, 20..30, 21); - | ^^ + | ------ ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:31:21 | LL | m!(0u8, 20..30, 25); - | ^^ + | ------ ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:32:21 | LL | m!(0u8, 20..30, 29); - | ^^ + | ------ ^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:36:22 | LL | m!(0u8, 20..=30, 20..=30); - | ^^^^^^^ + | ------- ^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:37:22 | LL | m!(0u8, 20.. 30, 20.. 30); - | ^^^^^^^ + | ------- ^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:38:22 | LL | m!(0u8, 20..=30, 20.. 30); - | ^^^^^^^ + | ------- ^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:40:22 | LL | m!(0u8, 20..=30, 21..=30); - | ^^^^^^^ + | ------- ^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:41:22 | LL | m!(0u8, 20..=30, 20..=29); - | ^^^^^^^ + | ------- ^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:43:24 | LL | m!('a', 'A'..='z', 'a'..='z'); - | ^^^^^^^^^ + | --------- ^^^^^^^^^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/reachability.rs:50:9 | LL | 5..=8 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:50:9 + | +LL | 5 => {}, + | - matches some of the same values +LL | 6 => {}, + | - matches some of the same values +LL | 7 => {}, + | - matches some of the same values +LL | 8 => {}, + | - matches some of the same values +LL | 5..=8 => {}, + | ^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:56:9 | LL | 5..15 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:56:9 + | +LL | 0..10 => {}, + | ----- matches some of the same values +LL | 10..20 => {}, + | ------ matches some of the same values +LL | 5..15 => {}, + | ^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:63:9 | LL | 5..25 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:63:9 + | +LL | 0..10 => {}, + | ----- matches some of the same values +LL | 10..20 => {}, + | ------ matches some of the same values +LL | 20..30 => {}, + | ------ matches some of the same values +LL | 5..25 => {}, + | ^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:71:9 | LL | 5..25 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:71:9 + | +LL | 0..10 => {}, + | ----- matches some of the same values +LL | 10 => {}, + | -- matches some of the same values +LL | 11..=23 => {}, + | ------- matches some of the same values +LL | 19..30 => {}, + | ------ matches some of the same values +LL | 5..25 => {}, + | ^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:77:9 | LL | 5..15 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:77:9 + | +LL | 0..10 => {}, + | ----- matches some of the same values +LL | 10..20 => {}, + | ------ matches some of the same values +LL | 5..15 => {}, + | ^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:84:9 @@ -142,19 +234,34 @@ error: unreachable pattern --> $DIR/reachability.rs:89:9 | LL | '\u{D7FF}'..='\u{E000}' => {}, - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/reachability.rs:89:9 + | +LL | '\u{0}'..='\u{D7FF}' => {}, + | -------------------- matches some of the same values +LL | '\u{E000}'..='\u{10_FFFF}' => {}, + | -------------------------- matches some of the same values +LL | '\u{D7FF}'..='\u{E000}' => {}, + | ^^^^^^^^^^^^^^^^^^^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/reachability.rs:105:9 | +LL | &42 => {} + | --- matches all the values already LL | &FOO => {} - | ^^^^ + | ^^^^ unreachable pattern error: unreachable pattern --> $DIR/reachability.rs:106:9 | +LL | &42 => {} + | --- matches all the values already +LL | &FOO => {} LL | BAR => {} - | ^^^ + | ^^^ unreachable pattern error: aborting due to 25 previous errors diff --git a/tests/ui/pattern/usefulness/issue-12116.stderr b/tests/ui/pattern/usefulness/issue-12116.stderr index 199bdc6ac97..b2c2be97563 100644 --- a/tests/ui/pattern/usefulness/issue-12116.stderr +++ b/tests/ui/pattern/usefulness/issue-12116.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/issue-12116.rs:15:9 | +LL | &IntList::Cons(val, box ref next_list) => tail(next_list), + | -------------------------------------- matches all the values already LL | &IntList::Cons(val, box IntList::Nil) => IntList::Cons(val, Box::new(IntList::Nil)), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/issue-12116.rs:4:9 diff --git a/tests/ui/pattern/usefulness/issue-12369.stderr b/tests/ui/pattern/usefulness/issue-12369.stderr index 2b6e2e14b7c..7754cbc2484 100644 --- a/tests/ui/pattern/usefulness/issue-12369.stderr +++ b/tests/ui/pattern/usefulness/issue-12369.stderr @@ -2,8 +2,17 @@ error: unreachable pattern --> $DIR/issue-12369.rs:9:9 | LL | &[10,a, ref rest @ ..] => 10 - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern | +note: these patterns collectively make the last one unreachable + --> $DIR/issue-12369.rs:9:9 + | +LL | &[a,b,c] => 3, + | -------- matches some of the same values +LL | &[a, ref rest @ ..] => a, + | ------------------- matches some of the same values +LL | &[10,a, ref rest @ ..] => 10 + | ^^^^^^^^^^^^^^^^^^^^^^ collectively making this unreachable note: the lint level is defined here --> $DIR/issue-12369.rs:1:9 | diff --git a/tests/ui/pattern/usefulness/issue-13727.stderr b/tests/ui/pattern/usefulness/issue-13727.stderr index ab80c56ea88..ca8533b33a4 100644 --- a/tests/ui/pattern/usefulness/issue-13727.stderr +++ b/tests/ui/pattern/usefulness/issue-13727.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/issue-13727.rs:7:5 | +LL | 256 => print!("0b1110\n"), + | --- matches all the values already LL | 512 => print!("0b1111\n"), - | ^^^ + | ^^^ unreachable pattern | note: the lint level is defined here --> $DIR/issue-13727.rs:2:9 diff --git a/tests/ui/pattern/usefulness/issue-30240-b.stderr b/tests/ui/pattern/usefulness/issue-30240-b.stderr index 74d39eba98c..749515fc94b 100644 --- a/tests/ui/pattern/usefulness/issue-30240-b.stderr +++ b/tests/ui/pattern/usefulness/issue-30240-b.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/issue-30240-b.rs:12:9 | LL | "hello" => {} - | ^^^^^^^ + | ------- matches all the values already +LL | "hello" => {} + | ^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/issue-30240-b.rs:1:9 diff --git a/tests/ui/pattern/usefulness/issue-31221.stderr b/tests/ui/pattern/usefulness/issue-31221.stderr index 7d349144456..596f4d8096d 100644 --- a/tests/ui/pattern/usefulness/issue-31221.stderr +++ b/tests/ui/pattern/usefulness/issue-31221.stderr @@ -23,10 +23,18 @@ LL | &Var2 => (), error: unreachable pattern --> $DIR/issue-31221.rs:31:9 | -LL | (c, d) => (), - | ------ matches any value LL | anything => () | ^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/issue-31221.rs:31:9 + | +LL | (Var1, b) => (), + | --------- matches some of the same values +LL | (c, d) => (), + | ------ matches some of the same values +LL | anything => () + | ^^^^^^^^ collectively making this unreachable error: aborting due to 3 previous errors diff --git a/tests/ui/pattern/usefulness/issue-57472.stderr b/tests/ui/pattern/usefulness/issue-57472.stderr index c814eaec0d1..68b5b7cb791 100644 --- a/tests/ui/pattern/usefulness/issue-57472.stderr +++ b/tests/ui/pattern/usefulness/issue-57472.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/issue-57472.rs:15:13 | +LL | Punned { foo: [_], .. } => println!("foo"), + | ----------------------- matches all the values already LL | Punned { bar: [_], .. } => println!("bar"), - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/issue-57472.rs:2:9 @@ -13,8 +15,10 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/issue-57472.rs:32:17 | +LL | Punned { foo: [_] } => println!("foo"), + | ------------------- matches all the values already LL | Punned { bar: [_] } => println!("bar"), - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ unreachable pattern error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/usefulness/match-arm-statics.stderr b/tests/ui/pattern/usefulness/match-arm-statics.stderr index a5dffebf699..b6f2b47047d 100644 --- a/tests/ui/pattern/usefulness/match-arm-statics.stderr +++ b/tests/ui/pattern/usefulness/match-arm-statics.stderr @@ -1,8 +1,11 @@ error: unreachable pattern --> $DIR/match-arm-statics.rs:25:9 | +LL | TRUE_TRUE => (), + | --------- matches all the values already +... LL | (true, true) => () - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/match-arm-statics.rs:2:9 @@ -13,14 +16,29 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/match-arm-statics.rs:40:9 | +LL | Some(Some(EAST)) => (), + | ---------------- matches all the values already +... LL | Some(Some(East)) => (), - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-arm-statics.rs:60:9 | LL | Foo { bar: Some(EAST), baz: NewBool(false) } => () - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/match-arm-statics.rs:60:9 + | +LL | Foo { bar: _, baz: NEW_FALSE } => (), + | ------------------------------ matches some of the same values +... +LL | Foo { bar: Some(EAST), .. } => (), + | --------------------------- matches some of the same values +LL | Foo { bar: Some(North), baz: NewBool(true) } => (), +LL | Foo { bar: Some(EAST), baz: NewBool(false) } => () + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ collectively making this unreachable error: aborting due to 3 previous errors diff --git a/tests/ui/pattern/usefulness/match-byte-array-patterns.stderr b/tests/ui/pattern/usefulness/match-byte-array-patterns.stderr index 0c582be8df8..39675e2bdd4 100644 --- a/tests/ui/pattern/usefulness/match-byte-array-patterns.stderr +++ b/tests/ui/pattern/usefulness/match-byte-array-patterns.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:8:9 | +LL | b"AAAA" => {}, + | ------- matches all the values already LL | &[0x41, 0x41, 0x41, 0x41] => {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/match-byte-array-patterns.rs:1:9 @@ -13,44 +15,58 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:14:9 | +LL | &[0x41, 0x41, 0x41, 0x41] => {} + | ------------------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:20:9 | +LL | &[_, 0x41, 0x41, 0x41] => {}, + | ---------------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:26:9 | +LL | &[0x41, .., 0x41] => {} + | ----------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:34:9 | +LL | b"AAAA" => {}, + | ------- matches all the values already LL | &[0x41, 0x41, 0x41, 0x41] => {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:40:9 | +LL | &[0x41, 0x41, 0x41, 0x41] => {} + | ------------------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:46:9 | +LL | &[_, 0x41, 0x41, 0x41] => {}, + | ---------------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-byte-array-patterns.rs:52:9 | +LL | &[0x41, .., 0x41] => {} + | ----------------- matches all the values already LL | b"AAAA" => {}, - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: aborting due to 8 previous errors diff --git a/tests/ui/pattern/usefulness/match-ref-ice.stderr b/tests/ui/pattern/usefulness/match-ref-ice.stderr index 0dbfa776f69..9c5af47cc1e 100644 --- a/tests/ui/pattern/usefulness/match-ref-ice.stderr +++ b/tests/ui/pattern/usefulness/match-ref-ice.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/match-ref-ice.rs:13:9 | +LL | [1, ref _madoka, 3] => (), + | ------------------- matches all the values already LL | [1, 2, 3] => (), - | ^^^^^^^^^ + | ^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/match-ref-ice.rs:1:9 diff --git a/tests/ui/pattern/usefulness/match-vec-fixed.stderr b/tests/ui/pattern/usefulness/match-vec-fixed.stderr index e388a06cb9a..04507a22856 100644 --- a/tests/ui/pattern/usefulness/match-vec-fixed.stderr +++ b/tests/ui/pattern/usefulness/match-vec-fixed.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/match-vec-fixed.rs:7:9 | LL | [_, _, _] => {} - | ^^^^^^^^^ + | --------- matches all the values already +LL | [_, _, _] => {} + | ^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/match-vec-fixed.rs:1:9 @@ -14,7 +16,9 @@ error: unreachable pattern --> $DIR/match-vec-fixed.rs:11:9 | LL | [_, 1, _] => {} - | ^^^^^^^^^ + | --------- matches all the values already +LL | [_, 1, _] => {} + | ^^^^^^^^^ unreachable pattern error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/usefulness/match-vec-unreachable.stderr b/tests/ui/pattern/usefulness/match-vec-unreachable.stderr index 672fd92fb5e..865f5b319a7 100644 --- a/tests/ui/pattern/usefulness/match-vec-unreachable.stderr +++ b/tests/ui/pattern/usefulness/match-vec-unreachable.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/match-vec-unreachable.rs:8:9 | +LL | [a, (2, 3), _] => (), + | -------------- matches all the values already LL | [(1, 2), (2, 3), b] => (), - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/match-vec-unreachable.rs:1:9 @@ -13,14 +15,18 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/match-vec-unreachable.rs:18:9 | +LL | [ref a, _, _, ..] => { println!("{}", a); } + | ----------------- matches all the values already LL | [_, _, _, _, _] => { } - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/match-vec-unreachable.rs:26:9 | +LL | ['a', 'b', 'c', ref _tail @ ..] => {} + | ------------------------------- matches all the values already LL | ['a', 'b', 'c'] => {} - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ unreachable pattern error: aborting due to 3 previous errors diff --git a/tests/ui/pattern/usefulness/slice-pattern-const-2.stderr b/tests/ui/pattern/usefulness/slice-pattern-const-2.stderr index dcad11a38a7..12db48590a4 100644 --- a/tests/ui/pattern/usefulness/slice-pattern-const-2.stderr +++ b/tests/ui/pattern/usefulness/slice-pattern-const-2.stderr @@ -1,8 +1,11 @@ error: unreachable pattern --> $DIR/slice-pattern-const-2.rs:9:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already +LL | [0x00, 0x00, 0x00, 0x00] => (), LL | [4, 5, 6, 7] => (), - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/slice-pattern-const-2.rs:1:9 @@ -13,20 +16,26 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/slice-pattern-const-2.rs:15:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already LL | [4, 5, 6, 7] => (), - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const-2.rs:21:9 | +LL | [4, 5, 6, 7] => (), + | ------------ matches all the values already LL | MAGIC_TEST => (), - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const-2.rs:28:9 | +LL | [4] => (), + | --- matches all the values already LL | FOO => (), - | ^^^ + | ^^^ unreachable pattern error: aborting due to 4 previous errors diff --git a/tests/ui/pattern/usefulness/slice-pattern-const-3.stderr b/tests/ui/pattern/usefulness/slice-pattern-const-3.stderr index b90b3a88a18..5a66799d9c9 100644 --- a/tests/ui/pattern/usefulness/slice-pattern-const-3.stderr +++ b/tests/ui/pattern/usefulness/slice-pattern-const-3.stderr @@ -1,8 +1,11 @@ error: unreachable pattern --> $DIR/slice-pattern-const-3.rs:9:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already +LL | ["0x00", "0x00", "0x00", "0x00"] => (), LL | ["4", "5", "6", "7"] => (), - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/slice-pattern-const-3.rs:1:9 @@ -13,20 +16,26 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/slice-pattern-const-3.rs:15:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already LL | ["4", "5", "6", "7"] => (), - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const-3.rs:21:9 | +LL | ["4", "5", "6", "7"] => (), + | -------------------- matches all the values already LL | MAGIC_TEST => (), - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const-3.rs:28:9 | +LL | ["boo"] => (), + | ------- matches all the values already LL | FOO => (), - | ^^^ + | ^^^ unreachable pattern error: aborting due to 4 previous errors diff --git a/tests/ui/pattern/usefulness/slice-pattern-const.stderr b/tests/ui/pattern/usefulness/slice-pattern-const.stderr index 1fffb9fedbf..87a85acc4c5 100644 --- a/tests/ui/pattern/usefulness/slice-pattern-const.stderr +++ b/tests/ui/pattern/usefulness/slice-pattern-const.stderr @@ -1,8 +1,11 @@ error: unreachable pattern --> $DIR/slice-pattern-const.rs:9:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already +LL | [0x00, 0x00, 0x00, 0x00] => (), LL | [84, 69, 83, 84] => (), - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/slice-pattern-const.rs:1:9 @@ -13,50 +16,68 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/slice-pattern-const.rs:15:9 | +LL | MAGIC_TEST => (), + | ---------- matches all the values already LL | [84, 69, 83, 84] => (), - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:21:9 | +LL | [84, 69, 83, 84] => (), + | ---------------- matches all the values already LL | MAGIC_TEST => (), - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:28:9 | +LL | [4] => (), + | --- matches all the values already LL | FOO => (), - | ^^^ + | ^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:35:9 | +LL | [4] => (), + | --- matches all the values already LL | BAR => (), - | ^^^ + | ^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:43:9 | +LL | [] => (), + | -- matches all the values already LL | BOO => (), - | ^^^ + | ^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:44:9 | +LL | [] => (), + | -- matches all the values already +LL | BOO => (), LL | b"" => (), - | ^^^ + | ^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:45:9 | +LL | [] => (), + | -- matches all the values already +... LL | _ => (), - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/slice-pattern-const.rs:51:9 | +LL | CONST1 => {} + | ------ matches all the values already LL | [true] => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: aborting due to 9 previous errors diff --git a/tests/ui/pattern/usefulness/slice-patterns-reachability.stderr b/tests/ui/pattern/usefulness/slice-patterns-reachability.stderr index 607ffb76595..40fbb00de1f 100644 --- a/tests/ui/pattern/usefulness/slice-patterns-reachability.stderr +++ b/tests/ui/pattern/usefulness/slice-patterns-reachability.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:8:9 | LL | [true, ..] => {} - | ^^^^^^^^^^ + | ---------- matches all the values already +LL | [true, ..] => {} + | ^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/slice-patterns-reachability.rs:1:9 @@ -13,32 +15,45 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:9:9 | +LL | [true, ..] => {} + | ---------- matches all the values already +LL | [true, ..] => {} LL | [true] => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:14:9 | LL | [.., true] => {} - | ^^^^^^^^^^ + | ---------- matches all the values already +LL | [.., true] => {} + | ^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:15:9 | +LL | [.., true] => {} + | ---------- matches all the values already +LL | [.., true] => {} LL | [true] => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:20:9 | LL | [false, .., true] => {} - | ^^^^^^^^^^^^^^^^^ + | ----------------- matches all the values already +LL | [false, .., true] => {} + | ^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/slice-patterns-reachability.rs:21:9 | +LL | [false, .., true] => {} + | ----------------- matches all the values already +LL | [false, .., true] => {} LL | [false, true] => {} - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ unreachable pattern error: aborting due to 6 previous errors diff --git a/tests/ui/pattern/usefulness/slice_of_empty.min_exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/slice_of_empty.min_exhaustive_patterns.stderr index a1239466c9c..f24ce154d14 100644 --- a/tests/ui/pattern/usefulness/slice_of_empty.min_exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/slice_of_empty.min_exhaustive_patterns.stderr @@ -5,6 +5,7 @@ LL | match nevers { | ^^^^^^ pattern `&[_, ..]` not covered | = note: the matched value is of type `&[!]` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ &[] => (), diff --git a/tests/ui/pattern/usefulness/top-level-alternation.stderr b/tests/ui/pattern/usefulness/top-level-alternation.stderr index 17fa951c539..ad846f23155 100644 --- a/tests/ui/pattern/usefulness/top-level-alternation.stderr +++ b/tests/ui/pattern/usefulness/top-level-alternation.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/top-level-alternation.rs:4:23 | LL | while let 0..=2 | 1 = 0 {} - | ^ + | ----- ^ unreachable pattern + | | + | matches all the values already | note: the lint level is defined here --> $DIR/top-level-alternation.rs:1:9 @@ -14,61 +16,90 @@ error: unreachable pattern --> $DIR/top-level-alternation.rs:5:20 | LL | if let 0..=2 | 1 = 0 {} - | ^ + | ----- ^ unreachable pattern + | | + | matches all the values already error: unreachable pattern --> $DIR/top-level-alternation.rs:9:15 | +LL | 0 + | - matches all the values already LL | | 0 => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:14:15 | +LL | Some(0) + | ------- matches all the values already LL | | Some(0) => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:19:9 | +LL | (0, _) | (_, 0) => {} + | --------------- matches all the values already LL | (0, 0) => {} - | ^^^^^^ + | ^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:39:9 | +LL | None | Some(_) => {} + | -------------- matches all the values already LL | _ => {} - | ^ + | ^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:43:9 | +LL | None | Some(_) => {} + | -------------- matches all the values already LL | Some(_) => {} - | ^^^^^^^ + | ^^^^^^^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:44:9 | +LL | None | Some(_) => {} + | -------------- matches all the values already +LL | Some(_) => {} LL | None => {} - | ^^^^ + | ^^^^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:49:9 | LL | None | Some(_) => {} - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ unreachable pattern + | +note: these patterns collectively make the last one unreachable + --> $DIR/top-level-alternation.rs:49:9 + | +LL | Some(_) => {} + | ------- matches some of the same values +LL | None => {} + | ---- matches some of the same values +LL | None | Some(_) => {} + | ^^^^^^^^^^^^^^ collectively making this unreachable error: unreachable pattern --> $DIR/top-level-alternation.rs:53:9 | +LL | 1 | 2 => {}, + | ----- matches all the values already LL | 1..=2 => {}, - | ^^^^^ + | ^^^^^ unreachable pattern error: unreachable pattern --> $DIR/top-level-alternation.rs:56:14 | LL | let (0 | 0) = 0 else { return }; - | ^ + | - ^ unreachable pattern + | | + | matches all the values already error: aborting due to 11 previous errors diff --git a/tests/ui/reachable/unreachable-arm.stderr b/tests/ui/reachable/unreachable-arm.stderr index 60db8217640..79627404030 100644 --- a/tests/ui/reachable/unreachable-arm.stderr +++ b/tests/ui/reachable/unreachable-arm.stderr @@ -1,8 +1,10 @@ error: unreachable pattern --> $DIR/unreachable-arm.rs:11:9 | +LL | Foo::B(_) | Foo::A(box _, 1) => { } + | ---------------------------- matches all the values already LL | Foo::A(_, 1) => { } - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/unreachable-arm.rs:4:9 diff --git a/tests/ui/reachable/unreachable-loop-patterns.stderr b/tests/ui/reachable/unreachable-loop-patterns.stderr index 1dea9d813f9..bdd9b5ee411 100644 --- a/tests/ui/reachable/unreachable-loop-patterns.stderr +++ b/tests/ui/reachable/unreachable-loop-patterns.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | for _ in unimplemented!() as Void {} | ^ | + = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here --> $DIR/unreachable-loop-patterns.rs:5:9 | diff --git a/tests/ui/reachable/unreachable-try-pattern.stderr b/tests/ui/reachable/unreachable-try-pattern.stderr index 8f3e23119fb..bc1a6fffda6 100644 --- a/tests/ui/reachable/unreachable-try-pattern.stderr +++ b/tests/ui/reachable/unreachable-try-pattern.stderr @@ -19,6 +19,7 @@ warning: unreachable pattern LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?; | ^^^^^ | + = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here --> $DIR/unreachable-try-pattern.rs:4:9 | @@ -30,6 +31,8 @@ warning: unreachable pattern | LL | let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?; | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited warning: 3 warnings emitted diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr index fe2a72d2a31..a875041d89c 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | Err(!), | ^^^^^^ | + = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here --> $DIR/unreachable.rs:7:9 | @@ -15,30 +16,40 @@ error: unreachable pattern | LL | let (Ok(_x) | Err(!)) = res_void; | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/unreachable.rs:22:12 | LL | if let Err(!) = res_void {} | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/unreachable.rs:24:24 | LL | if let (Ok(true) | Err(!)) = res_void {} | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/unreachable.rs:26:23 | LL | for (Ok(mut _x) | Err(!)) in [res_void] {} | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern --> $DIR/unreachable.rs:30:18 | LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited error: aborting due to 6 previous errors diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr index 7386f10a6fb..d5f58e436c5 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | _ => {} | ^ | + = note: this pattern matches no values because `EmptyNonExhaustiveEnum` is uninhabited note: the lint level is defined here --> $DIR/enum_same_crate_empty_match.rs:1:9 | diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.stderr index 3034a67dc43..4ec4ec9705a 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.stderr @@ -2,7 +2,9 @@ error: unreachable pattern --> $DIR/issue-65157-repeated-match-arm.rs:15:9 | LL | PartiallyInhabitedVariants::Struct { .. } => {}, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----------------------------------------- matches all the values already +LL | PartiallyInhabitedVariants::Struct { .. } => {}, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern | note: the lint level is defined here --> $DIR/issue-65157-repeated-match-arm.rs:2:9 diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr index 8bfd6e91f4d..d5192a70ed5 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | Some(_x) => (), | ^^^^^^^^ | + = note: this pattern matches no values because `UninhabitedEnum` is uninhabited note: the lint level is defined here --> $DIR/patterns_same_crate.rs:1:9 | @@ -15,24 +16,32 @@ error: unreachable pattern | LL | Some(_x) => (), | ^^^^^^^^ + | + = note: this pattern matches no values because `UninhabitedVariants` is uninhabited error: unreachable pattern --> $DIR/patterns_same_crate.rs:61:15 | LL | while let PartiallyInhabitedVariants::Struct { x } = partially_inhabited_variant() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern --> $DIR/patterns_same_crate.rs:65:15 | LL | while let Some(_x) = uninhabited_struct() { | ^^^^^^^^ + | + = note: this pattern matches no values because `UninhabitedStruct` is uninhabited error: unreachable pattern --> $DIR/patterns_same_crate.rs:68:15 | LL | while let Some(_x) = uninhabited_tuple_struct() { | ^^^^^^^^ + | + = note: this pattern matches no values because `UninhabitedTupleStruct` is uninhabited error: aborting due to 5 previous errors diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/warns.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/warns.stderr index eed5dbb88de..8d0874fa900 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/warns.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/warns.stderr @@ -16,7 +16,9 @@ error: unreachable pattern --> $DIR/warns.rs:15:25 | LL | x if let None | None = x => {} - | ^^^^ + | ---- ^^^^ unreachable pattern + | | + | matches all the values already | note: the lint level is defined here --> $DIR/warns.rs:12:8 diff --git a/tests/ui/rust-2024/unsafe-env-suggestion.fixed b/tests/ui/rust-2024/unsafe-env-suggestion.fixed index 1f3d2dc0a31..eba35180ef6 100644 --- a/tests/ui/rust-2024/unsafe-env-suggestion.fixed +++ b/tests/ui/rust-2024/unsafe-env-suggestion.fixed @@ -1,6 +1,6 @@ //@ run-rustfix -#![deny(deprecated_safe)] +#![deny(deprecated_safe_2024)] use std::env; diff --git a/tests/ui/rust-2024/unsafe-env-suggestion.rs b/tests/ui/rust-2024/unsafe-env-suggestion.rs index 3bd169973e3..c039d7f2583 100644 --- a/tests/ui/rust-2024/unsafe-env-suggestion.rs +++ b/tests/ui/rust-2024/unsafe-env-suggestion.rs @@ -1,6 +1,6 @@ //@ run-rustfix -#![deny(deprecated_safe)] +#![deny(deprecated_safe_2024)] use std::env; diff --git a/tests/ui/rust-2024/unsafe-env-suggestion.stderr b/tests/ui/rust-2024/unsafe-env-suggestion.stderr index 7c12f4aa5ed..3aa10a3bed6 100644 --- a/tests/ui/rust-2024/unsafe-env-suggestion.stderr +++ b/tests/ui/rust-2024/unsafe-env-suggestion.stderr @@ -9,8 +9,8 @@ LL | env::set_var("FOO", "BAR"); note: the lint level is defined here --> $DIR/unsafe-env-suggestion.rs:3:9 | -LL | #![deny(deprecated_safe)] - | ^^^^^^^^^^^^^^^ +LL | #![deny(deprecated_safe_2024)] + | ^^^^^^^^^^^^^^^^^^^^ help: you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code | LL + // TODO: Audit that the environment access only happens in single-threaded code. diff --git a/tests/ui/simd/intrinsic/generic-elements.rs b/tests/ui/simd/intrinsic/generic-elements.rs index abceb08ecc5..aec75a67306 100644 --- a/tests/ui/simd/intrinsic/generic-elements.rs +++ b/tests/ui/simd/intrinsic/generic-elements.rs @@ -1,6 +1,6 @@ //@ build-fail -#![feature(repr_simd, intrinsics, rustc_attrs, adt_const_params)] +#![feature(repr_simd, intrinsics, rustc_attrs, adt_const_params, unsized_const_params)] #![allow(incomplete_features)] #[repr(simd)] @@ -14,8 +14,7 @@ struct i32x4(i32, i32, i32, i32); #[repr(simd)] #[derive(Copy, Clone)] #[allow(non_camel_case_types)] -struct i32x8(i32, i32, i32, i32, - i32, i32, i32, i32); +struct i32x8(i32, i32, i32, i32, i32, i32, i32, i32); #[repr(simd)] #[derive(Copy, Clone)] @@ -28,8 +27,7 @@ struct f32x4(f32, f32, f32, f32); #[repr(simd)] #[derive(Copy, Clone)] #[allow(non_camel_case_types)] -struct f32x8(f32, f32, f32, f32, - f32, f32, f32, f32); +struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32); extern "rust-intrinsic" { fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T; @@ -61,11 +59,11 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shuffle::<_, _, f32x2>(x, x, IDX2); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` simd_shuffle::<_, _, f32x4>(x, x, IDX4); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` simd_shuffle::<_, _, f32x8>(x, x, IDX8); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` simd_shuffle::<_, _, i32x8>(x, x, IDX2); //~^ ERROR expected return type of length 2, found `i32x8` with length 8 @@ -85,11 +83,11 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shuffle_generic::<_, f32x2, I2>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` simd_shuffle_generic::<_, f32x4, I4>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` simd_shuffle_generic::<_, f32x8, I8>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` simd_shuffle_generic::<_, i32x8, I2>(x, x); //~^ ERROR expected return type of length 2, found `i32x8` with length 8 diff --git a/tests/ui/simd/intrinsic/generic-elements.stderr b/tests/ui/simd/intrinsic/generic-elements.stderr index 26e01344939..0788a7c17f9 100644 --- a/tests/ui/simd/intrinsic/generic-elements.stderr +++ b/tests/ui/simd/intrinsic/generic-elements.stderr @@ -1,125 +1,125 @@ error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:46:9 + --> $DIR/generic-elements.rs:44:9 | LL | simd_insert(0, 0, 0); | ^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected inserted type `i32` (element of input `i32x4`), found `f64` - --> $DIR/generic-elements.rs:48:9 + --> $DIR/generic-elements.rs:46:9 | LL | simd_insert(x, 0, 1.0); | ^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_extract` intrinsic: expected return type `i32` (element of input `i32x4`), found `f32` - --> $DIR/generic-elements.rs:50:9 + --> $DIR/generic-elements.rs:48:9 | LL | simd_extract::<_, f32>(x, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:54:9 + --> $DIR/generic-elements.rs:52:9 | LL | simd_shuffle::<i32, _, i32>(0, 0, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:57:9 + --> $DIR/generic-elements.rs:55:9 | LL | simd_shuffle::<i32, _, i32>(0, 0, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:60:9 + --> $DIR/generic-elements.rs:58:9 | LL | simd_shuffle::<i32, _, i32>(0, 0, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` - --> $DIR/generic-elements.rs:63:9 + --> $DIR/generic-elements.rs:61:9 | LL | simd_shuffle::<_, _, f32x2>(x, x, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` - --> $DIR/generic-elements.rs:65:9 + --> $DIR/generic-elements.rs:63:9 | LL | simd_shuffle::<_, _, f32x4>(x, x, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` - --> $DIR/generic-elements.rs:67:9 + --> $DIR/generic-elements.rs:65:9 | LL | simd_shuffle::<_, _, f32x8>(x, x, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 2, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:70:9 + --> $DIR/generic-elements.rs:68:9 | LL | simd_shuffle::<_, _, i32x8>(x, x, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 4, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:72:9 + --> $DIR/generic-elements.rs:70:9 | LL | simd_shuffle::<_, _, i32x8>(x, x, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 8, found `i32x2` with length 2 - --> $DIR/generic-elements.rs:74:9 + --> $DIR/generic-elements.rs:72:9 | LL | simd_shuffle::<_, _, i32x2>(x, x, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:78:9 + --> $DIR/generic-elements.rs:76:9 | LL | simd_shuffle_generic::<i32, i32, I2>(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:81:9 + --> $DIR/generic-elements.rs:79:9 | LL | simd_shuffle_generic::<i32, i32, I4>(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:84:9 + --> $DIR/generic-elements.rs:82:9 | LL | simd_shuffle_generic::<i32, i32, I8>(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` - --> $DIR/generic-elements.rs:87:9 + --> $DIR/generic-elements.rs:85:9 | LL | simd_shuffle_generic::<_, f32x2, I2>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` - --> $DIR/generic-elements.rs:89:9 + --> $DIR/generic-elements.rs:87:9 | LL | simd_shuffle_generic::<_, f32x4, I4>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` - --> $DIR/generic-elements.rs:91:9 + --> $DIR/generic-elements.rs:89:9 | LL | simd_shuffle_generic::<_, f32x8, I8>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 2, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:94:9 + --> $DIR/generic-elements.rs:92:9 | LL | simd_shuffle_generic::<_, i32x8, I2>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 4, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:96:9 + --> $DIR/generic-elements.rs:94:9 | LL | simd_shuffle_generic::<_, i32x8, I4>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 8, found `i32x2` with length 2 - --> $DIR/generic-elements.rs:98:9 + --> $DIR/generic-elements.rs:96:9 | LL | simd_shuffle_generic::<_, i32x2, I8>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/simd/monomorphize-shuffle-index.rs b/tests/ui/simd/monomorphize-shuffle-index.rs index 379616884a1..30c345cb904 100644 --- a/tests/ui/simd/monomorphize-shuffle-index.rs +++ b/tests/ui/simd/monomorphize-shuffle-index.rs @@ -1,7 +1,7 @@ //@[old]run-pass //@[generic_with_fn]run-pass //@ revisions: old generic generic_with_fn -#![feature(repr_simd, intrinsics, adt_const_params, generic_const_exprs)] +#![feature(repr_simd, intrinsics, adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(incomplete_features)] extern "rust-intrinsic" { diff --git a/tests/ui/static/raw-ref-deref-with-unsafe.rs b/tests/ui/static/raw-ref-deref-with-unsafe.rs new file mode 100644 index 00000000000..4b8f72de5b7 --- /dev/null +++ b/tests/ui/static/raw-ref-deref-with-unsafe.rs @@ -0,0 +1,16 @@ +//@ check-pass +#![feature(const_mut_refs)] +use std::ptr; + +// This code should remain unsafe because of the two unsafe operations here, +// even if in a hypothetical future we deem all &raw (const|mut) *ptr exprs safe. + +static mut BYTE: u8 = 0; +static mut BYTE_PTR: *mut u8 = ptr::addr_of_mut!(BYTE); +// An unsafe static's ident is a place expression in its own right, so despite the above being safe +// (it's fine to create raw refs to places!) the following derefs the ptr before creating its ref +static mut DEREF_BYTE_PTR: *mut u8 = unsafe { ptr::addr_of_mut!(*BYTE_PTR) }; + +fn main() { + let _ = unsafe { DEREF_BYTE_PTR }; +} diff --git a/tests/ui/static/raw-ref-deref-without-unsafe.rs b/tests/ui/static/raw-ref-deref-without-unsafe.rs new file mode 100644 index 00000000000..f9bce4368c1 --- /dev/null +++ b/tests/ui/static/raw-ref-deref-without-unsafe.rs @@ -0,0 +1,18 @@ +#![feature(const_mut_refs)] + +use std::ptr; + +// This code should remain unsafe because of the two unsafe operations here, +// even if in a hypothetical future we deem all &raw (const|mut) *ptr exprs safe. + +static mut BYTE: u8 = 0; +static mut BYTE_PTR: *mut u8 = ptr::addr_of_mut!(BYTE); +// An unsafe static's ident is a place expression in its own right, so despite the above being safe +// (it's fine to create raw refs to places!) the following derefs the ptr before creating its ref! +static mut DEREF_BYTE_PTR: *mut u8 = ptr::addr_of_mut!(*BYTE_PTR); +//~^ ERROR: use of mutable static +//~| ERROR: dereference of raw pointer + +fn main() { + let _ = unsafe { DEREF_BYTE_PTR }; +} diff --git a/tests/ui/static/raw-ref-deref-without-unsafe.stderr b/tests/ui/static/raw-ref-deref-without-unsafe.stderr new file mode 100644 index 00000000000..ac4df8b410c --- /dev/null +++ b/tests/ui/static/raw-ref-deref-without-unsafe.stderr @@ -0,0 +1,19 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/raw-ref-deref-without-unsafe.rs:12:56 + | +LL | static mut DEREF_BYTE_PTR: *mut u8 = ptr::addr_of_mut!(*BYTE_PTR); + | ^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/raw-ref-deref-without-unsafe.rs:12:57 + | +LL | static mut DEREF_BYTE_PTR: *mut u8 = ptr::addr_of_mut!(*BYTE_PTR); + | ^^^^^^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/static/raw-ref-extern-static.rs b/tests/ui/static/raw-ref-extern-static.rs new file mode 100644 index 00000000000..95a53a8640d --- /dev/null +++ b/tests/ui/static/raw-ref-extern-static.rs @@ -0,0 +1,27 @@ +//@ check-pass +#![feature(raw_ref_op)] +use std::ptr; + +// see https://github.com/rust-lang/rust/issues/125833 +// notionally, taking the address of an extern static is a safe operation, +// as we only point at it instead of generating a true reference to it + +// it may potentially induce linker errors, but the safety of that is not about taking addresses! +// any safety obligation of the extern static's correctness in declaration is on the extern itself, +// see RFC 3484 for more on that: https://rust-lang.github.io/rfcs/3484-unsafe-extern-blocks.html + +extern "C" { + static THERE: u8; + static mut SOMEWHERE: u8; +} + +fn main() { + let ptr2there = ptr::addr_of!(THERE); + let ptr2somewhere = ptr::addr_of!(SOMEWHERE); + let ptr2somewhere = ptr::addr_of_mut!(SOMEWHERE); + + // testing both addr_of and the expression it directly expands to + let raw2there = &raw const THERE; + let raw2somewhere = &raw const SOMEWHERE; + let raw2somewhere = &raw mut SOMEWHERE; +} diff --git a/tests/ui/static/raw-ref-static-mut.rs b/tests/ui/static/raw-ref-static-mut.rs new file mode 100644 index 00000000000..6855cc7b050 --- /dev/null +++ b/tests/ui/static/raw-ref-static-mut.rs @@ -0,0 +1,17 @@ +//@ check-pass +#![feature(raw_ref_op)] +use std::ptr; + +// see https://github.com/rust-lang/rust/issues/125833 +// notionally, taking the address of a static mut is a safe operation, +// as we only point at it instead of generating a true reference to it +static mut NOWHERE: usize = 0; + +fn main() { + let p2nowhere = ptr::addr_of!(NOWHERE); + let p2nowhere = ptr::addr_of_mut!(NOWHERE); + + // testing both addr_of and the expression it directly expands to + let raw2nowhere = &raw const NOWHERE; + let raw2nowhere = &raw mut NOWHERE; +} diff --git a/tests/ui/statics/const_generics.rs b/tests/ui/statics/const_generics.rs index 70d9b933a76..7f64f6995a4 100644 --- a/tests/ui/statics/const_generics.rs +++ b/tests/ui/statics/const_generics.rs @@ -11,7 +11,7 @@ //@[opt] compile-flags: -O #![feature(const_refs_to_static)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] static FOO: usize = 42; diff --git a/tests/ui/symbol-names/const-generics-str-demangling.rs b/tests/ui/symbol-names/const-generics-str-demangling.rs index 871f3694e00..87b1fdf8a47 100644 --- a/tests/ui/symbol-names/const-generics-str-demangling.rs +++ b/tests/ui/symbol-names/const-generics-str-demangling.rs @@ -1,7 +1,7 @@ //@ build-fail //@ compile-flags: -C symbol-mangling-version=v0 --crate-name=c //@ normalize-stderr-test: "c\[.*?\]" -> "c[HASH]" -#![feature(adt_const_params, rustc_attrs)] +#![feature(adt_const_params, unsized_const_params, rustc_attrs)] #![allow(incomplete_features)] pub struct Str<const S: &'static str>; diff --git a/tests/ui/symbol-names/const-generics-structural-demangling.rs b/tests/ui/symbol-names/const-generics-structural-demangling.rs index 6c79ed7314c..9f5f31177b3 100644 --- a/tests/ui/symbol-names/const-generics-structural-demangling.rs +++ b/tests/ui/symbol-names/const-generics-structural-demangling.rs @@ -3,10 +3,10 @@ //@ normalize-stderr-test: "c\[[0-9a-f]+\]" -> "c[HASH]" -#![feature(adt_const_params, decl_macro, rustc_attrs)] +#![feature(adt_const_params, unsized_const_params, decl_macro, rustc_attrs)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; pub struct RefByte<const RB: &'static u8>; @@ -14,7 +14,7 @@ pub struct RefByte<const RB: &'static u8>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::RefByte<{&123}>>) -impl RefByte<{&123}> {} +impl RefByte<{ &123 }> {} // FIXME(eddyb) this was supposed to be `RefMutZst` with `&mut []`, // but that is currently not allowed in const generics. @@ -24,7 +24,7 @@ pub struct RefZst<const RMZ: &'static [u8; 0]>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::RefZst<{&[]}>>) -impl RefZst<{&[]}> {} +impl RefZst<{ &[] }> {} pub struct Array3Bytes<const A3B: [u8; 3]>; @@ -32,7 +32,7 @@ pub struct Array3Bytes<const A3B: [u8; 3]>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::Array3Bytes<{[1, 2, 3]}>>) -impl Array3Bytes<{[1, 2, 3]}> {} +impl Array3Bytes<{ [1, 2, 3] }> {} pub struct TupleByteBool<const TBB: (u8, bool)>; @@ -40,9 +40,9 @@ pub struct TupleByteBool<const TBB: (u8, bool)>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::TupleByteBool<{(1, false)}>>) -impl TupleByteBool<{(1, false)}> {} +impl TupleByteBool<{ (1, false) }> {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] pub enum MyOption<T> { Some(T), None, @@ -56,7 +56,7 @@ pub struct OptionUsize<const OU: MyOption<usize>>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::OptionUsize<{c::MyOption::<usize>::None}>>) -impl OptionUsize<{MyOption::None}> {} +impl OptionUsize<{ MyOption::None }> {} // HACK(eddyb) the full mangling is only in `.stderr` because we can normalize // the `core` disambiguator hash away there, but not here. @@ -64,9 +64,9 @@ impl OptionUsize<{MyOption::None}> {} //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::OptionUsize<{c::MyOption::<usize>::Some(0)}>>) -impl OptionUsize<{MyOption::Some(0)}> {} +impl OptionUsize<{ MyOption::Some(0) }> {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] pub struct Foo { s: &'static str, ch: char, @@ -78,12 +78,12 @@ pub struct Foo_<const F: Foo>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::Foo_<{c::Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}>>) -impl Foo_<{Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}> {} +impl Foo_<{ Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] } }> {} // NOTE(eddyb) this tests specifically the use of disambiguators in field names, // using macros 2.0 hygiene to create a `struct` with conflicting field names. macro duplicate_field_name_test($x:ident) { - #[derive(PartialEq, Eq, ConstParamTy)] + #[derive(PartialEq, Eq, UnsizedConstParamTy)] pub struct Bar { $x: u8, x: u16, @@ -94,7 +94,7 @@ macro duplicate_field_name_test($x:ident) { //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(<c::Bar_<{c::Bar { x: 123, x: 4096 }}>>) - impl Bar_<{Bar { $x: 123, x: 4096 }}> {} + impl Bar_<{ Bar { $x: 123, x: 4096 } }> {} } duplicate_field_name_test!(x); diff --git a/tests/ui/target-feature/gate.rs b/tests/ui/target-feature/gate.rs index af47e84672f..94d79d56c59 100644 --- a/tests/ui/target-feature/gate.rs +++ b/tests/ui/target-feature/gate.rs @@ -21,6 +21,7 @@ // gate-test-loongarch_target_feature // gate-test-lahfsahf_target_feature // gate-test-prfchw_target_feature +// gate-test-s390x_target_feature #[target_feature(enable = "avx512bw")] //~^ ERROR: currently unstable diff --git a/tests/ui/target-feature/gate.stderr b/tests/ui/target-feature/gate.stderr index 31198f73c20..a69020e6864 100644 --- a/tests/ui/target-feature/gate.stderr +++ b/tests/ui/target-feature/gate.stderr @@ -1,5 +1,5 @@ error[E0658]: the target feature `avx512bw` is currently unstable - --> $DIR/gate.rs:25:18 + --> $DIR/gate.rs:26:18 | LL | #[target_feature(enable = "avx512bw")] | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.rs b/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.rs index fc64381b961..b61a21eab41 100644 --- a/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.rs +++ b/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.rs @@ -18,7 +18,8 @@ trait TraitC {} fn foo<T>() where for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl TraitC>>, - //~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~^ ERROR late-bound const parameters cannot be used currently + //~| ERROR defaults for generic parameters are not allowed in `for<...>` binders //~| ERROR `impl Trait` is not allowed in bounds { } diff --git a/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.stderr b/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.stderr index a4a79413a9b..e891df3f0c0 100644 --- a/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.stderr +++ b/tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.stderr @@ -1,3 +1,9 @@ +error: late-bound const parameters cannot be used currently + --> $DIR/bad-suggestion-on-missing-assoc.rs:20:15 + | +LL | for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl TraitC>>, + | ^ + warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/bad-suggestion-on-missing-assoc.rs:1:12 | @@ -29,6 +35,6 @@ LL | for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl Trai | = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error: aborting due to 2 previous errors; 2 warnings emitted +error: aborting due to 3 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0562`. diff --git a/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.rs b/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.rs index c6bf0dc1f72..13f9f196970 100644 --- a/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.rs +++ b/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.rs @@ -4,10 +4,11 @@ pub fn bar() where for<const N: usize = { + //~^ ERROR late-bound const parameters cannot be used currently + //~| ERROR defaults for generic parameters are not allowed in `for<...>` binders (||1usize)() }> V: IntoIterator -//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders -//~^^ ERROR cannot find type `V` in this scope +//~^ ERROR cannot find type `V` in this scope { } diff --git a/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.stderr b/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.stderr index edc55a3c8e6..d9e77dec794 100644 --- a/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.stderr +++ b/tests/ui/traits/non_lifetime_binders/binder-defaults-112547.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `V` in this scope - --> $DIR/binder-defaults-112547.rs:8:4 + --> $DIR/binder-defaults-112547.rs:10:4 | LL | }> V: IntoIterator | ^ not found in this scope @@ -9,6 +9,12 @@ help: you might be missing a type parameter LL | pub fn bar<V>() | +++ +error: late-bound const parameters cannot be used currently + --> $DIR/binder-defaults-112547.rs:6:15 + | +LL | for<const N: usize = { + | ^ + warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/binder-defaults-112547.rs:1:12 | @@ -23,10 +29,12 @@ error: defaults for generic parameters are not allowed in `for<...>` binders | LL | for<const N: usize = { | _________^ +LL | | +LL | | LL | | (||1usize)() LL | | }> V: IntoIterator | |_^ -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 3 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.rs b/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.rs index f33da416ad8..bdfe41ca11b 100644 --- a/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.rs +++ b/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.rs @@ -5,8 +5,9 @@ fn fun() where for<T = (), const N: usize = 1> ():, -//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders -//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~^ ERROR late-bound const parameters cannot be used currently + //~| ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~| ERROR defaults for generic parameters are not allowed in `for<...>` binders {} fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.stderr b/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.stderr index 7fe82f1f097..947dd3a73bf 100644 --- a/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.stderr +++ b/tests/ui/traits/non_lifetime_binders/binder-defaults-119489.stderr @@ -1,3 +1,9 @@ +error: late-bound const parameters cannot be used currently + --> $DIR/binder-defaults-119489.rs:7:23 + | +LL | for<T = (), const N: usize = 1> ():, + | ^ + warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/binder-defaults-119489.rs:1:12 | @@ -27,5 +33,5 @@ error: defaults for generic parameters are not allowed in `for<...>` binders LL | for<T = (), const N: usize = 1> ():, | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors; 2 warnings emitted +error: aborting due to 3 previous errors; 2 warnings emitted diff --git a/tests/ui/traits/non_lifetime_binders/late-const-param-wf.rs b/tests/ui/traits/non_lifetime_binders/late-const-param-wf.rs new file mode 100644 index 00000000000..2d44388f875 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/late-const-param-wf.rs @@ -0,0 +1,11 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn b() +where + for<const C: usize> [(); C]: Copy, + //~^ ERROR late-bound const parameters cannot be used currently +{ +} + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/late-const-param-wf.stderr b/tests/ui/traits/non_lifetime_binders/late-const-param-wf.stderr new file mode 100644 index 00000000000..136d533a03c --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/late-const-param-wf.stderr @@ -0,0 +1,17 @@ +error: late-bound const parameters cannot be used currently + --> $DIR/late-const-param-wf.rs:6:15 + | +LL | for<const C: usize> [(); C]: Copy, + | ^ + +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/late-const-param-wf.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to 1 previous error; 1 warning emitted + diff --git a/tests/ui/try-trait/bad-interconversion.stderr b/tests/ui/try-trait/bad-interconversion.stderr index c30b6334fed..642a93d64e2 100644 --- a/tests/ui/try-trait/bad-interconversion.stderr +++ b/tests/ui/try-trait/bad-interconversion.stderr @@ -23,9 +23,7 @@ LL | Some(3)?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>` | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>` - = help: the following other types implement trait `FromResidual<R>`: - `Result<T, F>` implements `FromResidual<Result<Infallible, E>>` - `Result<T, F>` implements `FromResidual<Yeet<E>>` + = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>` error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result` --> $DIR/bad-interconversion.rs:17:31 @@ -36,9 +34,7 @@ LL | Ok(ControlFlow::Break(123)?) | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result<u64, String>` | = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>` - = help: the following other types implement trait `FromResidual<R>`: - `Result<T, F>` implements `FromResidual<Result<Infallible, E>>` - `Result<T, F>` implements `FromResidual<Yeet<E>>` + = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>` error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/bad-interconversion.rs:22:22 @@ -49,9 +45,7 @@ LL | Some(Err("hello")?) | ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information | = help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>` - = help: the following other types implement trait `FromResidual<R>`: - `Option<T>` implements `FromResidual<Yeet<()>>` - `Option<T>` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option<T>` error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option` --> $DIR/bad-interconversion.rs:27:33 @@ -62,9 +56,7 @@ LL | Some(ControlFlow::Break(123)?) | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>` | = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>` - = help: the following other types implement trait `FromResidual<R>`: - `Option<T>` implements `FromResidual<Yeet<()>>` - `Option<T>` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option<T>` error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` --> $DIR/bad-interconversion.rs:32:39 diff --git a/tests/ui/try-trait/option-to-result.stderr b/tests/ui/try-trait/option-to-result.stderr index 2d97226275d..8055b2a0b04 100644 --- a/tests/ui/try-trait/option-to-result.stderr +++ b/tests/ui/try-trait/option-to-result.stderr @@ -8,9 +8,7 @@ LL | a?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), ()>` | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), ()>` - = help: the following other types implement trait `FromResidual<R>`: - `Result<T, F>` implements `FromResidual<Result<Infallible, E>>` - `Result<T, F>` implements `FromResidual<Yeet<E>>` + = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>` error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/option-to-result.rs:11:6 @@ -22,9 +20,7 @@ LL | a?; | ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information | = help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>` - = help: the following other types implement trait `FromResidual<R>`: - `Option<T>` implements `FromResidual<Yeet<()>>` - `Option<T>` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option<T>` error: aborting due to 2 previous errors diff --git a/tests/ui/try-trait/try-on-option.stderr b/tests/ui/try-trait/try-on-option.stderr index 84a51a078af..15d0b28ddc1 100644 --- a/tests/ui/try-trait/try-on-option.stderr +++ b/tests/ui/try-trait/try-on-option.stderr @@ -8,9 +8,7 @@ LL | x?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>` | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>` - = help: the following other types implement trait `FromResidual<R>`: - `Result<T, F>` implements `FromResidual<Result<Infallible, E>>` - `Result<T, F>` implements `FromResidual<Yeet<E>>` + = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>` error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) --> $DIR/try-on-option.rs:11:6 diff --git a/tests/ui/typeck/ice-unexpected-region-123863.stderr b/tests/ui/typeck/ice-unexpected-region-123863.stderr index 08f1ede95b4..0479f134a38 100644 --- a/tests/ui/typeck/ice-unexpected-region-123863.stderr +++ b/tests/ui/typeck/ice-unexpected-region-123863.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/ice-unexpected-region-123863.rs:3:27 @@ -21,6 +25,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | LL + #![feature(adt_const_params)] | +help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait + | +LL + #![feature(unsized_const_params)] + | error[E0223]: ambiguous associated type --> $DIR/ice-unexpected-region-123863.rs:5:5 diff --git a/tests/ui/uninhabited/uninhabited-patterns.stderr b/tests/ui/uninhabited/uninhabited-patterns.stderr index a6fda88f032..ca62386d7ef 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.stderr +++ b/tests/ui/uninhabited/uninhabited-patterns.stderr @@ -4,6 +4,7 @@ error: unreachable pattern LL | Ok(box _) => (), | ^^^^^^^^^ | + = note: this pattern matches no values because `NotSoSecretlyEmpty` is uninhabited note: the lint level is defined here --> $DIR/uninhabited-patterns.rs:4:9 | @@ -15,12 +16,16 @@ error: unreachable pattern | LL | Err(Ok(_y)) => (), | ^^^^^^^^^^^ + | + = note: this pattern matches no values because `NotSoSecretlyEmpty` is uninhabited error: unreachable pattern --> $DIR/uninhabited-patterns.rs:42:15 | LL | while let Some(_y) = foo() { | ^^^^^^^^ + | + = note: this pattern matches no values because `NotSoSecretlyEmpty` is uninhabited error: aborting due to 3 previous errors diff --git a/tests/ui/unsized/box-instead-of-dyn-fn.stderr b/tests/ui/unsized/box-instead-of-dyn-fn.stderr index f2828b384b2..1f1845569ef 100644 --- a/tests/ui/unsized/box-instead-of-dyn-fn.stderr +++ b/tests/ui/unsized/box-instead-of-dyn-fn.stderr @@ -4,11 +4,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> dyn Fn() + 'a { | ^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> impl Fn() + 'a { | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL ~ fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> Box<dyn Fn() + 'a> { LL | diff --git a/tests/ui/unsized/issue-91801.stderr b/tests/ui/unsized/issue-91801.stderr index d1d652d1860..e13cabbb81d 100644 --- a/tests/ui/unsized/issue-91801.stderr +++ b/tests/ui/unsized/issue-91801.stderr @@ -4,10 +4,14 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Validator<'a> { | ^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: box the return type, and wrap all of the returned values in `Box::new` +help: consider returning an `impl Trait` instead of a `dyn Trait` | -LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Box<Validator<'a>> { - | ++++ + +LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> impl Validator<'a> { + | ++++ +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` + | +LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Box<dyn Validator<'a>> { + | +++++++ + error: aborting due to 1 previous error diff --git a/tests/ui/unsized/issue-91803.stderr b/tests/ui/unsized/issue-91803.stderr index 632af02b4b6..3b89066499d 100644 --- a/tests/ui/unsized/issue-91803.stderr +++ b/tests/ui/unsized/issue-91803.stderr @@ -4,11 +4,11 @@ error[E0746]: return type cannot have an unboxed trait object LL | fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> { | ^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | LL | fn or<'a>(first: &'static dyn Foo<'a>) -> impl Foo<'a> { | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | LL | fn or<'a>(first: &'static dyn Foo<'a>) -> Box<dyn Foo<'a>> { | ++++ + diff --git a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr b/tests/ui/wf/wf-unsafe-trait-obj-match.stderr index e30cb8ff921..8d5b377988c 100644 --- a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/tests/ui/wf/wf-unsafe-trait-obj-match.stderr @@ -26,8 +26,8 @@ LL | trait Trait: Sized {} | | | this trait cannot be made into an object... = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Trait` for this new enum and using it instead: - R S + R = note: required for the cast from `&S` to `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object @@ -48,8 +48,8 @@ LL | trait Trait: Sized {} | | | this trait cannot be made into an object... = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Trait` for this new enum and using it instead: - R S + R = note: required for the cast from `&R` to `&dyn Trait` error: aborting due to 3 previous errors |
