diff options
Diffstat (limited to 'src/test')
383 files changed, 5340 insertions, 1122 deletions
diff --git a/src/test/assembly/x86_64-no-jump-tables.rs b/src/test/assembly/x86_64-no-jump-tables.rs new file mode 100644 index 00000000000..007c3591a4a --- /dev/null +++ b/src/test/assembly/x86_64-no-jump-tables.rs @@ -0,0 +1,34 @@ +// Test that jump tables are (not) emitted when the `-Zno-jump-tables` +// flag is (not) set. + +// revisions: unset set +// assembly-output: emit-asm +// compile-flags: -O +// [set] compile-flags: -Zno-jump-tables +// only-x86_64 + +#![crate_type = "lib"] + +extern "C" { + fn bar1(); + fn bar2(); + fn bar3(); + fn bar4(); + fn bar5(); + fn bar6(); +} + +// CHECK-LABEL: foo: +#[no_mangle] +pub unsafe fn foo(x: i32) { + // unset: LJTI0_0 + // set-NOT: LJTI0_0 + match x { + 1 => bar1(), + 2 => bar2(), + 3 => bar3(), + 4 => bar4(), + 5 => bar5(), + _ => bar6(), + } +} diff --git a/src/test/codegen/avr/avr-func-addrspace.rs b/src/test/codegen/avr/avr-func-addrspace.rs index cbbcfad3ef4..e9740e30da4 100644 --- a/src/test/codegen/avr/avr-func-addrspace.rs +++ b/src/test/codegen/avr/avr-func-addrspace.rs @@ -9,7 +9,7 @@ // It also validates that functions can be called through function pointers // through traits. -#![feature(no_core, lang_items, unboxed_closures, arbitrary_self_types)] +#![feature(no_core, lang_items, intrinsics, unboxed_closures, arbitrary_self_types)] #![crate_type = "lib"] #![no_core] @@ -49,6 +49,10 @@ pub trait Fn<Args: Tuple>: FnOnce<Args> { extern "rust-call" fn call(&self, args: Args) -> Self::Output; } +extern "rust-intrinsic" { + pub fn transmute<Src, Dst>(src: Src) -> Dst; +} + pub static mut STORAGE_FOO: fn(&usize, &mut u32) -> Result<(), ()> = arbitrary_black_box; pub static mut STORAGE_BAR: u32 = 12; @@ -87,3 +91,21 @@ pub extern "C" fn test() { STORAGE_FOO(&1, &mut buf); } } + +// Validate that we can codegen transmutes between data ptrs and fn ptrs. + +// CHECK: define{{.+}}{{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}} @transmute_data_ptr_to_fn({{\{\}\*|ptr}}{{.*}} %x) +#[no_mangle] +pub unsafe fn transmute_data_ptr_to_fn(x: *const ()) -> fn() { + // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), + // as long as it doesn't cause a verifier error by using `bitcast`. + transmute(x) +} + +// CHECK: define{{.+}}{{\{\}\*|ptr}} @transmute_fn_ptr_to_data({{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}}{{.*}} %x) +#[no_mangle] +pub unsafe fn transmute_fn_ptr_to_data(x: fn()) -> *const () { + // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), + // as long as it doesn't cause a verifier error by using `bitcast`. + transmute(x) +} diff --git a/src/test/codegen/comparison-operators-newtype.rs b/src/test/codegen/comparison-operators-newtype.rs new file mode 100644 index 00000000000..5cf6c3ac0a2 --- /dev/null +++ b/src/test/codegen/comparison-operators-newtype.rs @@ -0,0 +1,49 @@ +// The `derive(PartialOrd)` for a newtype doesn't override `lt`/`le`/`gt`/`ge`. +// This double-checks that the `Option<Ordering>` intermediate values used +// in the operators for such a type all optimize away. + +// compile-flags: -C opt-level=1 +// min-llvm-version: 15.0 + +#![crate_type = "lib"] + +use std::cmp::Ordering; + +#[derive(PartialOrd, PartialEq)] +pub struct Foo(u16); + +// CHECK-LABEL: @check_lt +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_lt(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ult i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a < b +} + +// CHECK-LABEL: @check_le +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_le(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ule i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a <= b +} + +// CHECK-LABEL: @check_gt +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_gt(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ugt i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a > b +} + +// CHECK-LABEL: @check_ge +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_ge(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp uge i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a >= b +} diff --git a/src/test/codegen/dst-vtable-align-nonzero.rs b/src/test/codegen/dst-vtable-align-nonzero.rs index 14c4c3f30f9..54f6e7f992f 100644 --- a/src/test/codegen/dst-vtable-align-nonzero.rs +++ b/src/test/codegen/dst-vtable-align-nonzero.rs @@ -1,6 +1,7 @@ -// compile-flags: -O +// compile-flags: -O -Z merge-functions=disabled #![crate_type = "lib"] +#![feature(core_intrinsics)] // This test checks that we annotate alignment loads from vtables with nonzero range metadata, // and that this allows LLVM to eliminate redundant `align >= 1` checks. @@ -42,4 +43,19 @@ pub fn does_not_eliminate_runtime_check_when_align_2( &x.dst } +// CHECK-LABEL: @align_load_from_align_of_val +#[no_mangle] +pub fn align_load_from_align_of_val(x: &dyn Trait) -> usize { + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]] + core::mem::align_of_val(x) +} + +// CHECK-LABEL: @align_load_from_vtable_align_intrinsic +#[no_mangle] +pub unsafe fn align_load_from_vtable_align_intrinsic(x: &dyn Trait) -> usize { + let (data, vtable): (*const (), *const ()) = core::mem::transmute(x); + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]] + core::intrinsics::vtable_align(vtable) +} + // CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] 0} diff --git a/src/test/codegen/dst-vtable-size-range.rs b/src/test/codegen/dst-vtable-size-range.rs new file mode 100644 index 00000000000..671c8abdebd --- /dev/null +++ b/src/test/codegen/dst-vtable-size-range.rs @@ -0,0 +1,35 @@ +// compile-flags: -O -Z merge-functions=disabled + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +// Check that we annotate size loads from vtables with 0..(isize::MAX + 1) range metadata. + +pub trait Trait { + fn f(&self); +} + +// Note that rustc uses inclusive bounds, but LLVM uses exclusive bounds for range metadata. +// CHECK-LABEL: @generate_exclusive_bound +#[no_mangle] +pub fn generate_exclusive_bound() -> usize { + // CHECK: ret [[USIZE:i[0-9]+]] [[EXCLUSIVE_BOUND:[-0-9]+]] + isize::MAX as usize + 1 +} + +// CHECK-LABEL: @size_load_from_size_of_val +#[no_mangle] +pub fn size_load_from_size_of_val(x: &dyn Trait) -> usize { + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META:![0-9]+]] + core::mem::size_of_val(x) +} + +// CHECK-LABEL: @size_load_from_vtable_size_intrinsic +#[no_mangle] +pub unsafe fn size_load_from_vtable_size_intrinsic(x: &dyn Trait) -> usize { + let (data, vtable): (*const (), *const ()) = core::mem::transmute(x); + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]] + core::intrinsics::vtable_size(vtable) +} + +// CHECK: [[RANGE_META]] = !{[[USIZE]] 0, [[USIZE]] [[EXCLUSIVE_BOUND]]} diff --git a/src/test/codegen/enum-match.rs b/src/test/codegen/enum-match.rs index 44f1b408d21..827eb20154a 100644 --- a/src/test/codegen/enum-match.rs +++ b/src/test/codegen/enum-match.rs @@ -34,8 +34,8 @@ pub enum Enum1 { // CHECK: define i8 @match1{{.*}} // CHECK-NEXT: start: -// CHECK-NEXT: %1 = {{.*}}call i8 @llvm.usub.sat.i8(i8 %0, i8 1) -// CHECK-NEXT: switch i8 %1, label {{.*}} [ +// CHECK-NEXT: [[DISCR:%.*]] = {{.*}}call i8 @llvm.usub.sat.i8(i8 %0, i8 1) +// CHECK-NEXT: switch i8 [[DISCR]], label {{.*}} [ #[no_mangle] pub fn match1(e: Enum1) -> u8 { use Enum1::*; diff --git a/src/test/codegen/no-jump-tables.rs b/src/test/codegen/no-jump-tables.rs new file mode 100644 index 00000000000..8e2cb47566e --- /dev/null +++ b/src/test/codegen/no-jump-tables.rs @@ -0,0 +1,22 @@ +// Test that the `no-jump-tables` function attribute are (not) emitted when +// the `-Zno-jump-tables` flag is (not) set. + +// revisions: unset set +// needs-llvm-components: x86 +// compile-flags: --target x86_64-unknown-linux-gnu +// [set] compile-flags: -Zno-jump-tables + +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_core] + +#[lang = "sized"] +trait Sized {} + +#[no_mangle] +pub fn foo() { + // CHECK: @foo() unnamed_addr #0 + + // unset-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} } + // set: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} } +} diff --git a/src/test/codegen/sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs b/src/test/codegen/sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs index 0afd9727517..8e0d02550ee 100644 --- a/src/test/codegen/sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs +++ b/src/test/codegen/sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs @@ -20,24 +20,21 @@ impl Copy for i32 {} pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 { // CHECK-LABEL: define{{.*}}foo - // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 - // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE1:[0-9]+]] + // CHECK-SAME: {{.*}}!{{<unknown kind #36>|kcfi_type}} ![[TYPE1:[0-9]+]] // CHECK: call i32 %f(i32 %arg){{.*}}[ "kcfi"(i32 -1666898348) ] f(arg) } pub fn bar(f: fn(i32, i32) -> i32, arg1: i32, arg2: i32) -> i32 { // CHECK-LABEL: define{{.*}}bar - // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 - // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE2:[0-9]+]] + // CHECK-SAME: {{.*}}!{{<unknown kind #36>|kcfi_type}} ![[TYPE2:[0-9]+]] // CHECK: call i32 %f(i32 %arg1, i32 %arg2){{.*}}[ "kcfi"(i32 -1789026986) ] f(arg1, arg2) } pub fn baz(f: fn(i32, i32, i32) -> i32, arg1: i32, arg2: i32, arg3: i32) -> i32 { // CHECK-LABEL: define{{.*}}baz - // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 - // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE3:[0-9]+]] + // CHECK-SAME: {{.*}}!{{<unknown kind #36>|kcfi_type}} ![[TYPE3:[0-9]+]] // CHECK: call i32 %f(i32 %arg1, i32 %arg2, i32 %arg3){{.*}}[ "kcfi"(i32 1248878270) ] f(arg1, arg2, arg3) } diff --git a/src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs b/src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs index 8447bbeb1ed..ea5bae18e23 100644 --- a/src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs +++ b/src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs @@ -9,7 +9,8 @@ // CHECK: @rust_item_that_can_unwind() unnamed_addr [[ATTR0:#[0-9]+]] #[no_mangle] pub unsafe extern "C-unwind" fn rust_item_that_can_unwind() { - // CHECK: call void @_ZN4core9panicking15panic_no_unwind + // Handle both legacy and v0 symbol mangling. + // CHECK: call void @{{.*core9panicking19panic_cannot_unwind}} may_unwind(); } diff --git a/src/test/codegen/unwind-and-panic-abort.rs b/src/test/codegen/unwind-and-panic-abort.rs index f238741e599..e43e73b96b9 100644 --- a/src/test/codegen/unwind-and-panic-abort.rs +++ b/src/test/codegen/unwind-and-panic-abort.rs @@ -9,7 +9,8 @@ extern "C-unwind" { // CHECK: Function Attrs:{{.*}}nounwind // CHECK-NEXT: define{{.*}}void @foo -// CHECK: call void @_ZN4core9panicking15panic_no_unwind +// Handle both legacy and v0 symbol mangling. +// CHECK: call void @{{.*core9panicking19panic_cannot_unwind}} #[no_mangle] pub unsafe extern "C" fn foo() { bar(); diff --git a/src/test/codegen/vec-shrink-panik.rs b/src/test/codegen/vec-shrink-panik.rs index 18409014bde..aa6589dc35b 100644 --- a/src/test/codegen/vec-shrink-panik.rs +++ b/src/test/codegen/vec-shrink-panik.rs @@ -18,11 +18,11 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) { pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> { // CHECK-NOT: panic - // Call to panic_no_unwind in case of double-panic is expected, + // Call to panic_cannot_unwind in case of double-panic is expected, // but other panics are not. // CHECK: cleanup - // CHECK-NEXT: ; call core::panicking::panic_no_unwind - // CHECK-NEXT: panic_no_unwind + // CHECK-NEXT: ; call core::panicking::panic_cannot_unwind + // CHECK-NEXT: panic_cannot_unwind // CHECK-NOT: panic vec.into_boxed_slice() @@ -33,15 +33,15 @@ pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> { pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> { // CHECK-NOT: panic - // Call to panic_no_unwind in case of double-panic is expected, + // Call to panic_cannot_unwind in case of double-panic is expected, // but other panics are not. // CHECK: cleanup - // CHECK-NEXT: ; call core::panicking::panic_no_unwind - // CHECK-NEXT: panic_no_unwind + // CHECK-NEXT: ; call core::panicking::panic_cannot_unwind + // CHECK-NEXT: panic_cannot_unwind // CHECK-NOT: panic iter.iter().copied().collect() } -// CHECK: ; core::panicking::panic_no_unwind -// CHECK: declare void @{{.*}}panic_no_unwind +// CHECK: ; core::panicking::panic_cannot_unwind +// CHECK: declare void @{{.*}}panic_cannot_unwind diff --git a/src/test/mir-opt/building/custom/enums.rs b/src/test/mir-opt/building/custom/enums.rs new file mode 100644 index 00000000000..e5cd4563778 --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.rs @@ -0,0 +1,120 @@ +#![feature(custom_mir, core_intrinsics)] + +extern crate core; +use core::intrinsics::mir::*; + +// EMIT_MIR enums.switch_bool.built.after.mir +#[custom_mir(dialect = "built")] +pub fn switch_bool(b: bool) -> u32 { + mir!( + { + match b { + true => t, + false => f, + _ => f, + } + } + + t = { + RET = 5; + Return() + } + + f = { + RET = 10; + Return() + } + ) +} + +// EMIT_MIR enums.switch_option.built.after.mir +#[custom_mir(dialect = "built")] +pub fn switch_option(option: Option<()>) -> bool { + mir!( + { + let discr = Discriminant(option); + match discr { + 0 => n, + 1 => s, + _ => s, + } + } + + n = { + RET = false; + Return() + } + + s = { + RET = true; + Return() + } + ) +} + +#[repr(u8)] +enum Bool { + False = 0, + True = 1, +} + +// EMIT_MIR enums.switch_option_repr.built.after.mir +#[custom_mir(dialect = "built")] +fn switch_option_repr(option: Bool) -> bool { + mir!( + { + let discr = Discriminant(option); + match discr { + 0 => f, + _ => t, + } + } + + t = { + RET = true; + Return() + } + + f = { + RET = false; + Return() + } + ) +} + +// EMIT_MIR enums.set_discr.built.after.mir +#[custom_mir(dialect = "runtime", phase = "initial")] +fn set_discr(option: &mut Option<()>) { + mir!({ + SetDiscriminant(*option, 0); + Return() + }) +} + +// EMIT_MIR enums.set_discr_repr.built.after.mir +#[custom_mir(dialect = "runtime", phase = "initial")] +fn set_discr_repr(b: &mut Bool) { + mir!({ + SetDiscriminant(*b, 0); + Return() + }) +} + +fn main() { + assert_eq!(switch_bool(true), 5); + assert_eq!(switch_bool(false), 10); + + assert_eq!(switch_option(Some(())), true); + assert_eq!(switch_option(None), false); + + assert_eq!(switch_option_repr(Bool::True), true); + assert_eq!(switch_option_repr(Bool::False), false); + + let mut opt = Some(()); + set_discr(&mut opt); + assert_eq!(opt, None); + + let mut b = Bool::True; + set_discr_repr(&mut b); + assert!(matches!(b, Bool::False)); +} diff --git a/src/test/mir-opt/building/custom/enums.set_discr.built.after.mir b/src/test/mir-opt/building/custom/enums.set_discr.built.after.mir new file mode 100644 index 00000000000..7de9ed0983f --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.set_discr.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `set_discr` after built + +fn set_discr(_1: &mut Option<()>) -> () { + let mut _0: (); // return place in scope 0 at $DIR/enums.rs:+0:39: +0:39 + + bb0: { + discriminant((*_1)) = 0; // scope 0 at $DIR/enums.rs:+2:9: +2:36 + return; // scope 0 at $DIR/enums.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/enums.set_discr_repr.built.after.mir b/src/test/mir-opt/building/custom/enums.set_discr_repr.built.after.mir new file mode 100644 index 00000000000..6fdc3d0f4d4 --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.set_discr_repr.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `set_discr_repr` after built + +fn set_discr_repr(_1: &mut Bool) -> () { + let mut _0: (); // return place in scope 0 at $DIR/enums.rs:+0:33: +0:33 + + bb0: { + discriminant((*_1)) = 0; // scope 0 at $DIR/enums.rs:+2:9: +2:31 + return; // scope 0 at $DIR/enums.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/enums.switch_bool.built.after.mir b/src/test/mir-opt/building/custom/enums.switch_bool.built.after.mir new file mode 100644 index 00000000000..95c57d2dca3 --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.switch_bool.built.after.mir @@ -0,0 +1,19 @@ +// MIR for `switch_bool` after built + +fn switch_bool(_1: bool) -> u32 { + let mut _0: u32; // return place in scope 0 at $DIR/enums.rs:+0:32: +0:35 + + bb0: { + switchInt(_1) -> [1: bb1, 0: bb2, otherwise: bb2]; // scope 0 at $DIR/enums.rs:+3:13: +7:14 + } + + bb1: { + _0 = const 5_u32; // scope 0 at $DIR/enums.rs:+11:13: +11:20 + return; // scope 0 at $DIR/enums.rs:+12:13: +12:21 + } + + bb2: { + _0 = const 10_u32; // scope 0 at $DIR/enums.rs:+16:13: +16:21 + return; // scope 0 at $DIR/enums.rs:+17:13: +17:21 + } +} diff --git a/src/test/mir-opt/building/custom/enums.switch_option.built.after.mir b/src/test/mir-opt/building/custom/enums.switch_option.built.after.mir new file mode 100644 index 00000000000..a659ba7c114 --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.switch_option.built.after.mir @@ -0,0 +1,21 @@ +// MIR for `switch_option` after built + +fn switch_option(_1: Option<()>) -> bool { + let mut _0: bool; // return place in scope 0 at $DIR/enums.rs:+0:45: +0:49 + let mut _2: isize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + + bb0: { + _2 = discriminant(_1); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + switchInt(_2) -> [0: bb1, 1: bb2, otherwise: bb2]; // scope 0 at $DIR/enums.rs:+4:13: +8:14 + } + + bb1: { + _0 = const false; // scope 0 at $DIR/enums.rs:+12:13: +12:24 + return; // scope 0 at $DIR/enums.rs:+13:13: +13:21 + } + + bb2: { + _0 = const true; // scope 0 at $DIR/enums.rs:+17:13: +17:23 + return; // scope 0 at $DIR/enums.rs:+18:13: +18:21 + } +} diff --git a/src/test/mir-opt/building/custom/enums.switch_option_repr.built.after.mir b/src/test/mir-opt/building/custom/enums.switch_option_repr.built.after.mir new file mode 100644 index 00000000000..d60e4b1b712 --- /dev/null +++ b/src/test/mir-opt/building/custom/enums.switch_option_repr.built.after.mir @@ -0,0 +1,21 @@ +// MIR for `switch_option_repr` after built + +fn switch_option_repr(_1: Bool) -> bool { + let mut _0: bool; // return place in scope 0 at $DIR/enums.rs:+0:40: +0:44 + let mut _2: u8; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + + bb0: { + _2 = discriminant(_1); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + switchInt(_2) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/enums.rs:+4:13: +7:14 + } + + bb1: { + _0 = const true; // scope 0 at $DIR/enums.rs:+11:13: +11:23 + return; // scope 0 at $DIR/enums.rs:+12:13: +12:21 + } + + bb2: { + _0 = const false; // scope 0 at $DIR/enums.rs:+16:13: +16:24 + return; // scope 0 at $DIR/enums.rs:+17:13: +17:21 + } +} diff --git a/src/test/mir-opt/building/custom/projections.rs b/src/test/mir-opt/building/custom/projections.rs new file mode 100644 index 00000000000..5e472e531c7 --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.rs @@ -0,0 +1,85 @@ +#![feature(custom_mir, core_intrinsics)] + +extern crate core; +use core::intrinsics::mir::*; + +union U { + a: i32, + b: u32, +} + +// EMIT_MIR projections.unions.built.after.mir +#[custom_mir(dialect = "built")] +fn unions(u: U) -> i32 { + mir!({ + RET = u.a; + Return() + }) +} + +// EMIT_MIR projections.tuples.built.after.mir +#[custom_mir(dialect = "analysis", phase = "post-cleanup")] +fn tuples(i: (u32, i32)) -> (u32, i32) { + mir!( + // FIXME(JakobDegen): This is necessary because we can't give type hints for `RET` + let temp: (u32, i32); + { + temp.0 = i.0; + temp.1 = i.1; + + RET = temp; + Return() + } + ) +} + +// EMIT_MIR projections.unwrap.built.after.mir +#[custom_mir(dialect = "built")] +fn unwrap(opt: Option<i32>) -> i32 { + mir!({ + RET = Field(Variant(opt, 1), 0); + Return() + }) +} + +// EMIT_MIR projections.unwrap_deref.built.after.mir +#[custom_mir(dialect = "built")] +fn unwrap_deref(opt: Option<&i32>) -> i32 { + mir!({ + RET = *Field::<&i32>(Variant(opt, 1), 0); + Return() + }) +} + +// EMIT_MIR projections.set.built.after.mir +#[custom_mir(dialect = "built")] +fn set(opt: &mut Option<i32>) { + mir!({ + place!(Field(Variant(*opt, 1), 0)) = 10; + Return() + }) +} + +// EMIT_MIR projections.simple_index.built.after.mir +#[custom_mir(dialect = "built")] +fn simple_index(a: [i32; 10], b: &[i32]) -> i32 { + mir!({ + let temp = 3; + RET = a[temp]; + RET = (*b)[temp]; + Return() + }) +} + +fn main() { + assert_eq!(unions(U { a: 5 }), 5); + assert_eq!(tuples((5, 6)), (5, 6)); + + assert_eq!(unwrap(Some(5)), 5); + assert_eq!(unwrap_deref(Some(&5)), 5); + let mut o = Some(5); + set(&mut o); + assert_eq!(o, Some(10)); + + assert_eq!(simple_index([0; 10], &[0; 10]), 0); +} diff --git a/src/test/mir-opt/building/custom/projections.set.built.after.mir b/src/test/mir-opt/building/custom/projections.set.built.after.mir new file mode 100644 index 00000000000..2f15176a61f --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.set.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `set` after built + +fn set(_1: &mut Option<i32>) -> () { + let mut _0: (); // return place in scope 0 at $DIR/projections.rs:+0:31: +0:31 + + bb0: { + (((*_1) as variant#1).0: i32) = const 10_i32; // scope 0 at $DIR/projections.rs:+2:9: +2:48 + return; // scope 0 at $DIR/projections.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/projections.simple_index.built.after.mir b/src/test/mir-opt/building/custom/projections.simple_index.built.after.mir new file mode 100644 index 00000000000..fc422e4b3f0 --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.simple_index.built.after.mir @@ -0,0 +1,13 @@ +// MIR for `simple_index` after built + +fn simple_index(_1: [i32; 10], _2: &[i32]) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/projections.rs:+0:45: +0:48 + let mut _3: usize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + + bb0: { + _3 = const 3_usize; // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + _0 = _1[_3]; // scope 0 at $DIR/projections.rs:+3:9: +3:22 + _0 = (*_2)[_3]; // scope 0 at $DIR/projections.rs:+4:9: +4:25 + return; // scope 0 at $DIR/projections.rs:+5:9: +5:17 + } +} diff --git a/src/test/mir-opt/building/custom/projections.tuples.built.after.mir b/src/test/mir-opt/building/custom/projections.tuples.built.after.mir new file mode 100644 index 00000000000..65487d3c9ed --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.tuples.built.after.mir @@ -0,0 +1,13 @@ +// MIR for `tuples` after built + +fn tuples(_1: (u32, i32)) -> (u32, i32) { + let mut _0: (u32, i32); // return place in scope 0 at $DIR/projections.rs:+0:29: +0:39 + let mut _2: (u32, i32); // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL + + bb0: { + (_2.0: u32) = (_1.0: u32); // scope 0 at $DIR/projections.rs:+5:13: +5:25 + (_2.1: i32) = (_1.1: i32); // scope 0 at $DIR/projections.rs:+6:13: +6:25 + _0 = _2; // scope 0 at $DIR/projections.rs:+8:13: +8:23 + return; // scope 0 at $DIR/projections.rs:+9:13: +9:21 + } +} diff --git a/src/test/mir-opt/building/custom/projections.unions.built.after.mir b/src/test/mir-opt/building/custom/projections.unions.built.after.mir new file mode 100644 index 00000000000..922538a5f17 --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.unions.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `unions` after built + +fn unions(_1: U) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/projections.rs:+0:20: +0:23 + + bb0: { + _0 = (_1.0: i32); // scope 0 at $DIR/projections.rs:+2:9: +2:18 + return; // scope 0 at $DIR/projections.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/projections.unwrap.built.after.mir b/src/test/mir-opt/building/custom/projections.unwrap.built.after.mir new file mode 100644 index 00000000000..75b03a3c393 --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.unwrap.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `unwrap` after built + +fn unwrap(_1: Option<i32>) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/projections.rs:+0:32: +0:35 + + bb0: { + _0 = ((_1 as variant#1).0: i32); // scope 0 at $DIR/projections.rs:+2:9: +2:40 + return; // scope 0 at $DIR/projections.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/projections.unwrap_deref.built.after.mir b/src/test/mir-opt/building/custom/projections.unwrap_deref.built.after.mir new file mode 100644 index 00000000000..c6b0f7efa9b --- /dev/null +++ b/src/test/mir-opt/building/custom/projections.unwrap_deref.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `unwrap_deref` after built + +fn unwrap_deref(_1: Option<&i32>) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/projections.rs:+0:39: +0:42 + + bb0: { + _0 = (*((_1 as variant#1).0: &i32)); // scope 0 at $DIR/projections.rs:+2:9: +2:49 + return; // scope 0 at $DIR/projections.rs:+3:9: +3:17 + } +} diff --git a/src/test/mir-opt/building/custom/references.immut_ref.built.after.mir b/src/test/mir-opt/building/custom/references.immut_ref.built.after.mir index 4d38d45c0f4..f5ee1126235 100644 --- a/src/test/mir-opt/building/custom/references.immut_ref.built.after.mir +++ b/src/test/mir-opt/building/custom/references.immut_ref.built.after.mir @@ -6,9 +6,8 @@ fn immut_ref(_1: &i32) -> &i32 { bb0: { _2 = &raw const (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:29 - Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24 - _0 = &(*_2); // scope 0 at $DIR/references.rs:+7:13: +7:23 - Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23 - return; // scope 0 at $DIR/references.rs:+9:13: +9:21 + _0 = &(*_2); // scope 0 at $DIR/references.rs:+6:13: +6:23 + Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23 + return; // scope 0 at $DIR/references.rs:+8:13: +8:21 } } diff --git a/src/test/mir-opt/building/custom/references.mut_ref.built.after.mir b/src/test/mir-opt/building/custom/references.mut_ref.built.after.mir index 01bc8a9cd35..8e2ffc33b1a 100644 --- a/src/test/mir-opt/building/custom/references.mut_ref.built.after.mir +++ b/src/test/mir-opt/building/custom/references.mut_ref.built.after.mir @@ -6,9 +6,8 @@ fn mut_ref(_1: &mut i32) -> &mut i32 { bb0: { _2 = &raw mut (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:33 - Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24 - _0 = &mut (*_2); // scope 0 at $DIR/references.rs:+7:13: +7:26 - Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23 - return; // scope 0 at $DIR/references.rs:+9:13: +9:21 + _0 = &mut (*_2); // scope 0 at $DIR/references.rs:+6:13: +6:26 + Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23 + return; // scope 0 at $DIR/references.rs:+8:13: +8:21 } } diff --git a/src/test/mir-opt/building/custom/references.raw_pointer.built.after.mir b/src/test/mir-opt/building/custom/references.raw_pointer.built.after.mir new file mode 100644 index 00000000000..775e5e3ad9b --- /dev/null +++ b/src/test/mir-opt/building/custom/references.raw_pointer.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `raw_pointer` after built + +fn raw_pointer(_1: *const i32) -> *const i32 { + let mut _0: *const i32; // return place in scope 0 at $DIR/references.rs:+0:38: +0:48 + + bb0: { + _0 = &raw const (*_1); // scope 0 at $DIR/references.rs:+4:9: +4:27 + return; // scope 0 at $DIR/references.rs:+5:9: +5:17 + } +} diff --git a/src/test/mir-opt/building/custom/references.rs b/src/test/mir-opt/building/custom/references.rs index dee85722e86..a1c896de04c 100644 --- a/src/test/mir-opt/building/custom/references.rs +++ b/src/test/mir-opt/building/custom/references.rs @@ -12,7 +12,6 @@ pub fn mut_ref(x: &mut i32) -> &mut i32 { { t = addr_of_mut!(*x); - RetagRaw(t); RET = &mut *t; Retag(RET); Return() @@ -28,7 +27,6 @@ pub fn immut_ref(x: &i32) -> &i32 { { t = addr_of!(*x); - RetagRaw(t); RET = & *t; Retag(RET); Return() @@ -36,8 +34,22 @@ pub fn immut_ref(x: &i32) -> &i32 { ) } +// EMIT_MIR references.raw_pointer.built.after.mir +#[custom_mir(dialect = "built")] +pub fn raw_pointer(x: *const i32) -> *const i32 { + // Regression test for a bug in which unsafetyck was not correctly turned off for + // `dialect = "built"` + mir!({ + RET = addr_of!(*x); + Return() + }) +} + fn main() { let mut x = 5; assert_eq!(*mut_ref(&mut x), 5); assert_eq!(*immut_ref(&x), 5); + unsafe { + assert_eq!(*raw_pointer(addr_of!(x)), 5); + } } diff --git a/src/test/mir-opt/building/custom/terminators.assert_nonzero.built.after.mir b/src/test/mir-opt/building/custom/terminators.assert_nonzero.built.after.mir new file mode 100644 index 00000000000..a1a27226b4e --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.assert_nonzero.built.after.mir @@ -0,0 +1,17 @@ +// MIR for `assert_nonzero` after built + +fn assert_nonzero(_1: i32) -> () { + let mut _0: (); // return place in scope 0 at $DIR/terminators.rs:+0:27: +0:27 + + bb0: { + switchInt(_1) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/terminators.rs:+3:13: +6:14 + } + + bb1: { + unreachable; // scope 0 at $DIR/terminators.rs:+10:13: +10:26 + } + + bb2: { + return; // scope 0 at $DIR/terminators.rs:+14:13: +14:21 + } +} diff --git a/src/test/mir-opt/building/custom/terminators.direct_call.built.after.mir b/src/test/mir-opt/building/custom/terminators.direct_call.built.after.mir new file mode 100644 index 00000000000..1b2345a965e --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.direct_call.built.after.mir @@ -0,0 +1,16 @@ +// MIR for `direct_call` after built + +fn direct_call(_1: i32) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/terminators.rs:+0:27: +0:30 + + bb0: { + _0 = ident::<i32>(_1) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:42 + // mir::Constant + // + span: $DIR/terminators.rs:15:33: 15:38 + // + literal: Const { ty: fn(i32) -> i32 {ident::<i32>}, val: Value(<ZST>) } + } + + bb1: { + return; // scope 0 at $DIR/terminators.rs:+7:13: +7:21 + } +} diff --git a/src/test/mir-opt/building/custom/terminators.drop_first.built.after.mir b/src/test/mir-opt/building/custom/terminators.drop_first.built.after.mir new file mode 100644 index 00000000000..c903e594696 --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.drop_first.built.after.mir @@ -0,0 +1,13 @@ +// MIR for `drop_first` after built + +fn drop_first(_1: WriteOnDrop<'_>, _2: WriteOnDrop<'_>) -> () { + let mut _0: (); // return place in scope 0 at $DIR/terminators.rs:+0:59: +0:59 + + bb0: { + replace(_1 <- move _2) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:49 + } + + bb1: { + return; // scope 0 at $DIR/terminators.rs:+7:13: +7:21 + } +} diff --git a/src/test/mir-opt/building/custom/terminators.drop_second.built.after.mir b/src/test/mir-opt/building/custom/terminators.drop_second.built.after.mir new file mode 100644 index 00000000000..f14246f2d12 --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.drop_second.built.after.mir @@ -0,0 +1,13 @@ +// MIR for `drop_second` after built + +fn drop_second(_1: WriteOnDrop<'_>, _2: WriteOnDrop<'_>) -> () { + let mut _0: (); // return place in scope 0 at $DIR/terminators.rs:+0:60: +0:60 + + bb0: { + drop(_2) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:30 + } + + bb1: { + return; // scope 0 at $DIR/terminators.rs:+7:13: +7:21 + } +} diff --git a/src/test/mir-opt/building/custom/terminators.indirect_call.built.after.mir b/src/test/mir-opt/building/custom/terminators.indirect_call.built.after.mir new file mode 100644 index 00000000000..2f1b14069ab --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.indirect_call.built.after.mir @@ -0,0 +1,13 @@ +// MIR for `indirect_call` after built + +fn indirect_call(_1: i32, _2: fn(i32) -> i32) -> i32 { + let mut _0: i32; // return place in scope 0 at $DIR/terminators.rs:+0:48: +0:51 + + bb0: { + _0 = _2(_1) -> bb1; // scope 0 at $DIR/terminators.rs:+3:13: +3:38 + } + + bb1: { + return; // scope 0 at $DIR/terminators.rs:+7:13: +7:21 + } +} diff --git a/src/test/mir-opt/building/custom/terminators.rs b/src/test/mir-opt/building/custom/terminators.rs new file mode 100644 index 00000000000..c23233fcf9a --- /dev/null +++ b/src/test/mir-opt/building/custom/terminators.rs @@ -0,0 +1,108 @@ +#![feature(custom_mir, core_intrinsics)] + +extern crate core; +use core::intrinsics::mir::*; + +fn ident<T>(t: T) -> T { + t +} + +// EMIT_MIR terminators.direct_call.built.after.mir +#[custom_mir(dialect = "built")] +fn direct_call(x: i32) -> i32 { + mir!( + { + Call(RET, retblock, ident(x)) + } + + retblock = { + Return() + } + ) +} + +// EMIT_MIR terminators.indirect_call.built.after.mir +#[custom_mir(dialect = "built")] +fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 { + mir!( + { + Call(RET, retblock, f(x)) + } + + retblock = { + Return() + } + ) +} + +struct WriteOnDrop<'a>(&'a mut i32, i32); + +impl<'a> Drop for WriteOnDrop<'a> { + fn drop(&mut self) { + *self.0 = self.1; + } +} + +// EMIT_MIR terminators.drop_first.built.after.mir +#[custom_mir(dialect = "built")] +fn drop_first<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) { + mir!( + { + DropAndReplace(a, Move(b), retblock) + } + + retblock = { + Return() + } + ) +} + +// EMIT_MIR terminators.drop_second.built.after.mir +#[custom_mir(dialect = "built")] +fn drop_second<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) { + mir!( + { + Drop(b, retblock) + } + + retblock = { + Return() + } + ) +} + +// EMIT_MIR terminators.assert_nonzero.built.after.mir +#[custom_mir(dialect = "built")] +fn assert_nonzero(a: i32) { + mir!( + { + match a { + 0 => unreachable, + _ => retblock + } + } + + unreachable = { + Unreachable() + } + + retblock = { + Return() + } + ) +} + +fn main() { + assert_eq!(direct_call(5), 5); + assert_eq!(indirect_call(5, ident), 5); + + let mut a = 0; + let mut b = 0; + drop_first(WriteOnDrop(&mut a, 1), WriteOnDrop(&mut b, 1)); + assert_eq!((a, b), (1, 0)); + + let mut a = 0; + let mut b = 0; + drop_second(WriteOnDrop(&mut a, 1), WriteOnDrop(&mut b, 1)); + assert_eq!((a, b), (0, 1)); +} diff --git a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff index 624376769b7..44445731e72 100644 --- a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff +++ b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff @@ -12,7 +12,6 @@ let mut _7: usize; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33 let mut _8: bool; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33 let mut _9: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - let mut _10: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19 bb0: { StorageLive(_1); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 @@ -25,16 +24,14 @@ // + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - StorageLive(_10); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - _10 = _3; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19 StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32 _6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32 - _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - StorageDead(_10); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 +- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 ++ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 + _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 + assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 } diff --git a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff index 624376769b7..44445731e72 100644 --- a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff +++ b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff @@ -12,7 +12,6 @@ let mut _7: usize; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33 let mut _8: bool; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33 let mut _9: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - let mut _10: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19 bb0: { StorageLive(_1); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 @@ -25,16 +24,14 @@ // + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - StorageLive(_10); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 - _10 = _3; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19 StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19 StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32 _6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32 - _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - StorageDead(_10); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 +- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 ++ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 + _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 + assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33 } diff --git a/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff new file mode 100644 index 00000000000..9ea756c2712 --- /dev/null +++ b/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff @@ -0,0 +1,86 @@ +- // MIR for `f` before DestinationPropagation ++ // MIR for `f` after DestinationPropagation + + fn f(_1: T) -> () { + debug a => _1; // in scope 0 at $DIR/unreachable.rs:+0:19: +0:20 + let mut _0: (); // return place in scope 0 at $DIR/unreachable.rs:+0:25: +0:25 + let _2: T; // in scope 0 at $DIR/unreachable.rs:+1:9: +1:10 + let mut _3: bool; // in scope 0 at $DIR/unreachable.rs:+2:8: +2:13 + let _4: (); // in scope 0 at $DIR/unreachable.rs:+3:9: +3:16 + let mut _5: T; // in scope 0 at $DIR/unreachable.rs:+3:11: +3:12 + let mut _6: T; // in scope 0 at $DIR/unreachable.rs:+3:14: +3:15 + let _7: (); // in scope 0 at $DIR/unreachable.rs:+5:9: +5:16 + let mut _8: T; // in scope 0 at $DIR/unreachable.rs:+5:11: +5:12 + let mut _9: T; // in scope 0 at $DIR/unreachable.rs:+5:14: +5:15 + scope 1 { +- debug b => _2; // in scope 1 at $DIR/unreachable.rs:+1:9: +1:10 ++ debug b => _1; // in scope 1 at $DIR/unreachable.rs:+1:9: +1:10 + } + + bb0: { +- StorageLive(_2); // scope 0 at $DIR/unreachable.rs:+1:9: +1:10 +- _2 = _1; // scope 0 at $DIR/unreachable.rs:+1:13: +1:14 ++ nop; // scope 0 at $DIR/unreachable.rs:+1:9: +1:10 ++ nop; // scope 0 at $DIR/unreachable.rs:+1:13: +1:14 + StorageLive(_3); // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 + _3 = const false; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 +- goto -> bb3; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 ++ goto -> bb1; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 + } + + bb1: { +- StorageLive(_4); // scope 1 at $DIR/unreachable.rs:+3:9: +3:16 +- StorageLive(_5); // scope 1 at $DIR/unreachable.rs:+3:11: +3:12 +- _5 = _1; // scope 1 at $DIR/unreachable.rs:+3:11: +3:12 +- StorageLive(_6); // scope 1 at $DIR/unreachable.rs:+3:14: +3:15 +- _6 = _2; // scope 1 at $DIR/unreachable.rs:+3:14: +3:15 +- _4 = g::<T>(move _5, move _6) -> bb2; // scope 1 at $DIR/unreachable.rs:+3:9: +3:16 +- // mir::Constant +- // + span: $DIR/unreachable.rs:11:9: 11:10 +- // + literal: Const { ty: fn(T, T) {g::<T>}, val: Value(<ZST>) } +- } +- +- bb2: { +- StorageDead(_6); // scope 1 at $DIR/unreachable.rs:+3:15: +3:16 +- StorageDead(_5); // scope 1 at $DIR/unreachable.rs:+3:15: +3:16 +- StorageDead(_4); // scope 1 at $DIR/unreachable.rs:+3:16: +3:17 +- _0 = const (); // scope 1 at $DIR/unreachable.rs:+2:14: +4:6 +- goto -> bb5; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 +- } +- +- bb3: { + StorageLive(_7); // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 +- StorageLive(_8); // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 +- _8 = _2; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 + StorageLive(_9); // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 +- _9 = _2; // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 +- _7 = g::<T>(move _8, move _9) -> bb4; // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 ++ _9 = _1; // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 ++ _7 = g::<T>(move _1, move _9) -> bb2; // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 + // mir::Constant + // + span: $DIR/unreachable.rs:13:9: 13:10 + // + literal: Const { ty: fn(T, T) {g::<T>}, val: Value(<ZST>) } + } + +- bb4: { ++ bb2: { + StorageDead(_9); // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 +- StorageDead(_8); // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 + StorageDead(_7); // scope 1 at $DIR/unreachable.rs:+5:16: +5:17 + _0 = const (); // scope 1 at $DIR/unreachable.rs:+4:12: +6:6 +- goto -> bb5; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 ++ goto -> bb3; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 + } + +- bb5: { ++ bb3: { + StorageDead(_3); // scope 1 at $DIR/unreachable.rs:+6:5: +6:6 +- StorageDead(_2); // scope 0 at $DIR/unreachable.rs:+7:1: +7:2 ++ nop; // scope 0 at $DIR/unreachable.rs:+7:1: +7:2 + return; // scope 0 at $DIR/unreachable.rs:+7:2: +7:2 + } + } + diff --git a/src/test/mir-opt/dest-prop/unreachable.rs b/src/test/mir-opt/dest-prop/unreachable.rs new file mode 100644 index 00000000000..32b5def984a --- /dev/null +++ b/src/test/mir-opt/dest-prop/unreachable.rs @@ -0,0 +1,18 @@ +// Check that unreachable code is removed after the destination propagation. +// Regression test for issue #105428. +// +// compile-flags: --crate-type=lib -Zmir-opt-level=0 +// compile-flags: -Zmir-enable-passes=+ConstProp,+SimplifyConstCondition-after-const-prop,+DestinationPropagation + +// EMIT_MIR unreachable.f.DestinationPropagation.diff +pub fn f<T: Copy>(a: T) { + let b = a; + if false { + g(a, b); + } else { + g(b, b); + } +} + +#[inline(never)] +pub fn g<T: Copy>(_: T, _: T) {} diff --git a/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff b/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff index 2368c021eda..e97b46f6ecc 100644 --- a/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff +++ b/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff @@ -22,7 +22,6 @@ let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:+3:70: +3:84 let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:+3:70: +3:84 let mut _22: !; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL - let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 scope 1 { debug v => _2; // in scope 1 at $DIR/issue_76432.rs:+1:9: +1:10 let _13: &T; // in scope 1 at $DIR/issue_76432.rs:+3:10: +3:16 @@ -52,17 +51,16 @@ StorageDead(_6); // scope 0 at $DIR/issue_76432.rs:+1:28: +1:29 _4 = &_5; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 _3 = _4; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 - StorageLive(_23); // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 - _23 = _3; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 _2 = move _3 as &[T] (Pointer(Unsize)); // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29 StorageDead(_3); // scope 0 at $DIR/issue_76432.rs:+1:28: +1:29 StorageDead(_4); // scope 0 at $DIR/issue_76432.rs:+1:29: +1:30 StorageLive(_9); // scope 1 at $DIR/issue_76432.rs:+2:5: +5:6 - _10 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 - StorageDead(_23); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 + _10 = Len((*_2)); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 _11 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 - _12 = const true; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 - goto -> bb2; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 +- _12 = Eq(move _10, const 3_usize); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 +- switchInt(move _12) -> [0: bb1, otherwise: bb2]; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 ++ nop; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 ++ switchInt(move _10) -> [3: bb2, otherwise: bb1]; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33 } bb1: { diff --git a/src/test/mir-opt/lower_array_len_e2e.rs b/src/test/mir-opt/lower_array_len_e2e.rs index 49b35d509f0..d8e4e521ee6 100644 --- a/src/test/mir-opt/lower_array_len_e2e.rs +++ b/src/test/mir-opt/lower_array_len_e2e.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z mir-opt-level=4 +// compile-flags: -Z mir-opt-level=4 -Zunsound-mir-opts // EMIT_MIR lower_array_len_e2e.array_bound.PreCodegen.after.mir pub fn array_bound<const N: usize>(index: usize, slice: &[u8; N]) -> u8 { diff --git a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.diff index bb5920b28ca..0b3da98a5a1 100644 --- a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff +++ b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.diff @@ -1,5 +1,5 @@ -- // MIR for `match_guard` before CleanupNonCodegenStatements -+ // MIR for `match_guard` after CleanupNonCodegenStatements +- // MIR for `match_guard` before CleanupPostBorrowck ++ // MIR for `match_guard` after CleanupPostBorrowck fn match_guard(_1: Option<&&i32>, _2: bool) -> i32 { debug x => _1; // in scope 0 at $DIR/remove_fake_borrows.rs:+0:16: +0:17 @@ -29,7 +29,8 @@ } bb3: { - goto -> bb4; // scope 0 at $DIR/remove_fake_borrows.rs:+2:9: +2:16 +- falseEdge -> [real: bb4, imaginary: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:+2:9: +2:16 ++ goto -> bb4; // scope 0 at $DIR/remove_fake_borrows.rs:+2:9: +2:16 } bb4: { @@ -62,15 +63,12 @@ bb6: { StorageDead(_8); // scope 0 at $DIR/remove_fake_borrows.rs:+2:20: +2:21 - goto -> bb1; // scope 0 at $DIR/remove_fake_borrows.rs:+2:20: +2:21 +- falseEdge -> [real: bb1, imaginary: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:+2:20: +2:21 ++ goto -> bb1; // scope 0 at $DIR/remove_fake_borrows.rs:+2:20: +2:21 } bb7: { return; // scope 0 at $DIR/remove_fake_borrows.rs:+5:2: +5:2 } - - bb8 (cleanup): { - resume; // scope 0 at $DIR/remove_fake_borrows.rs:+0:1: +5:2 - } } diff --git a/src/test/mir-opt/remove_fake_borrows.rs b/src/test/mir-opt/remove_fake_borrows.rs index a980f386b69..d26c6f5d7e5 100644 --- a/src/test/mir-opt/remove_fake_borrows.rs +++ b/src/test/mir-opt/remove_fake_borrows.rs @@ -2,7 +2,7 @@ // ignore-wasm32-bare compiled with panic=abort by default -// EMIT_MIR remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff +// EMIT_MIR remove_fake_borrows.match_guard.CleanupPostBorrowck.diff fn match_guard(x: Option<&&i32>, c: bool) -> i32 { match x { Some(0) if c => 0, diff --git a/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir b/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir index 14f297e948b..f495f147be3 100644 --- a/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir +++ b/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir @@ -3,11 +3,14 @@ fn std::ptr::drop_in_place(_1: *mut Test) -> () { let mut _0: (); // return place in scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 let mut _2: &mut Test; // in scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 - let mut _3: (); // in scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 + let mut _3: &mut Test; // in scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 + let mut _4: (); // in scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 bb0: { _2 = &mut (*_1); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 - _3 = <Test as Drop>::drop(move _2) -> bb1; // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 + Retag([fn entry] _2); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 + _3 = &mut (*_2); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 + _4 = <Test as Drop>::drop(move _3) -> bb1; // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56 // mir::Constant // + span: $SRC_DIR/core/src/ptr/mod.rs:LL:COL // + literal: Const { ty: for<'a> fn(&'a mut Test) {<Test as Drop>::drop}, val: Value(<ZST>) } diff --git a/src/test/run-make-fulldeps/core-no-fp-fmt-parse/Makefile b/src/test/run-make-fulldeps/core-no-fp-fmt-parse/Makefile index d083aaa6620..ec05ebea555 100644 --- a/src/test/run-make-fulldeps/core-no-fp-fmt-parse/Makefile +++ b/src/test/run-make-fulldeps/core-no-fp-fmt-parse/Makefile @@ -1,4 +1,4 @@ include ../tools.mk all: - $(RUSTC) --edition=2021 --crate-type=rlib ../../../../library/core/src/lib.rs --cfg no_fp_fmt_parse + $(RUSTC) --edition=2021 -Dwarnings --crate-type=rlib ../../../../library/core/src/lib.rs --cfg no_fp_fmt_parse diff --git a/src/test/rustdoc-gui/basic-code.goml b/src/test/rustdoc-gui/basic-code.goml index f4ba5a12845..108cf8abcb5 100644 --- a/src/test/rustdoc-gui/basic-code.goml +++ b/src/test/rustdoc-gui/basic-code.goml @@ -1,3 +1,4 @@ goto: "file://" + |DOC_PATH| + "/test_docs/index.html" click: ".srclink" +wait-for: ".src-line-numbers" assert-count: (".src-line-numbers", 1) diff --git a/src/test/rustdoc-gui/code-sidebar-toggle.goml b/src/test/rustdoc-gui/code-sidebar-toggle.goml index 00a0ea1e1a2..df665bd46c0 100644 --- a/src/test/rustdoc-gui/code-sidebar-toggle.goml +++ b/src/test/rustdoc-gui/code-sidebar-toggle.goml @@ -1,7 +1,7 @@ // This test checks that the source code pages sidebar toggle is working as expected. goto: "file://" + |DOC_PATH| + "/test_docs/index.html" click: ".srclink" -wait-for: "#sidebar-toggle" -click: "#sidebar-toggle" +wait-for: "#src-sidebar-toggle" +click: "#src-sidebar-toggle" fail: true assert-css: ("#source-sidebar", { "left": "-300px" }) diff --git a/src/test/rustdoc-gui/codeblock-sub.goml b/src/test/rustdoc-gui/codeblock-sub.goml new file mode 100644 index 00000000000..cbd314d2791 --- /dev/null +++ b/src/test/rustdoc-gui/codeblock-sub.goml @@ -0,0 +1,5 @@ +// Test that code blocks nested within <sub> do not have a line height of 0. +goto: "file://" + |DOC_PATH| + "/test_docs/codeblock_sub/index.html" + +store-property: (codeblock_sub_1, "#codeblock-sub-1", "offsetHeight") +assert-property-false: ("#codeblock-sub-3", { "offsetHeight": |codeblock_sub_1| }) diff --git a/src/test/rustdoc-gui/codeblock-tooltip.goml b/src/test/rustdoc-gui/codeblock-tooltip.goml index 4d923be3e78..aab27394eb1 100644 --- a/src/test/rustdoc-gui/codeblock-tooltip.goml +++ b/src/test/rustdoc-gui/codeblock-tooltip.goml @@ -20,7 +20,7 @@ define-function: ( {"border-left": "2px solid rgba(255, 0, 0, 0.5)"}, )), - ("move-cursor-to", ".docblock .example-wrap.compile_fail"), + ("move-cursor-to", ".docblock .example-wrap.compile_fail .tooltip"), ("assert-css", ( ".docblock .example-wrap.compile_fail .tooltip", @@ -60,7 +60,7 @@ define-function: ( {"border-left": "2px solid rgba(255, 0, 0, 0.5)"}, )), - ("move-cursor-to", ".docblock .example-wrap.should_panic"), + ("move-cursor-to", ".docblock .example-wrap.should_panic .tooltip"), ("assert-css", ( ".docblock .example-wrap.should_panic .tooltip", @@ -100,7 +100,7 @@ define-function: ( {"border-left": "2px solid rgba(255, 142, 0, 0.6)"}, )), - ("move-cursor-to", ".docblock .example-wrap.ignore"), + ("move-cursor-to", ".docblock .example-wrap.ignore .tooltip"), ("assert-css", ( ".docblock .example-wrap.ignore .tooltip", diff --git a/src/test/rustdoc-gui/cursor.goml b/src/test/rustdoc-gui/cursor.goml index b2e91cb81fb..59b1397970b 100644 --- a/src/test/rustdoc-gui/cursor.goml +++ b/src/test/rustdoc-gui/cursor.goml @@ -12,8 +12,8 @@ write: (".search-input", "Foo") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-css: ("#titles > button", {"cursor": "pointer"}) +wait-for: "#search-tabs" +assert-css: ("#search-tabs > button", {"cursor": "pointer"}) // mobile sidebar toggle button size: (500, 700) @@ -21,4 +21,4 @@ assert-css: (".sidebar-menu-toggle", {"cursor": "pointer"}) // the sidebar toggle button on the source code pages goto: "file://" + |DOC_PATH| + "/src/lib2/lib.rs.html" -assert-css: ("#sidebar-toggle > button", {"cursor": "pointer"}) +assert-css: ("#src-sidebar-toggle > button", {"cursor": "pointer"}) diff --git a/src/test/rustdoc-gui/docblock-big-code-mobile.goml b/src/test/rustdoc-gui/docblock-big-code-mobile.goml index 9f8df44d762..3ce921c2c91 100644 --- a/src/test/rustdoc-gui/docblock-big-code-mobile.goml +++ b/src/test/rustdoc-gui/docblock-big-code-mobile.goml @@ -7,3 +7,7 @@ show-text: true // We need to enable text draw to be able to have the "real" siz // Little explanations for this test: if the text wasn't displayed on two lines, it would take // around 20px (which is the font size). assert-property: (".docblock p > code", {"offsetHeight": "44"}) + +// Same check, but where the long code block is also a link +goto: "file://" + |DOC_PATH| + "/test_docs/long_code_block_link/index.html" +assert-property: (".docblock p > a > code", {"offsetHeight": "44"}) diff --git a/src/test/rustdoc-gui/docblock-code-block-line-number.goml b/src/test/rustdoc-gui/docblock-code-block-line-number.goml index b094c483876..a3ed008719c 100644 --- a/src/test/rustdoc-gui/docblock-code-block-line-number.goml +++ b/src/test/rustdoc-gui/docblock-code-block-line-number.goml @@ -1,23 +1,53 @@ // Checks that the setting "line numbers" is working as expected. goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" +// Otherwise, we can't check text color +show-text: true + // We check that without this setting, there is no line number displayed. assert-false: "pre.example-line-numbers" -// We now set the setting to show the line numbers on code examples. -local-storage: {"rustdoc-line-numbers": "true" } -// We reload to make the line numbers appear. -reload: - -// We wait for them to be added into the DOM by the JS... -wait-for: "pre.example-line-numbers" -// If the test didn't fail, it means that it was found! // Let's now check some CSS properties... -assert-css: ("pre.example-line-numbers", { - "margin": "0px", - "padding": "13px 8px", - "text-align": "right", +define-function: ( + "check-colors", + (theme, color), + [ + // We now set the setting to show the line numbers on code examples. + ("local-storage", { + "rustdoc-theme": |theme|, + "rustdoc-use-system-theme": "false", + "rustdoc-line-numbers": "true" + }), + // We reload to make the line numbers appear and change theme. + ("reload"), + // We wait for them to be added into the DOM by the JS... + ("wait-for", "pre.example-line-numbers"), + // If the test didn't fail, it means that it was found! + ("assert-css", ( + "pre.example-line-numbers", + { + "color": |color|, + "margin": "0px", + "padding": "14px 8px", + "text-align": "right", + }, + ALL, + )), + ], +) +call-function: ("check-colors", { + "theme": "ayu", + "color": "rgb(92, 103, 115)", }) +call-function: ("check-colors", { + "theme": "dark", + "color": "rgb(59, 145, 226)", +}) +call-function: ("check-colors", { + "theme": "light", + "color": "rgb(198, 126, 45)", +}) + // The first code block has two lines so let's check its `<pre>` elements lists both of them. assert-text: ("pre.example-line-numbers", "1\n2") diff --git a/src/test/rustdoc-gui/help-page.goml b/src/test/rustdoc-gui/help-page.goml index 799ba851c92..80203901ed3 100644 --- a/src/test/rustdoc-gui/help-page.goml +++ b/src/test/rustdoc-gui/help-page.goml @@ -27,7 +27,6 @@ define-function: ( "color": |color|, "background-color": |background|, "box-shadow": |box_shadow| + " 0px -1px 0px 0px inset", - "cursor": "default", }, ALL)), ], ) diff --git a/src/test/rustdoc-gui/impl-doc.goml b/src/test/rustdoc-gui/impl-doc.goml new file mode 100644 index 00000000000..7322032b3f5 --- /dev/null +++ b/src/test/rustdoc-gui/impl-doc.goml @@ -0,0 +1,9 @@ +// A docblock on an impl must have a margin to separate it from the contents. +goto: "file://" + |DOC_PATH| + "/test_docs/struct.TypeWithImplDoc.html" + +// The text is about 24px tall, so if there's a margin, then their position will be >24px apart +compare-elements-position-near-false: ( + "#implementations-list > .implementors-toggle > .docblock > p", + "#implementations-list > .implementors-toggle > .impl-items", + {"y": 24} +) diff --git a/src/test/rustdoc-gui/links-color.goml b/src/test/rustdoc-gui/links-color.goml index 839629ad982..9402c09eb69 100644 --- a/src/test/rustdoc-gui/links-color.goml +++ b/src/test/rustdoc-gui/links-color.goml @@ -4,82 +4,95 @@ goto: "file://" + |DOC_PATH| + "/test_docs/index.html" // This is needed so that the text color is computed. show-text: true -// Ayu theme -local-storage: { - "rustdoc-theme": "ayu", - "rustdoc-use-system-theme": "false", -} -reload: - -assert-css: (".item-table .mod", {"color": "rgb(57, 175, 215)"}, ALL) -assert-css: (".item-table .macro", {"color": "rgb(163, 122, 204)"}, ALL) -assert-css: (".item-table .struct", {"color": "rgb(255, 160, 165)"}, ALL) -assert-css: (".item-table .enum", {"color": "rgb(255, 160, 165)"}, ALL) -assert-css: (".item-table .trait", {"color": "rgb(57, 175, 215)"}, ALL) -assert-css: (".item-table .fn", {"color": "rgb(253, 214, 135)"}, ALL) -assert-css: (".item-table .type", {"color": "rgb(255, 160, 165)"}, ALL) -assert-css: (".item-table .union", {"color": "rgb(255, 160, 165)"}, ALL) -assert-css: (".item-table .keyword", {"color": "rgb(57, 175, 215)"}, ALL) - -assert-css: ( - ".sidebar-elems a:not(.current)", - {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, - ALL, -) -assert-css: ( - ".sidebar-elems a.current", - {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "500"}, - ALL, +define-function: ( + "check-colors", + (theme, mod, macro, struct, enum, trait, fn, type, union, keyword, + sidebar, sidebar_current, sidebar_current_background), + [ + ("local-storage", { + "rustdoc-theme": |theme|, + "rustdoc-use-system-theme": "false", + }), + ("reload"), + // Checking results colors. + ("assert-css", (".item-table .mod", {"color": |mod|}, ALL)), + ("assert-css", (".item-table .macro", {"color": |macro|}, ALL)), + ("assert-css", (".item-table .struct", {"color": |struct|}, ALL)), + ("assert-css", (".item-table .enum", {"color": |enum|}, ALL)), + ("assert-css", (".item-table .trait", {"color": |trait|}, ALL)), + ("assert-css", (".item-table .fn", {"color": |fn|}, ALL)), + ("assert-css", (".item-table .type", {"color": |type|}, ALL)), + ("assert-css", (".item-table .union", {"color": |union|}, ALL)), + ("assert-css", (".item-table .keyword", {"color": |keyword|}, ALL)), + // Checking sidebar elements. + ("assert-css", ( + ".sidebar-elems a:not(.current)", + {"color": |sidebar|, "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, + ALL, + )), + ("assert-css", ( + ".sidebar-elems a.current", + { + "color": |sidebar_current|, + "background-color": |sidebar_current_background|, + "font-weight": "500", + }, + ALL, + )), + ], ) - -// Dark theme -local-storage: {"rustdoc-theme": "dark"} -reload: - -assert-css: (".item-table .mod", {"color": "rgb(210, 153, 29)"}, ALL) -assert-css: (".item-table .macro", {"color": "rgb(9, 189, 0)"}, ALL) -assert-css: (".item-table .struct", {"color": "rgb(45, 191, 184)"}, ALL) -assert-css: (".item-table .enum", {"color": "rgb(45, 191, 184)"}, ALL) -assert-css: (".item-table .trait", {"color": "rgb(183, 140, 242)"}, ALL) -assert-css: (".item-table .fn", {"color": "rgb(43, 171, 99)"}, ALL) -assert-css: (".item-table .type", {"color": "rgb(45, 191, 184)"}, ALL) -assert-css: (".item-table .union", {"color": "rgb(45, 191, 184)"}, ALL) -assert-css: (".item-table .keyword", {"color": "rgb(210, 153, 29)"}, ALL) - -assert-css: ( - ".sidebar-elems a:not(.current)", - {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, - ALL, +call-function: ( + "check-colors", + { + "theme": "ayu", + "mod": "rgb(57, 175, 215)", + "macro": "rgb(163, 122, 204)", + "struct": "rgb(255, 160, 165)", + "enum": "rgb(255, 160, 165)", + "trait": "rgb(57, 175, 215)", + "fn": "rgb(253, 214, 135)", + "type": "rgb(255, 160, 165)", + "union": "rgb(255, 160, 165)", + "keyword": "rgb(57, 175, 215)", + "sidebar": "rgb(83, 177, 219)", + "sidebar_current": "rgb(255, 180, 76)", + "sidebar_current_background": "rgba(0, 0, 0, 0)", + }, ) -assert-css: ( - ".sidebar-elems a.current", - {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)", "font-weight": "500"}, - ALL, -) - - -// Light theme -local-storage: {"rustdoc-theme": "light"} -reload: - -assert-css: (".item-table .mod", {"color": "rgb(56, 115, 173)"}, ALL) -assert-css: (".item-table .macro", {"color": "rgb(6, 128, 0)"}, ALL) -assert-css: (".item-table .struct", {"color": "rgb(173, 55, 138)"}, ALL) -assert-css: (".item-table .enum", {"color": "rgb(173, 55, 138)"}, ALL) -assert-css: (".item-table .trait", {"color": "rgb(110, 79, 201)"}, ALL) -assert-css: (".item-table .fn", {"color": "rgb(173, 124, 55)"}, ALL) -assert-css: (".item-table .type", {"color": "rgb(173, 55, 138)"}, ALL) -assert-css: (".item-table .union", {"color": "rgb(173, 55, 138)"}, ALL) -assert-css: (".item-table .keyword", {"color": "rgb(56, 115, 173)"}, ALL) - -assert-css: ( - ".sidebar-elems a:not(.current)", - {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, - ALL, +call-function: ( + "check-colors", + { + "theme": "dark", + "mod": "rgb(210, 153, 29)", + "macro": "rgb(9, 189, 0)", + "struct": "rgb(45, 191, 184)", + "enum": "rgb(45, 191, 184)", + "trait": "rgb(183, 140, 242)", + "fn": "rgb(43, 171, 99)", + "type": "rgb(45, 191, 184)", + "union": "rgb(45, 191, 184)", + "keyword": "rgb(210, 153, 29)", + "sidebar": "rgb(253, 191, 53)", + "sidebar_current": "rgb(253, 191, 53)", + "sidebar_current_background": "rgb(68, 68, 68)", + }, ) -assert-css: ( - ".sidebar-elems a.current", - {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)", "font-weight": "500"}, - ALL, +call-function: ( + "check-colors", + { + "theme": "light", + "mod": "rgb(56, 115, 173)", + "macro": "rgb(6, 128, 0)", + "struct": "rgb(173, 55, 138)", + "enum": "rgb(173, 55, 138)", + "trait": "rgb(110, 79, 201)", + "fn": "rgb(173, 124, 55)", + "type": "rgb(173, 55, 138)", + "union": "rgb(173, 55, 138)", + "keyword": "rgb(56, 115, 173)", + "sidebar": "rgb(53, 109, 164)", + "sidebar_current": "rgb(53, 109, 164)", + "sidebar_current_background": "rgb(255, 255, 255)", + }, ) diff --git a/src/test/rustdoc-gui/scrape-examples-layout.goml b/src/test/rustdoc-gui/scrape-examples-layout.goml new file mode 100644 index 00000000000..fde9a0ab0bc --- /dev/null +++ b/src/test/rustdoc-gui/scrape-examples-layout.goml @@ -0,0 +1,35 @@ +// Check that the line number column has the correct layout. +goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" + +// Check that it's not zero. +assert-property-false: ( + ".more-scraped-examples .scraped-example .code-wrapper .src-line-numbers", + {"clientWidth": "0"} +) + +// Check that examples with very long lines have the same width as ones that don't. +store-property: ( + clientWidth, + ".more-scraped-examples .scraped-example:nth-child(2) .code-wrapper .src-line-numbers", + "clientWidth" +) + +assert-property: ( + ".more-scraped-examples .scraped-example:nth-child(3) .code-wrapper .src-line-numbers", + {"clientWidth": |clientWidth|} +) + +assert-property: ( + ".more-scraped-examples .scraped-example:nth-child(4) .code-wrapper .src-line-numbers", + {"clientWidth": |clientWidth|} +) + +assert-property: ( + ".more-scraped-examples .scraped-example:nth-child(5) .code-wrapper .src-line-numbers", + {"clientWidth": |clientWidth|} +) + +assert-property: ( + ".more-scraped-examples .scraped-example:nth-child(6) .code-wrapper .src-line-numbers", + {"clientWidth": |clientWidth|} +) diff --git a/src/test/rustdoc-gui/scrape-examples-toggle.goml b/src/test/rustdoc-gui/scrape-examples-toggle.goml index ee720afb788..8c84fbc0c30 100644 --- a/src/test/rustdoc-gui/scrape-examples-toggle.goml +++ b/src/test/rustdoc-gui/scrape-examples-toggle.goml @@ -1,9 +1,46 @@ +// This tests checks that the "scraped examples" toggle is working as expected. goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" -// Clicking "More examples..." will open additional examples -assert-attribute-false: (".more-examples-toggle", {"open": ""}) -click: ".more-examples-toggle" -assert-attribute: (".more-examples-toggle", {"open": ""}) +// Checking the color of the toggle line. +show-text: true +define-function: ( + "check-color", + (theme, toggle_line_color, toggle_line_hover_color), + [ + ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), + ("reload"), + + // Clicking "More examples..." will open additional examples + ("assert-attribute-false", (".more-examples-toggle", {"open": ""})), + ("click", ".more-examples-toggle"), + ("assert-attribute", (".more-examples-toggle", {"open": ""})), + + ("assert-css", (".toggle-line-inner", {"background-color": |toggle_line_color|}, ALL)), + ("move-cursor-to", ".toggle-line"), + ("assert-css", ( + ".toggle-line:hover .toggle-line-inner", + {"background-color": |toggle_line_hover_color|}, + )), + // Moving cursor away from the toggle line to prevent disrupting next test. + ("move-cursor-to", ".search-input"), + ], +) + +call-function: ("check-color", { + "theme": "ayu", + "toggle_line_color": "rgb(153, 153, 153)", + "toggle_line_hover_color": "rgb(197, 197, 197)", +}) +call-function: ("check-color", { + "theme": "dark", + "toggle_line_color": "rgb(153, 153, 153)", + "toggle_line_hover_color": "rgb(197, 197, 197)", +}) +call-function: ("check-color", { + "theme": "light", + "toggle_line_color": "rgb(204, 204, 204)", + "toggle_line_hover_color": "rgb(153, 153, 153)", +}) // Toggling all docs will close additional examples click: "#toggle-all-docs" diff --git a/src/test/rustdoc-gui/search-filter.goml b/src/test/rustdoc-gui/search-filter.goml index e0228694eec..e556da0c54e 100644 --- a/src/test/rustdoc-gui/search-filter.goml +++ b/src/test/rustdoc-gui/search-filter.goml @@ -5,7 +5,7 @@ write: (".search-input", "test") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" assert-text: ("#results .externcrate", "test_docs") wait-for: "#crate-search" @@ -17,7 +17,7 @@ press-key: "ArrowDown" press-key: "ArrowDown" press-key: "Enter" // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" assert-document-property: ({"URL": "&filter-crate="}, CONTAINS) // We check that there is no more "test_docs" appearing. assert-false: "#results .externcrate" @@ -41,7 +41,7 @@ press-key: "ArrowUp" press-key: "ArrowUp" press-key: "Enter" // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" assert-property: ("#crate-search", {"value": "all crates"}) // Checking that the URL parameter is taken into account for crate filtering. diff --git a/src/test/rustdoc-gui/search-keyboard.goml b/src/test/rustdoc-gui/search-keyboard.goml index be642fc4997..ed975664c66 100644 --- a/src/test/rustdoc-gui/search-keyboard.goml +++ b/src/test/rustdoc-gui/search-keyboard.goml @@ -5,7 +5,7 @@ write: (".search-input", "Foo") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" // Now use the keyboard commands to switch to the third result. press-key: "ArrowDown" diff --git a/src/test/rustdoc-gui/search-result-color.goml b/src/test/rustdoc-gui/search-result-color.goml index dde43b1c980..3c5fe9b74b7 100644 --- a/src/test/rustdoc-gui/search-result-color.goml +++ b/src/test/rustdoc-gui/search-result-color.goml @@ -65,7 +65,12 @@ local-storage: { reload: // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" +assert-css: ( + "#search-tabs > button > .count", + {"color": "rgb(136, 136, 136)"}, + ALL, +) assert-css: ( "//*[@class='desc'][text()='Just a normal struct.']", {"color": "rgb(197, 197, 197)"}, @@ -177,7 +182,12 @@ local-storage: { reload: // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" +assert-css: ( + "#search-tabs > button > .count", + {"color": "rgb(136, 136, 136)"}, + ALL, +) assert-css: ( "//*[@class='desc'][text()='Just a normal struct.']", {"color": "rgb(221, 221, 221)"}, @@ -274,7 +284,12 @@ local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} reload: // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" +assert-css: ( + "#search-tabs > button > .count", + {"color": "rgb(136, 136, 136)"}, + ALL, +) assert-css: ( "//*[@class='desc'][text()='Just a normal struct.']", {"color": "rgb(0, 0, 0)"}, @@ -381,7 +396,7 @@ define-function: ( // To be SURE that the search will be run. ("press-key", 'Enter'), // Waiting for the search results to appear... - ("wait-for", "#titles"), + ("wait-for", "#search-tabs"), // Checking that the colors for the alias element are the ones expected. ("assert-css", (".result-name > .alias", {"color": |alias|})), ("assert-css", (".result-name > .alias > .grey", {"color": |grey|})), diff --git a/src/test/rustdoc-gui/search-result-description.goml b/src/test/rustdoc-gui/search-result-description.goml index 53a335b6335..9fa2108045d 100644 --- a/src/test/rustdoc-gui/search-result-description.goml +++ b/src/test/rustdoc-gui/search-result-description.goml @@ -1,5 +1,5 @@ // This test is to ensure that the codeblocks are correctly rendered in the search results. goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=some_more_function" // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" assert-text: (".search-results .desc code", "format!") diff --git a/src/test/rustdoc-gui/search-result-go-to-first.goml b/src/test/rustdoc-gui/search-result-go-to-first.goml index eeddf5ef6e8..994fd87c996 100644 --- a/src/test/rustdoc-gui/search-result-go-to-first.goml +++ b/src/test/rustdoc-gui/search-result-go-to-first.goml @@ -8,7 +8,7 @@ assert-text-false: (".fqn", "Struct test_docs::Foo") // We now check that we land on the search result page if "go_to_first" isn't set. goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo" // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" assert-text-false: (".fqn", "Struct test_docs::Foo") // Ensure that the search results are displayed, not the "normal" content. assert-css: ("#main-content", {"display": "none"}) diff --git a/src/test/rustdoc-gui/search-result-keyword.goml b/src/test/rustdoc-gui/search-result-keyword.goml index 66e63155a4e..8c3577d9fd3 100644 --- a/src/test/rustdoc-gui/search-result-keyword.goml +++ b/src/test/rustdoc-gui/search-result-keyword.goml @@ -4,7 +4,7 @@ write: (".search-input", "CookieMonster") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" +wait-for: "#search-tabs" // Note: The two next assert commands could be merged as one but readability would be // less good. // diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml index a19dc6a8b40..1433dc4d7e5 100644 --- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -5,21 +5,21 @@ write: (".search-input", "Foo") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Names", STARTS_WITH) +wait-for: "#search-tabs" +assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#search-tabs > button:nth-of-type(1)", "In Names", STARTS_WITH) assert: "input.search-input:focus" // Use left-right keys press-key: "ArrowDown" assert: "#results > .search-results.active > a:nth-of-type(1):focus" press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(2)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(2)", {"class": "selected"}) press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(3)", {"class": "selected"}) press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) press-key: "ArrowLeft" -wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(3)", {"class": "selected"}) // Now try search-by-return goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -27,21 +27,21 @@ write: (".search-input", "-> String") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) +wait-for: "#search-tabs" +assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) assert: "input.search-input:focus" // Use left-right keys press-key: "ArrowDown" assert: "#results > .search-results.active > a:nth-of-type(1):focus" press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) press-key: "ArrowRight" -wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) press-key: "ArrowLeft" -wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) // Try with a search-by-return with no results goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -49,9 +49,9 @@ write: (".search-input", "-> Something") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) +wait-for: "#search-tabs" +assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) // Try with a search-by-parameter goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -59,9 +59,9 @@ write: (".search-input", "usize pattern") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH) +wait-for: "#search-tabs" +assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH) // Try with a search-by-parameter-and-return goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -69,6 +69,6 @@ write: (".search-input", "pattern -> str") // To be SURE that the search will be run. press-key: 'Enter' // Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH) +wait-for: "#search-tabs" +assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH) diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml index 40ae4af81be..df4506e1119 100644 --- a/src/test/rustdoc-gui/sidebar-source-code-display.goml +++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml @@ -2,18 +2,18 @@ javascript: false goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" // Since the javascript is disabled, there shouldn't be a toggle. -assert-false: "#sidebar-toggle" +assert-false: "#src-sidebar-toggle" wait-for-css: (".sidebar", {"display": "none"}) // Let's retry with javascript enabled. javascript: true reload: -wait-for: "#sidebar-toggle" -assert-css: ("#sidebar-toggle", {"visibility": "visible"}) -assert-css: (".sidebar > *:not(#sidebar-toggle)", {"visibility": "hidden"}) +wait-for: "#src-sidebar-toggle" +assert-css: ("#src-sidebar-toggle", {"visibility": "visible"}) +assert-css: (".sidebar > *:not(#src-sidebar-toggle)", {"visibility": "hidden"}) // Let's expand the sidebar now. -click: "#sidebar-toggle" -wait-for-css: ("#sidebar-toggle", {"visibility": "visible"}) +click: "#src-sidebar-toggle" +wait-for-css: ("#src-sidebar-toggle", {"visibility": "visible"}) // We now check that opening the sidebar and clicking a link will leave it open. // The behavior here on desktop is different than the behavior on mobile, @@ -38,25 +38,25 @@ define-function: ( [ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), ("reload"), - ("wait-for-css", ("#sidebar-toggle", {"visibility": "visible"})), + ("wait-for-css", ("#src-sidebar-toggle", {"visibility": "visible"})), ("assert-css", ( "#source-sidebar details[open] > .files a.selected", {"color": |color_hover|, "background-color": |background|}, )), // Without hover or focus. - ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle|})), + ("assert-css", ("#src-sidebar-toggle > button", {"background-color": |background_toggle|})), // With focus. - ("focus", "#sidebar-toggle > button"), + ("focus", "#src-sidebar-toggle > button"), ("assert-css", ( - "#sidebar-toggle > button:focus", + "#src-sidebar-toggle > button:focus", {"background-color": |background_toggle_hover|}, )), ("focus", ".search-input"), // With hover. - ("move-cursor-to", "#sidebar-toggle > button"), + ("move-cursor-to", "#src-sidebar-toggle > button"), ("assert-css", ( - "#sidebar-toggle > button:hover", + "#src-sidebar-toggle > button:hover", {"background-color": |background_toggle_hover|}, )), @@ -151,16 +151,16 @@ call-function: ("check-colors", { size: (500, 700) reload: // Waiting for the sidebar to be displayed... -wait-for-css: ("#sidebar-toggle", {"visibility": "visible"}) +wait-for-css: ("#src-sidebar-toggle", {"visibility": "visible"}) // We now check it takes the full size of the display. assert-property: ("body", {"clientWidth": "500", "clientHeight": "700"}) assert-property: (".sidebar", {"clientWidth": "500", "clientHeight": "700"}) // We now check the display of the toggle once the sidebar is expanded. -assert-property: ("#sidebar-toggle", {"clientWidth": "500", "clientHeight": "39"}) +assert-property: ("#src-sidebar-toggle", {"clientWidth": "500", "clientHeight": "39"}) assert-css: ( - "#sidebar-toggle", + "#src-sidebar-toggle", { "border-top-width": "0px", "border-right-width": "0px", @@ -170,28 +170,28 @@ assert-css: ( ) // We now check that the scroll position is kept when opening the sidebar. -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: (".sidebar", {"width": "0px"}) // We scroll to line 117 to change the scroll position. scroll-to: '//*[@id="117"]' assert-window-property: {"pageYOffset": "2542"} // Expanding the sidebar... -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: (".sidebar", {"width": "500px"}) -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: (".sidebar", {"width": "0px"}) // The "scrollTop" property should be the same. assert-window-property: {"pageYOffset": "2542"} // We now check that the scroll position is restored if the window is resized. size: (500, 700) -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: ("#source-sidebar", {"visibility": "visible"}) assert-window-property: {"pageYOffset": "0"} size: (900, 900) assert-window-property: {"pageYOffset": "2542"} size: (500, 700) -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: ("#source-sidebar", {"visibility": "hidden"}) // We now check that opening the sidebar and clicking a link will close it. @@ -199,7 +199,7 @@ wait-for-css: ("#source-sidebar", {"visibility": "hidden"}) // but common sense dictates that if you have a list of files that fills the entire screen, and // you click one of them, you probably want to actually see the file's contents, and not just // make it the current selection. -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: ("#source-sidebar", {"visibility": "visible"}) assert-local-storage: {"rustdoc-source-sidebar-show": "true"} click: ".sidebar a.selected" @@ -210,6 +210,6 @@ assert-local-storage: {"rustdoc-source-sidebar-show": "false"} size: (1000, 1000) wait-for-css: ("#source-sidebar", {"visibility": "hidden"}) assert-local-storage: {"rustdoc-source-sidebar-show": "false"} -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" wait-for-css: ("#source-sidebar", {"visibility": "visible"}) assert-local-storage: {"rustdoc-source-sidebar-show": "true"} diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml index b3b837ad377..8a33e713191 100644 --- a/src/test/rustdoc-gui/source-code-page.goml +++ b/src/test/rustdoc-gui/source-code-page.goml @@ -89,15 +89,15 @@ assert-css: (".src-line-numbers", {"text-align": "right"}) // do anything (and certainly not add a `#NaN` to the URL!). goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" // We use this assert-position to know where we will click. -assert-position: ("//*[@id='1']", {"x": 104, "y": 112}) +assert-position: ("//*[@id='1']", {"x": 88, "y": 112}) // We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`. -click: (103, 103) +click: (87, 103) assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH) // Checking the source code sidebar. // First we "open" it. -click: "#sidebar-toggle" +click: "#src-sidebar-toggle" assert: ".source-sidebar-expanded" // We check that the first entry of the sidebar is collapsed diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-1.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-1.rs index 1d1bc5002aa..81a48ac50c8 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-1.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-1.rs @@ -1,3 +1,13 @@ fn main() { + // all examples have same line count + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); scrape_examples::test_many(); } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-2.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-2.rs index 1d1bc5002aa..c9fdf68d3be 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-2.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-2.rs @@ -1,3 +1,13 @@ fn main() { - scrape_examples::test_many(); + // ignore-tidy-linelength + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-3.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-3.rs index 1d1bc5002aa..c9fdf68d3be 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-3.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-3.rs @@ -1,3 +1,13 @@ fn main() { - scrape_examples::test_many(); + // ignore-tidy-linelength + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ + scrape_examples::test_many(); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. */ } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-4.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-4.rs index 1d1bc5002aa..81a48ac50c8 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-4.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-4.rs @@ -1,3 +1,13 @@ fn main() { + // all examples have same line count + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); scrape_examples::test_many(); } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-5.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-5.rs index 1d1bc5002aa..81a48ac50c8 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-5.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-5.rs @@ -1,3 +1,13 @@ fn main() { + // all examples have same line count + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); scrape_examples::test_many(); } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-6.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-6.rs index 1d1bc5002aa..81a48ac50c8 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-6.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-6.rs @@ -1,3 +1,13 @@ fn main() { + // all examples have same line count + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); scrape_examples::test_many(); } diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-7.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-7.rs index 1d1bc5002aa..81a48ac50c8 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-7.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check-many-7.rs @@ -1,3 +1,13 @@ fn main() { + // all examples have same line count + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); + scrape_examples::test_many(); scrape_examples::test_many(); } diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index d6eeab803df..51250439694 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -154,6 +154,11 @@ pub mod huge_amount_of_consts { /// Very long code text `hereIgoWithLongTextBecauseWhyNotAndWhyWouldntI`. pub mod long_code_block {} +/// Very long code text [`hereIgoWithLongTextBecauseWhyNotAndWhyWouldntI`][lnk]. +/// +/// [lnk]: crate::long_code_block_link +pub mod long_code_block_link {} + #[macro_export] macro_rules! repro { () => {}; @@ -442,3 +447,30 @@ pub mod trait_members { fn function2() {} } } + +pub struct TypeWithImplDoc; + +/// impl doc +impl TypeWithImplDoc { + /// fn doc + pub fn test_fn() {} +} + +/// <sub id="codeblock-sub-1"> +/// +/// ``` +/// one +/// ``` +/// +/// </sub> +/// +/// <sub id="codeblock-sub-3"> +/// +/// ``` +/// one +/// two +/// three +/// ``` +/// +/// </sub> +pub mod codeblock_sub {} diff --git a/src/test/rustdoc-gui/struct-fields.goml b/src/test/rustdoc-gui/struct-fields.goml index 3ec60b58cfd..fa3e16cb81e 100644 --- a/src/test/rustdoc-gui/struct-fields.goml +++ b/src/test/rustdoc-gui/struct-fields.goml @@ -1,5 +1,5 @@ +// This test ensures that each field is on its own line (In other words, they have display: block). goto: "file://" + |DOC_PATH| + "/test_docs/struct.StructWithPublicUndocumentedFields.html" -// Both fields must be on their own line. In other words, they have display: block. store-property: (first_top, "//*[@id='structfield.first']", "offsetTop") assert-property-false: ("//*[@id='structfield.second']", { "offsetTop": |first_top| }) diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs index 4b1e04234c8..939da186fbc 100644 --- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs @@ -1,12 +1,10 @@ -// check-pass // normalize-stderr-test: "`.*`" -> "`DEF_ID`" // normalize-stdout-test: "`.*`" -> "`DEF_ID`" // edition:2018 pub async fn f() -> impl std::fmt::Debug { - // rustdoc doesn't care that this is infinitely sized #[derive(Debug)] - enum E { + enum E { //~ ERROR This(E), Unit, } diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr new file mode 100644 index 00000000000..aff7402bc91 --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr @@ -0,0 +1,16 @@ +error[E0072]: recursive type `DEF_ID` has infinite size + --> $DIR/infinite-recursive-type-impl-trait-return.rs:7:5 + | +LL | enum E { + | ^^^^^^ +LL | This(E), + | - recursive without indirection + | +help: insert some indirection (e.g., a `DEF_ID`) to break the cycle + | +LL | This(Box<E>), + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `DEF_ID`. diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs index ac79582fb3f..ac517257498 100644 --- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs @@ -1,8 +1,5 @@ -// check-pass - fn f() -> impl Sized { - // rustdoc doesn't care that this is infinitely sized - enum E { + enum E { //~ ERROR V(E), } unimplemented!() diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr new file mode 100644 index 00000000000..a61577bd14a --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr @@ -0,0 +1,16 @@ +error[E0072]: recursive type `f::E` has infinite size + --> $DIR/infinite-recursive-type-impl-trait.rs:2:5 + | +LL | enum E { + | ^^^^^^ +LL | V(E), + | - recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | V(Box<E>), + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/rustdoc-ui/z-help.stdout b/src/test/rustdoc-ui/z-help.stdout index 94cf7b94241..53677b18377 100644 --- a/src/test/rustdoc-ui/z-help.stdout +++ b/src/test/rustdoc-ui/z-help.stdout @@ -35,6 +35,7 @@ -Z dump-mir-exclude-pass-number=val -- exclude the pass number when dumping MIR (used in tests) (default: no) -Z dump-mir-graphviz=val -- in addition to `.mir` files, create graphviz `.dot` files (and with `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived coverage graph) (default: no) -Z dump-mir-spanview=val -- in addition to `.mir` files, create `.html` files to view spans for all `statement`s (including terminators), only `terminator` spans, or computed `block` spans (one span encompassing a block's terminator and all statements). If `-Z instrument-coverage` is also enabled, create an additional `.html` file showing the computed coverage spans. + -Z dump-mono-stats=val -- output statistics about monomorphization collection (format: markdown) -Z dwarf-version=val -- version of DWARF debug information to emit (default: 2 or 4, depending on platform) -Z dylib-lto=val -- enables LTO for dylib crate type -Z emit-stack-sizes=val -- emit a section containing stack size metadata (default: no) @@ -91,6 +92,7 @@ -Z no-analysis=val -- parse and expand the source, but run no analysis -Z no-codegen=val -- run all passes except codegen; no output -Z no-generate-arange-section=val -- omit DWARF address ranges that give faster lookups + -Z no-jump-tables=val -- disable the jump tables and lookup tables that can be generated from a switch case lowering -Z no-leak-check=val -- disable the 'leak check' for subtyping; unsound, but useful for tests -Z no-link=val -- compile without linking -Z no-parallel-llvm=val -- run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO) diff --git a/src/test/rustdoc/impl-in-const-block.rs b/src/test/rustdoc/impl-in-const-block.rs new file mode 100644 index 00000000000..b44e7135246 --- /dev/null +++ b/src/test/rustdoc/impl-in-const-block.rs @@ -0,0 +1,43 @@ +// Regression test for #83026. +// The goal of this test is to ensure that impl blocks inside +// const expressions are documented as well. + +#![crate_name = "foo"] + +// @has 'foo/struct.A.html' +// @has - '//*[@id="method.new"]/*[@class="code-header"]' 'pub fn new() -> A' +// @has - '//*[@id="method.bar"]/*[@class="code-header"]' 'pub fn bar(&self)' +// @has - '//*[@id="method.woo"]/*[@class="code-header"]' 'pub fn woo(&self)' +// @has - '//*[@id="method.yoo"]/*[@class="code-header"]' 'pub fn yoo()' +// @has - '//*[@id="method.yuu"]/*[@class="code-header"]' 'pub fn yuu()' +pub struct A; + +const _: () = { + impl A { + const FOO: () = { + impl A { + pub fn woo(&self) {} + } + }; + + pub fn new() -> A { + A + } + } +}; +pub const X: () = { + impl A { + pub fn bar(&self) {} + } +}; + +fn foo() { + impl A { + pub fn yoo() {} + } + const _: () = { + impl A { + pub fn yuu() {} + } + }; +} diff --git a/src/test/rustdoc/issue-105952.rs b/src/test/rustdoc/issue-105952.rs new file mode 100644 index 00000000000..e3f1df0063d --- /dev/null +++ b/src/test/rustdoc/issue-105952.rs @@ -0,0 +1,14 @@ +#![crate_name = "foo"] + +#![feature(associated_const_equality)] +pub enum ParseMode { + Raw, +} +pub trait Parse { + const PARSE_MODE: ParseMode; +} +pub trait RenderRaw {} + +// @hasraw foo/trait.RenderRaw.html 'impl' +// @hasraw foo/trait.RenderRaw.html 'ParseMode::Raw' +impl<T: Parse<PARSE_MODE = { ParseMode::Raw }>> RenderRaw for T {} diff --git a/src/test/rustdoc/read-more-unneeded.rs b/src/test/rustdoc/read-more-unneeded.rs new file mode 100644 index 00000000000..0303e444261 --- /dev/null +++ b/src/test/rustdoc/read-more-unneeded.rs @@ -0,0 +1,34 @@ +// Regression test for https://github.com/rust-lang/rust/issues/105677. +// This test ensures that the "Read more" link is only generated when +// there is actually more documentation to read after the short summary. + +#![crate_name = "foo"] + +pub trait MyFrom { + /// # Hello + /// ## Yolo + /// more! + fn try_from1(); + /// a + /// b + /// c + fn try_from2(); + /// a + /// + /// b + /// + /// c + fn try_from3(); +} + +pub struct NonZero; + +// @has 'foo/struct.NonZero.html' +impl MyFrom for NonZero { + // @matches - '//*[@class="docblock"]' '^Hello Read more$' + fn try_from1() {} + // @matches - '//*[@class="docblock"]' '^a\sb\sc$' + fn try_from2() {} + // @matches - '//*[@class="docblock"]' '^a Read more$' + fn try_from3() {} +} diff --git a/src/test/rustdoc/trait-impl.rs b/src/test/rustdoc/trait-impl.rs index 195cdf009b9..9cf3226f738 100644 --- a/src/test/rustdoc/trait-impl.rs +++ b/src/test/rustdoc/trait-impl.rs @@ -30,8 +30,6 @@ impl Trait for Struct { // @has - '//*[@id="method.b"]/../../div[@class="docblock"]' 'These docs contain' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'reference link' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'https://example.com' - // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'Read more' - // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.b' fn b() {} // @!has - '//*[@id="method.c"]/../../div[@class="docblock"]' 'code block' diff --git a/src/test/ui-fulldeps/macro-crate-rlib.stderr b/src/test/ui-fulldeps/macro-crate-rlib.stderr index 7b31f28a26e..9c2b992b765 100644 --- a/src/test/ui-fulldeps/macro-crate-rlib.stderr +++ b/src/test/ui-fulldeps/macro-crate-rlib.stderr @@ -6,3 +6,4 @@ LL | #![plugin(rlib_crate_test)] error: aborting due to previous error +For more information about this error, try `rustc --explain E0457`. diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index cb4cd466590..c19b639a8d5 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -683,7 +683,7 @@ struct RawIdentDiagnosticArg { #[diag(compiletest_example)] struct SubdiagnosticBad { #[subdiagnostic(bad)] - //~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute + //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute note: Note, } @@ -707,7 +707,7 @@ struct SubdiagnosticBadTwice { #[diag(compiletest_example)] struct SubdiagnosticBadLitStr { #[subdiagnostic("bad")] - //~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute + //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute note: Note, } @@ -723,6 +723,7 @@ struct SubdiagnosticEagerLint { #[diag(compiletest_example)] struct SubdiagnosticEagerCorrect { #[subdiagnostic(eager)] + //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute note: Note, } @@ -743,6 +744,7 @@ pub(crate) struct SubdiagnosticWithSuggestion { #[diag(compiletest_example)] struct SubdiagnosticEagerSuggestion { #[subdiagnostic(eager)] + //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute sub: SubdiagnosticWithSuggestion, } diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 1b7ef4e4f19..f39d32a221c 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -533,21 +533,19 @@ LL | #[label] | = help: `#[label]` and `#[suggestion]` can only be applied to fields -error: `#[subdiagnostic(bad)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:685:21 +error: `#[subdiagnostic(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:685:5 | LL | #[subdiagnostic(bad)] - | ^^^ + | ^^^^^^^^^^^^^^^^^^^^^ | - = help: `eager` is the only supported nested attribute for `subdiagnostic` + = help: `subdiagnostic` does not support nested attributes error: `#[subdiagnostic = ...]` is not a valid attribute --> $DIR/diagnostic-derive.rs:693:5 | LL | #[subdiagnostic = "bad"] | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `eager` is the only supported nested attribute for `subdiagnostic` error: `#[subdiagnostic(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:701:5 @@ -555,15 +553,15 @@ error: `#[subdiagnostic(...)]` is not a valid attribute LL | #[subdiagnostic(bad, bad)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: `eager` is the only supported nested attribute for `subdiagnostic` + = help: `subdiagnostic` does not support nested attributes -error: `#[subdiagnostic("...")]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:709:21 +error: `#[subdiagnostic(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:709:5 | LL | #[subdiagnostic("bad")] - | ^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | - = help: `eager` is the only supported nested attribute for `subdiagnostic` + = help: `subdiagnostic` does not support nested attributes error: `#[subdiagnostic(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:717:5 @@ -571,22 +569,38 @@ error: `#[subdiagnostic(...)]` is not a valid attribute LL | #[subdiagnostic(eager)] | ^^^^^^^^^^^^^^^^^^^^^^^ | - = help: eager subdiagnostics are not supported on lints + = help: `subdiagnostic` does not support nested attributes + +error: `#[subdiagnostic(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:725:5 + | +LL | #[subdiagnostic(eager)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `subdiagnostic` does not support nested attributes + +error: `#[subdiagnostic(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:746:5 + | +LL | #[subdiagnostic(eager)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `subdiagnostic` does not support nested attributes error: expected at least one string literal for `code(...)` - --> $DIR/diagnostic-derive.rs:775:18 + --> $DIR/diagnostic-derive.rs:777:18 | LL | #[suggestion(code())] | ^^^^^^ error: `code(...)` must contain only string literals - --> $DIR/diagnostic-derive.rs:783:23 + --> $DIR/diagnostic-derive.rs:785:23 | LL | #[suggestion(code(foo))] | ^^^ error: `code = "..."`/`code(...)` must contain only string literals - --> $DIR/diagnostic-derive.rs:791:18 + --> $DIR/diagnostic-derive.rs:793:18 | LL | #[suggestion(code = 3)] | ^^^^^^^^ @@ -662,7 +676,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` --> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC = note: this error originates in the derive macro `Diagnostic` which comes from the expansion of the macro `forward` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 83 previous errors +error: aborting due to 85 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/allocator/no_std-alloc-error-handler-custom.rs b/src/test/ui/allocator/no_std-alloc-error-handler-custom.rs index 851da231a73..28926243390 100644 --- a/src/test/ui/allocator/no_std-alloc-error-handler-custom.rs +++ b/src/test/ui/allocator/no_std-alloc-error-handler-custom.rs @@ -7,9 +7,10 @@ // compile-flags:-C panic=abort // aux-build:helper.rs -#![feature(start, rustc_private, new_uninit, panic_info_message, lang_items)] +#![feature(rustc_private, lang_items)] #![feature(alloc_error_handler)] #![no_std] +#![no_main] extern crate alloc; extern crate libc; @@ -21,35 +22,30 @@ pub fn __aeabi_unwind_cpp_pr0() {} #[no_mangle] pub fn __aeabi_unwind_cpp_pr1() {} -use core::ptr::null_mut; -use core::alloc::{GlobalAlloc, Layout}; use alloc::boxed::Box; +use alloc::string::ToString; +use core::alloc::{GlobalAlloc, Layout}; +use core::ptr::null_mut; extern crate helper; struct MyAllocator; #[alloc_error_handler] -fn my_oom(layout: Layout) -> ! -{ +fn my_oom(layout: Layout) -> ! { use alloc::fmt::write; unsafe { let size = layout.size(); let mut s = alloc::string::String::new(); write(&mut s, format_args!("My OOM: failed to allocate {} bytes!\n", size)).unwrap(); - let s = s.as_str(); - libc::write(libc::STDERR_FILENO, s as *const _ as _, s.len()); + libc::write(libc::STDERR_FILENO, s.as_ptr() as *const _, s.len()); libc::exit(0) } } unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - if layout.size() < 4096 { - libc::malloc(layout.size()) as _ - } else { - null_mut() - } + if layout.size() < 4096 { libc::malloc(layout.size()) as _ } else { null_mut() } } unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } @@ -60,26 +56,12 @@ static A: MyAllocator = MyAllocator; #[panic_handler] fn panic(panic_info: &core::panic::PanicInfo) -> ! { unsafe { - if let Some(s) = panic_info.payload().downcast_ref::<&str>() { - const PSTR: &str = "panic occurred: "; - const CR: &str = "\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - libc::write(libc::STDERR_FILENO, s as *const _ as _, s.len()); - libc::write(libc::STDERR_FILENO, CR as *const _ as _, CR.len()); - } - if let Some(args) = panic_info.message() { - let mut s = alloc::string::String::new(); - alloc::fmt::write(&mut s, *args).unwrap(); - let s = s.as_str(); - const PSTR: &str = "panic occurred: "; - const CR: &str = "\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - libc::write(libc::STDERR_FILENO, s as *const _ as _, s.len()); - libc::write(libc::STDERR_FILENO, CR as *const _ as _, CR.len()); - } else { - const PSTR: &str = "panic occurred\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - } + let s = panic_info.to_string(); + const PSTR: &str = "panic occurred: "; + const CR: &str = "\n"; + libc::write(libc::STDERR_FILENO, PSTR.as_ptr() as *const _, PSTR.len()); + libc::write(libc::STDERR_FILENO, s.as_ptr() as *const _, s.len()); + libc::write(libc::STDERR_FILENO, CR.as_ptr() as *const _, CR.len()); libc::exit(1) } } @@ -89,15 +71,14 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! { // in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't // unwind. So, for this test case we will define the symbol. #[lang = "eh_personality"] -extern fn rust_eh_personality() {} +extern "C" fn rust_eh_personality() {} -#[derive(Debug)] +#[derive(Default, Debug)] struct Page(#[allow(unused_tuple_struct_fields)] [[u64; 32]; 16]); -#[start] -pub fn main(_argc: isize, _argv: *const *const u8) -> isize { - let zero = Box::<Page>::new_zeroed(); - let zero = unsafe { zero.assume_init() }; +#[no_mangle] +fn main(_argc: i32, _argv: *const *const u8) -> isize { + let zero = Box::<Page>::new(Default::default()); helper::work_with(&zero); 1 } diff --git a/src/test/ui/allocator/no_std-alloc-error-handler-default.rs b/src/test/ui/allocator/no_std-alloc-error-handler-default.rs index 30ce0f162c7..56409e71339 100644 --- a/src/test/ui/allocator/no_std-alloc-error-handler-default.rs +++ b/src/test/ui/allocator/no_std-alloc-error-handler-default.rs @@ -6,11 +6,10 @@ // only-linux // compile-flags:-C panic=abort // aux-build:helper.rs -// gate-test-default_alloc_error_handler -#![feature(start, rustc_private, new_uninit, panic_info_message, lang_items)] -#![feature(default_alloc_error_handler)] +#![feature(rustc_private, lang_items)] #![no_std] +#![no_main] extern crate alloc; extern crate libc; @@ -23,6 +22,7 @@ pub fn __aeabi_unwind_cpp_pr0() {} pub fn __aeabi_unwind_cpp_pr1() {} use alloc::boxed::Box; +use alloc::string::ToString; use core::alloc::{GlobalAlloc, Layout}; use core::ptr::null_mut; @@ -32,11 +32,7 @@ struct MyAllocator; unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - if layout.size() < 4096 { - libc::malloc(layout.size()) as _ - } else { - null_mut() - } + if layout.size() < 4096 { libc::malloc(layout.size()) as _ } else { null_mut() } } unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } @@ -47,26 +43,12 @@ static A: MyAllocator = MyAllocator; #[panic_handler] fn panic(panic_info: &core::panic::PanicInfo) -> ! { unsafe { - if let Some(s) = panic_info.payload().downcast_ref::<&str>() { - const PSTR: &str = "panic occurred: "; - const CR: &str = "\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - libc::write(libc::STDERR_FILENO, s as *const _ as _, s.len()); - libc::write(libc::STDERR_FILENO, CR as *const _ as _, CR.len()); - } - if let Some(args) = panic_info.message() { - let mut s = alloc::string::String::new(); - alloc::fmt::write(&mut s, *args).unwrap(); - let s = s.as_str(); - const PSTR: &str = "panic occurred: "; - const CR: &str = "\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - libc::write(libc::STDERR_FILENO, s as *const _ as _, s.len()); - libc::write(libc::STDERR_FILENO, CR as *const _ as _, CR.len()); - } else { - const PSTR: &str = "panic occurred\n"; - libc::write(libc::STDERR_FILENO, PSTR as *const _ as _, PSTR.len()); - } + let s = panic_info.to_string(); + const PSTR: &str = "panic occurred: "; + const CR: &str = "\n"; + libc::write(libc::STDERR_FILENO, PSTR.as_ptr() as *const _, PSTR.len()); + libc::write(libc::STDERR_FILENO, s.as_ptr() as *const _, s.len()); + libc::write(libc::STDERR_FILENO, CR.as_ptr() as *const _, CR.len()); libc::exit(0) } } @@ -76,15 +58,14 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! { // in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't // unwind. So, for this test case we will define the symbol. #[lang = "eh_personality"] -extern fn rust_eh_personality() {} +extern "C" fn rust_eh_personality() {} -#[derive(Debug)] +#[derive(Default, Debug)] struct Page(#[allow(unused_tuple_struct_fields)] [[u64; 32]; 16]); -#[start] -pub fn main(_argc: isize, _argv: *const *const u8) -> isize { - let zero = Box::<Page>::new_zeroed(); - let zero = unsafe { zero.assume_init() }; +#[no_mangle] +fn main(_argc: i32, _argv: *const *const u8) -> isize { + let zero = Box::<Page>::new(Default::default()); helper::work_with(&zero); 1 } diff --git a/src/test/ui/argument-suggestions/basic.stderr b/src/test/ui/argument-suggestions/basic.stderr index b118ce1bd0e..062b3768858 100644 --- a/src/test/ui/argument-suggestions/basic.stderr +++ b/src/test/ui/argument-suggestions/basic.stderr @@ -94,8 +94,8 @@ LL | let closure = |x| x; | ^^^ help: provide the argument | -LL | closure(/* value */); - | ~~~~~~~~~~~~~ +LL | closure(/* x */); + | ~~~~~~~~~ error: aborting due to 6 previous errors diff --git a/src/test/ui/argument-suggestions/display-is-suggestable.rs b/src/test/ui/argument-suggestions/display-is-suggestable.rs new file mode 100644 index 00000000000..d765bc4f74d --- /dev/null +++ b/src/test/ui/argument-suggestions/display-is-suggestable.rs @@ -0,0 +1,8 @@ +use std::fmt::Display; + +fn foo(x: &(dyn Display + Send)) {} + +fn main() { + foo(); + //~^ ERROR this function takes 1 argument but 0 arguments were supplied +} diff --git a/src/test/ui/argument-suggestions/display-is-suggestable.stderr b/src/test/ui/argument-suggestions/display-is-suggestable.stderr new file mode 100644 index 00000000000..edd72b53eb3 --- /dev/null +++ b/src/test/ui/argument-suggestions/display-is-suggestable.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/display-is-suggestable.rs:6:5 + | +LL | foo(); + | ^^^-- an argument of type `&dyn std::fmt::Display + Send` is missing + | +note: function defined here + --> $DIR/display-is-suggestable.rs:3:4 + | +LL | fn foo(x: &(dyn Display + Send)) {} + | ^^^ ------------------------ +help: provide the argument + | +LL | foo(/* &dyn std::fmt::Display + Send */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/array-slice-vec/infer_array_len.stderr b/src/test/ui/array-slice-vec/infer_array_len.stderr index 919550cac30..c2a509a1963 100644 --- a/src/test/ui/array-slice-vec/infer_array_len.stderr +++ b/src/test/ui/array-slice-vec/infer_array_len.stderr @@ -6,8 +6,8 @@ LL | let [_, _] = a.into(); | help: consider giving this pattern a type | -LL | let [_, _]: _ = a.into(); - | +++ +LL | let [_, _]: /* Type */ = a.into(); + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/asm/bad-arch.mirunsafeck.stderr b/src/test/ui/asm/bad-arch.mirunsafeck.stderr index 4aa27180758..d7af296152f 100644 --- a/src/test/ui/asm/bad-arch.mirunsafeck.stderr +++ b/src/test/ui/asm/bad-arch.mirunsafeck.stderr @@ -14,3 +14,4 @@ LL | global_asm!(""); error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0472`. diff --git a/src/test/ui/asm/bad-arch.thirunsafeck.stderr b/src/test/ui/asm/bad-arch.thirunsafeck.stderr index 4aa27180758..d7af296152f 100644 --- a/src/test/ui/asm/bad-arch.thirunsafeck.stderr +++ b/src/test/ui/asm/bad-arch.thirunsafeck.stderr @@ -14,3 +14,4 @@ LL | global_asm!(""); error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0472`. diff --git a/src/test/ui/associated-inherent-types/style.rs b/src/test/ui/associated-inherent-types/style.rs new file mode 100644 index 00000000000..8775bd19e1f --- /dev/null +++ b/src/test/ui/associated-inherent-types/style.rs @@ -0,0 +1,12 @@ +#![feature(inherent_associated_types)] +#![allow(incomplete_features, dead_code)] +#![deny(non_camel_case_types)] + +struct S; + +impl S { + type typ = (); + //~^ ERROR associated type `typ` should have an upper camel case name +} + +fn main() {} diff --git a/src/test/ui/associated-inherent-types/style.stderr b/src/test/ui/associated-inherent-types/style.stderr new file mode 100644 index 00000000000..f83061f8c42 --- /dev/null +++ b/src/test/ui/associated-inherent-types/style.stderr @@ -0,0 +1,14 @@ +error: associated type `typ` should have an upper camel case name + --> $DIR/style.rs:8:10 + | +LL | type typ = (); + | ^^^ help: convert the identifier to upper camel case: `Typ` + | +note: the lint level is defined here + --> $DIR/style.rs:3:9 + | +LL | #![deny(non_camel_case_types)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/associated-type-bounds/const-projection-err.gce.stderr b/src/test/ui/associated-type-bounds/const-projection-err.gce.stderr new file mode 100644 index 00000000000..0f1ec9ad052 --- /dev/null +++ b/src/test/ui/associated-type-bounds/const-projection-err.gce.stderr @@ -0,0 +1,24 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/const-projection-err.rs:4:26 + | +LL | #![cfg_attr(gce, feature(generic_const_exprs))] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 1` + --> $DIR/const-projection-err.rs:14:11 + | +LL | foo::<T>(); + | ^ expected `0`, found `1` + | +note: required by a bound in `foo` + --> $DIR/const-projection-err.rs:11:28 + | +LL | fn foo<T: TraitWAssocConst<A = 1>>() {} + | ^^^^^ required by this bound in `foo` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/associated-type-bounds/const-projection-err.rs b/src/test/ui/associated-type-bounds/const-projection-err.rs new file mode 100644 index 00000000000..bead8563001 --- /dev/null +++ b/src/test/ui/associated-type-bounds/const-projection-err.rs @@ -0,0 +1,18 @@ +// revisions: stock gce + +#![feature(associated_const_equality)] +#![cfg_attr(gce, feature(generic_const_exprs))] +//[gce]~^ WARN the feature `generic_const_exprs` is incomplete + +trait TraitWAssocConst { + const A: usize; +} + +fn foo<T: TraitWAssocConst<A = 1>>() {} + +fn bar<T: TraitWAssocConst<A = 0>>() { + foo::<T>(); + //~^ ERROR type mismatch resolving `<T as TraitWAssocConst>::A == 1` +} + +fn main() {} diff --git a/src/test/ui/associated-type-bounds/const-projection-err.stock.stderr b/src/test/ui/associated-type-bounds/const-projection-err.stock.stderr new file mode 100644 index 00000000000..bf0824259a5 --- /dev/null +++ b/src/test/ui/associated-type-bounds/const-projection-err.stock.stderr @@ -0,0 +1,17 @@ +error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 1` + --> $DIR/const-projection-err.rs:14:11 + | +LL | foo::<T>(); + | ^ expected `1`, found `<T as TraitWAssocConst>::A` + | + = note: expected constant `1` + found constant `<T as TraitWAssocConst>::A` +note: required by a bound in `foo` + --> $DIR/const-projection-err.rs:11:28 + | +LL | fn foo<T: TraitWAssocConst<A = 1>>() {} + | ^^^^^ required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/associated-types/associated-types-overridden-binding-2.rs b/src/test/ui/associated-types/associated-types-overridden-binding-2.rs index 26b9f4b3a92..fed60ccf089 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding-2.rs +++ b/src/test/ui/associated-types/associated-types-overridden-binding-2.rs @@ -4,5 +4,5 @@ trait I32Iterator = Iterator<Item = i32>; fn main() { let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter(); - //~^ ERROR expected `std::vec::IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32` + //~^ ERROR expected `IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32` } diff --git a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr index 2d25f68de44..a28a0b74e4a 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `std::vec::IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32` +error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32` --> $DIR/associated-types-overridden-binding-2.rs:6:43 | LL | let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter(); diff --git a/src/test/ui/associated-types/associated-types-unconstrained.stderr b/src/test/ui/associated-types/associated-types-unconstrained.stderr index e51a8f3bd1a..ef9b7cae01b 100644 --- a/src/test/ui/associated-types/associated-types-unconstrained.stderr +++ b/src/test/ui/associated-types/associated-types-unconstrained.stderr @@ -6,6 +6,11 @@ LL | fn bar() -> isize; ... LL | let x: isize = Foo::bar(); | ^^^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | let x: isize = <isize as Foo>::bar(); + | +++++++++ + error: aborting due to previous error diff --git a/src/test/ui/async-await/async-await-let-else.drop-tracking.stderr b/src/test/ui/async-await/async-await-let-else.drop-tracking.stderr index f0f5245a3b4..fb83ca90a37 100644 --- a/src/test/ui/async-await/async-await-let-else.drop-tracking.stderr +++ b/src/test/ui/async-await/async-await-let-else.drop-tracking.stderr @@ -40,7 +40,7 @@ LL | async fn bar2<T>(_: T) -> ! { LL | | panic!() LL | | } | |_^ - = note: required because it captures the following types: `&mut Context<'_>`, `Option<bool>`, `impl Future<Output = !>`, `()` + = note: required because it captures the following types: `ResumeTy`, `Option<bool>`, `impl Future<Output = !>`, `()` note: required because it's used within this `async fn` body --> $DIR/async-await-let-else.rs:21:32 | diff --git a/src/test/ui/async-await/async-is-unwindsafe.rs b/src/test/ui/async-await/async-is-unwindsafe.rs new file mode 100644 index 00000000000..56ed2847292 --- /dev/null +++ b/src/test/ui/async-await/async-is-unwindsafe.rs @@ -0,0 +1,30 @@ +// edition:2018 + +fn is_unwindsafe(_: impl std::panic::UnwindSafe) {} + +fn main() { + // A normal future created by an async block takes a `&mut Context<'_>` argument. + // That should not leak through to the whole async block. + is_unwindsafe(async { + async {}.await; // this needs an inner await point + }); + + is_unwindsafe(async { + //~^ ERROR the type `&mut Context<'_>` may not be safely transferred across an unwind boundary + use std::ptr::null; + use std::task::{Context, RawWaker, RawWakerVTable, Waker}; + let waker = unsafe { + Waker::from_raw(RawWaker::new( + null(), + &RawWakerVTable::new(|_| todo!(), |_| todo!(), |_| todo!(), |_| todo!()), + )) + }; + let mut cx = Context::from_waker(&waker); + let cx_ref = &mut cx; + + async {}.await; // this needs an inner await point + + // in this case, `&mut Context<'_>` is *truly* alive across an await point + drop(cx_ref); + }); +} diff --git a/src/test/ui/async-await/async-is-unwindsafe.stderr b/src/test/ui/async-await/async-is-unwindsafe.stderr new file mode 100644 index 00000000000..d6404b30e74 --- /dev/null +++ b/src/test/ui/async-await/async-is-unwindsafe.stderr @@ -0,0 +1,38 @@ +error[E0277]: the type `&mut Context<'_>` may not be safely transferred across an unwind boundary + --> $DIR/async-is-unwindsafe.rs:12:19 + | +LL | is_unwindsafe(async { + | ___________________^ +LL | | +LL | | use std::ptr::null; +LL | | use std::task::{Context, RawWaker, RawWakerVTable, Waker}; +... | +LL | | drop(cx_ref); +LL | | }); + | | ^ + | | | + | |_____`&mut Context<'_>` may not be safely transferred across an unwind boundary + | within this `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]` + | + = help: within `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>` + = note: `UnwindSafe` is implemented for `&std::task::Context<'_>`, but not for `&mut std::task::Context<'_>` +note: future does not implement `UnwindSafe` as this value is used across an await + --> $DIR/async-is-unwindsafe.rs:25:17 + | +LL | let cx_ref = &mut cx; + | ------ has type `&mut Context<'_>` which does not implement `UnwindSafe` +LL | +LL | async {}.await; // this needs an inner await point + | ^^^^^^ await occurs here, with `cx_ref` maybe used later +... +LL | }); + | - `cx_ref` is later dropped here +note: required by a bound in `is_unwindsafe` + --> $DIR/async-is-unwindsafe.rs:3:26 + | +LL | fn is_unwindsafe(_: impl std::panic::UnwindSafe) {} + | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_unwindsafe` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs index 61d7e2520ea..1b1b3cffd58 100644 --- a/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs +++ b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs @@ -1,4 +1,3 @@ -// check-pass // edition: 2021 #![feature(async_fn_in_trait)] @@ -13,11 +12,9 @@ trait MyTrait { } impl MyTrait for i32 { - // This will break once a PR that implements #102745 is merged fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> { - Box::pin(async { - *self - }) + //~^ ERROR method `foo` should be async + Box::pin(async { *self }) } } diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-boxed.stderr b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.stderr new file mode 100644 index 00000000000..60fa534a64f --- /dev/null +++ b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.stderr @@ -0,0 +1,11 @@ +error: method `foo` should be async because the method from the trait is async + --> $DIR/async-example-desugared-boxed.rs:15:5 + | +LL | async fn foo(&self) -> i32; + | --------------------------- required because the trait method is async +... +LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-extra.rs b/src/test/ui/async-await/in-trait/async-example-desugared-extra.rs new file mode 100644 index 00000000000..81e1e59a362 --- /dev/null +++ b/src/test/ui/async-await/in-trait/async-example-desugared-extra.rs @@ -0,0 +1,37 @@ +// check-pass +// edition: 2021 + +#![feature(async_fn_in_trait)] +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; +use std::pin::Pin; +use std::task::Poll; + +trait MyTrait { + async fn foo(&self) -> i32; +} + +#[derive(Clone)] +struct MyFuture(i32); + +impl Future for MyFuture { + type Output = i32; + fn poll( + self: Pin<&mut Self>, + _: &mut std::task::Context<'_>, + ) -> Poll<<Self as Future>::Output> { + Poll::Ready(self.0) + } +} + +impl MyTrait for i32 { + // FIXME: this should eventually require `#[refine]` to compile, because it also provides + // `Clone`. + fn foo(&self) -> impl Future<Output = i32> + Clone { + MyFuture(*self) + } +} + +fn main() {} diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-manual.rs b/src/test/ui/async-await/in-trait/async-example-desugared-manual.rs new file mode 100644 index 00000000000..71473e7455f --- /dev/null +++ b/src/test/ui/async-await/in-trait/async-example-desugared-manual.rs @@ -0,0 +1,29 @@ +// edition: 2021 + +#![feature(async_fn_in_trait)] +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; +use std::task::Poll; + +trait MyTrait { + async fn foo(&self) -> i32; +} + +struct MyFuture; +impl Future for MyFuture { + type Output = i32; + fn poll(self: std::pin::Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> { + Poll::Ready(0) + } +} + +impl MyTrait for u32 { + fn foo(&self) -> MyFuture { + //~^ ERROR method `foo` should be async + MyFuture + } +} + +fn main() {} diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-manual.stderr b/src/test/ui/async-await/in-trait/async-example-desugared-manual.stderr new file mode 100644 index 00000000000..567a36a86d1 --- /dev/null +++ b/src/test/ui/async-await/in-trait/async-example-desugared-manual.stderr @@ -0,0 +1,11 @@ +error: method `foo` should be async because the method from the trait is async + --> $DIR/async-example-desugared-manual.rs:23:5 + | +LL | async fn foo(&self) -> i32; + | --------------------------- required because the trait method is async +... +LL | fn foo(&self) -> MyFuture { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/async-await/in-trait/async-example-desugared.rs b/src/test/ui/async-await/in-trait/async-example-desugared.rs index 1313c9edd86..fb92ec78674 100644 --- a/src/test/ui/async-await/in-trait/async-example-desugared.rs +++ b/src/test/ui/async-await/in-trait/async-example-desugared.rs @@ -12,11 +12,8 @@ trait MyTrait { } impl MyTrait for i32 { - // This will break once a PR that implements #102745 is merged fn foo(&self) -> impl Future<Output = i32> + '_ { - async { - *self - } + async { *self } } } diff --git a/src/test/ui/async-await/in-trait/bad-signatures.rs b/src/test/ui/async-await/in-trait/bad-signatures.rs new file mode 100644 index 00000000000..b86f1d1c135 --- /dev/null +++ b/src/test/ui/async-await/in-trait/bad-signatures.rs @@ -0,0 +1,16 @@ +// edition:2021 + +#![feature(async_fn_in_trait)] +//~^ WARN the feature `async_fn_in_trait` is incomplete + +trait MyTrait { + async fn bar(&abc self); + //~^ ERROR expected identifier, found keyword `self` + //~| ERROR expected one of `:`, `@`, or `|`, found keyword `self` +} + +impl MyTrait for () { + async fn bar(&self) {} +} + +fn main() {} diff --git a/src/test/ui/async-await/in-trait/bad-signatures.stderr b/src/test/ui/async-await/in-trait/bad-signatures.stderr new file mode 100644 index 00000000000..e0ba7b53ec4 --- /dev/null +++ b/src/test/ui/async-await/in-trait/bad-signatures.stderr @@ -0,0 +1,26 @@ +error: expected identifier, found keyword `self` + --> $DIR/bad-signatures.rs:7:23 + | +LL | async fn bar(&abc self); + | ^^^^ expected identifier, found keyword + +error: expected one of `:`, `@`, or `|`, found keyword `self` + --> $DIR/bad-signatures.rs:7:23 + | +LL | async fn bar(&abc self); + | -----^^^^ + | | | + | | expected one of `:`, `@`, or `|` + | help: declare the type after the parameter binding: `<identifier>: <type>` + +warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/bad-signatures.rs:3:12 + | +LL | #![feature(async_fn_in_trait)] + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to 2 previous errors; 1 warning emitted + diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err.rs b/src/test/ui/async-await/in-trait/fn-not-async-err.rs index f94d32145a2..9598d53bce8 100644 --- a/src/test/ui/async-await/in-trait/fn-not-async-err.rs +++ b/src/test/ui/async-await/in-trait/fn-not-async-err.rs @@ -9,7 +9,7 @@ trait MyTrait { impl MyTrait for i32 { fn foo(&self) -> i32 { - //~^ ERROR: `i32` is not a future [E0277] + //~^ ERROR: method `foo` should be async *self } } diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err.stderr b/src/test/ui/async-await/in-trait/fn-not-async-err.stderr index 03321dc5b5a..579801d0f39 100644 --- a/src/test/ui/async-await/in-trait/fn-not-async-err.stderr +++ b/src/test/ui/async-await/in-trait/fn-not-async-err.stderr @@ -1,17 +1,11 @@ -error[E0277]: `i32` is not a future - --> $DIR/fn-not-async-err.rs:11:22 - | -LL | fn foo(&self) -> i32 { - | ^^^ `i32` is not a future - | - = help: the trait `Future` is not implemented for `i32` - = note: i32 must be a future or must implement `IntoFuture` to be awaited -note: required by a bound in `MyTrait::foo::{opaque#0}` - --> $DIR/fn-not-async-err.rs:7:28 +error: method `foo` should be async because the method from the trait is async + --> $DIR/fn-not-async-err.rs:11:5 | LL | async fn foo(&self) -> i32; - | ^^^ required by this bound in `MyTrait::foo::{opaque#0}` + | --------------------------- required because the trait method is async +... +LL | fn foo(&self) -> i32 { + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err2.rs b/src/test/ui/async-await/in-trait/fn-not-async-err2.rs index 594baa91ad8..2c4ed553580 100644 --- a/src/test/ui/async-await/in-trait/fn-not-async-err2.rs +++ b/src/test/ui/async-await/in-trait/fn-not-async-err2.rs @@ -12,9 +12,7 @@ trait MyTrait { impl MyTrait for i32 { fn foo(&self) -> impl Future<Output = i32> { //~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `impl` method return [E0562] - async { - *self - } + async { *self } } } diff --git a/src/test/ui/async-await/in-trait/issue-104678.rs b/src/test/ui/async-await/in-trait/issue-104678.rs new file mode 100644 index 00000000000..e396df4e5d1 --- /dev/null +++ b/src/test/ui/async-await/in-trait/issue-104678.rs @@ -0,0 +1,31 @@ +// edition:2021 +// check-pass + +#![feature(async_fn_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; +pub trait Pool { + type Conn; + + async fn async_callback<'a, F: FnOnce(&'a Self::Conn) -> Fut, Fut: Future<Output = ()>>( + &'a self, + callback: F, + ) -> (); +} + +pub struct PoolImpl; +pub struct ConnImpl; + +impl Pool for PoolImpl { + type Conn = ConnImpl; + + async fn async_callback<'a, F: FnOnce(&'a Self::Conn) -> Fut, Fut: Future<Output = ()>>( + &'a self, + _callback: F, + ) -> () { + todo!() + } +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-68112.drop_tracking.stderr b/src/test/ui/async-await/issue-68112.drop_tracking.stderr index 1c90bedae79..f2802698fd5 100644 --- a/src/test/ui/async-await/issue-68112.drop_tracking.stderr +++ b/src/test/ui/async-await/issue-68112.drop_tracking.stderr @@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC | LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>` + = note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>` note: required because it's used within this `async` block --> $DIR/issue-68112.rs:60:20 | diff --git a/src/test/ui/async-await/issue-68112.no_drop_tracking.stderr b/src/test/ui/async-await/issue-68112.no_drop_tracking.stderr index e09ae7fedd8..38eb85b302f 100644 --- a/src/test/ui/async-await/issue-68112.no_drop_tracking.stderr +++ b/src/test/ui/async-await/issue-68112.no_drop_tracking.stderr @@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC | LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>` + = note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>` note: required because it's used within this `async` block --> $DIR/issue-68112.rs:60:20 | diff --git a/src/test/ui/async-await/issue-69446-fnmut-capture.stderr b/src/test/ui/async-await/issue-69446-fnmut-capture.stderr index e6ad2f0d444..3d2b0402bc5 100644 --- a/src/test/ui/async-await/issue-69446-fnmut-capture.stderr +++ b/src/test/ui/async-await/issue-69446-fnmut-capture.stderr @@ -14,9 +14,6 @@ LL | | }); | = note: `FnMut` closures only have access to their captured variables while they are executing... = note: ...therefore, they cannot allow references to captured variables to escape - = note: requirement occurs because of a mutable reference to `Context<'_>` - = note: mutable references are invariant over their type parameter - = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance error: aborting due to previous error diff --git a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr index a8fd97cde8f..721234aa4a7 100644 --- a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr +++ b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr @@ -18,7 +18,7 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> { | ___________________________________________________________________^ LL | | } | |_^ - = note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = ()>`, `()` + = note: required because it captures the following types: `ResumeTy`, `impl Future<Output = ()>`, `()` note: required because it's used within this `async` block --> $DIR/issue-70935-complex-spans.rs:16:5 | diff --git a/src/test/ui/async-await/issues/issue-102206.rs b/src/test/ui/async-await/issues/issue-102206.rs new file mode 100644 index 00000000000..a3a2ebc5896 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-102206.rs @@ -0,0 +1,8 @@ +// edition:2021 + +async fn foo() {} + +fn main() { + std::mem::size_of_val(foo()); + //~^ ERROR: mismatched types +} diff --git a/src/test/ui/async-await/issues/issue-102206.stderr b/src/test/ui/async-await/issues/issue-102206.stderr new file mode 100644 index 00000000000..2ab790ac761 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-102206.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/issue-102206.rs:6:27 + | +LL | std::mem::size_of_val(foo()); + | --------------------- ^^^^^ + | | | + | | expected reference, found opaque type + | | help: consider borrowing here: `&foo()` + | arguments to this function are incorrect + | +note: while checking the return type of the `async fn` + --> $DIR/issue-102206.rs:3:16 + | +LL | async fn foo() {} + | ^ checked the `Output` of this `async fn`, found opaque type + = note: expected reference `&_` + found opaque type `impl Future<Output = ()>` +note: function defined here + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr b/src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr index 25876d50840..17b4ef7bdc6 100644 --- a/src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr +++ b/src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr @@ -11,7 +11,7 @@ LL | async fn foo() { | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend` = note: required because it appears within the type `(NotSend,)` - = note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `()`, `impl Future<Output = ()>` + = note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `()`, `impl Future<Output = ()>` note: required because it's used within this `async fn` body --> $DIR/partial-drop-partial-reinit.rs:31:16 | diff --git a/src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr b/src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr index dba2a620779..34d8a159f10 100644 --- a/src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr +++ b/src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr @@ -11,7 +11,7 @@ LL | async fn foo() { | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend` = note: required because it appears within the type `(NotSend,)` - = note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `impl Future<Output = ()>`, `()` + = note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `impl Future<Output = ()>`, `()` note: required because it's used within this `async fn` body --> $DIR/partial-drop-partial-reinit.rs:31:16 | diff --git a/src/test/ui/async-await/track-caller/async-closure-gate.rs b/src/test/ui/async-await/track-caller/async-closure-gate.rs index 9593fdb1908..d9d55685599 100644 --- a/src/test/ui/async-await/track-caller/async-closure-gate.rs +++ b/src/test/ui/async-await/track-caller/async-closure-gate.rs @@ -5,6 +5,5 @@ fn main() { let _ = #[track_caller] async || { //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] - //~| ERROR `#[track_caller]` on closures is currently unstable [E0658] }; } diff --git a/src/test/ui/async-await/track-caller/async-closure-gate.stderr b/src/test/ui/async-await/track-caller/async-closure-gate.stderr index be3d110eccd..498f1b43b9b 100644 --- a/src/test/ui/async-await/track-caller/async-closure-gate.stderr +++ b/src/test/ui/async-await/track-caller/async-closure-gate.stderr @@ -7,19 +7,6 @@ LL | let _ = #[track_caller] async || { = note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable -error[E0658]: `#[track_caller]` on closures is currently unstable - --> $DIR/async-closure-gate.rs:6:38 - | -LL | let _ = #[track_caller] async || { - | ______________________________________^ -LL | | -LL | | -LL | | }; - | |_____^ - | - = note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information - = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr b/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr new file mode 100644 index 00000000000..51ea225f4cb --- /dev/null +++ b/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr @@ -0,0 +1,29 @@ +warning: `#[track_caller]` on async functions is a no-op + --> $DIR/panic-track-caller.rs:50:1 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +LL | / async fn bar_track_caller() { +LL | | panic!() +LL | | } + | |_- this function will not propagate the caller location + | + = note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + = note: `#[warn(ungated_async_fn_track_caller)]` on by default + +warning: `#[track_caller]` on async functions is a no-op + --> $DIR/panic-track-caller.rs:62:5 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +LL | / async fn bar_assoc() { +LL | | panic!(); +LL | | } + | |_____- this function will not propagate the caller location + | + = note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +warning: 2 warnings emitted + diff --git a/src/test/ui/async-await/track-caller/panic-track-caller.rs b/src/test/ui/async-await/track-caller/panic-track-caller.rs index 066cf97628f..f45243b0ea6 100644 --- a/src/test/ui/async-await/track-caller/panic-track-caller.rs +++ b/src/test/ui/async-await/track-caller/panic-track-caller.rs @@ -1,7 +1,9 @@ // run-pass // edition:2021 +// revisions: feat nofeat // needs-unwind -#![feature(closure_track_caller, async_closure, stmt_expr_attributes)] +#![feature(async_closure, stmt_expr_attributes)] +#![cfg_attr(feat, feature(closure_track_caller))] use std::future::Future; use std::panic; @@ -45,7 +47,7 @@ async fn foo() { bar().await } -#[track_caller] +#[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op async fn bar_track_caller() { panic!() } @@ -57,7 +59,7 @@ async fn foo_track_caller() { struct Foo; impl Foo { - #[track_caller] + #[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op async fn bar_assoc() { panic!(); } @@ -67,6 +69,9 @@ async fn foo_assoc() { Foo::bar_assoc().await } +// Since compilation is expected to fail for this fn when using +// `nofeat`, we test that separately in `async-closure-gate.rs` +#[cfg(feat)] async fn foo_closure() { let c = #[track_caller] async || { panic!(); @@ -91,8 +96,18 @@ fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 { } fn main() { - assert_eq!(panicked_at(|| block_on(foo())), 41); - assert_eq!(panicked_at(|| block_on(foo_track_caller())), 54); - assert_eq!(panicked_at(|| block_on(foo_assoc())), 67); - assert_eq!(panicked_at(|| block_on(foo_closure())), 74); + assert_eq!(panicked_at(|| block_on(foo())), 43); + + #[cfg(feat)] + assert_eq!(panicked_at(|| block_on(foo_track_caller())), 56); + #[cfg(nofeat)] + assert_eq!(panicked_at(|| block_on(foo_track_caller())), 52); + + #[cfg(feat)] + assert_eq!(panicked_at(|| block_on(foo_assoc())), 69); + #[cfg(nofeat)] + assert_eq!(panicked_at(|| block_on(foo_assoc())), 64); + + #[cfg(feat)] + assert_eq!(panicked_at(|| block_on(foo_closure())), 79); } diff --git a/src/test/ui/borrowck/issue-103095.rs b/src/test/ui/borrowck/issue-103095.rs new file mode 100644 index 00000000000..0340f39243f --- /dev/null +++ b/src/test/ui/borrowck/issue-103095.rs @@ -0,0 +1,30 @@ +// check-pass + +trait FnOnceForGenericRef<T>: FnOnce(&T) -> Self::FnOutput { + type FnOutput; +} + +impl<T, R, F: FnOnce(&T) -> R> FnOnceForGenericRef<T> for F { + type FnOutput = R; +} + +struct Data<T, D: FnOnceForGenericRef<T>> { + value: Option<T>, + output: Option<D::FnOutput>, +} + +impl<T, D: FnOnceForGenericRef<T>> Data<T, D> { + fn new(value: T, f: D) -> Self { + let output = f(&value); + Self { + value: Some(value), + output: Some(output), + } + } +} + +fn test() { + Data::new(String::new(), |_| {}); +} + +fn main() {} diff --git a/src/test/ui/borrowck/issue-104639-lifetime-order.rs b/src/test/ui/borrowck/issue-104639-lifetime-order.rs new file mode 100644 index 00000000000..db1f8f8d588 --- /dev/null +++ b/src/test/ui/borrowck/issue-104639-lifetime-order.rs @@ -0,0 +1,10 @@ +// edition:2018 +// check-pass + +#![allow(dead_code)] +async fn fail<'a, 'b, 'c>(_: &'static str) where 'a: 'c, 'b: 'c, {} +async fn pass<'a, 'c, 'b>(_: &'static str) where 'a: 'c, 'b: 'c, {} +async fn pass2<'a, 'b, 'c>(_: &'static str) where 'a: 'c, 'b: 'c, 'c: 'a, {} +async fn pass3<'a, 'b, 'c>(_: &'static str) where 'a: 'b, 'b: 'c, 'c: 'a, {} + +fn main() { } diff --git a/src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr b/src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr index d5432755cfe..7a04ed7381e 100644 --- a/src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr +++ b/src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr @@ -6,8 +6,8 @@ LL | with_closure(|x: u32, y| {}); | help: consider giving this closure parameter an explicit type | -LL | with_closure(|x: u32, y: _| {}); - | +++ +LL | with_closure(|x: u32, y: /* Type */| {}); + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/closures/issue-52437.stderr b/src/test/ui/closures/issue-52437.stderr index 4c24a54bbbe..9ba24c7a886 100644 --- a/src/test/ui/closures/issue-52437.stderr +++ b/src/test/ui/closures/issue-52437.stderr @@ -12,8 +12,8 @@ LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize] | help: consider giving this closure parameter an explicit type | -LL | [(); &(&'static: loop { |x: _| {}; }) as *const _ as usize] - | +++ +LL | [(); &(&'static: loop { |x: /* Type */| {}; }) as *const _ as usize] + | ++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/codegen/issue-55976.rs b/src/test/ui/codegen/issue-55976.rs new file mode 100644 index 00000000000..3142704b78c --- /dev/null +++ b/src/test/ui/codegen/issue-55976.rs @@ -0,0 +1,13 @@ +// run-pass +// ^-- The above is needed as this issue is related to LLVM/codegen. +// min-llvm-version:15.0.0 +// ^-- The above is needed as this issue is fixed by the opaque pointers. + +fn main() { + type_error(|x| &x); +} + +fn type_error<T>( + _selector: for<'a> fn(&'a Vec<Box<dyn for<'b> Fn(&'b u8)>>) -> &'a Vec<Box<dyn Fn(T)>>, +) { +} diff --git a/src/test/ui/confuse-field-and-method/issue-33784.stderr b/src/test/ui/confuse-field-and-method/issue-33784.stderr index 34debb68317..3906d64c946 100644 --- a/src/test/ui/confuse-field-and-method/issue-33784.stderr +++ b/src/test/ui/confuse-field-and-method/issue-33784.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `closure` found for reference `&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope +error[E0599]: no method named `closure` found for reference `&Obj<[closure@issue-33784.rs:25:43]>` in the current scope --> $DIR/issue-33784.rs:27:7 | LL | p.closure(); @@ -9,7 +9,7 @@ help: to call the function stored in `closure`, surround the field access with p LL | (p.closure)(); | + + -error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope +error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@issue-33784.rs:25:43]>` in the current scope --> $DIR/issue-33784.rs:29:7 | LL | q.fn_ptr(); diff --git a/src/test/ui/const-generics/defaults/complex-unord-param.min.stderr b/src/test/ui/const-generics/defaults/complex-unord-param.min.stderr deleted file mode 100644 index 8e8d26a0004..00000000000 --- a/src/test/ui/const-generics/defaults/complex-unord-param.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/complex-unord-param.rs:8:41 - | -LL | struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> { - | ---------------------^----------------------^--------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, A: 'a, T: 'a = u32, const N: usize, const M: usize>` - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr b/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr index 293ca6232b1..13ea4a295af 100644 --- a/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr +++ b/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr @@ -5,6 +5,12 @@ LL | let y = Mask::<_, _>::splat(false); | ^ ------------------- type must be known at this point | = note: cannot satisfy `_: MaskElement` + = help: the following types implement trait `MaskElement`: + i16 + i32 + i64 + i8 + isize note: required by a bound in `Mask::<T, LANES>::splat` --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL help: consider giving `y` an explicit type, where the type for type parameter `T` is specified diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-105608.rs b/src/test/ui/const-generics/generic_const_exprs/issue-105608.rs new file mode 100644 index 00000000000..e28ba3b1ada --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-105608.rs @@ -0,0 +1,15 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Combination<const STRATEGIES: usize>; + +impl<const STRATEGIES: usize> Combination<STRATEGIES> { + fn and<M>(self) -> Combination<{ STRATEGIES + 1 }> { + Combination + } +} + +pub fn main() { + Combination::<0>.and::<_>().and::<_>(); + //~^ ERROR: type annotations needed +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-105608.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-105608.stderr new file mode 100644 index 00000000000..0be4c43daac --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-105608.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/issue-105608.rs:13:22 + | +LL | Combination::<0>.and::<_>().and::<_>(); + | ^^^ cannot infer type of the type parameter `M` declared on the associated function `and` + | +help: consider specifying the generic argument + | +LL | Combination::<0>.and::<_>().and::<_>(); + | ~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr index 4d0d0253f1b..0af5493f816 100644 --- a/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr @@ -40,7 +40,17 @@ error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True LL | IsLessOrEqual<I, 8>: True, | ^^^^ | - = note: cannot satisfy `IsLessOrEqual<I, 8>: True` +note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual<I, 8>: True` found + --> $DIR/issue-72787.rs:10:1 + | +LL | impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | IsLessOrEqual<I, 8>: True, + | ^^^^ +... +LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, + | ^^^^ error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True` --> $DIR/issue-72787.rs:21:26 @@ -48,7 +58,17 @@ error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True LL | IsLessOrEqual<I, 8>: True, | ^^^^ | - = note: cannot satisfy `IsLessOrEqual<I, 8>: True` +note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual<I, 8>: True` found + --> $DIR/issue-72787.rs:10:1 + | +LL | impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | IsLessOrEqual<I, 8>: True, + | ^^^^ +... +LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, + | ^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-94293.rs b/src/test/ui/const-generics/generic_const_exprs/issue-94293.rs new file mode 100644 index 00000000000..713c5d89a93 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-94293.rs @@ -0,0 +1,31 @@ +// check-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] +#![deny(const_evaluatable_unchecked)] + +pub struct If<const CONDITION: bool>; +pub trait True {} +impl True for If<true> {} + +pub struct FixedI8<const FRAC: u32> { + pub bits: i8, +} + +impl<const FRAC_LHS: u32, const FRAC_RHS: u32> PartialEq<FixedI8<FRAC_RHS>> for FixedI8<FRAC_LHS> +where + If<{ FRAC_RHS <= 8 }>: True, +{ + fn eq(&self, _rhs: &FixedI8<FRAC_RHS>) -> bool { + unimplemented!() + } +} + +impl<const FRAC: u32> PartialEq<i8> for FixedI8<FRAC> { + fn eq(&self, rhs: &i8) -> bool { + let rhs_as_fixed = FixedI8::<0> { bits: *rhs }; + PartialEq::eq(self, &rhs_as_fixed) + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/issue-105689.rs b/src/test/ui/const-generics/issue-105689.rs new file mode 100644 index 00000000000..4237b3cad8e --- /dev/null +++ b/src/test/ui/const-generics/issue-105689.rs @@ -0,0 +1,14 @@ +// check-pass +// edition:2021 +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +#[allow(unused)] +async fn foo<'a>() { + let _data = &mut [0u8; { 1 + 4 }]; + bar().await +} + +async fn bar() {} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83249.stderr b/src/test/ui/const-generics/issues/issue-83249.stderr index 362b8554b2f..7491fdc8a69 100644 --- a/src/test/ui/const-generics/issues/issue-83249.stderr +++ b/src/test/ui/const-generics/issues/issue-83249.stderr @@ -6,8 +6,8 @@ LL | let _ = foo([0; 1]); | help: consider giving this pattern a type | -LL | let _: _ = foo([0; 1]); - | +++ +LL | let _: /* Type */ = foo([0; 1]); + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/const-generics/type-after-const-ok.min.stderr b/src/test/ui/const-generics/type-after-const-ok.min.stderr deleted file mode 100644 index ad38754c741..00000000000 --- a/src/test/ui/const-generics/type-after-const-ok.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/type-after-const-ok.rs:8:26 - | -LL | struct A<const N: usize, T>(T); - | -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>` - -error: aborting due to previous error - diff --git a/src/test/ui/const-ptr/forbidden_slices.32bit.stderr b/src/test/ui/const-ptr/forbidden_slices.32bit.stderr index 3a58a7cd7ef..0079bb3aad6 100644 --- a/src/test/ui/const-ptr/forbidden_slices.32bit.stderr +++ b/src/test/ui/const-ptr/forbidden_slices.32bit.stderr @@ -27,7 +27,7 @@ LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) }; error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | - = note: dereferencing pointer failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds + = note: dereferencing pointer failed: allocN has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds | note: inside `std::slice::from_raw_parts::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL @@ -45,7 +45,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─ALLOC_ID─╼ 01 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 01 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value @@ -57,7 +57,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─ALLOC_ID─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 04 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value @@ -68,24 +68,24 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─ALLOC_ID─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 04 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value --> $DIR/forbidden_slices.rs:32:1 | LL | pub static S7: &[u16] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) + | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized bytes | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─A_ID+0x1─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID+0x2╼ 04 00 00 00 │ ╾──╼.... } error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | - = note: dereferencing pointer failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds + = note: dereferencing pointer failed: allocN has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds | note: inside `std::slice::from_raw_parts::<'_, u64>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL @@ -129,7 +129,7 @@ LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds pointer arithmetic: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds + = note: out-of-bounds pointer arithmetic: allocN has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds | note: inside `ptr::const_ptr::<impl *const u32>::offset` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL @@ -149,7 +149,7 @@ LL | pub static R4: &[u8] = unsafe { | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾ALLOC_ID─╼ 01 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 01 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value @@ -161,7 +161,7 @@ LL | pub static R5: &[u8] = unsafe { = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = note: the raw bytes of the constant (size: 8, align: 4) { - ╾ALLOC_ID─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 04 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value @@ -172,31 +172,35 @@ LL | pub static R6: &[bool] = unsafe { | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾ALLOC_ID─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 04 00 00 00 │ ╾──╼.... } -error[E0080]: it is undefined behavior to use this value - --> $DIR/forbidden_slices.rs:67:1 +error[E0080]: could not evaluate static initializer + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | -LL | pub static R7: &[u16] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) + = note: accessing memory with alignment 1, but alignment 2 is required | - = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: 8, align: 4) { - ╾A_ID+0x1─╼ 04 00 00 00 │ ╾──╼.... - } +note: inside `std::slice::from_raw_parts::<'_, u16>` + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL +note: inside `from_ptr_range::<'_, u16>` + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL +note: inside `R7` + --> $DIR/forbidden_slices.rs:69:5 + | +LL | from_ptr_range(ptr..ptr.add(4)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds pointer arithmetic: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds + = note: out-of-bounds pointer arithmetic: allocN has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds | note: inside `ptr::const_ptr::<impl *const u64>::offset` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `ptr::const_ptr::<impl *const u64>::add` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `R8` - --> $DIR/forbidden_slices.rs:74:25 + --> $DIR/forbidden_slices.rs:73:25 | LL | from_ptr_range(ptr..ptr.add(1)) | ^^^^^^^^^^ @@ -211,7 +215,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr` note: inside `from_ptr_range::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL note: inside `R9` - --> $DIR/forbidden_slices.rs:79:34 + --> $DIR/forbidden_slices.rs:78:34 | LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,7 +230,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr` note: inside `from_ptr_range::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL note: inside `R10` - --> $DIR/forbidden_slices.rs:80:35 + --> $DIR/forbidden_slices.rs:79:35 | LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/const-ptr/forbidden_slices.64bit.stderr b/src/test/ui/const-ptr/forbidden_slices.64bit.stderr index 4e929e3525c..f4f9fe69516 100644 --- a/src/test/ui/const-ptr/forbidden_slices.64bit.stderr +++ b/src/test/ui/const-ptr/forbidden_slices.64bit.stderr @@ -27,7 +27,7 @@ LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) }; error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | - = note: dereferencing pointer failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds + = note: dereferencing pointer failed: allocN has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds | note: inside `std::slice::from_raw_parts::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL @@ -45,7 +45,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────ALLOC_ID───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value @@ -57,7 +57,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────ALLOC_ID───────╼ 08 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 08 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value @@ -68,24 +68,24 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────ALLOC_ID───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value --> $DIR/forbidden_slices.rs:32:1 | LL | pub static S7: &[u16] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) + | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized bytes | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾─────ALLOC_ID+0x1─────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID+0x2╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | - = note: dereferencing pointer failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds + = note: dereferencing pointer failed: allocN has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds | note: inside `std::slice::from_raw_parts::<'_, u64>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL @@ -129,7 +129,7 @@ LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds pointer arithmetic: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds + = note: out-of-bounds pointer arithmetic: allocN has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds | note: inside `ptr::const_ptr::<impl *const u32>::offset` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL @@ -149,7 +149,7 @@ LL | pub static R4: &[u8] = unsafe { | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────ALLOC_ID───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value @@ -161,7 +161,7 @@ LL | pub static R5: &[u8] = unsafe { = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────ALLOC_ID───────╼ 08 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 08 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value @@ -172,31 +172,35 @@ LL | pub static R6: &[bool] = unsafe { | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────ALLOC_ID───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ } -error[E0080]: it is undefined behavior to use this value - --> $DIR/forbidden_slices.rs:67:1 +error[E0080]: could not evaluate static initializer + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL | -LL | pub static R7: &[u16] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) + = note: accessing memory with alignment 1, but alignment 2 is required | - = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: 16, align: 8) { - ╾────ALLOC_ID+0x1─────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ - } +note: inside `std::slice::from_raw_parts::<'_, u16>` + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL +note: inside `from_ptr_range::<'_, u16>` + --> $SRC_DIR/core/src/slice/raw.rs:LL:COL +note: inside `R7` + --> $DIR/forbidden_slices.rs:69:5 + | +LL | from_ptr_range(ptr..ptr.add(4)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: could not evaluate static initializer --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds pointer arithmetic: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds + = note: out-of-bounds pointer arithmetic: allocN has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds | note: inside `ptr::const_ptr::<impl *const u64>::offset` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `ptr::const_ptr::<impl *const u64>::add` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `R8` - --> $DIR/forbidden_slices.rs:74:25 + --> $DIR/forbidden_slices.rs:73:25 | LL | from_ptr_range(ptr..ptr.add(1)) | ^^^^^^^^^^ @@ -211,7 +215,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr` note: inside `from_ptr_range::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL note: inside `R9` - --> $DIR/forbidden_slices.rs:79:34 + --> $DIR/forbidden_slices.rs:78:34 | LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,7 +230,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr` note: inside `from_ptr_range::<'_, u32>` --> $SRC_DIR/core/src/slice/raw.rs:LL:COL note: inside `R10` - --> $DIR/forbidden_slices.rs:80:35 + --> $DIR/forbidden_slices.rs:79:35 | LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/const-ptr/forbidden_slices.rs b/src/test/ui/const-ptr/forbidden_slices.rs index e2184911f42..cc6100226dc 100644 --- a/src/test/ui/const-ptr/forbidden_slices.rs +++ b/src/test/ui/const-ptr/forbidden_slices.rs @@ -1,6 +1,6 @@ // stderr-per-bitwidth -// normalize-stderr-test "alloc[0-9]+" -> "ALLOC_ID" -// normalize-stderr-test "a[0-9]+\+0x" -> "A_ID+0x" +// normalize-stderr-test "╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼" -> "╾ALLOC_ID$2╼" +// normalize-stderr-test "alloc\d+" -> "allocN" // error-pattern: could not evaluate static initializer #![feature( slice_from_ptr_range, @@ -31,7 +31,7 @@ pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; / // Reading padding is not ok pub static S7: &[u16] = unsafe { //~^ ERROR: it is undefined behavior to use this value - let ptr = (&D2 as *const Struct as *const u16).byte_add(1); + let ptr = (&D2 as *const Struct as *const u16).add(1); from_raw_parts(ptr, 4) }; @@ -65,13 +65,12 @@ pub static R6: &[bool] = unsafe { from_ptr_range(ptr..ptr.add(4)) }; pub static R7: &[u16] = unsafe { - //~^ ERROR: it is undefined behavior to use this value let ptr = (&D2 as *const Struct as *const u16).byte_add(1); - from_ptr_range(ptr..ptr.add(4)) + from_ptr_range(ptr..ptr.add(4)) //~ inside `R7` }; pub static R8: &[u64] = unsafe { let ptr = (&D4 as *const [u32; 2] as *const u32).byte_add(1).cast::<u64>(); - from_ptr_range(ptr..ptr.add(1)) + from_ptr_range(ptr..ptr.add(1)) //~ inside `R8` }; // This is sneaky: &D0 and &D0 point to different objects diff --git a/src/test/ui/consts/assert-type-intrinsics.rs b/src/test/ui/consts/assert-type-intrinsics.rs index 263d1ae6a3e..b4fd423becd 100644 --- a/src/test/ui/consts/assert-type-intrinsics.rs +++ b/src/test/ui/consts/assert-type-intrinsics.rs @@ -13,7 +13,7 @@ fn main() { //~^ERROR: evaluation of constant value failed }; const _BAD2: () = { - intrinsics::assert_uninit_valid::<&'static i32>(); + intrinsics::assert_mem_uninitialized_valid::<&'static i32>(); //~^ERROR: evaluation of constant value failed }; const _BAD3: () = { diff --git a/src/test/ui/consts/assert-type-intrinsics.stderr b/src/test/ui/consts/assert-type-intrinsics.stderr index f92f9fda069..70aec91e226 100644 --- a/src/test/ui/consts/assert-type-intrinsics.stderr +++ b/src/test/ui/consts/assert-type-intrinsics.stderr @@ -7,8 +7,8 @@ LL | MaybeUninit::<!>::uninit().assume_init(); error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:16:9 | -LL | intrinsics::assert_uninit_valid::<&'static i32>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid +LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:20:9 diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr index e5b5c7a846c..a0a8d76d10d 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:13:1 + --> $DIR/ub-ref-ptr.rs:14:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) @@ -10,7 +10,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:17:1 + --> $DIR/ub-ref-ptr.rs:18:1 | LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) @@ -21,7 +21,7 @@ LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:21:1 + --> $DIR/ub-ref-ptr.rs:22:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference @@ -32,7 +32,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:24:1 + --> $DIR/ub-ref-ptr.rs:25:1 | LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box @@ -43,7 +43,7 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:31:1 + --> $DIR/ub-ref-ptr.rs:32:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -52,7 +52,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:34:39 + --> $DIR/ub-ref-ptr.rs:35:39 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -61,13 +61,13 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported note: erroneous constant used - --> $DIR/ub-ref-ptr.rs:34:38 + --> $DIR/ub-ref-ptr.rs:35:38 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:37:86 + --> $DIR/ub-ref-ptr.rs:38:86 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -76,13 +76,13 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported note: erroneous constant used - --> $DIR/ub-ref-ptr.rs:37:85 + --> $DIR/ub-ref-ptr.rs:38:85 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:40:1 + --> $DIR/ub-ref-ptr.rs:41:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated) @@ -93,7 +93,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:43:1 + --> $DIR/ub-ref-ptr.rs:44:1 | LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated) @@ -104,13 +104,13 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:46:41 + --> $DIR/ub-ref-ptr.rs:47:41 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:50:1 + --> $DIR/ub-ref-ptr.rs:51:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer @@ -121,13 +121,13 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:52:38 + --> $DIR/ub-ref-ptr.rs:53:38 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:55:1 + --> $DIR/ub-ref-ptr.rs:56:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer @@ -138,7 +138,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:57:1 + --> $DIR/ub-ref-ptr.rs:58:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer @@ -148,6 +148,39 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; ╾─alloc41─╼ │ ╾──╼ } -error: aborting due to 14 previous errors +error: accessing memory with alignment 1, but alignment 4 is required + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 + | +LL | ptr.read(); + | ^^^^^^^^^^ + = note: `#[deny(invalid_alignment)]` on by default + +error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0080`. +Future incompatibility report: Future breakage diagnostic: +error: accessing memory with alignment 1, but alignment 4 is required + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 + | +LL | ptr.read(); + | ^^^^^^^^^^ + = note: `#[deny(invalid_alignment)]` on by default + diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr index 607366cabc4..d53b44671e3 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:13:1 + --> $DIR/ub-ref-ptr.rs:14:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) @@ -10,7 +10,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:17:1 + --> $DIR/ub-ref-ptr.rs:18:1 | LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) @@ -21,7 +21,7 @@ LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:21:1 + --> $DIR/ub-ref-ptr.rs:22:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference @@ -32,7 +32,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:24:1 + --> $DIR/ub-ref-ptr.rs:25:1 | LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box @@ -43,7 +43,7 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:31:1 + --> $DIR/ub-ref-ptr.rs:32:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -52,7 +52,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:34:39 + --> $DIR/ub-ref-ptr.rs:35:39 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -61,13 +61,13 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported note: erroneous constant used - --> $DIR/ub-ref-ptr.rs:34:38 + --> $DIR/ub-ref-ptr.rs:35:38 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:37:86 + --> $DIR/ub-ref-ptr.rs:38:86 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -76,13 +76,13 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported note: erroneous constant used - --> $DIR/ub-ref-ptr.rs:37:85 + --> $DIR/ub-ref-ptr.rs:38:85 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:40:1 + --> $DIR/ub-ref-ptr.rs:41:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated) @@ -93,7 +93,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:43:1 + --> $DIR/ub-ref-ptr.rs:44:1 | LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated) @@ -104,13 +104,13 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:46:41 + --> $DIR/ub-ref-ptr.rs:47:41 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:50:1 + --> $DIR/ub-ref-ptr.rs:51:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer @@ -121,13 +121,13 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-ref-ptr.rs:52:38 + --> $DIR/ub-ref-ptr.rs:53:38 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:55:1 + --> $DIR/ub-ref-ptr.rs:56:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer @@ -138,7 +138,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref-ptr.rs:57:1 + --> $DIR/ub-ref-ptr.rs:58:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer @@ -148,6 +148,39 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; ╾───────alloc41───────╼ │ ╾──────╼ } -error: aborting due to 14 previous errors +error: accessing memory with alignment 1, but alignment 4 is required + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 + | +LL | ptr.read(); + | ^^^^^^^^^^ + = note: `#[deny(invalid_alignment)]` on by default + +error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0080`. +Future incompatibility report: Future breakage diagnostic: +error: accessing memory with alignment 1, but alignment 4 is required + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 + | +LL | ptr.read(); + | ^^^^^^^^^^ + = note: `#[deny(invalid_alignment)]` on by default + diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.rs b/src/test/ui/consts/const-eval/ub-ref-ptr.rs index a1c81239009..b0fc3c196a4 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.rs +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.rs @@ -1,6 +1,7 @@ // ignore-tidy-linelength // stderr-per-bitwidth #![allow(invalid_value)] +#![feature(const_ptr_read)] use std::mem; @@ -57,4 +58,12 @@ const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; //~^ ERROR it is undefined behavior to use this value + +const UNALIGNED_READ: () = unsafe { + let x = &[0u8; 4]; + let ptr = x.as_ptr().cast::<u32>(); + ptr.read(); //~ inside `UNALIGNED_READ` +}; + + fn main() {} diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr index 9994c2e5a83..90a3dcada05 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr @@ -1,27 +1,27 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:36:1 + --> $DIR/ub-wide-ptr.rs:37:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN──╼ e7 03 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ e7 03 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:38:1 + --> $DIR/ub-wide-ptr.rs:39:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ ff ff ff ff │ ╾──╼.... + ╾ALLOC_ID╼ ff ff ff ff │ ╾──╼.... } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:41:1 + --> $DIR/ub-wide-ptr.rs:42:1 | LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -30,7 +30,7 @@ LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:44:1 + --> $DIR/ub-wide-ptr.rs:45:1 | LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -39,68 +39,68 @@ LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:46:1 + --> $DIR/ub-wide-ptr.rs:47:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ ff ff ff ff │ ╾──╼.... + ╾ALLOC_ID╼ ff ff ff ff │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:50:1 + --> $DIR/ub-wide-ptr.rs:51:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized data in `str` | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ 01 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 01 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:53:1 + --> $DIR/ub-wide-ptr.rs:54:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized data in `str` | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ 01 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 01 00 00 00 │ ╾──╼.... } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:60:1 + --> $DIR/ub-wide-ptr.rs:61:1 | LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:67:1 + --> $DIR/ub-wide-ptr.rs:68:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ e7 03 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ e7 03 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:70:1 + --> $DIR/ub-wide-ptr.rs:71:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ ff ff ff 7f │ ╾──╼.... + ╾ALLOC_ID╼ ff ff ff 7f │ ╾──╼.... } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:73:1 + --> $DIR/ub-wide-ptr.rs:74:1 | LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -109,18 +109,18 @@ LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:76:1 + --> $DIR/ub-wide-ptr.rs:77:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─allocN─╼ e7 03 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ e7 03 00 00 │ ╾──╼.... } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:79:1 + --> $DIR/ub-wide-ptr.rs:80:1 | LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -129,165 +129,165 @@ LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3) = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:83:1 + --> $DIR/ub-wide-ptr.rs:84:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { - ╾─allocN─╼ │ ╾──╼ + ╾ALLOC_ID╼ │ ╾──╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:83:40 + --> $DIR/ub-wide-ptr.rs:84:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:90:1 + --> $DIR/ub-wide-ptr.rs:91:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { - ╾allocN─╼ │ ╾──╼ + ╾ALLOC_ID╼ │ ╾──╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:90:42 + --> $DIR/ub-wide-ptr.rs:91:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:94:1 + --> $DIR/ub-wide-ptr.rs:95:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { - ╾allocN─╼ │ ╾──╼ + ╾ALLOC_ID╼ │ ╾──╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:94:42 + --> $DIR/ub-wide-ptr.rs:95:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:102:1 + --> $DIR/ub-wide-ptr.rs:103:1 | LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:111:1 + --> $DIR/ub-wide-ptr.rs:112:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──╼╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:115:1 + --> $DIR/ub-wide-ptr.rs:116:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──╼╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:119:1 + --> $DIR/ub-wide-ptr.rs:120:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ 04 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 04 00 00 00 │ ╾──╼.... } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:122:57 + --> $DIR/ub-wide-ptr.rs:123:57 | LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:125:57 + --> $DIR/ub-wide-ptr.rs:126:57 | LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:128:56 + --> $DIR/ub-wide-ptr.rs:129:56 | LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:131:1 + --> $DIR/ub-wide-ptr.rs:132:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──╼╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:136:1 + --> $DIR/ub-wide-ptr.rs:137:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──╼╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:141:1 + --> $DIR/ub-wide-ptr.rs:142:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ 00 00 00 00 │ ╾──╼.... + ╾ALLOC_ID╼ 00 00 00 00 │ ╾──╼.... } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:143:1 + --> $DIR/ub-wide-ptr.rs:144:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 4) { - ╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──╼╾──╼ } error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:149:5 + --> $DIR/ub-wide-ptr.rs:150:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance) error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:153:5 + --> $DIR/ub-wide-ptr.rs:154:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr index 06a377d9f7c..ab25303ddc0 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr @@ -1,27 +1,27 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:36:1 + --> $DIR/ub-wide-ptr.rs:37:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN────────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:38:1 + --> $DIR/ub-wide-ptr.rs:39:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ ff ff ff ff ff ff ff ff │ ╾──────╼........ + ╾ALLOC_ID╼ ff ff ff ff ff ff ff ff │ ╾──────╼........ } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:41:1 + --> $DIR/ub-wide-ptr.rs:42:1 | LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -30,7 +30,7 @@ LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:44:1 + --> $DIR/ub-wide-ptr.rs:45:1 | LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -39,68 +39,68 @@ LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:46:1 + --> $DIR/ub-wide-ptr.rs:47:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ ff ff ff ff ff ff ff ff │ ╾──────╼........ + ╾ALLOC_ID╼ ff ff ff ff ff ff ff ff │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:50:1 + --> $DIR/ub-wide-ptr.rs:51:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized data in `str` | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:53:1 + --> $DIR/ub-wide-ptr.rs:54:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized data in `str` | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:60:1 + --> $DIR/ub-wide-ptr.rs:61:1 | LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:67:1 + --> $DIR/ub-wide-ptr.rs:68:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:70:1 + --> $DIR/ub-wide-ptr.rs:71:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ ff ff ff ff ff ff ff 7f │ ╾──────╼........ + ╾ALLOC_ID╼ ff ff ff ff ff ff ff 7f │ ╾──────╼........ } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:73:1 + --> $DIR/ub-wide-ptr.rs:74:1 | LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -109,18 +109,18 @@ LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:76:1 + --> $DIR/ub-wide-ptr.rs:77:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────allocN───────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:79:1 + --> $DIR/ub-wide-ptr.rs:80:1 | LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes @@ -129,165 +129,165 @@ LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3) = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:83:1 + --> $DIR/ub-wide-ptr.rs:84:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { - ╾───────allocN───────╼ │ ╾──────╼ + ╾ALLOC_ID╼ │ ╾──────╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:83:40 + --> $DIR/ub-wide-ptr.rs:84:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:90:1 + --> $DIR/ub-wide-ptr.rs:91:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { - ╾──────allocN───────╼ │ ╾──────╼ + ╾ALLOC_ID╼ │ ╾──────╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:90:42 + --> $DIR/ub-wide-ptr.rs:91:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:94:1 + --> $DIR/ub-wide-ptr.rs:95:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { - ╾──────allocN───────╼ │ ╾──────╼ + ╾ALLOC_ID╼ │ ╾──────╼ } note: erroneous constant used - --> $DIR/ub-wide-ptr.rs:94:42 + --> $DIR/ub-wide-ptr.rs:95:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:102:1 + --> $DIR/ub-wide-ptr.rs:103:1 | LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:111:1 + --> $DIR/ub-wide-ptr.rs:112:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──────╼╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:115:1 + --> $DIR/ub-wide-ptr.rs:116:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──────╼╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:119:1 + --> $DIR/ub-wide-ptr.rs:120:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:122:57 + --> $DIR/ub-wide-ptr.rs:123:57 | LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:125:57 + --> $DIR/ub-wide-ptr.rs:126:57 | LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: evaluation of constant value failed - --> $DIR/ub-wide-ptr.rs:128:56 + --> $DIR/ub-wide-ptr.rs:129:56 | LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:131:1 + --> $DIR/ub-wide-ptr.rs:132:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──────╼╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:136:1 + --> $DIR/ub-wide-ptr.rs:137:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──────╼╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:141:1 + --> $DIR/ub-wide-ptr.rs:142:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........ + ╾ALLOC_ID╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:143:1 + --> $DIR/ub-wide-ptr.rs:144:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 16, align: 8) { - ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼ + ╾ALLOC_ID╼ ╾ALLOC_ID╼ │ ╾──────╼╾──────╼ } error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:149:5 + --> $DIR/ub-wide-ptr.rs:150:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance) error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:153:5 + --> $DIR/ub-wide-ptr.rs:154:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.rs b/src/test/ui/consts/const-eval/ub-wide-ptr.rs index 2894ef83188..d12e5e2bed9 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.rs +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.rs @@ -4,6 +4,7 @@ use std::mem; +// normalize-stderr-test "╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼" -> "╾ALLOC_ID$2╼" // normalize-stderr-test "offset \d+" -> "offset N" // normalize-stderr-test "alloc\d+" -> "allocN" // normalize-stderr-test "size \d+" -> "size N" diff --git a/src/test/ui/consts/copy-intrinsic.rs b/src/test/ui/consts/copy-intrinsic.rs index 249bbb5991c..94d7bdc6bae 100644 --- a/src/test/ui/consts/copy-intrinsic.rs +++ b/src/test/ui/consts/copy-intrinsic.rs @@ -17,7 +17,7 @@ const COPY_ZERO: () = unsafe { // Since we are not copying anything, this should be allowed. let src = (); let mut dst = (); - copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0); + copy_nonoverlapping(&src as *const _ as *const u8, &mut dst as *mut _ as *mut u8, 0); }; const COPY_OOB_1: () = unsafe { diff --git a/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs b/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs index 9c239c8a100..e2f8149883b 100644 --- a/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs +++ b/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs @@ -28,15 +28,4 @@ const UNALIGNED_PTR: () = unsafe { //[with_flag]~| invalid value }; -const UNALIGNED_READ: () = { - INNER; //[with_flag]~ constant - // There is an error here but its span is in the standard library so we cannot match it... - // so we have this in a *nested* const, such that the *outer* const fails to use it. - const INNER: () = unsafe { - let x = &[0u8; 4]; - let ptr = x.as_ptr().cast::<u32>(); - ptr.read(); - }; -}; - fn main() {} diff --git a/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr b/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr index 51eec783365..b2a5fd90149 100644 --- a/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr +++ b/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr @@ -28,27 +28,6 @@ error[E0080]: evaluation of constant value failed LL | let _x: &u32 = transmute(&[0u8; 4]); | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1) -error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | - = note: accessing memory with alignment 1, but alignment 4 is required - | -note: inside `std::ptr::read::<u32>` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `ptr::const_ptr::<impl *const u32>::read` - --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL -note: inside `INNER` - --> $DIR/detect-extra-ub.rs:38:9 - | -LL | ptr.read(); - | ^^^^^^^^^^ - -note: erroneous constant used - --> $DIR/detect-extra-ub.rs:32:5 - | -LL | INNER; - | ^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/issue-104396.rs b/src/test/ui/consts/issue-104396.rs new file mode 100644 index 00000000000..315b0cf0fd6 --- /dev/null +++ b/src/test/ui/consts/issue-104396.rs @@ -0,0 +1,36 @@ +// compile-flags: -Zmir-opt-level=3 +// check-pass + +#![feature(generic_const_exprs)] +//~^ WARN the feature `generic_const_exprs` is incomplete + +#[inline(always)] +fn from_fn_1<const N: usize, F: FnMut(usize) -> f32>(mut f: F) -> [f32; N] { + let mut result = [0.0; N]; + let mut i = 0; + while i < N { + result[i] = f(i); + i += 1; + } + result +} + +pub struct TestArray<const N: usize> +where + [(); N / 2]:, +{ + array: [f32; N / 2], +} + +impl<const N: usize> TestArray<N> +where + [(); N / 2]:, +{ + fn from_fn_2<F: FnMut(usize) -> f32>(f: F) -> Self { + Self { array: from_fn_1(f) } + } +} + +fn main() { + TestArray::<4>::from_fn_2(|i| 0.0); +} diff --git a/src/test/ui/consts/issue-104396.stderr b/src/test/ui/consts/issue-104396.stderr new file mode 100644 index 00000000000..5856bee09a3 --- /dev/null +++ b/src/test/ui/consts/issue-104396.stderr @@ -0,0 +1,11 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-104396.rs:4:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/consts/promoted_const_call.rs b/src/test/ui/consts/promoted_const_call.rs new file mode 100644 index 00000000000..30ae730535c --- /dev/null +++ b/src/test/ui/consts/promoted_const_call.rs @@ -0,0 +1,19 @@ +#![feature(const_mut_refs)] +#![feature(const_trait_impl)] +struct Panic; +impl const Drop for Panic { fn drop(&mut self) { panic!(); } } +pub const fn id<T>(x: T) -> T { x } +pub const C: () = { + let _: &'static _ = &id(&Panic); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed +}; + +fn main() { + let _: &'static _ = &id(&Panic); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + let _: &'static _ = &&(Panic, 0).1; + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed +} diff --git a/src/test/ui/consts/promoted_const_call.stderr b/src/test/ui/consts/promoted_const_call.stderr new file mode 100644 index 00000000000..83cc16f6f94 --- /dev/null +++ b/src/test/ui/consts/promoted_const_call.stderr @@ -0,0 +1,65 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:7:26 + | +LL | let _: &'static _ = &id(&Panic); + | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:7:30 + | +LL | let _: &'static _ = &id(&Panic); + | ---------- ^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:13:26 + | +LL | let _: &'static _ = &id(&Panic); + | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:13:30 + | +LL | let _: &'static _ = &id(&Panic); + | ---------- ^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:16:26 + | +LL | let _: &'static _ = &&(Panic, 0).1; + | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call.rs:16:27 + | +LL | let _: &'static _ = &&(Panic, 0).1; + | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0716`. diff --git a/src/test/ui/consts/promoted_const_call2.rs b/src/test/ui/consts/promoted_const_call2.rs new file mode 100644 index 00000000000..f332cd18cea --- /dev/null +++ b/src/test/ui/consts/promoted_const_call2.rs @@ -0,0 +1,14 @@ +#![feature(const_precise_live_drops)] +pub const fn id<T>(x: T) -> T { x } +pub const C: () = { + let _: &'static _ = &id(&String::new()); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + //~| ERROR: destructor of `String` cannot be evaluated at compile-time +}; + +fn main() { + let _: &'static _ = &id(&String::new()); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed +} diff --git a/src/test/ui/consts/promoted_const_call2.stderr b/src/test/ui/consts/promoted_const_call2.stderr new file mode 100644 index 00000000000..13d864ed3db --- /dev/null +++ b/src/test/ui/consts/promoted_const_call2.stderr @@ -0,0 +1,50 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call2.rs:4:26 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call2.rs:4:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call2.rs:11:26 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call2.rs:11:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/promoted_const_call2.rs:4:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0493, E0716. +For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/promoted_const_call3.rs b/src/test/ui/consts/promoted_const_call3.rs new file mode 100644 index 00000000000..6d68a2de70e --- /dev/null +++ b/src/test/ui/consts/promoted_const_call3.rs @@ -0,0 +1,26 @@ +pub const fn id<T>(x: T) -> T { x } +pub const C: () = { + let _: &'static _ = &String::new(); + //~^ ERROR: destructor of `String` cannot be evaluated at compile-time + //~| ERROR: temporary value dropped while borrowed + + let _: &'static _ = &id(&String::new()); + //~^ ERROR: destructor of `String` cannot be evaluated at compile-time + //~| ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + + let _: &'static _ = &std::mem::ManuallyDrop::new(String::new()); + //~^ ERROR: temporary value dropped while borrowed +}; + +fn main() { + let _: &'static _ = &String::new(); + //~^ ERROR: temporary value dropped while borrowed + + let _: &'static _ = &id(&String::new()); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + + let _: &'static _ = &std::mem::ManuallyDrop::new(String::new()); + //~^ ERROR: temporary value dropped while borrowed +} diff --git a/src/test/ui/consts/promoted_const_call3.stderr b/src/test/ui/consts/promoted_const_call3.stderr new file mode 100644 index 00000000000..af17457a10a --- /dev/null +++ b/src/test/ui/consts/promoted_const_call3.stderr @@ -0,0 +1,105 @@ +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/promoted_const_call3.rs:7:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ^^^^^^^^^^^^^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constants + +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/promoted_const_call3.rs:3:26 + | +LL | let _: &'static _ = &String::new(); + | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants +... +LL | }; + | - value is dropped here + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:3:26 + | +LL | let _: &'static _ = &String::new(); + | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:7:26 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:7:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:12:26 + | +LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:17:26 + | +LL | let _: &'static _ = &String::new(); + | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:20:26 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:20:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call3.rs:24:26 + | +LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new()); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to 10 previous errors + +Some errors have detailed explanations: E0493, E0716. +For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/promoted_const_call4.rs b/src/test/ui/consts/promoted_const_call4.rs new file mode 100644 index 00000000000..82a17b7bf86 --- /dev/null +++ b/src/test/ui/consts/promoted_const_call4.rs @@ -0,0 +1,18 @@ +// run-pass + +use std::sync::atomic::*; + +static FLAG: AtomicBool = AtomicBool::new(false); + +struct NoisyDrop(&'static str); +impl Drop for NoisyDrop { + fn drop(&mut self) { + FLAG.store(true, Ordering::SeqCst); + } +} +fn main() { + { + let _val = &&(NoisyDrop("drop!"), 0).1; + } + assert!(FLAG.load(Ordering::SeqCst)); +} diff --git a/src/test/ui/consts/promoted_const_call5.rs b/src/test/ui/consts/promoted_const_call5.rs new file mode 100644 index 00000000000..3ac8d358ce4 --- /dev/null +++ b/src/test/ui/consts/promoted_const_call5.rs @@ -0,0 +1,42 @@ +#![feature(rustc_attrs)] +#![feature(staged_api)] +#![stable(feature = "a", since = "1.0.0")] + +#[rustc_promotable] +#[stable(feature = "a", since = "1.0.0")] +#[rustc_const_stable(feature = "a", since = "1.0.0")] +pub const fn id<T>(x: &'static T) -> &'static T { x } + +#[rustc_promotable] +#[stable(feature = "a", since = "1.0.0")] +#[rustc_const_stable(feature = "a", since = "1.0.0")] +pub const fn new_string() -> String { + String::new() +} + +#[rustc_promotable] +#[stable(feature = "a", since = "1.0.0")] +#[rustc_const_stable(feature = "a", since = "1.0.0")] +pub const fn new_manually_drop<T>(t: T) -> std::mem::ManuallyDrop<T> { + std::mem::ManuallyDrop::new(t) +} + + +const C: () = { + let _: &'static _ = &id(&new_string()); + //~^ ERROR destructor of `String` cannot be evaluated at compile-time + //~| ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + + let _: &'static _ = &new_manually_drop(new_string()); + //~^ ERROR: temporary value dropped while borrowed +}; + +fn main() { + let _: &'static _ = &id(&new_string()); + //~^ ERROR: temporary value dropped while borrowed + //~| ERROR: temporary value dropped while borrowed + + let _: &'static _ = &new_manually_drop(new_string()); + //~^ ERROR: temporary value dropped while borrowed +} diff --git a/src/test/ui/consts/promoted_const_call5.stderr b/src/test/ui/consts/promoted_const_call5.stderr new file mode 100644 index 00000000000..f736220b183 --- /dev/null +++ b/src/test/ui/consts/promoted_const_call5.stderr @@ -0,0 +1,74 @@ +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/promoted_const_call5.rs:26:30 + | +LL | let _: &'static _ = &id(&new_string()); + | ^^^^^^^^^^^^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constants + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:26:26 + | +LL | let _: &'static _ = &id(&new_string()); + | ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:26:30 + | +LL | let _: &'static _ = &id(&new_string()); + | ----^^^^^^^^^^^^-- temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | argument requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:31:26 + | +LL | let _: &'static _ = &new_manually_drop(new_string()); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | }; + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:36:26 + | +LL | let _: &'static _ = &id(&new_string()); + | ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +... +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:36:30 + | +LL | let _: &'static _ = &id(&new_string()); + | ----^^^^^^^^^^^^-- temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | argument requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promoted_const_call5.rs:40:26 + | +LL | let _: &'static _ = &new_manually_drop(new_string()); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0493, E0716. +For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr index c447e2f7987..3e39d15f9b0 100644 --- a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr +++ b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr @@ -8,3 +8,4 @@ LL | let ft = error: aborting due to previous error +For more information about this error, try `rustc --explain E0320`. diff --git a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr index cd4706dd903..dbb74354471 100644 --- a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr +++ b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr @@ -8,3 +8,4 @@ LL | let ft = error: aborting due to previous error +For more information about this error, try `rustc --explain E0320`. diff --git a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr index 18cd1b6cd41..deaf116b647 100644 --- a/src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr +++ b/src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr @@ -16,3 +16,4 @@ LL | Some(Wrapper::Simple::<u32>); error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0320`. diff --git a/src/test/ui/dyn-star/dyn-to-rigid.rs b/src/test/ui/dyn-star/dyn-to-rigid.rs new file mode 100644 index 00000000000..e80ee15902e --- /dev/null +++ b/src/test/ui/dyn-star/dyn-to-rigid.rs @@ -0,0 +1,11 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +trait Tr {} + +fn f(x: dyn* Tr) -> usize { + x as usize + //~^ ERROR casting `(dyn* Tr + 'static)` as `usize` is invalid +} + +fn main() {} diff --git a/src/test/ui/dyn-star/dyn-to-rigid.stderr b/src/test/ui/dyn-star/dyn-to-rigid.stderr new file mode 100644 index 00000000000..588e6d97e5c --- /dev/null +++ b/src/test/ui/dyn-star/dyn-to-rigid.stderr @@ -0,0 +1,9 @@ +error[E0606]: casting `(dyn* Tr + 'static)` as `usize` is invalid + --> $DIR/dyn-to-rigid.rs:7:5 + | +LL | x as usize + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0606`. diff --git a/src/test/ui/empty/empty-struct-braces-expr.stderr b/src/test/ui/empty/empty-struct-braces-expr.stderr index e1a7a02a568..0e580aedeaa 100644 --- a/src/test/ui/empty/empty-struct-braces-expr.stderr +++ b/src/test/ui/empty/empty-struct-braces-expr.stderr @@ -100,22 +100,22 @@ help: a unit struct with a similar name exists LL | let xe1 = XEmpty2(); | ~~~~~~~ -error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope +error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:25:19 | LL | let xe3 = XE::Empty3; | ^^^^^^ | | - | variant or associated item not found in `empty_struct::XE` + | variant or associated item not found in `XE` | help: there is a variant with a similar name: `XEmpty3` -error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope +error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:26:19 | LL | let xe3 = XE::Empty3(); | ^^^^^^ | | - | variant or associated item not found in `empty_struct::XE` + | variant or associated item not found in `XE` | help: there is a variant with a similar name: `XEmpty3` error[E0599]: no variant named `Empty1` found for enum `empty_struct::XE` diff --git a/src/test/ui/error-codes/E0057.stderr b/src/test/ui/error-codes/E0057.stderr index bea226f09dc..163737895fe 100644 --- a/src/test/ui/error-codes/E0057.stderr +++ b/src/test/ui/error-codes/E0057.stderr @@ -11,8 +11,8 @@ LL | let f = |x| x * 3; | ^^^ help: provide the argument | -LL | let a = f(/* value */); - | ~~~~~~~~~~~~~ +LL | let a = f(/* x */); + | ~~~~~~~~~ error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 diff --git a/src/test/ui/error-codes/E0282.stderr b/src/test/ui/error-codes/E0282.stderr index d01aa3617c7..892d3a81f27 100644 --- a/src/test/ui/error-codes/E0282.stderr +++ b/src/test/ui/error-codes/E0282.stderr @@ -6,8 +6,8 @@ LL | let x = "hello".chars().rev().collect(); | help: consider giving `x` an explicit type | -LL | let x: _ = "hello".chars().rev().collect(); - | +++ +LL | let x: Vec<_> = "hello".chars().rev().collect(); + | ++++++++ error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0377.rs b/src/test/ui/error-codes/E0377.rs new file mode 100644 index 00000000000..6da2c20956a --- /dev/null +++ b/src/test/ui/error-codes/E0377.rs @@ -0,0 +1,14 @@ +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +pub struct Foo<T: ?Sized> { + field_with_unsized_type: T, +} + +pub struct Bar<T: ?Sized> { + field_with_unsized_type: T, +} + +impl<T, U> CoerceUnsized<Bar<U>> for Foo<T> where T: CoerceUnsized<U> {} //~ ERROR E0377 + +fn main() {} diff --git a/src/test/ui/error-codes/E0377.stderr b/src/test/ui/error-codes/E0377.stderr new file mode 100644 index 00000000000..bf7d8c8d39d --- /dev/null +++ b/src/test/ui/error-codes/E0377.stderr @@ -0,0 +1,9 @@ +error[E0377]: the trait `CoerceUnsized` may only be implemented for a coercion between structures with the same definition; expected `Foo`, found `Bar` + --> $DIR/E0377.rs:12:1 + | +LL | impl<T, U> CoerceUnsized<Bar<U>> for Foo<T> where T: CoerceUnsized<U> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0377`. diff --git a/src/test/ui/error-codes/E0401.stderr b/src/test/ui/error-codes/E0401.stderr index 9687eca61fa..fa4b91cacef 100644 --- a/src/test/ui/error-codes/E0401.stderr +++ b/src/test/ui/error-codes/E0401.stderr @@ -59,7 +59,7 @@ note: required by a bound in `bfnr` | LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) { | ^^^^ required by this bound in `bfnr` -help: consider specifying the type arguments in the function call +help: consider specifying the generic arguments | LL | bfnr::<U, V, W>(x); | +++++++++++ diff --git a/src/test/ui/error-codes/E0462.rs b/src/test/ui/error-codes/E0462.rs new file mode 100644 index 00000000000..f839ee783b5 --- /dev/null +++ b/src/test/ui/error-codes/E0462.rs @@ -0,0 +1,11 @@ +// aux-build:found-staticlib.rs + +// normalize-stderr-test: "\.nll/" -> "/" +// normalize-stderr-test: "\\\?\\" -> "" +// normalize-stderr-test: "(lib)?found_staticlib\.[a-z]+" -> "libfound_staticlib.somelib" + +extern crate found_staticlib; //~ ERROR E0462 + +fn main() { + found_staticlib::foo(); +} diff --git a/src/test/ui/error-codes/E0462.stderr b/src/test/ui/error-codes/E0462.stderr new file mode 100644 index 00000000000..43e27965ffc --- /dev/null +++ b/src/test/ui/error-codes/E0462.stderr @@ -0,0 +1,13 @@ +error[E0462]: found staticlib `found_staticlib` instead of rlib or dylib + --> $DIR/E0462.rs:7:1 + | +LL | extern crate found_staticlib; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the following crate versions were found: + crate `found_staticlib`: $TEST_BUILD_DIR/error-codes/E0462/auxiliary/libfound_staticlib.somelib + = help: please recompile that crate using --crate-type lib + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0462`. diff --git a/src/test/ui/error-codes/E0790.stderr b/src/test/ui/error-codes/E0790.stderr index f68c0e7d220..fc025a3fca2 100644 --- a/src/test/ui/error-codes/E0790.stderr +++ b/src/test/ui/error-codes/E0790.stderr @@ -37,8 +37,8 @@ LL | inner::MyTrait::my_fn(); | help: use the fully-qualified path to the only available implementation | -LL | inner::<MyStruct as MyTrait>::my_fn(); - | ++++++++++++ + +LL | <MyStruct as inner::MyTrait>::my_fn(); + | ++++++++++++ + error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type --> $DIR/E0790.rs:30:13 @@ -51,8 +51,8 @@ LL | let _ = inner::MyTrait::MY_ASSOC_CONST; | help: use the fully-qualified path to the only available implementation | -LL | let _ = inner::<MyStruct as MyTrait>::MY_ASSOC_CONST; - | ++++++++++++ + +LL | let _ = <MyStruct as inner::MyTrait>::MY_ASSOC_CONST; + | ++++++++++++ + error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/E0790.rs:50:5 diff --git a/src/test/ui/error-codes/auxiliary/found-staticlib.rs b/src/test/ui/error-codes/auxiliary/found-staticlib.rs new file mode 100644 index 00000000000..04e2c59789d --- /dev/null +++ b/src/test/ui/error-codes/auxiliary/found-staticlib.rs @@ -0,0 +1,4 @@ +// no-prefer-dynamic +#![crate_type = "staticlib"] + +pub fn foo() {} diff --git a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.rs b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.rs index 9b868ed7a9e..c04e57843d4 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.rs +++ b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.rs @@ -1,5 +1,5 @@ +#![allow(unused, bare_trait_objects)] #[repr(align(256))] -#[allow(dead_code)] struct A { v: u8, } @@ -14,13 +14,17 @@ impl Foo for A { } } -fn foo(x: dyn Foo) { - //~^ ERROR [E0277] +fn foo(x: dyn Foo) { //~ ERROR [E0277] x.foo() } +fn bar(x: Foo) { //~ ERROR [E0277] + x.foo() +} + +fn qux(_: [()]) {} //~ ERROR [E0277] + fn main() { let x: Box<dyn Foo> = Box::new(A { v: 22 }); - foo(*x); - //~^ ERROR [E0277] + foo(*x); //~ ERROR [E0277] } diff --git a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr index 0f7520ef7f8..92c71392672 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr @@ -6,13 +6,47 @@ LL | fn foo(x: dyn Foo) { | = help: the trait `Sized` is not implemented for `(dyn Foo + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn foo(x: impl Foo) { + | ~~~~ help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn foo(x: &dyn Foo) { | + error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time - --> $DIR/feature-gate-unsized_fn_params.rs:24:9 + --> $DIR/feature-gate-unsized_fn_params.rs:21:8 + | +LL | fn bar(x: Foo) { + | ^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Foo + 'static)` + = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn bar(x: impl Foo) { + | ++++ +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn bar(x: &Foo) { + | + + +error[E0277]: the size for values of type `[()]` cannot be known at compilation time + --> $DIR/feature-gate-unsized_fn_params.rs:25:8 + | +LL | fn qux(_: [()]) {} + | ^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[()]` + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn qux(_: &[()]) {} + | + + +error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time + --> $DIR/feature-gate-unsized_fn_params.rs:29:9 | LL | foo(*x); | ^^ doesn't have a size known at compile-time @@ -21,6 +55,6 @@ LL | foo(*x); = note: all function arguments must have a statically known size = help: unsized fn params are gated as an unstable feature -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr b/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr index c4507843e36..9aeeb88cf04 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr @@ -6,6 +6,10 @@ LL | fn f(f: dyn FnOnce()) {} | = help: the trait `Sized` is not implemented for `(dyn FnOnce() + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn f(f: impl FnOnce()) {} + | ~~~~ help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn f(f: &dyn FnOnce()) {} diff --git a/src/test/ui/issues/issue-3044.rs b/src/test/ui/fn/issue-3044.rs index 7c626a01b12..7c626a01b12 100644 --- a/src/test/ui/issues/issue-3044.rs +++ b/src/test/ui/fn/issue-3044.rs diff --git a/src/test/ui/issues/issue-3044.stderr b/src/test/ui/fn/issue-3044.stderr index 2b142f688ec..1232b83c391 100644 --- a/src/test/ui/issues/issue-3044.stderr +++ b/src/test/ui/fn/issue-3044.stderr @@ -13,7 +13,7 @@ help: provide the argument | LL ~ needlesArr.iter().fold(|x, y| { LL + -LL ~ }, /* value */); +LL ~ }, /* f */); | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3904.rs b/src/test/ui/fn/issue-3904.rs index 7beb91a28d2..7beb91a28d2 100644 --- a/src/test/ui/issues/issue-3904.rs +++ b/src/test/ui/fn/issue-3904.rs diff --git a/src/test/ui/functions-closures/fn-help-with-err.stderr b/src/test/ui/functions-closures/fn-help-with-err.stderr index 2296666219e..463ac7684ec 100644 --- a/src/test/ui/functions-closures/fn-help-with-err.stderr +++ b/src/test/ui/functions-closures/fn-help-with-err.stderr @@ -17,11 +17,11 @@ note: `Bar` defines an item `bar`, perhaps you need to implement it LL | trait Bar { | ^^^^^^^^^ -error[E0599]: no method named `bar` found for struct `Arc<[closure@$DIR/fn-help-with-err.rs:22:36: 22:38]>` in the current scope +error[E0599]: no method named `bar` found for struct `Arc<[closure@fn-help-with-err.rs:22:36]>` in the current scope --> $DIR/fn-help-with-err.rs:23:10 | LL | arc2.bar(); - | ^^^ method not found in `Arc<[closure@$DIR/fn-help-with-err.rs:22:36: 22:38]>` + | ^^^ method not found in `Arc<[closure@fn-help-with-err.rs:22:36]>` | = help: items from traits can only be used if the trait is implemented and in scope note: `Bar` defines an item `bar`, perhaps you need to implement it diff --git a/src/test/ui/generator/ref-upvar-not-send.rs b/src/test/ui/generator/ref-upvar-not-send.rs new file mode 100644 index 00000000000..eb9ef63ecfc --- /dev/null +++ b/src/test/ui/generator/ref-upvar-not-send.rs @@ -0,0 +1,31 @@ +// For `Send` generators, suggest a `T: Sync` requirement for `&T` upvars, +// and suggest a `T: Send` requirement for `&mut T` upvars. + +#![feature(generators)] + +fn assert_send<T: Send>(_: T) {} +//~^ NOTE required by a bound in `assert_send` +//~| NOTE required by this bound in `assert_send` +//~| NOTE required by a bound in `assert_send` +//~| NOTE required by this bound in `assert_send` + +fn main() { + let x: &*mut () = &std::ptr::null_mut(); + let y: &mut *mut () = &mut std::ptr::null_mut(); + assert_send(move || { + //~^ ERROR generator cannot be sent between threads safely + //~| NOTE generator is not `Send` + yield; + let _x = x; + }); + //~^^ NOTE captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + //~| NOTE has type `&*mut ()` which is not `Send`, because `*mut ()` is not `Sync` + assert_send(move || { + //~^ ERROR generator cannot be sent between threads safely + //~| NOTE generator is not `Send` + yield; + let _y = y; + }); + //~^^ NOTE captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send` + //~| NOTE has type `&mut *mut ()` which is not `Send`, because `*mut ()` is not `Send` +} diff --git a/src/test/ui/generator/ref-upvar-not-send.stderr b/src/test/ui/generator/ref-upvar-not-send.stderr new file mode 100644 index 00000000000..689ace67e34 --- /dev/null +++ b/src/test/ui/generator/ref-upvar-not-send.stderr @@ -0,0 +1,50 @@ +error: generator cannot be sent between threads safely + --> $DIR/ref-upvar-not-send.rs:15:17 + | +LL | assert_send(move || { + | _________________^ +LL | | +LL | | +LL | | yield; +LL | | let _x = x; +LL | | }); + | |_____^ generator is not `Send` + | + = help: the trait `Sync` is not implemented for `*mut ()` +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + --> $DIR/ref-upvar-not-send.rs:19:18 + | +LL | let _x = x; + | ^ has type `&*mut ()` which is not `Send`, because `*mut ()` is not `Sync` +note: required by a bound in `assert_send` + --> $DIR/ref-upvar-not-send.rs:6:19 + | +LL | fn assert_send<T: Send>(_: T) {} + | ^^^^ required by this bound in `assert_send` + +error: generator cannot be sent between threads safely + --> $DIR/ref-upvar-not-send.rs:23:17 + | +LL | assert_send(move || { + | _________________^ +LL | | +LL | | +LL | | yield; +LL | | let _y = y; +LL | | }); + | |_____^ generator is not `Send` + | + = help: within `[generator@$DIR/ref-upvar-not-send.rs:23:17: 23:24]`, the trait `Send` is not implemented for `*mut ()` +note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send` + --> $DIR/ref-upvar-not-send.rs:27:18 + | +LL | let _y = y; + | ^ has type `&mut *mut ()` which is not `Send`, because `*mut ()` is not `Send` +note: required by a bound in `assert_send` + --> $DIR/ref-upvar-not-send.rs:6:19 + | +LL | fn assert_send<T: Send>(_: T) {} + | ^^^^ required by this bound in `assert_send` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/generator/unresolved-ct-var-drop-tracking.rs b/src/test/ui/generator/unresolved-ct-var-drop-tracking.rs new file mode 100644 index 00000000000..a6589348d30 --- /dev/null +++ b/src/test/ui/generator/unresolved-ct-var-drop-tracking.rs @@ -0,0 +1,15 @@ +// incremental +// edition:2021 +// compile-flags: -Zdrop-tracking + +fn main() { + let _ = async { + let s = std::array::from_fn(|_| ()).await; + //~^ ERROR `[(); _]` is not a future + //~| ERROR type inside `async` block must be known in this context + //~| ERROR type inside `async` block must be known in this context + //~| ERROR type inside `async` block must be known in this context + //~| ERROR type inside `async` block must be known in this context + //~| ERROR type inside `async` block must be known in this context + }; +} diff --git a/src/test/ui/generator/unresolved-ct-var-drop-tracking.stderr b/src/test/ui/generator/unresolved-ct-var-drop-tracking.stderr new file mode 100644 index 00000000000..9e1fed54c54 --- /dev/null +++ b/src/test/ui/generator/unresolved-ct-var-drop-tracking.stderr @@ -0,0 +1,78 @@ +error[E0277]: `[(); _]` is not a future + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ---------------------------^^^^^^ + | | | + | | `[(); _]` is not a future + | | help: remove the `.await` + | this call returns `[(); _]` + | + = help: the trait `Future` is not implemented for `[(); _]` + = note: [(); _] must be a future or must implement `IntoFuture` to be awaited + = note: required for `[(); _]` to implement `IntoFuture` + +error[E0698]: type inside `async` block must be known in this context + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:17 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `from_fn` + | +note: the type is part of the `async` block because of this `await` + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^ + +error[E0698]: type inside `async` block must be known in this context + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:17 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `from_fn` + | +note: the type is part of the `async` block because of this `await` + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^ + +error[E0698]: type inside `async` block must be known in this context + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:17 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `from_fn` + | +note: the type is part of the `async` block because of this `await` + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^ + +error[E0698]: type inside `async` block must be known in this context + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:17 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `from_fn` + | +note: the type is part of the `async` block because of this `await` + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^ + +error[E0698]: type inside `async` block must be known in this context + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:17 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `from_fn` + | +note: the type is part of the `async` block because of this `await` + --> $DIR/unresolved-ct-var-drop-tracking.rs:7:44 + | +LL | let s = std::array::from_fn(|_| ()).await; + | ^^^^^^ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0277, E0698. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr b/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr index c1e235441d6..0458d2535f2 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr @@ -1,4 +1,4 @@ -error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>`, but its trait bounds were not satisfied +error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@issue-30786.rs:117:27]>`, but its trait bounds were not satisfied --> $DIR/issue-30786.rs:118:22 | LL | pub struct Map<S, F> { @@ -8,7 +8,7 @@ LL | pub struct Map<S, F> { | doesn't satisfy `_: StreamExt` ... LL | let filter = map.filterx(|x: &_| true); - | ^^^^^^^ method cannot be called on `Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>` due to unsatisfied trait bounds + | ^^^^^^^ method cannot be called on `Map<Repeat, [closure@issue-30786.rs:117:27]>` due to unsatisfied trait bounds | note: the following trait bounds were not satisfied: `&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream` @@ -19,7 +19,7 @@ note: the following trait bounds were not satisfied: LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {} | --------- - ^^^^^^ unsatisfied trait bound introduced here -error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>`, but its trait bounds were not satisfied +error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@issue-30786.rs:129:30]>`, but its trait bounds were not satisfied --> $DIR/issue-30786.rs:130:24 | LL | pub struct Filter<S, F> { @@ -29,7 +29,7 @@ LL | pub struct Filter<S, F> { | doesn't satisfy `_: StreamExt` ... LL | let count = filter.countx(); - | ^^^^^^ method cannot be called on `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>` due to unsatisfied trait bounds + | ^^^^^^ method cannot be called due to unsatisfied trait bounds | note: the following trait bounds were not satisfied: `&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream` diff --git a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr index 09e25f4dc96..0f051be2128 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr @@ -11,8 +11,8 @@ LL | fn f<I>(i: I) | ^ ---- help: provide the argument | -LL | f(&[f(/* value */)]); - | ~~~~~~~~~~~~~ +LL | f(&[f(/* i */)]); + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr index ab5598e364f..fdd192f4313 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr @@ -30,7 +30,7 @@ LL | where LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>, | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m` -error[E0271]: expected `[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]` to be a closure that returns `Unit3`, but it returns `Unit4` +error[E0271]: expected `[closure@issue-62203-hrtb-ice.rs:42:16]` to be a closure that returns `Unit3`, but it returns `Unit4` --> $DIR/issue-62203-hrtb-ice.rs:39:9 | LL | let v = Unit2.m( diff --git a/src/test/ui/illegal-sized-bound/mutability-mismatch.rs b/src/test/ui/illegal-sized-bound/mutability-mismatch.rs new file mode 100644 index 00000000000..deb84f6fe97 --- /dev/null +++ b/src/test/ui/illegal-sized-bound/mutability-mismatch.rs @@ -0,0 +1,34 @@ +struct MutType; + +pub trait MutTrait { + fn function(&mut self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl MutTrait for MutType { + fn function(&mut self) {} +} + +struct Type; + +pub trait Trait { + fn function(&self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl Trait for Type { + fn function(&self) {} +} + +fn main() { + (&MutType as &dyn MutTrait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object + //~| NOTE you need `&mut dyn MutTrait` instead of `&dyn MutTrait` + (&mut Type as &mut dyn Trait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object + //~| NOTE you need `&dyn Trait` instead of `&mut dyn Trait` +} diff --git a/src/test/ui/illegal-sized-bound/mutability-mismatch.stderr b/src/test/ui/illegal-sized-bound/mutability-mismatch.stderr new file mode 100644 index 00000000000..dbbf79a4f1a --- /dev/null +++ b/src/test/ui/illegal-sized-bound/mutability-mismatch.stderr @@ -0,0 +1,24 @@ +error: the `function` method cannot be invoked on a trait object + --> $DIR/mutability-mismatch.rs:28:33 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&MutType as &dyn MutTrait).function(); + | ^^^^^^^^ + | + = note: you need `&mut dyn MutTrait` instead of `&dyn MutTrait` + +error: the `function` method cannot be invoked on a trait object + --> $DIR/mutability-mismatch.rs:31:35 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&mut Type as &mut dyn Trait).function(); + | ^^^^^^^^ + | + = note: you need `&dyn Trait` instead of `&mut dyn Trait` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/illegal-sized-bound/regular.rs b/src/test/ui/illegal-sized-bound/regular.rs new file mode 100644 index 00000000000..7abd27ef983 --- /dev/null +++ b/src/test/ui/illegal-sized-bound/regular.rs @@ -0,0 +1,32 @@ +struct MutType; + +pub trait MutTrait { + fn function(&mut self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl MutTrait for MutType { + fn function(&mut self) {} +} + +struct Type; + +pub trait Trait { + fn function(&self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl Trait for Type { + fn function(&self) {} +} + +fn main() { + (&mut MutType as &mut dyn MutTrait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object + (&Type as &dyn Trait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object +} diff --git a/src/test/ui/illegal-sized-bound/regular.stderr b/src/test/ui/illegal-sized-bound/regular.stderr new file mode 100644 index 00000000000..7f3744145d9 --- /dev/null +++ b/src/test/ui/illegal-sized-bound/regular.stderr @@ -0,0 +1,20 @@ +error: the `function` method cannot be invoked on a trait object + --> $DIR/regular.rs:28:41 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&mut MutType as &mut dyn MutTrait).function(); + | ^^^^^^^^ + +error: the `function` method cannot be invoked on a trait object + --> $DIR/regular.rs:30:27 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&Type as &dyn Trait).function(); + | ^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr b/src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr index f90399b6b94..7f73d5e12d1 100644 --- a/src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr +++ b/src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr @@ -70,10 +70,6 @@ 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: use some type `T` that is `T: Sized` as the return type if all return paths have the same type - | -LL | fn bak() -> T { unimplemented!() } - | ~ help: use `impl Trait` as the return type if all return paths have the same type but you want to expose only the trait in the signature | LL | fn bak() -> impl Trait { unimplemented!() } diff --git a/src/test/ui/impl-trait/issues/issue-86719.stderr b/src/test/ui/impl-trait/issues/issue-86719.stderr index 09047cdcbe1..7592418fdfd 100644 --- a/src/test/ui/impl-trait/issues/issue-86719.stderr +++ b/src/test/ui/impl-trait/issues/issue-86719.stderr @@ -20,8 +20,8 @@ LL | |_| true | help: consider giving this closure parameter an explicit type | -LL | |_: _| true - | +++ +LL | |_: /* Type */| true + | ++++++++++++ error: aborting due to 3 previous errors diff --git a/src/test/ui/impl-trait/no-method-suggested-traits.stderr b/src/test/ui/impl-trait/no-method-suggested-traits.stderr index 3d4ae11e576..548c89d0a38 100644 --- a/src/test/ui/impl-trait/no-method-suggested-traits.stderr +++ b/src/test/ui/impl-trait/no-method-suggested-traits.stderr @@ -145,11 +145,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope +error[E0599]: no method named `method2` found for struct `Foo` in the current scope --> $DIR/no-method-suggested-traits.rs:50:37 | LL | no_method_suggested_traits::Foo.method2(); - | ^^^^^^^ method not found in `no_method_suggested_traits::Foo` + | ^^^^^^^ method not found in `Foo` | = help: items from traits can only be used if the trait is implemented and in scope note: `foo::Bar` defines an item `method2`, perhaps you need to implement it @@ -158,11 +158,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope +error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Foo>>` in the current scope --> $DIR/no-method-suggested-traits.rs:52:71 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); - | ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Foo>>` + | ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>` | = help: items from traits can only be used if the trait is implemented and in scope note: `foo::Bar` defines an item `method2`, perhaps you need to implement it @@ -171,11 +171,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope +error[E0599]: no method named `method2` found for enum `Bar` in the current scope --> $DIR/no-method-suggested-traits.rs:54:40 | LL | no_method_suggested_traits::Bar::X.method2(); - | ^^^^^^^ method not found in `no_method_suggested_traits::Bar` + | ^^^^^^^ method not found in `Bar` | = help: items from traits can only be used if the trait is implemented and in scope note: `foo::Bar` defines an item `method2`, perhaps you need to implement it @@ -184,11 +184,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope +error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Bar>>` in the current scope --> $DIR/no-method-suggested-traits.rs:56:74 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); - | ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Bar>>` + | ^^^^^^^ method not found in `Rc<&mut Box<&Bar>>` | = help: items from traits can only be used if the trait is implemented and in scope note: `foo::Bar` defines an item `method2`, perhaps you need to implement it @@ -255,29 +255,29 @@ error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&usize>>` LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); | ^^^^^^^ method not found in `Rc<&mut Box<&usize>>` -error[E0599]: no method named `method3` found for struct `no_method_suggested_traits::Foo` in the current scope +error[E0599]: no method named `method3` found for struct `Foo` in the current scope --> $DIR/no-method-suggested-traits.rs:71:37 | LL | no_method_suggested_traits::Foo.method3(); - | ^^^^^^^ method not found in `no_method_suggested_traits::Foo` + | ^^^^^^^ method not found in `Foo` -error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope +error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Foo>>` in the current scope --> $DIR/no-method-suggested-traits.rs:72:71 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); - | ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Foo>>` + | ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>` -error[E0599]: no method named `method3` found for enum `no_method_suggested_traits::Bar` in the current scope +error[E0599]: no method named `method3` found for enum `Bar` in the current scope --> $DIR/no-method-suggested-traits.rs:74:40 | LL | no_method_suggested_traits::Bar::X.method3(); - | ^^^^^^^ method not found in `no_method_suggested_traits::Bar` + | ^^^^^^^ method not found in `Bar` -error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope +error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Bar>>` in the current scope --> $DIR/no-method-suggested-traits.rs:75:74 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); - | ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Bar>>` + | ^^^^^^^ method not found in `Rc<&mut Box<&Bar>>` error: aborting due to 24 previous errors diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs new file mode 100644 index 00000000000..6ccbb5bb266 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs @@ -0,0 +1,22 @@ +#![deny(implied_bounds_entailment)] + +trait Project { + type Ty; +} +impl Project for &'_ &'_ () { + type Ty = (); +} +trait Trait { + fn get<'s>(s: &'s str, _: ()) -> &'static str; +} +impl Trait for () { + fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { + //~^ ERROR impl method assumes more implied bounds than the corresponding trait method + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + s + } +} +fn main() { + let val = <() as Trait>::get(&String::from("blah blah blah"), ()); + println!("{}", val); +} diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr new file mode 100644 index 00000000000..0ac31c642eb --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr @@ -0,0 +1,16 @@ +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:13:5 + | +LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572> +note: the lint level is defined here + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:1:9 + | +LL | #![deny(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs new file mode 100644 index 00000000000..d097bc16a22 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs @@ -0,0 +1,21 @@ +#![deny(implied_bounds_entailment)] + +use std::cell::RefCell; + +pub struct MessageListeners<'a> { + listeners: RefCell<Vec<Box<dyn FnMut(()) + 'a>>>, +} + +pub trait MessageListenersInterface { + fn listeners<'c>(&'c self) -> &'c MessageListeners<'c>; +} + +impl<'a> MessageListenersInterface for MessageListeners<'a> { + fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { + //~^ ERROR impl method assumes more implied bounds than the corresponding trait method + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + self + } +} + +fn main() {} diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr new file mode 100644 index 00000000000..0dfa8167a99 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr @@ -0,0 +1,16 @@ +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility.rs:14:5 + | +LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572> +note: the lint level is defined here + --> $DIR/impl-implied-bounds-compatibility.rs:1:9 + | +LL | #![deny(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/imports/local-modularized-tricky-fail-1.rs b/src/test/ui/imports/local-modularized-tricky-fail-1.rs index 37fe0eceed6..29e9b8ec841 100644 --- a/src/test/ui/imports/local-modularized-tricky-fail-1.rs +++ b/src/test/ui/imports/local-modularized-tricky-fail-1.rs @@ -26,7 +26,6 @@ mod inner1 { } exported!(); //~ ERROR `exported` is ambiguous - //~| ERROR `exported` is ambiguous mod inner2 { define_exported!(); diff --git a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr index c048d2ea204..20eadaaaa56 100644 --- a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr +++ b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr @@ -23,33 +23,8 @@ LL | use inner1::*; = help: consider adding an explicit import of `exported` to disambiguate = note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0659]: `exported` is ambiguous - --> $DIR/local-modularized-tricky-fail-1.rs:28:1 - | -LL | exported!(); - | ^^^^^^^^ ambiguous name - | - = note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution -note: `exported` could refer to the macro defined here - --> $DIR/local-modularized-tricky-fail-1.rs:5:5 - | -LL | / macro_rules! exported { -LL | | () => () -LL | | } - | |_____^ -... -LL | define_exported!(); - | ------------------ in this macro invocation -note: `exported` could also refer to the macro imported here - --> $DIR/local-modularized-tricky-fail-1.rs:22:5 - | -LL | use inner1::*; - | ^^^^^^^^^ - = help: consider adding an explicit import of `exported` to disambiguate - = note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0659]: `panic` is ambiguous - --> $DIR/local-modularized-tricky-fail-1.rs:36:5 + --> $DIR/local-modularized-tricky-fail-1.rs:35:5 | LL | panic!(); | ^^^^^ ambiguous name @@ -70,7 +45,7 @@ LL | define_panic!(); = note: this error originates in the macro `define_panic` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `include` is ambiguous - --> $DIR/local-modularized-tricky-fail-1.rs:47:1 + --> $DIR/local-modularized-tricky-fail-1.rs:46:1 | LL | include!(); | ^^^^^^^ ambiguous name @@ -90,6 +65,6 @@ LL | define_include!(); = help: use `crate::include` to refer to this macro unambiguously = note: this error originates in the macro `define_include` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0659`. diff --git a/src/test/ui/imports/macros.rs b/src/test/ui/imports/macros.rs index f39711898cd..f2a22ad620b 100644 --- a/src/test/ui/imports/macros.rs +++ b/src/test/ui/imports/macros.rs @@ -14,7 +14,6 @@ mod m1 { mod m2 { use two_macros::*; m! { //~ ERROR ambiguous - //~| ERROR ambiguous use foo::m; } } diff --git a/src/test/ui/imports/macros.stderr b/src/test/ui/imports/macros.stderr index 110548d1d6a..e34e5359b48 100644 --- a/src/test/ui/imports/macros.stderr +++ b/src/test/ui/imports/macros.stderr @@ -6,7 +6,7 @@ LL | m! { | = note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution note: `m` could refer to the macro imported here - --> $DIR/macros.rs:18:13 + --> $DIR/macros.rs:17:13 | LL | use foo::m; | ^^^^^^ @@ -18,43 +18,24 @@ LL | use two_macros::*; = help: consider adding an explicit import of `m` to disambiguate error[E0659]: `m` is ambiguous - --> $DIR/macros.rs:16:5 - | -LL | m! { - | ^ ambiguous name - | - = note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution -note: `m` could refer to the macro imported here - --> $DIR/macros.rs:18:13 - | -LL | use foo::m; - | ^^^^^^ -note: `m` could also refer to the macro imported here - --> $DIR/macros.rs:15:9 - | -LL | use two_macros::*; - | ^^^^^^^^^^^^^ - = help: consider adding an explicit import of `m` to disambiguate - -error[E0659]: `m` is ambiguous - --> $DIR/macros.rs:30:9 + --> $DIR/macros.rs:29:9 | LL | m! { | ^ ambiguous name | = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution note: `m` could refer to the macro imported here - --> $DIR/macros.rs:31:17 + --> $DIR/macros.rs:30:17 | LL | use two_macros::n as m; | ^^^^^^^^^^^^^^^^^^ note: `m` could also refer to the macro imported here - --> $DIR/macros.rs:23:9 + --> $DIR/macros.rs:22:9 | LL | use two_macros::m; | ^^^^^^^^^^^^^ = help: use `self::m` to refer to this macro unambiguously -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0659`. diff --git a/src/test/ui/inference/erase-type-params-in-label.stderr b/src/test/ui/inference/erase-type-params-in-label.stderr index 5c52e7bcfab..9be18286480 100644 --- a/src/test/ui/inference/erase-type-params-in-label.stderr +++ b/src/test/ui/inference/erase-type-params-in-label.stderr @@ -10,10 +10,10 @@ note: required by a bound in `foo` | LL | fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> { | ^^^^^^^ required by this bound in `foo` -help: consider specifying the type arguments in the function call +help: consider giving `foo` an explicit type, where the type for type parameter `W` is specified | -LL | let foo = foo::<T, K, W, Z>(1, ""); - | ++++++++++++++ +LL | let foo: Foo<i32, &str, W, Z> = foo(1, ""); + | ++++++++++++++++++++++ error[E0283]: type annotations needed for `Bar<i32, &str, Z>` --> $DIR/erase-type-params-in-label.rs:5:9 @@ -27,10 +27,10 @@ note: required by a bound in `bar` | LL | fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> { | ^^^^^^^ required by this bound in `bar` -help: consider specifying the type arguments in the function call +help: consider giving `bar` an explicit type, where the type for type parameter `Z` is specified | -LL | let bar = bar::<T, K, Z>(1, ""); - | +++++++++++ +LL | let bar: Bar<i32, &str, Z> = bar(1, ""); + | +++++++++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/inference/issue-72690.stderr b/src/test/ui/inference/issue-72690.stderr index d4eeda07366..8eda71ec09b 100644 --- a/src/test/ui/inference/issue-72690.stderr +++ b/src/test/ui/inference/issue-72690.stderr @@ -32,8 +32,8 @@ LL | |x| String::from("x".as_ref()); | help: consider giving this closure parameter an explicit type | -LL | |x: _| String::from("x".as_ref()); - | +++ +LL | |x: /* Type */| String::from("x".as_ref()); + | ++++++++++++ error[E0283]: type annotations needed --> $DIR/issue-72690.rs:12:26 diff --git a/src/test/ui/inference/issue-80816.rs b/src/test/ui/inference/issue-80816.rs new file mode 100644 index 00000000000..ead320a4fe4 --- /dev/null +++ b/src/test/ui/inference/issue-80816.rs @@ -0,0 +1,54 @@ +#![allow(unreachable_code)] + +use std::marker::PhantomData; +use std::ops::Deref; +use std::sync::Arc; + +pub struct Guard<T> { + _phantom: PhantomData<T>, +} +impl<T> Deref for Guard<T> { + type Target = T; + fn deref(&self) -> &T { + unimplemented!() + } +} + +pub struct DirectDeref<T>(T); +impl<T> Deref for DirectDeref<Arc<T>> { + type Target = T; + fn deref(&self) -> &T { + unimplemented!() + } +} + +pub trait Access<T> { + type Guard: Deref<Target = T>; + fn load(&self) -> Self::Guard { + unimplemented!() + } +} +impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P { + //~^ NOTE: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>` + type Guard = A::Guard; +} +impl<T> Access<T> for ArcSwapAny<T> { + //~^ NOTE: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: Access<_>` found + type Guard = Guard<T>; +} +impl<T> Access<T> for ArcSwapAny<Arc<T>> { + type Guard = DirectDeref<Arc<T>>; +} + +pub struct ArcSwapAny<T> { + _phantom_arc: PhantomData<T>, +} + +pub fn foo() { + let s: Arc<ArcSwapAny<Arc<usize>>> = unimplemented!(); + let guard: Guard<Arc<usize>> = s.load(); + //~^ ERROR: type annotations needed + //~| HELP: try using a fully qualified path to specify the expected types +} + +fn main() {} diff --git a/src/test/ui/inference/issue-80816.stderr b/src/test/ui/inference/issue-80816.stderr new file mode 100644 index 00000000000..bd833340df4 --- /dev/null +++ b/src/test/ui/inference/issue-80816.stderr @@ -0,0 +1,27 @@ +error[E0283]: type annotations needed + --> $DIR/issue-80816.rs:49:38 + | +LL | let guard: Guard<Arc<usize>> = s.load(); + | ^^^^ + | +note: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: Access<_>` found + --> $DIR/issue-80816.rs:35:1 + | +LL | impl<T> Access<T> for ArcSwapAny<T> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | impl<T> Access<T> for ArcSwapAny<Arc<T>> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>` + --> $DIR/issue-80816.rs:31:45 + | +LL | impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P { + | ^^^^^^^^^ ^ +help: try using a fully qualified path to specify the expected types + | +LL | let guard: Guard<Arc<usize>> = <Arc<ArcSwapAny<Arc<usize>>> as Access<T>>::load(&s); + | ++++++++++++++++++++++++++++++++++++++++++++++++++ ~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-print.rs b/src/test/ui/infinite/issue-41731-infinite-macro-print.rs new file mode 100644 index 00000000000..d52e6e7e9eb --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-print.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + print!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr b/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr new file mode 100644 index 00000000000..e30b2039d69 --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args!` + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_print`) + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | print!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-println.rs b/src/test/ui/infinite/issue-41731-infinite-macro-println.rs new file mode 100644 index 00000000000..3c2b7ee023b --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-println.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + println!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr b/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr new file mode 100644 index 00000000000..66b466dafa0 --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args_nl!` + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_println`) + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | println!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs index ec3860a322f..1a0104b859e 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs @@ -1,9 +1,9 @@ // run-pass -// needs-unwind -// revisions: mir thir strict -// [thir]compile-flags: -Zthir-unsafeck +// revisions: default strict // [strict]compile-flags: -Zstrict-init-checks // ignore-tidy-linelength +// ignore-emscripten spawning processes is not supported +// ignore-sgx no processes // This test checks panic emitted from `mem::{uninitialized,zeroed}`. @@ -12,7 +12,6 @@ use std::{ mem::{self, MaybeUninit, ManuallyDrop}, - panic, ptr::NonNull, num, }; @@ -70,21 +69,42 @@ enum ZeroIsValid { } #[track_caller] -fn test_panic_msg<T>(op: impl (FnOnce() -> T) + panic::UnwindSafe, msg: &str) { - let err = panic::catch_unwind(op).err(); - assert_eq!( - err.as_ref().and_then(|a| a.downcast_ref::<&str>()), - Some(&msg) - ); +fn test_panic_msg<T, F: (FnOnce() -> T) + 'static>(op: F, msg: &str) { + use std::{panic, env, process}; + + // The tricky part is that we can't just run `op`, as that would *abort* the process. + // So instead, we reinvoke this process with the caller location as argument. + // For the purpose of this test, the line number is unique enough. + // If we are running in such a re-invocation, we skip all the tests *except* for the one with that type name. + let our_loc = panic::Location::caller().line().to_string(); + let mut args = env::args(); + let this = args.next().unwrap(); + if let Some(loc) = args.next() { + if loc == our_loc { + op(); + panic!("we did not abort"); + } else { + // Nothing, we are running another test. + } + } else { + // Invoke new process for actual test, and check result. + let mut cmd = process::Command::new(this); + cmd.arg(our_loc); + let res = cmd.output().unwrap(); + assert!(!res.status.success(), "test did not fail"); + let stderr = String::from_utf8_lossy(&res.stderr); + assert!(stderr.contains(msg), "test did not contain expected output: looking for {:?}, output:\n{}", msg, stderr); + } } #[track_caller] -fn test_panic_msg_only_if_strict<T>(op: impl (FnOnce() -> T) + panic::UnwindSafe, msg: &str) { - let err = panic::catch_unwind(op).err(); - assert_eq!( - err.as_ref().and_then(|a| a.downcast_ref::<&str>()), - if cfg!(strict) { Some(&msg) } else { None }, - ); +fn test_panic_msg_only_if_strict<T>(op: impl (FnOnce() -> T) + 'static, msg: &str) { + if !cfg!(strict) { + // Just run it. + op(); + } else { + test_panic_msg(op, msg); + } } fn main() { diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr index 6bd9c6a0276..52a59190264 100644 --- a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr @@ -1,4 +1,4 @@ -error: -Zbranch-protection is only supported on aarch64 +error: `-Zbranch-protection` is only supported on aarch64 error: aborting due to previous error diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs index 4bc4919bc93..1d7ec5cba17 100644 --- a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs @@ -3,7 +3,7 @@ // [BADFLAGS] check-fail // [BADFLAGS] needs-llvm-components: aarch64 // [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti -// [BADTARGET] build-fail +// [BADTARGET] check-fail // [BADTARGET] needs-llvm-components: x86 #![crate_type = "lib"] diff --git a/src/test/ui/issues/issue-105330.stderr b/src/test/ui/issues/issue-105330.stderr index 92f2ccb6544..30c380152a5 100644 --- a/src/test/ui/issues/issue-105330.stderr +++ b/src/test/ui/issues/issue-105330.stderr @@ -55,8 +55,10 @@ error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32` --> $DIR/issue-105330.rs:12:11 | LL | foo::<Demo>()(); - | ^^^^ types differ + | ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A` | + = note: expected constant `32` + found constant `<Demo as TraitWAssocConst>::A` note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:28 | @@ -89,8 +91,10 @@ error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32` --> $DIR/issue-105330.rs:19:11 | LL | foo::<Demo>(); - | ^^^^ types differ + | ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A` | + = note: expected constant `32` + found constant `<Demo as TraitWAssocConst>::A` note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:28 | diff --git a/src/test/ui/issues/issue-18107.stderr b/src/test/ui/issues/issue-18107.stderr index 28478457b29..1669b550a9b 100644 --- a/src/test/ui/issues/issue-18107.stderr +++ b/src/test/ui/issues/issue-18107.stderr @@ -4,10 +4,6 @@ error[E0746]: return type cannot have an unboxed trait object LL | dyn AbstractRenderer | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type - | -LL | T - | help: use `impl AbstractRenderer` as the return type if all return paths have the same type but you want to expose only the trait in the signature | LL | impl AbstractRenderer diff --git a/src/test/ui/issues/issue-18159.stderr b/src/test/ui/issues/issue-18159.stderr index 605ff3829d1..5e0589eed43 100644 --- a/src/test/ui/issues/issue-18159.stderr +++ b/src/test/ui/issues/issue-18159.stderr @@ -6,8 +6,8 @@ LL | let x; | help: consider giving `x` an explicit type | -LL | let x: _; - | +++ +LL | let x: /* Type */; + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-2151.stderr b/src/test/ui/issues/issue-2151.stderr index 31a8ca5fbfa..c75038b6169 100644 --- a/src/test/ui/issues/issue-2151.stderr +++ b/src/test/ui/issues/issue-2151.stderr @@ -8,8 +8,8 @@ LL | x.clone(); | help: consider giving `x` an explicit type | -LL | let x: _ = panic!(); - | +++ +LL | let x: /* Type */ = panic!(); + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-21974.stderr b/src/test/ui/issues/issue-21974.stderr index 4e010a13653..2d60b18b1f2 100644 --- a/src/test/ui/issues/issue-21974.stderr +++ b/src/test/ui/issues/issue-21974.stderr @@ -4,7 +4,13 @@ error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo` LL | where &'a T : Foo, | ^^^ | - = note: cannot satisfy `&'a T: Foo` +note: multiple `impl`s or `where` clauses satisfying `&'a T: Foo` found + --> $DIR/issue-21974.rs:11:19 + | +LL | where &'a T : Foo, + | ^^^ +LL | &'b T : Foo + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-24036.stderr b/src/test/ui/issues/issue-24036.stderr index a42e35c4cad..0e73a51faed 100644 --- a/src/test/ui/issues/issue-24036.stderr +++ b/src/test/ui/issues/issue-24036.stderr @@ -19,8 +19,8 @@ LL | 1 => |c| c + 1, | help: consider giving this closure parameter an explicit type | -LL | 1 => |c: _| c + 1, - | +++ +LL | 1 => |c: /* Type */| c + 1, + | ++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-24424.stderr b/src/test/ui/issues/issue-24424.stderr index 8f3b2ac7319..50d7f988e19 100644 --- a/src/test/ui/issues/issue-24424.stderr +++ b/src/test/ui/issues/issue-24424.stderr @@ -4,7 +4,11 @@ error[E0283]: type annotations needed: cannot satisfy `T0: Trait0<'l0>` LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} | ^^^^^^^^^^^ | - = note: cannot satisfy `T0: Trait0<'l0>` +note: multiple `impl`s or `where` clauses satisfying `T0: Trait0<'l0>` found + --> $DIR/issue-24424.rs:4:57 + | +LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} + | ^^^^^^^^^^^ ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-30123.stderr b/src/test/ui/issues/issue-30123.stderr index e9d934332f1..7808cbf8aa1 100644 --- a/src/test/ui/issues/issue-30123.stderr +++ b/src/test/ui/issues/issue-30123.stderr @@ -1,8 +1,8 @@ -error[E0599]: no function or associated item named `new_undirected` found for struct `issue_30123_aux::Graph<i32, i32>` in the current scope +error[E0599]: no function or associated item named `new_undirected` found for struct `Graph<i32, i32>` in the current scope --> $DIR/issue-30123.rs:7:33 | LL | let ug = Graph::<i32, i32>::new_undirected(); - | ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>` + | ^^^^^^^^^^^^^^ function or associated item not found in `Graph<i32, i32>` | = note: the function or associated item was found for - `issue_30123_aux::Graph<N, E, Undirected>` diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index b667ae0a789..f3be99f9bcb 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>` to be an iterator that yields `&_`, but it yields `u8` +error[E0271]: expected `TakeWhile<&mut IntoIter<u8>, [closure@issue-31173.rs:7:21]>` to be an iterator that yields `&_`, but it yields `u8` --> $DIR/issue-31173.rs:11:10 | LL | .cloned() @@ -6,14 +6,26 @@ LL | .cloned() | = note: expected reference `&_` found type `u8` +note: the method call chain might not have had the expected associated types + --> $DIR/issue-31173.rs:3:20 + | +LL | pub fn get_tok(it: &mut IntoIter<u8>) { + | ^^^^^^^^^^^^^^^^^ `Iterator::Item` is `u8` here +... +LL | .take_while(|&x| { + | __________- +LL | | found_e = true; +LL | | false +LL | | }) + | |__________- `Iterator::Item` remains `u8` here note: required by a bound in `cloned` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>`, but its trait bounds were not satisfied +error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut IntoIter<u8>, [closure@issue-31173.rs:7:21]>>`, but its trait bounds were not satisfied --> $DIR/issue-31173.rs:12:10 | LL | .collect(); - | ^^^^^^^ method cannot be called on `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>` due to unsatisfied trait bounds + | ^^^^^^^ method cannot be called due to unsatisfied trait bounds --> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL | = note: doesn't satisfy `<_ as Iterator>::Item = &_` diff --git a/src/test/ui/issues/issue-33941.rs b/src/test/ui/issues/issue-33941.rs index 8430e85df87..e3b6dcf55a7 100644 --- a/src/test/ui/issues/issue-33941.rs +++ b/src/test/ui/issues/issue-33941.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; fn main() { - for _ in HashMap::new().iter().cloned() {} //~ ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` - //~^ ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` - //~| ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` + for _ in HashMap::new().iter().cloned() {} //~ ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` + //~^ ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` + //~| ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` } diff --git a/src/test/ui/issues/issue-33941.stderr b/src/test/ui/issues/issue-33941.stderr index 49702c47658..668eaabca4c 100644 --- a/src/test/ui/issues/issue-33941.stderr +++ b/src/test/ui/issues/issue-33941.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` +error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` --> $DIR/issue-33941.rs:6:36 | LL | for _ in HashMap::new().iter().cloned() {} @@ -6,10 +6,17 @@ LL | for _ in HashMap::new().iter().cloned() {} | = note: expected reference `&_` found tuple `(&_, &_)` +note: the method call chain might not have had the expected associated types + --> $DIR/issue-33941.rs:6:29 + | +LL | for _ in HashMap::new().iter().cloned() {} + | -------------- ^^^^^^ `Iterator::Item` is `(&_, &_)` here + | | + | this expression has type `HashMap<_, _>` note: required by a bound in `cloned` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` +error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` --> $DIR/issue-33941.rs:6:14 | LL | for _ in HashMap::new().iter().cloned() {} @@ -20,7 +27,7 @@ LL | for _ in HashMap::new().iter().cloned() {} = note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `Iterator` = note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `IntoIterator` -error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` +error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` --> $DIR/issue-33941.rs:6:14 | LL | for _ in HashMap::new().iter().cloned() {} diff --git a/src/test/ui/issues/issue-41880.stderr b/src/test/ui/issues/issue-41880.stderr index fd694df3045..00c375f8d2a 100644 --- a/src/test/ui/issues/issue-41880.stderr +++ b/src/test/ui/issues/issue-41880.stderr @@ -5,7 +5,7 @@ LL | pub struct Iterate<T, F> { | ------------------------ method `iter` not found for this struct ... LL | println!("{:?}", a.iter().take(10).collect::<Vec<usize>>()); - | ^^^^ method not found in `Iterate<{integer}, [closure@$DIR/issue-41880.rs:26:24: 26:27]>` + | ^^^^ method not found in `Iterate<{integer}, [closure@issue-41880.rs:26:24]>` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-42312.stderr b/src/test/ui/issues/issue-42312.stderr index 6fe15162243..3ca6a2957e1 100644 --- a/src/test/ui/issues/issue-42312.stderr +++ b/src/test/ui/issues/issue-42312.stderr @@ -23,6 +23,10 @@ LL | pub fn f(_: dyn ToString) {} | = help: the trait `Sized` is not implemented for `(dyn ToString + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | pub fn f(_: impl ToString) {} + | ~~~~ help: function arguments must have a statically known size, borrowed types always have a known size | LL | pub fn f(_: &dyn ToString) {} diff --git a/src/test/ui/issues/issue-5883.stderr b/src/test/ui/issues/issue-5883.stderr index 8a20a60853a..ffff403e0d4 100644 --- a/src/test/ui/issues/issue-5883.stderr +++ b/src/test/ui/issues/issue-5883.stderr @@ -6,6 +6,10 @@ LL | r: dyn A + 'static | = help: the trait `Sized` is not implemented for `(dyn A + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | r: impl A + 'static + | ~~~~ help: function arguments must have a statically known size, borrowed types always have a known size | LL | r: &dyn A + 'static diff --git a/src/test/ui/issues/issue-6470.rs b/src/test/ui/issues/issue-6470.rs deleted file mode 100644 index 8c6192a59db..00000000000 --- a/src/test/ui/issues/issue-6470.rs +++ /dev/null @@ -1,17 +0,0 @@ -// build-pass -#![allow(dead_code)] -#![allow(improper_ctypes)] -// pretty-expanded FIXME #23616 -#![allow(non_snake_case)] - -pub mod Bar { - pub struct Foo { - v: isize, - } - - extern "C" { - pub fn foo(v: *const Foo) -> Foo; - } -} - -pub fn main() {} diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs index 87116e49245..ebdf33303c9 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.rs +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -1,3 +1,11 @@ +use std::collections::hash_set::Iter; +use std::collections::HashSet; + +fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> { + let i = i.map(|x| x.clone()); + i.collect() //~ ERROR E0277 +} + fn main() { let scores = vec![(0, 0)] .iter() @@ -38,4 +46,8 @@ fn main() { }); let f = e.filter(|_| false); let g: Vec<i32> = f.collect(); //~ ERROR E0277 + + let mut s = HashSet::new(); + s.insert(1u8); + println!("{:?}", iter_to_vec(s.iter())); } diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 84bac7833f6..f3dceca7e41 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -1,5 +1,23 @@ +error[E0277]: a value of type `Vec<X>` cannot be built from an iterator over elements of type `&X` + --> $DIR/invalid-iterator-chain.rs:6:7 + | +LL | i.collect() + | ^^^^^^^ value of type `Vec<X>` cannot be built from `std::iter::Iterator<Item=&X>` + | + = help: the trait `FromIterator<&X>` is not implemented for `Vec<X>` + = help: the trait `FromIterator<T>` is implemented for `Vec<T>` +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:4:26 + | +LL | fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> { + | ^^^^^^^^^^^ `Iterator::Item` is `&X` here +LL | let i = i.map(|x| x.clone()); + | ------------------ `Iterator::Item` remains `&X` here +note: required by a bound in `collect` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:7:27 + --> $DIR/invalid-iterator-chain.rs:15:27 | LL | println!("{}", scores.sum::<i32>()); | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` @@ -9,7 +27,7 @@ LL | println!("{}", scores.sum::<i32>()); <i32 as Sum<&'a i32>> <i32 as Sum> note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:4:10 + --> $DIR/invalid-iterator-chain.rs:12:10 | LL | let scores = vec![(0, 0)] | ------------ this expression has type `Vec<({integer}, {integer})>` @@ -24,7 +42,7 @@ note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:18:14 + --> $DIR/invalid-iterator-chain.rs:26:14 | LL | .sum::<i32>(), | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` @@ -34,14 +52,14 @@ LL | .sum::<i32>(), <i32 as Sum<&'a i32>> <i32 as Sum> note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:12:14 + --> $DIR/invalid-iterator-chain.rs:25:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() | ------ `Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here + | -------------- `Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) | ----------------- `Iterator::Item` changed to `f64` here LL | .map(|x| x as i64) @@ -56,7 +74,7 @@ note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64` - --> $DIR/invalid-iterator-chain.rs:28:14 + --> $DIR/invalid-iterator-chain.rs:36:14 | LL | .sum::<i32>(), | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=f64>` @@ -66,14 +84,14 @@ LL | .sum::<i32>(), <i32 as Sum<&'a i32>> <i32 as Sum> note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:24:14 + --> $DIR/invalid-iterator-chain.rs:33:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() | ------ `Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here + | -------------- `Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) | ^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `f64` here LL | .filter(|x| *x > 0.0) @@ -84,7 +102,7 @@ note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:30:54 + --> $DIR/invalid-iterator-chain.rs:38:54 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` @@ -94,7 +112,7 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); <i32 as Sum<&'a i32>> <i32 as Sum> note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:30:38 + --> $DIR/invalid-iterator-chain.rs:38:38 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); | ---------- ------ ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here @@ -105,7 +123,7 @@ note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` - --> $DIR/invalid-iterator-chain.rs:31:40 + --> $DIR/invalid-iterator-chain.rs:39:40 | LL | println!("{}", vec![(), ()].iter().sum::<i32>()); | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>` @@ -115,7 +133,7 @@ LL | println!("{}", vec![(), ()].iter().sum::<i32>()); <i32 as Sum<&'a i32>> <i32 as Sum> note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:31:33 + --> $DIR/invalid-iterator-chain.rs:39:33 | LL | println!("{}", vec![(), ()].iter().sum::<i32>()); | ------------ ^^^^^^ `Iterator::Item` is `&()` here @@ -125,7 +143,7 @@ note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:40:25 + --> $DIR/invalid-iterator-chain.rs:48:25 | LL | let g: Vec<i32> = f.collect(); | ^^^^^^^ value of type `Vec<i32>` cannot be built from `std::iter::Iterator<Item=()>` @@ -133,7 +151,7 @@ LL | let g: Vec<i32> = f.collect(); = help: the trait `FromIterator<()>` is not implemented for `Vec<i32>` = help: the trait `FromIterator<T>` is implemented for `Vec<T>` note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:36:15 + --> $DIR/invalid-iterator-chain.rs:44:15 | LL | let a = vec![0]; | ------- this expression has type `Vec<{integer}>` @@ -153,6 +171,6 @@ LL | let f = e.filter(|_| false); note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-36381.rs b/src/test/ui/late-bound-lifetimes/issue-36381.rs index 7db56f1dce8..7db56f1dce8 100644 --- a/src/test/ui/issues/issue-36381.rs +++ b/src/test/ui/late-bound-lifetimes/issue-36381.rs diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr b/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr index 420104e526d..fe2631f9474 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr +++ b/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr @@ -6,8 +6,8 @@ LL | |s| s.len() | help: consider giving this closure parameter an explicit type | -LL | |s: _| s.len() - | +++ +LL | |s: /* Type */| s.len() + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/branches3.rs:15:10 @@ -17,8 +17,8 @@ LL | |s| s.len() | help: consider giving this closure parameter an explicit type | -LL | |s: _| s.len() - | +++ +LL | |s: /* Type */| s.len() + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/branches3.rs:23:10 @@ -28,8 +28,8 @@ LL | |s| s.len() | help: consider giving this closure parameter an explicit type | -LL | |s: _| s.len() - | +++ +LL | |s: /* Type */| s.len() + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/branches3.rs:30:10 @@ -39,8 +39,8 @@ LL | |s| s.len() | help: consider giving this closure parameter an explicit type | -LL | |s: _| s.len() - | +++ +LL | |s: /* Type */| s.len() + | ++++++++++++ error: aborting due to 4 previous errors diff --git a/src/test/ui/lifetimes/conflicting-bounds.rs b/src/test/ui/lifetimes/conflicting-bounds.rs new file mode 100644 index 00000000000..f37f163dbb6 --- /dev/null +++ b/src/test/ui/lifetimes/conflicting-bounds.rs @@ -0,0 +1,11 @@ +//~ type annotations needed: cannot satisfy `Self: Gen<'source>` + +pub trait Gen<'source> { + type Output; + + fn gen<T>(&self) -> T + where + Self: for<'s> Gen<'s, Output = T>; +} + +fn main() {} diff --git a/src/test/ui/lifetimes/conflicting-bounds.stderr b/src/test/ui/lifetimes/conflicting-bounds.stderr new file mode 100644 index 00000000000..42aa393667d --- /dev/null +++ b/src/test/ui/lifetimes/conflicting-bounds.stderr @@ -0,0 +1,14 @@ +error[E0283]: type annotations needed: cannot satisfy `Self: Gen<'source>` + | +note: multiple `impl`s or `where` clauses satisfying `Self: Gen<'source>` found + --> $DIR/conflicting-bounds.rs:3:1 + | +LL | pub trait Gen<'source> { + | ^^^^^^^^^^^^^^^^^^^^^^ +... +LL | Self: for<'s> Gen<'s, Output = T>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/lifetimes/issue-34979.stderr b/src/test/ui/lifetimes/issue-34979.stderr index 5832c4d173c..3d4208031cd 100644 --- a/src/test/ui/lifetimes/issue-34979.stderr +++ b/src/test/ui/lifetimes/issue-34979.stderr @@ -4,7 +4,16 @@ error[E0283]: type annotations needed: cannot satisfy `&'a (): Foo` LL | &'a (): Foo, | ^^^ | - = note: cannot satisfy `&'a (): Foo` +note: multiple `impl`s or `where` clauses satisfying `&'a (): Foo` found + --> $DIR/issue-34979.rs:2:1 + | +LL | impl<'a, T> Foo for &'a T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | &'a (): Foo, + | ^^^ +LL | &'static (): Foo; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/lint/lint-uppercase-variables.rs b/src/test/ui/lint/lint-uppercase-variables.rs index b590fa697ad..d4e88aa2643 100644 --- a/src/test/ui/lint/lint-uppercase-variables.rs +++ b/src/test/ui/lint/lint-uppercase-variables.rs @@ -20,19 +20,19 @@ fn main() { match foo::Foo::Foo { Foo => {} -//~^ ERROR variable `Foo` should have a snake case name -//~^^ WARN `Foo` is named the same as one of the variants of the type `Foo` -//~^^^ WARN unused variable: `Foo` + //~^ ERROR variable `Foo` should have a snake case name + //~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` + //~^^^ WARN unused variable: `Foo` } let Foo = foo::Foo::Foo; //~^ ERROR variable `Foo` should have a snake case name - //~^^ WARN `Foo` is named the same as one of the variants of the type `Foo` + //~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` //~^^^ WARN unused variable: `Foo` fn in_param(Foo: foo::Foo) {} //~^ ERROR variable `Foo` should have a snake case name - //~^^ WARN `Foo` is named the same as one of the variants of the type `Foo` + //~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` //~^^^ WARN unused variable: `Foo` test(1); diff --git a/src/test/ui/lint/lint-uppercase-variables.stderr b/src/test/ui/lint/lint-uppercase-variables.stderr index 71b24a835bc..d476d856e24 100644 --- a/src/test/ui/lint/lint-uppercase-variables.stderr +++ b/src/test/ui/lint/lint-uppercase-variables.stderr @@ -1,22 +1,22 @@ -warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `Foo` +warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo` --> $DIR/lint-uppercase-variables.rs:22:9 | LL | Foo => {} - | ^^^ help: to match on the variant, qualify the path: `Foo::Foo` + | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` | = note: `#[warn(bindings_with_variant_name)]` on by default -warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `Foo` +warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo` --> $DIR/lint-uppercase-variables.rs:28:9 | LL | let Foo = foo::Foo::Foo; - | ^^^ help: to match on the variant, qualify the path: `Foo::Foo` + | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` -warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `Foo` +warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo` --> $DIR/lint-uppercase-variables.rs:33:17 | LL | fn in_param(Foo: foo::Foo) {} - | ^^^ help: to match on the variant, qualify the path: `Foo::Foo` + | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` warning: unused variable: `Foo` --> $DIR/lint-uppercase-variables.rs:22:9 diff --git a/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs b/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs new file mode 100644 index 00000000000..c7e14e42561 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs @@ -0,0 +1,9 @@ +#![feature(generators)] + +fn main() { + let _generator = || { + yield ((), ((), ())); + yield ((), ()); + //~^ ERROR mismatched types + }; +} diff --git a/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr b/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr new file mode 100644 index 00000000000..cca8cd9bd89 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/tuple-mismatch.rs:6:20 + | +LL | yield ((), ()); + | ^^ expected tuple, found `()` + | + = note: expected tuple `((), ())` + found unit type `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/lto/auxiliary/thinlto-dylib.rs b/src/test/ui/lto/auxiliary/thinlto-dylib.rs new file mode 100644 index 00000000000..9d17c35dafc --- /dev/null +++ b/src/test/ui/lto/auxiliary/thinlto-dylib.rs @@ -0,0 +1,23 @@ +// Auxiliary crate for test issue-105637: the LTOed dylib which had duplicate symbols from libstd, +// breaking the panic hook feature. +// +// This simulates the `rustc_driver` crate, and the main crate simulates rustc's main binary hooking +// into this driver. + +// compile-flags: -Zdylib-lto -C lto=thin + +use std::panic; + +pub fn main() { + // Install the hook we want to see executed + panic::set_hook(Box::new(|_| { + eprintln!("LTOed auxiliary crate panic hook"); + })); + + // Trigger the panic hook with an ICE + run_compiler(); +} + +fn run_compiler() { + panic!("ICEing"); +} diff --git a/src/test/ui/lto/issue-105637.rs b/src/test/ui/lto/issue-105637.rs new file mode 100644 index 00000000000..0d9f0bec00f --- /dev/null +++ b/src/test/ui/lto/issue-105637.rs @@ -0,0 +1,28 @@ +// Regression test for issue #105637: `-Zdylib-lto` with LTO duplicated symbols from other dylibs, +// in this case from libstd. +// +// That manifested as both `rustc_driver` and rustc's "main" (`compiler/rustc`) having their own +// `std::panicking::HOOK` static, and the hook in rustc's main (the default stdlib's) being executed +// when rustc ICEs, instead of the overriden hook from `rustc_driver` (which also displays the query +// stack and information on how to open a GH issue for the encountered ICE). +// +// In this test, we reproduce this setup by installing a panic hook in both the main and an LTOed +// dylib: the last hook set should be the one being executed, the dylib's. + +// aux-build: thinlto-dylib.rs +// run-fail +// check-run-results + +extern crate thinlto_dylib; + +use std::panic; + +fn main() { + // We don't want to see this panic hook executed + std::panic::set_hook(Box::new(|_| { + eprintln!("main crate panic hook"); + })); + + // Have the LTOed dylib install its own hook and panic, we want to see its hook executed. + thinlto_dylib::main(); +} diff --git a/src/test/ui/lto/issue-105637.run.stderr b/src/test/ui/lto/issue-105637.run.stderr new file mode 100644 index 00000000000..43388e7763e --- /dev/null +++ b/src/test/ui/lto/issue-105637.run.stderr @@ -0,0 +1 @@ +LTOed auxiliary crate panic hook diff --git a/src/test/ui/issues/issue-25385.rs b/src/test/ui/macros/issue-25385.rs index ea042a6c76b..ea042a6c76b 100644 --- a/src/test/ui/issues/issue-25385.rs +++ b/src/test/ui/macros/issue-25385.rs diff --git a/src/test/ui/issues/issue-25385.stderr b/src/test/ui/macros/issue-25385.stderr index 39dbdd753a6..39dbdd753a6 100644 --- a/src/test/ui/issues/issue-25385.stderr +++ b/src/test/ui/macros/issue-25385.stderr diff --git a/src/test/ui/issues/issue-5530.rs b/src/test/ui/match/issue-5530.rs index 72731cbb177..72731cbb177 100644 --- a/src/test/ui/issues/issue-5530.rs +++ b/src/test/ui/match/issue-5530.rs diff --git a/src/test/ui/match/match-unresolved-one-arm.stderr b/src/test/ui/match/match-unresolved-one-arm.stderr index 9eadb88a8ba..e3b501b2fd5 100644 --- a/src/test/ui/match/match-unresolved-one-arm.stderr +++ b/src/test/ui/match/match-unresolved-one-arm.stderr @@ -6,8 +6,8 @@ LL | let x = match () { | help: consider giving `x` an explicit type | -LL | let x: _ = match () { - | +++ +LL | let x: /* Type */ = match () { + | ++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/methods/issues/issue-105732.rs b/src/test/ui/methods/issues/issue-105732.rs new file mode 100644 index 00000000000..98b7a8d0d04 --- /dev/null +++ b/src/test/ui/methods/issues/issue-105732.rs @@ -0,0 +1,13 @@ +#![feature(auto_traits)] + +auto trait Foo { + fn g(&self); //~ ERROR auto traits cannot have associated items +} + +trait Bar { + fn f(&self) { + self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied + } +} + +fn main() {} diff --git a/src/test/ui/methods/issues/issue-105732.stderr b/src/test/ui/methods/issues/issue-105732.stderr new file mode 100644 index 00000000000..fb2bdf47de7 --- /dev/null +++ b/src/test/ui/methods/issues/issue-105732.stderr @@ -0,0 +1,28 @@ +error[E0380]: auto traits cannot have associated items + --> $DIR/issue-105732.rs:4:8 + | +LL | auto trait Foo { + | --- auto trait cannot have associated items +LL | fn g(&self); + | ---^-------- help: remove these associated items + +error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied + --> $DIR/issue-105732.rs:9:14 + | +LL | self.g(); + | ^ + | + = note: the following trait bounds were not satisfied: + `Self: Foo` + which is required by `&Self: Foo` + `&Self: Foo` + = help: items from traits can only be used if the type parameter is bounded by the trait +help: the following trait defines an item `g`, perhaps you need to add a supertrait for it: + | +LL | trait Bar: Foo { + | +++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0380, E0599. +For more information about an error, try `rustc --explain E0380`. diff --git a/src/test/ui/methods/method-not-found-generic-arg-elision.stderr b/src/test/ui/methods/method-not-found-generic-arg-elision.stderr index fc42d1a4dcd..8846efba871 100644 --- a/src/test/ui/methods/method-not-found-generic-arg-elision.stderr +++ b/src/test/ui/methods/method-not-found-generic-arg-elision.stderr @@ -23,7 +23,7 @@ error[E0599]: no method named `extend` found for struct `Map` in the current sco --> $DIR/method-not-found-generic-arg-elision.rs:87:29 | LL | v.iter().map(|x| x * x).extend(std::iter::once(100)); - | ^^^^^^ method not found in `Map<std::slice::Iter<'_, i32>, [closure@$DIR/method-not-found-generic-arg-elision.rs:87:18: 87:21]>` + | ^^^^^^ method not found in `Map<Iter<'_, i32>, [closure@method-not-found-generic-arg-elision.rs:87:18]>` error[E0599]: no method named `method` found for struct `Wrapper<bool>` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:90:13 diff --git a/src/test/ui/mir/issue-105809.rs b/src/test/ui/mir/issue-105809.rs new file mode 100644 index 00000000000..57828feef2d --- /dev/null +++ b/src/test/ui/mir/issue-105809.rs @@ -0,0 +1,36 @@ +// Non-regression test ICE from issue #105809 and duplicates. + +// build-pass: the ICE is during codegen +// compile-flags: --edition 2018 -Zmir-opt-level=1 + +use std::{future::Future, pin::Pin}; + +// Create a `T` without affecting analysis like `loop {}`. +fn create<T>() -> T { + loop {} +} + +async fn trivial_future() {} + +struct Connection<H> { + _h: H, +} + +async fn complex_future<H>(conn: &Connection<H>) { + let small_fut = async move { + let _ = conn; + trivial_future().await; + }; + + let mut tuple = (small_fut,); + let (small_fut_again,) = &mut tuple; + let _ = small_fut_again; +} + +fn main() { + let mut fut = complex_future(&Connection { _h: () }); + + let mut cx = create(); + let future = unsafe { Pin::new_unchecked(&mut fut) }; + let _ = future.poll(&mut cx); +} diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index b91f75b97f8..72fb0e4d774 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -13,11 +13,11 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); note: required by a bound in `filter` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error[E0599]: the method `count` exists for struct `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>`, but its trait bounds were not satisfied +error[E0599]: the method `count` exists for struct `Filter<Fuse<Once<&str>>, [closure@issue-36053-2.rs:7:39]>`, but its trait bounds were not satisfied --> $DIR/issue-36053-2.rs:7:55 | LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); - | --------- ^^^^^ method cannot be called on `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>` due to unsatisfied trait bounds + | --------- ^^^^^ method cannot be called due to unsatisfied trait bounds | | | doesn't satisfy `<_ as FnOnce<(&&str,)>>::Output = bool` | doesn't satisfy `_: FnMut<(&&str,)>` diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.fixed index 63b65ab20fe..63b65ab20fe 100644 --- a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed +++ b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.fixed diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.rs index 2ab4e3955f3..2ab4e3955f3 100644 --- a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs +++ b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.rs diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.stderr index 82a7f276372..35871afb58b 100644 --- a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr +++ b/src/test/ui/mismatched_types/suggest-removing-tuple-struct-field.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/suggest-removing-tulpe-struct-field.rs:11:13 + --> $DIR/suggest-removing-tuple-struct-field.rs:11:13 | LL | some_fn(value.0); | ------- ^^^^^^^ expected struct `MyWrapper`, found `u32` @@ -7,7 +7,7 @@ LL | some_fn(value.0); | arguments to this function are incorrect | note: function defined here - --> $DIR/suggest-removing-tulpe-struct-field.rs:15:4 + --> $DIR/suggest-removing-tuple-struct-field.rs:15:4 | LL | fn some_fn(wrapped: MyWrapper) { | ^^^^^^^ ------------------ @@ -18,7 +18,7 @@ LL + some_fn(value); | error[E0308]: mismatched types - --> $DIR/suggest-removing-tulpe-struct-field.rs:12:13 + --> $DIR/suggest-removing-tuple-struct-field.rs:12:13 | LL | some_fn(my_wrapper!(123).0); | ------- ^^^^^^^^^^^^^^^^^^ expected struct `MyWrapper`, found `u32` @@ -26,7 +26,7 @@ LL | some_fn(my_wrapper!(123).0); | arguments to this function are incorrect | note: function defined here - --> $DIR/suggest-removing-tulpe-struct-field.rs:15:4 + --> $DIR/suggest-removing-tuple-struct-field.rs:15:4 | LL | fn some_fn(wrapped: MyWrapper) { | ^^^^^^^ ------------------ diff --git a/src/test/ui/missing/missing-alloc_error_handler.rs b/src/test/ui/missing/missing-alloc_error_handler.rs deleted file mode 100644 index 4d378f010ed..00000000000 --- a/src/test/ui/missing/missing-alloc_error_handler.rs +++ /dev/null @@ -1,23 +0,0 @@ -// compile-flags: -C panic=abort -// no-prefer-dynamic - -#![no_std] -#![crate_type = "staticlib"] -#![feature(alloc_error_handler)] - -#[panic_handler] -fn panic(_: &core::panic::PanicInfo) -> ! { - loop {} -} - -extern crate alloc; - -#[global_allocator] -static A: MyAlloc = MyAlloc; - -struct MyAlloc; - -unsafe impl core::alloc::GlobalAlloc for MyAlloc { - unsafe fn alloc(&self, _: core::alloc::Layout) -> *mut u8 { 0 as _ } - unsafe fn dealloc(&self, _: *mut u8, _: core::alloc::Layout) {} -} diff --git a/src/test/ui/missing/missing-alloc_error_handler.stderr b/src/test/ui/missing/missing-alloc_error_handler.stderr deleted file mode 100644 index 995fa7cf85e..00000000000 --- a/src/test/ui/missing/missing-alloc_error_handler.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: `#[alloc_error_handler]` function required, but not found - -note: use `#![feature(default_alloc_error_handler)]` for a default error handler - -error: aborting due to previous error - diff --git a/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr index 45cf3723483..a0f790dba15 100644 --- a/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr +++ b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `[closure@$DIR/fallback-closure-wrap.rs:18:40: 18:47]` to be a closure that returns `()`, but it returns `!` +error[E0271]: expected `[closure@fallback-closure-wrap.rs:18:40]` to be a closure that returns `()`, but it returns `!` --> $DIR/fallback-closure-wrap.rs:18:31 | LL | let error = Closure::wrap(Box::new(move || { diff --git a/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.rs b/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.rs new file mode 100644 index 00000000000..f00cde4a74c --- /dev/null +++ b/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.rs @@ -0,0 +1,34 @@ +// Checks that integers with seeming uppercase base prefixes do not get bogus capitalization +// suggestions. + +fn main() { + _ = 123X1a3; + //~^ ERROR invalid suffix `X1a3` for number literal + //~| NOTE invalid suffix `X1a3` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + + _ = 456O123; + //~^ ERROR invalid suffix `O123` for number literal + //~| NOTE invalid suffix `O123` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + + _ = 789B101; + //~^ ERROR invalid suffix `B101` for number literal + //~| NOTE invalid suffix `B101` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + + _ = 0XYZ; + //~^ ERROR invalid suffix `XYZ` for number literal + //~| NOTE invalid suffix `XYZ` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + + _ = 0OPQ; + //~^ ERROR invalid suffix `OPQ` for number literal + //~| NOTE invalid suffix `OPQ` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + + _ = 0BCD; + //~^ ERROR invalid suffix `BCD` for number literal + //~| NOTE invalid suffix `BCD` + //~| HELP the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) +} diff --git a/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.stderr b/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.stderr new file mode 100644 index 00000000000..380c16ca789 --- /dev/null +++ b/src/test/ui/numeric/uppercase-base-prefix-invalid-no-fix.stderr @@ -0,0 +1,50 @@ +error: invalid suffix `X1a3` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:5:9 + | +LL | _ = 123X1a3; + | ^^^^^^^ invalid suffix `X1a3` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: invalid suffix `O123` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:10:9 + | +LL | _ = 456O123; + | ^^^^^^^ invalid suffix `O123` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: invalid suffix `B101` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:15:9 + | +LL | _ = 789B101; + | ^^^^^^^ invalid suffix `B101` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: invalid suffix `XYZ` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:20:9 + | +LL | _ = 0XYZ; + | ^^^^ invalid suffix `XYZ` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: invalid suffix `OPQ` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:25:9 + | +LL | _ = 0OPQ; + | ^^^^ invalid suffix `OPQ` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: invalid suffix `BCD` for number literal + --> $DIR/uppercase-base-prefix-invalid-no-fix.rs:30:9 + | +LL | _ = 0BCD; + | ^^^^ invalid suffix `BCD` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: aborting due to 6 previous errors + diff --git a/src/test/ui/parser/increment-autofix-2.fixed b/src/test/ui/parser/increment-autofix-2.fixed new file mode 100644 index 00000000000..580ebaf5dbb --- /dev/null +++ b/src/test/ui/parser/increment-autofix-2.fixed @@ -0,0 +1,63 @@ +// run-rustfix + +struct Foo { + bar: Bar, +} + +struct Bar { + qux: i32, +} + +pub fn post_regular() { + let mut i = 0; + i += 1; //~ ERROR Rust has no postfix increment operator + println!("{}", i); +} + +pub fn post_while() { + let mut i = 0; + while { let tmp = i; i += 1; tmp } < 5 { + //~^ ERROR Rust has no postfix increment operator + println!("{}", i); + } +} + +pub fn post_regular_tmp() { + let mut tmp = 0; + tmp += 1; //~ ERROR Rust has no postfix increment operator + println!("{}", tmp); +} + +pub fn post_while_tmp() { + let mut tmp = 0; + while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 { + //~^ ERROR Rust has no postfix increment operator + println!("{}", tmp); + } +} + +pub fn post_field() { + let mut foo = Foo { bar: Bar { qux: 0 } }; + foo.bar.qux += 1; + //~^ ERROR Rust has no postfix increment operator + println!("{}", foo.bar.qux); +} + +pub fn post_field_tmp() { + struct S { + tmp: i32 + } + let mut s = S { tmp: 0 }; + s.tmp += 1; + //~^ ERROR Rust has no postfix increment operator + println!("{}", s.tmp); +} + +pub fn pre_field() { + let mut foo = Foo { bar: Bar { qux: 0 } }; + foo.bar.qux += 1; + //~^ ERROR Rust has no prefix increment operator + println!("{}", foo.bar.qux); +} + +fn main() {} diff --git a/src/test/ui/parser/increment-notfixed.rs b/src/test/ui/parser/increment-autofix-2.rs index 15f159e53d2..ebe5fa6ca1e 100644 --- a/src/test/ui/parser/increment-notfixed.rs +++ b/src/test/ui/parser/increment-autofix-2.rs @@ -1,3 +1,5 @@ +// run-rustfix + struct Foo { bar: Bar, } @@ -35,7 +37,7 @@ pub fn post_while_tmp() { } pub fn post_field() { - let foo = Foo { bar: Bar { qux: 0 } }; + let mut foo = Foo { bar: Bar { qux: 0 } }; foo.bar.qux++; //~^ ERROR Rust has no postfix increment operator println!("{}", foo.bar.qux); @@ -45,14 +47,14 @@ pub fn post_field_tmp() { struct S { tmp: i32 } - let s = S { tmp: 0 }; + let mut s = S { tmp: 0 }; s.tmp++; //~^ ERROR Rust has no postfix increment operator println!("{}", s.tmp); } pub fn pre_field() { - let foo = Foo { bar: Bar { qux: 0 } }; + let mut foo = Foo { bar: Bar { qux: 0 } }; ++foo.bar.qux; //~^ ERROR Rust has no prefix increment operator println!("{}", foo.bar.qux); diff --git a/src/test/ui/parser/increment-notfixed.stderr b/src/test/ui/parser/increment-autofix-2.stderr index ae55ae06714..11e985480d6 100644 --- a/src/test/ui/parser/increment-notfixed.stderr +++ b/src/test/ui/parser/increment-autofix-2.stderr @@ -1,18 +1,16 @@ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:11:6 + --> $DIR/increment-autofix-2.rs:13:6 | LL | i++; | ^^ not a valid postfix operator | help: use `+= 1` instead | -LL | { let tmp = i; i += 1; tmp }; - | +++++++++++ ~~~~~~~~~~~~~~~ LL | i += 1; | ~~~~ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:17:12 + --> $DIR/increment-autofix-2.rs:19:12 | LL | while i++ < 5 { | ----- ^^ not a valid postfix operator @@ -23,24 +21,20 @@ help: use `+= 1` instead | LL | while { let tmp = i; i += 1; tmp } < 5 { | +++++++++++ ~~~~~~~~~~~~~~~ -LL | while i += 1 < 5 { - | ~~~~ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:25:8 + --> $DIR/increment-autofix-2.rs:27:8 | LL | tmp++; | ^^ not a valid postfix operator | help: use `+= 1` instead | -LL | { let tmp_ = tmp; tmp += 1; tmp_ }; - | ++++++++++++ ~~~~~~~~~~~~~~~~~~ LL | tmp += 1; | ~~~~ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:31:14 + --> $DIR/increment-autofix-2.rs:33:14 | LL | while tmp++ < 5 { | ----- ^^ not a valid postfix operator @@ -51,37 +45,31 @@ help: use `+= 1` instead | LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 { | ++++++++++++ ~~~~~~~~~~~~~~~~~~ -LL | while tmp += 1 < 5 { - | ~~~~ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:39:16 + --> $DIR/increment-autofix-2.rs:41:16 | LL | foo.bar.qux++; | ^^ not a valid postfix operator | help: use `+= 1` instead | -LL | { let tmp = foo.bar.qux; foo.bar.qux += 1; tmp }; - | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ LL | foo.bar.qux += 1; | ~~~~ error: Rust has no postfix increment operator - --> $DIR/increment-notfixed.rs:49:10 + --> $DIR/increment-autofix-2.rs:51:10 | LL | s.tmp++; | ^^ not a valid postfix operator | help: use `+= 1` instead | -LL | { let tmp = s.tmp; s.tmp += 1; tmp }; - | +++++++++++ ~~~~~~~~~~~~~~~~~~~ LL | s.tmp += 1; | ~~~~ error: Rust has no prefix increment operator - --> $DIR/increment-notfixed.rs:56:5 + --> $DIR/increment-autofix-2.rs:58:5 | LL | ++foo.bar.qux; | ^^ not a valid prefix operator diff --git a/src/test/ui/parser/issue-104867-inc-dec-2.rs b/src/test/ui/parser/issue-104867-inc-dec-2.rs new file mode 100644 index 00000000000..a006421a975 --- /dev/null +++ b/src/test/ui/parser/issue-104867-inc-dec-2.rs @@ -0,0 +1,52 @@ +fn test1() { + let mut i = 0; + let _ = i + ++i; //~ ERROR Rust has no prefix increment operator +} + +fn test2() { + let mut i = 0; + let _ = ++i + i; //~ ERROR Rust has no prefix increment operator +} + +fn test3() { + let mut i = 0; + let _ = ++i + ++i; //~ ERROR Rust has no prefix increment operator +} + +fn test4() { + let mut i = 0; + let _ = i + i++; //~ ERROR Rust has no postfix increment operator + // won't suggest since we can not handle the precedences +} + +fn test5() { + let mut i = 0; + let _ = i++ + i; //~ ERROR Rust has no postfix increment operator +} + +fn test6() { + let mut i = 0; + let _ = i++ + i++; //~ ERROR Rust has no postfix increment operator +} + +fn test7() { + let mut i = 0; + let _ = ++i + i++; //~ ERROR Rust has no prefix increment operator +} + +fn test8() { + let mut i = 0; + let _ = i++ + ++i; //~ ERROR Rust has no postfix increment operator +} + +fn test9() { + let mut i = 0; + let _ = (1 + 2 + i)++; //~ ERROR Rust has no postfix increment operator +} + +fn test10() { + let mut i = 0; + let _ = (i++ + 1) + 2; //~ ERROR Rust has no postfix increment operator +} + +fn main() { } diff --git a/src/test/ui/parser/issue-104867-inc-dec-2.stderr b/src/test/ui/parser/issue-104867-inc-dec-2.stderr new file mode 100644 index 00000000000..4e2d0546851 --- /dev/null +++ b/src/test/ui/parser/issue-104867-inc-dec-2.stderr @@ -0,0 +1,107 @@ +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:3:17 + | +LL | let _ = i + ++i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL | let _ = i + { i += 1; i }; + | ~ +++++++++ + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:8:13 + | +LL | let _ = ++i + i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL | let _ = { i += 1; i } + i; + | ~ +++++++++ + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:13:13 + | +LL | let _ = ++i + ++i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL | let _ = { i += 1; i } + ++i; + | ~ +++++++++ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:18:18 + | +LL | let _ = i + i++; + | ^^ not a valid postfix operator + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:24:14 + | +LL | let _ = i++ + i; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | let _ = { let tmp = i; i += 1; tmp } + i; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:29:14 + | +LL | let _ = i++ + i++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | let _ = { let tmp = i; i += 1; tmp } + i++; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:34:13 + | +LL | let _ = ++i + i++; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL | let _ = { i += 1; i } + i++; + | ~ +++++++++ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:39:14 + | +LL | let _ = i++ + ++i; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | let _ = { let tmp = i; i += 1; tmp } + ++i; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:44:24 + | +LL | let _ = (1 + 2 + i)++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | let _ = { let tmp = (1 + 2 + i); (1 + 2 + i) += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec-2.rs:49:15 + | +LL | let _ = (i++ + 1) + 2; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | let _ = ({ let tmp = i; i += 1; tmp } + 1) + 2; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: aborting due to 10 previous errors + diff --git a/src/test/ui/parser/issue-104867-inc-dec.rs b/src/test/ui/parser/issue-104867-inc-dec.rs new file mode 100644 index 00000000000..760c67b4bed --- /dev/null +++ b/src/test/ui/parser/issue-104867-inc-dec.rs @@ -0,0 +1,45 @@ +struct S { + x: i32, +} + +fn test1() { + let mut i = 0; + i++; //~ ERROR Rust has no postfix increment operator +} + +fn test2() { + let s = S { x: 0 }; + s.x++; //~ ERROR Rust has no postfix increment operator +} + +fn test3() { + let mut i = 0; + if i++ == 1 {} //~ ERROR Rust has no postfix increment operator +} + +fn test4() { + let mut i = 0; + ++i; //~ ERROR Rust has no prefix increment operator +} + +fn test5() { + let mut i = 0; + if ++i == 1 { } //~ ERROR Rust has no prefix increment operator +} + +fn test6() { + let mut i = 0; + loop { break; } + i++; //~ ERROR Rust has no postfix increment operator + loop { break; } + ++i; +} + +fn test7() { + let mut i = 0; + loop { break; } + ++i; //~ ERROR Rust has no prefix increment operator +} + + +fn main() {} diff --git a/src/test/ui/parser/issue-104867-inc-dec.stderr b/src/test/ui/parser/issue-104867-inc-dec.stderr new file mode 100644 index 00000000000..78bfd3e82f0 --- /dev/null +++ b/src/test/ui/parser/issue-104867-inc-dec.stderr @@ -0,0 +1,81 @@ +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec.rs:7:6 + | +LL | i++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | i += 1; + | ~~~~ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec.rs:12:8 + | +LL | s.x++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | s.x += 1; + | ~~~~ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec.rs:17:9 + | +LL | if i++ == 1 {} + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | if { let tmp = i; i += 1; tmp } == 1 {} + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec.rs:22:5 + | +LL | ++i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL - ++i; +LL + i += 1; + | + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec.rs:27:8 + | +LL | if ++i == 1 { } + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL | if { i += 1; i } == 1 { } + | ~ +++++++++ + +error: Rust has no postfix increment operator + --> $DIR/issue-104867-inc-dec.rs:33:6 + | +LL | i++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | i += 1; + | ~~~~ + +error: Rust has no prefix increment operator + --> $DIR/issue-104867-inc-dec.rs:41:5 + | +LL | ++i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL - ++i; +LL + i += 1; + | + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/parser/issue-105366.fixed b/src/test/ui/parser/issue-105366.fixed new file mode 100644 index 00000000000..ad26643c327 --- /dev/null +++ b/src/test/ui/parser/issue-105366.fixed @@ -0,0 +1,12 @@ +// run-rustfix + +struct Foo; + +impl From<i32> for Foo { + //~^ ERROR you might have meant to write `impl` instead of `fn` + fn from(_a: i32) -> Self { + Foo + } +} + +fn main() {} diff --git a/src/test/ui/parser/issue-105366.rs b/src/test/ui/parser/issue-105366.rs new file mode 100644 index 00000000000..311b6a60f1a --- /dev/null +++ b/src/test/ui/parser/issue-105366.rs @@ -0,0 +1,12 @@ +// run-rustfix + +struct Foo; + +fn From<i32> for Foo { + //~^ ERROR you might have meant to write `impl` instead of `fn` + fn from(_a: i32) -> Self { + Foo + } +} + +fn main() {} diff --git a/src/test/ui/parser/issue-105366.stderr b/src/test/ui/parser/issue-105366.stderr new file mode 100644 index 00000000000..0a7408e2c17 --- /dev/null +++ b/src/test/ui/parser/issue-105366.stderr @@ -0,0 +1,13 @@ +error: you might have meant to write `impl` instead of `fn` + --> $DIR/issue-105366.rs:5:1 + | +LL | fn From<i32> for Foo { + | ^^ + | +help: replace `fn` with `impl` here + | +LL | impl From<i32> for Foo { + | ~~~~ + +error: aborting due to previous error + diff --git a/src/test/ui/parser/issue-105634.rs b/src/test/ui/parser/issue-105634.rs new file mode 100644 index 00000000000..579aa6e5bfb --- /dev/null +++ b/src/test/ui/parser/issue-105634.rs @@ -0,0 +1,8 @@ +// check-pass + +fn main() { + let _a = ..; + let _b = ..=10; + let _c = &..; + let _d = &..=10; +} diff --git a/src/test/ui/pattern/pat-tuple-bad-type.stderr b/src/test/ui/pattern/pat-tuple-bad-type.stderr index 3342b8e4002..da369d33397 100644 --- a/src/test/ui/pattern/pat-tuple-bad-type.stderr +++ b/src/test/ui/pattern/pat-tuple-bad-type.stderr @@ -9,8 +9,8 @@ LL | (..) => {} | help: consider giving `x` an explicit type | -LL | let x: _; - | +++ +LL | let x: /* Type */; + | ++++++++++++ error[E0308]: mismatched types --> $DIR/pat-tuple-bad-type.rs:10:9 diff --git a/src/test/ui/pattern/rest-pat-semantic-disallowed.stderr b/src/test/ui/pattern/rest-pat-semantic-disallowed.stderr index e6a4e5f19b7..beba7def96f 100644 --- a/src/test/ui/pattern/rest-pat-semantic-disallowed.stderr +++ b/src/test/ui/pattern/rest-pat-semantic-disallowed.stderr @@ -193,8 +193,8 @@ LL | let x @ ..; | help: consider giving this pattern a type | -LL | let x @ ..: _; - | +++ +LL | let x @ ..: /* Type */; + | ++++++++++++ error: aborting due to 23 previous errors diff --git a/src/test/ui/print_type_sizes/async.rs b/src/test/ui/print_type_sizes/async.rs index 3491ad5afbc..1598b069691 100644 --- a/src/test/ui/print_type_sizes/async.rs +++ b/src/test/ui/print_type_sizes/async.rs @@ -1,19 +1,11 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type lib // edition:2021 // build-pass // ignore-pass -#![feature(start)] - async fn wait() {} -async fn test(arg: [u8; 8192]) { +pub async fn test(arg: [u8; 8192]) { wait().await; drop(arg); } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - let _ = test([0; 8192]); - 0 -} diff --git a/src/test/ui/print_type_sizes/async.stdout b/src/test/ui/print_type_sizes/async.stdout index 94ad09ef296..6e47bb4930d 100644 --- a/src/test/ui/print_type_sizes/async.stdout +++ b/src/test/ui/print_type_sizes/async.stdout @@ -1,4 +1,4 @@ -print-type-size type: `[async fn body@$DIR/async.rs:10:32: 13:2]`: 16386 bytes, alignment: 1 bytes +print-type-size type: `[async fn body@$DIR/async.rs:8:36: 11:2]`: 16386 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Suspend0`: 16385 bytes print-type-size field `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes @@ -16,14 +16,14 @@ print-type-size type: `std::mem::MaybeUninit<[u8; 8192]>`: 8192 bytes, alignment print-type-size variant `MaybeUninit`: 8192 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 8192 bytes -print-type-size type: `[async fn body@$DIR/async.rs:8:17: 8:19]`: 1 bytes, alignment: 1 bytes +print-type-size type: `[async fn body@$DIR/async.rs:6:17: 6:19]`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes print-type-size variant `Returned`: 0 bytes print-type-size variant `Panicked`: 0 bytes -print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async.rs:8:17: 8:19]>`: 1 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async.rs:6:17: 6:19]>`: 1 bytes, alignment: 1 bytes print-type-size field `.value`: 1 bytes -print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async.rs:8:17: 8:19]>`: 1 bytes, alignment: 1 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async.rs:6:17: 6:19]>`: 1 bytes, alignment: 1 bytes print-type-size variant `MaybeUninit`: 1 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 1 bytes diff --git a/src/test/ui/print_type_sizes/generator.rs b/src/test/ui/print_type_sizes/generator.rs index a46db612104..d1cd36274ef 100644 --- a/src/test/ui/print_type_sizes/generator.rs +++ b/src/test/ui/print_type_sizes/generator.rs @@ -1,8 +1,8 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass -#![feature(start, generators, generator_trait)] +#![feature(generators, generator_trait)] use std::ops::Generator; @@ -13,8 +13,6 @@ fn generator<const C: usize>(array: [u8; C]) -> impl Generator<Yield = (), Retur } } -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn foo() { let _ = generator([0; 8192]); - 0 } diff --git a/src/test/ui/print_type_sizes/generator_discr_placement.rs b/src/test/ui/print_type_sizes/generator_discr_placement.rs new file mode 100644 index 00000000000..1a85fe95bb6 --- /dev/null +++ b/src/test/ui/print_type_sizes/generator_discr_placement.rs @@ -0,0 +1,23 @@ +// compile-flags: -Z print-type-sizes --crate-type lib +// build-pass +// ignore-pass + +// Tests a generator that has its discriminant as the *final* field. + +// Avoid emitting panic handlers, like the rest of these tests... +#![feature(generators)] + +pub fn foo() { + let a = || { + { + let w: i32 = 4; + yield; + drop(w); + } + { + let z: i32 = 7; + yield; + drop(z); + } + }; +} diff --git a/src/test/ui/print_type_sizes/generator_discr_placement.stdout b/src/test/ui/print_type_sizes/generator_discr_placement.stdout new file mode 100644 index 00000000000..7f8f4ccae7c --- /dev/null +++ b/src/test/ui/print_type_sizes/generator_discr_placement.stdout @@ -0,0 +1,11 @@ +print-type-size type: `[generator@$DIR/generator_discr_placement.rs:11:13: 11:15]`: 8 bytes, alignment: 4 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Suspend0`: 7 bytes +print-type-size padding: 3 bytes +print-type-size field `.w`: 4 bytes, alignment: 4 bytes +print-type-size variant `Suspend1`: 7 bytes +print-type-size padding: 3 bytes +print-type-size field `.z`: 4 bytes, alignment: 4 bytes +print-type-size variant `Unresumed`: 0 bytes +print-type-size variant `Returned`: 0 bytes +print-type-size variant `Panicked`: 0 bytes diff --git a/src/test/ui/print_type_sizes/generics.rs b/src/test/ui/print_type_sizes/generics.rs index 3ef7b60db2c..05097087d5a 100644 --- a/src/test/ui/print_type_sizes/generics.rs +++ b/src/test/ui/print_type_sizes/generics.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. @@ -8,24 +8,6 @@ // monomorphized, in the MIR of the original function in which they // occur, to have their size reported. -#![feature(start)] - -// In an ad-hoc attempt to avoid the injection of unwinding code -// (which clutters the output of `-Z print-type-sizes` with types from -// `unwind::libunwind`): -// -// * I am not using Default to build values because that seems to -// cause the injection of unwinding code. (Instead I just make `fn new` -// methods.) -// -// * Pair derive Copy to ensure that we don't inject -// unwinding code into generic uses of Pair when T itself is also -// Copy. -// -// (I suspect this reflect some naivety within the rust compiler -// itself; it should be checking for drop glue, i.e., a destructor -// somewhere in the monomorphized types. It should not matter whether -// the type is Copy.) #[derive(Copy, Clone)] pub struct Pair<T> { _car: T, @@ -61,11 +43,9 @@ pub fn f1<T:Copy>(x: T) { Pair::new(FiftyBytes::new(), FiftyBytes::new()); } -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn start() { let _b: Pair<u8> = Pair::new(0, 0); let _s: Pair<SevenBytes> = Pair::new(SevenBytes::new(), SevenBytes::new()); let ref _z: ZeroSized = ZeroSized; f1::<SevenBytes>(SevenBytes::new()); - 0 } diff --git a/src/test/ui/print_type_sizes/multiple_types.rs b/src/test/ui/print_type_sizes/multiple_types.rs index f1ad27ec131..91590389247 100644 --- a/src/test/ui/print_type_sizes/multiple_types.rs +++ b/src/test/ui/print_type_sizes/multiple_types.rs @@ -1,11 +1,9 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // This file illustrates that when multiple structural types occur in // a function, every one of them is included in the output. -#![feature(start)] - pub struct SevenBytes([u8; 7]); pub struct FiftyBytes([u8; 50]); @@ -13,11 +11,3 @@ pub enum Enum { Small(SevenBytes), Large(FiftyBytes), } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - let _e: Enum; - let _f: FiftyBytes; - let _s: SevenBytes; - 0 -} diff --git a/src/test/ui/print_type_sizes/niche-filling.rs b/src/test/ui/print_type_sizes/niche-filling.rs index 0716cee21c6..5e620f248b6 100644 --- a/src/test/ui/print_type_sizes/niche-filling.rs +++ b/src/test/ui/print_type_sizes/niche-filling.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. @@ -14,7 +14,6 @@ // aligned (while on most it is 8-byte aligned) and so the resulting // padding and overall computed sizes can be quite different. -#![feature(start)] #![feature(rustc_attrs)] #![allow(dead_code)] @@ -56,7 +55,7 @@ pub struct NestedNonZero { impl Default for NestedNonZero { fn default() -> Self { - NestedNonZero { pre: 0, val: NonZeroU32::new(1).unwrap(), post: 0 } + NestedNonZero { pre: 0, val: unsafe { NonZeroU32::new_unchecked(1) }, post: 0 } } } @@ -76,8 +75,7 @@ pub union Union2<A: Copy, B: Copy> { b: B, } -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn test() { let _x: MyOption<NonZeroU32> = Default::default(); let _y: EmbeddedDiscr = Default::default(); let _z: MyOption<IndirectNonZero> = Default::default(); @@ -96,6 +94,4 @@ fn start(_: isize, _: *const *const u8) -> isize { // ...even when theoretically possible. let _j: MyOption<Union1<NonZeroU32>> = Default::default(); let _k: MyOption<Union2<NonZeroU32, NonZeroU32>> = Default::default(); - - 0 } diff --git a/src/test/ui/print_type_sizes/no_duplicates.rs b/src/test/ui/print_type_sizes/no_duplicates.rs index e45e4794a35..2ec5d9e64bf 100644 --- a/src/test/ui/print_type_sizes/no_duplicates.rs +++ b/src/test/ui/print_type_sizes/no_duplicates.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. @@ -8,16 +8,12 @@ // (even if multiple functions), it is only printed once in the // print-type-sizes output. -#![feature(start)] - pub struct SevenBytes([u8; 7]); pub fn f1() { let _s: SevenBytes = SevenBytes([0; 7]); } -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn test() { let _s: SevenBytes = SevenBytes([0; 7]); - 0 } diff --git a/src/test/ui/print_type_sizes/packed.rs b/src/test/ui/print_type_sizes/packed.rs index 269cc3cc282..5ddfe4bf4db 100644 --- a/src/test/ui/print_type_sizes/packed.rs +++ b/src/test/ui/print_type_sizes/packed.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. @@ -13,11 +13,10 @@ // padding and overall computed sizes can be quite different. #![allow(dead_code)] -#![feature(start)] #[derive(Default)] #[repr(packed)] -struct Packed1 { +pub struct Packed1 { a: u8, b: u8, g: i32, @@ -28,7 +27,7 @@ struct Packed1 { #[derive(Default)] #[repr(packed(2))] -struct Packed2 { +pub struct Packed2 { a: u8, b: u8, g: i32, @@ -40,7 +39,7 @@ struct Packed2 { #[derive(Default)] #[repr(packed(2))] #[repr(C)] -struct Packed2C { +pub struct Packed2C { a: u8, b: u8, g: i32, @@ -50,7 +49,7 @@ struct Packed2C { } #[derive(Default)] -struct Padded { +pub struct Padded { a: u8, b: u8, g: i32, @@ -58,12 +57,3 @@ struct Padded { h: i16, d: u8, } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - let _c: Packed1 = Default::default(); - let _d: Packed2 = Default::default(); - let _e: Packed2C = Default::default(); - let _f: Padded = Default::default(); - 0 -} diff --git a/src/test/ui/print_type_sizes/padding.rs b/src/test/ui/print_type_sizes/padding.rs index d1acad16d7e..f41c677dc6c 100644 --- a/src/test/ui/print_type_sizes/padding.rs +++ b/src/test/ui/print_type_sizes/padding.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // This file illustrates how padding is handled: alignment @@ -9,7 +9,6 @@ // aligned (while on most it is 8-byte aligned) and so the resulting // padding and overall computed sizes can be quite different. -#![feature(start)] #![allow(dead_code)] struct S { @@ -27,8 +26,3 @@ enum E2 { A(i8, i32), B(S), } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - 0 -} diff --git a/src/test/ui/print_type_sizes/repr-align.rs b/src/test/ui/print_type_sizes/repr-align.rs index 07544935b2f..0bd11ebc958 100644 --- a/src/test/ui/print_type_sizes/repr-align.rs +++ b/src/test/ui/print_type_sizes/repr-align.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. @@ -11,7 +11,7 @@ // It avoids using u64/i64 because on some targets that is only 4-byte // aligned (while on most it is 8-byte aligned) and so the resulting // padding and overall computed sizes can be quite different. -#![feature(start)] + #![allow(dead_code)] #[repr(align(16))] @@ -24,15 +24,9 @@ enum E { } #[derive(Default)] -struct S { +pub struct S { a: i32, b: i32, c: A, d: i8, } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - let _s: S = Default::default(); - 0 -} diff --git a/src/test/ui/print_type_sizes/repr_int_c.rs b/src/test/ui/print_type_sizes/repr_int_c.rs index b8067c112ee..6b103776a30 100644 --- a/src/test/ui/print_type_sizes/repr_int_c.rs +++ b/src/test/ui/print_type_sizes/repr_int_c.rs @@ -1,10 +1,9 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // This test makes sure that the tag is not grown for `repr(C)` or `repr(u8)` // variants (see https://github.com/rust-lang/rust/issues/50098 for the original bug). -#![feature(start)] #![allow(dead_code)] #[repr(C, u8)] @@ -18,8 +17,3 @@ enum Repru8 { A(u16), B, } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - 0 -} diff --git a/src/test/ui/print_type_sizes/uninhabited.rs b/src/test/ui/print_type_sizes/uninhabited.rs index 06a62db4ebb..86fab7b500a 100644 --- a/src/test/ui/print_type_sizes/uninhabited.rs +++ b/src/test/ui/print_type_sizes/uninhabited.rs @@ -1,14 +1,12 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // ^-- needed because `--pass check` does not emit the output needed. // FIXME: consider using an attribute instead of side-effects. #![feature(never_type)] -#![feature(start)] -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn test() { let _x: Option<!> = None; let _y: Result<u32, !> = Ok(42); let _z: Result<!, !> = loop {}; diff --git a/src/test/ui/print_type_sizes/variants.rs b/src/test/ui/print_type_sizes/variants.rs index 6c8553cc23d..5a302052026 100644 --- a/src/test/ui/print_type_sizes/variants.rs +++ b/src/test/ui/print_type_sizes/variants.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // This file illustrates two things: @@ -9,8 +9,6 @@ // 2. For an enum, the print-type-sizes output will also include the // size of each variant. -#![feature(start)] - pub struct SevenBytes([u8; 7]); pub struct FiftyBytes([u8; 50]); @@ -18,9 +16,3 @@ pub enum Enum { Small(SevenBytes), Large(FiftyBytes), } - -#[start] -fn start(_: isize, _: *const *const u8) -> isize { - let _e: Enum; - 0 -} diff --git a/src/test/ui/print_type_sizes/zero-sized-fields.rs b/src/test/ui/print_type_sizes/zero-sized-fields.rs index e02a33109e5..09415824d5d 100644 --- a/src/test/ui/print_type_sizes/zero-sized-fields.rs +++ b/src/test/ui/print_type_sizes/zero-sized-fields.rs @@ -1,12 +1,10 @@ -// compile-flags: -Z print-type-sizes +// compile-flags: -Z print-type-sizes --crate-type=lib // build-pass // ignore-pass // At one point, zero-sized fields such as those in this file were causing // incorrect output from `-Z print-type-sizes`. -#![feature(start)] - struct S1 { x: u32, y: u32, @@ -28,8 +26,7 @@ struct S5<TagW, TagZ> { tagz: TagZ, } -#[start] -fn start(_: isize, _: *const *const u8) -> isize { +pub fn test() { let _s1: S1 = S1 { x: 0, y: 0, tag: () }; let _s5: S5<(), Empty> = S5 { @@ -43,5 +40,4 @@ fn start(_: isize, _: *const *const u8) -> isize { z: 4, tagz: Empty {}, }; - 0 } diff --git a/src/test/ui/proc-macro/quote-debug.stdout b/src/test/ui/proc-macro/quote-debug.stdout index d2cc5c6e2a3..9f64a1e06b9 100644 --- a/src/test/ui/proc-macro/quote-debug.stdout +++ b/src/test/ui/proc-macro/quote-debug.stdout @@ -42,6 +42,7 @@ const _: () = { extern crate proc_macro; #[rustc_proc_macro_decls] + #[used] #[allow(deprecated)] static _DECLS: &[proc_macro::bridge::client::ProcMacro] = &[]; }; diff --git a/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.stderr b/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.stderr index 1da29be43db..002dfe115b0 100644 --- a/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.stderr +++ b/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.stderr @@ -8,3 +8,4 @@ LL | fn f(x: S<u32>) {} error: aborting due to previous error +For more information about this error, try `rustc --explain E0320`. diff --git a/src/test/ui/regions/closure-in-projection-issue-97405.rs b/src/test/ui/regions/closure-in-projection-issue-97405.rs index 88b1c139651..e567d5c2723 100644 --- a/src/test/ui/regions/closure-in-projection-issue-97405.rs +++ b/src/test/ui/regions/closure-in-projection-issue-97405.rs @@ -22,11 +22,11 @@ fn good_generic_fn<T>() { // This should fail because `T` ends up in the upvars of the closure. fn bad_generic_fn<T: Copy>(t: T) { assert_static(opaque(async move { t; }).next()); - //~^ ERROR the parameter type `T` may not live long enough + //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough assert_static(opaque(move || { t; }).next()); //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough assert_static(opaque(opaque(async move { t; }).next()).next()); - //~^ ERROR the parameter type `T` may not live long enough + //~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough } fn main() {} diff --git a/src/test/ui/regions/closure-in-projection-issue-97405.stderr b/src/test/ui/regions/closure-in-projection-issue-97405.stderr index 907964aaf37..c08f1059ebf 100644 --- a/src/test/ui/regions/closure-in-projection-issue-97405.stderr +++ b/src/test/ui/regions/closure-in-projection-issue-97405.stderr @@ -1,13 +1,11 @@ -error[E0310]: the parameter type `T` may not live long enough +error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough --> $DIR/closure-in-projection-issue-97405.rs:24:5 | LL | assert_static(opaque(async move { t; }).next()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -LL | fn bad_generic_fn<T: Copy + 'static>(t: T) { - | +++++++++ + = help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`... + = note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough --> $DIR/closure-in-projection-issue-97405.rs:26:5 @@ -18,16 +16,14 @@ LL | assert_static(opaque(move || { t; }).next()); = help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`... = note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds -error[E0310]: the parameter type `T` may not live long enough +error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough --> $DIR/closure-in-projection-issue-97405.rs:28:5 | LL | assert_static(opaque(opaque(async move { t; }).next()).next()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -LL | fn bad_generic_fn<T: Copy + 'static>(t: T) { - | +++++++++ + = help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`... + = note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/auxiliary/issue-30535.rs b/src/test/ui/resolve/auxiliary/issue-30535.rs index 3608d4a2f14..3608d4a2f14 100644 --- a/src/test/ui/issues/auxiliary/issue-30535.rs +++ b/src/test/ui/resolve/auxiliary/issue-30535.rs diff --git a/src/test/ui/issues/issue-30535.rs b/src/test/ui/resolve/issue-30535.rs index d48f00d5aca..d48f00d5aca 100644 --- a/src/test/ui/issues/issue-30535.rs +++ b/src/test/ui/resolve/issue-30535.rs diff --git a/src/test/ui/issues/issue-30535.stderr b/src/test/ui/resolve/issue-30535.stderr index e3692934b62..e3692934b62 100644 --- a/src/test/ui/issues/issue-30535.stderr +++ b/src/test/ui/resolve/issue-30535.stderr diff --git a/src/test/ui/issues/issue-39559-2.rs b/src/test/ui/resolve/issue-39559-2.rs index 07d3a82b1ed..07d3a82b1ed 100644 --- a/src/test/ui/issues/issue-39559-2.rs +++ b/src/test/ui/resolve/issue-39559-2.rs diff --git a/src/test/ui/issues/issue-39559-2.stderr b/src/test/ui/resolve/issue-39559-2.stderr index ea27e7bd250..ea27e7bd250 100644 --- a/src/test/ui/issues/issue-39559-2.stderr +++ b/src/test/ui/resolve/issue-39559-2.stderr diff --git a/src/test/ui/issues/issue-39559.rs b/src/test/ui/resolve/issue-39559.rs index 58d25940733..58d25940733 100644 --- a/src/test/ui/issues/issue-39559.rs +++ b/src/test/ui/resolve/issue-39559.rs diff --git a/src/test/ui/issues/issue-39559.stderr b/src/test/ui/resolve/issue-39559.stderr index 7626f827fc5..7626f827fc5 100644 --- a/src/test/ui/issues/issue-39559.stderr +++ b/src/test/ui/resolve/issue-39559.stderr diff --git a/src/test/ui/resolve/issue-5035-2.stderr b/src/test/ui/resolve/issue-5035-2.stderr index 939392733f0..558e6b7b118 100644 --- a/src/test/ui/resolve/issue-5035-2.stderr +++ b/src/test/ui/resolve/issue-5035-2.stderr @@ -6,6 +6,10 @@ LL | fn foo(_x: K) {} | = help: the trait `Sized` is not implemented for `(dyn I + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn foo(_x: impl K) {} + | ++++ help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn foo(_x: &K) {} diff --git a/src/test/ui/resolve/issue-85348.stderr b/src/test/ui/resolve/issue-85348.stderr index f839dd927db..42b43f825d1 100644 --- a/src/test/ui/resolve/issue-85348.stderr +++ b/src/test/ui/resolve/issue-85348.stderr @@ -21,8 +21,8 @@ LL | let mut N; | help: consider giving `N` an explicit type | -LL | let mut N: _; - | +++ +LL | let mut N: /* Type */; + | ++++++++++++ error: aborting due to 3 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/const-impl-trait.rs new file mode 100644 index 00000000000..0622f96e70d --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-trait.rs @@ -0,0 +1,55 @@ +// check-pass +#![allow(incomplete_features)] +#![feature( + associated_type_bounds, + const_trait_impl, + const_cmp, + return_position_impl_trait_in_trait, +)] + +use std::marker::Destruct; + +const fn cmp(a: &impl ~const PartialEq) -> bool { + a == a +} + +const fn wrap(x: impl ~const PartialEq + ~const Destruct) + -> impl ~const PartialEq + ~const Destruct +{ + x +} + +#[const_trait] +trait Foo { + fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; +} + +impl const Foo for () { + fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { + 123 + } +} + +const _: () = { + assert!(cmp(&0xDEADBEEFu32)); + assert!(cmp(&())); + assert!(wrap(123) == wrap(123)); + assert!(wrap(123) != wrap(456)); + let x = <() as Foo>::huh(); + assert!(x == x); +}; + +#[const_trait] +trait T {} +struct S; +impl const T for S {} + +const fn rpit() -> impl ~const T { S } + +const fn apit(_: impl ~const T + ~const Destruct) {} + +const fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } + +const fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T> + ~const Destruct) {} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs index 5bd52151f42..95f7aaba0fc 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -1,23 +1,6 @@ #![feature(const_trait_impl)] #![feature(associated_type_bounds)] -#[const_trait] -trait T {} -struct S; -impl T for S {} - -fn rpit() -> impl ~const T { S } -//~^ ERROR `~const` is not allowed - -fn apit(_: impl ~const T) {} -//~^ ERROR `~const` is not allowed - -fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } -//~^ ERROR `~const` is not allowed - -fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {} -//~^ ERROR `~const` is not allowed - struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>); //~^ ERROR `~const` and `?` are mutually exclusive diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr index 84867cb4a53..d20f146df3f 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -1,40 +1,8 @@ -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:9:19 - | -LL | fn rpit() -> impl ~const T { S } - | ^^^^^^^^ - | - = note: `impl Trait`s cannot have `~const` trait bounds - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:12:17 - | -LL | fn apit(_: impl ~const T) {} - | ^^^^^^^^ - | - = note: `impl Trait`s cannot have `~const` trait bounds - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:15:50 - | -LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } - | ^^^^^^^^ - | - = note: `impl Trait`s cannot have `~const` trait bounds - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:18:48 - | -LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {} - | ^^^^^^^^ - | - = note: `impl Trait`s cannot have `~const` trait bounds - error: `~const` and `?` are mutually exclusive - --> $DIR/tilde-const-invalid-places.rs:21:25 + --> $DIR/tilde-const-invalid-places.rs:4:25 | LL | struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>); | ^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to previous error diff --git a/src/test/ui/span/method-and-field-eager-resolution.stderr b/src/test/ui/span/method-and-field-eager-resolution.stderr index 7d240589a3f..f6efbe40bc2 100644 --- a/src/test/ui/span/method-and-field-eager-resolution.stderr +++ b/src/test/ui/span/method-and-field-eager-resolution.stderr @@ -9,8 +9,8 @@ LL | x.0; | help: consider giving `x` an explicit type | -LL | let mut x: _ = Default::default(); - | +++ +LL | let mut x: /* Type */ = Default::default(); + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/method-and-field-eager-resolution.rs:11:9 @@ -23,8 +23,8 @@ LL | x[0]; | help: consider giving `x` an explicit type | -LL | let mut x: _ = Default::default(); - | +++ +LL | let mut x: /* Type */ = Default::default(); + | ++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-18118-2.rs b/src/test/ui/static/issue-18118-2.rs index f712a2eedb7..f712a2eedb7 100644 --- a/src/test/ui/issues/issue-18118-2.rs +++ b/src/test/ui/static/issue-18118-2.rs diff --git a/src/test/ui/issues/issue-18118-2.stderr b/src/test/ui/static/issue-18118-2.stderr index 4fc3ca78f96..4fc3ca78f96 100644 --- a/src/test/ui/issues/issue-18118-2.stderr +++ b/src/test/ui/static/issue-18118-2.stderr diff --git a/src/test/ui/issues/issue-18118.rs b/src/test/ui/static/issue-18118.rs index f58a3de281f..f58a3de281f 100644 --- a/src/test/ui/issues/issue-18118.rs +++ b/src/test/ui/static/issue-18118.rs diff --git a/src/test/ui/issues/issue-18118.stderr b/src/test/ui/static/issue-18118.stderr index 49798a148de..49798a148de 100644 --- a/src/test/ui/issues/issue-18118.stderr +++ b/src/test/ui/static/issue-18118.stderr diff --git a/src/test/ui/suggestions/assoc-ct-for-assoc-method.rs b/src/test/ui/suggestions/assoc-ct-for-assoc-method.rs new file mode 100644 index 00000000000..fe222776989 --- /dev/null +++ b/src/test/ui/suggestions/assoc-ct-for-assoc-method.rs @@ -0,0 +1,25 @@ +struct MyS; + +impl MyS { + const FOO: i32 = 1; + fn foo() -> MyS { + MyS + } +} + +fn main() { + let x: i32 = MyS::foo; + //~^ ERROR mismatched types + //~| HELP try referring to the + + let z: i32 = i32::max; + //~^ ERROR mismatched types + //~| HELP try referring to the + + // This example is still broken though... This is a hard suggestion to make, + // because we don't have access to the associated const probing code to make + // this suggestion where it's emitted, i.e. in trait selection. + let y: i32 = i32::max - 42; + //~^ ERROR cannot subtract + //~| HELP use parentheses +} diff --git a/src/test/ui/suggestions/assoc-ct-for-assoc-method.stderr b/src/test/ui/suggestions/assoc-ct-for-assoc-method.stderr new file mode 100644 index 00000000000..afef38f1296 --- /dev/null +++ b/src/test/ui/suggestions/assoc-ct-for-assoc-method.stderr @@ -0,0 +1,47 @@ +error[E0308]: mismatched types + --> $DIR/assoc-ct-for-assoc-method.rs:11:18 + | +LL | let x: i32 = MyS::foo; + | --- ^^^^^^^^ expected `i32`, found fn item + | | + | expected due to this + | + = note: expected type `i32` + found fn item `fn() -> MyS {MyS::foo}` +help: try referring to the associated const `FOO` instead + | +LL | let x: i32 = MyS::FOO; + | ~~~ + +error[E0308]: mismatched types + --> $DIR/assoc-ct-for-assoc-method.rs:15:18 + | +LL | let z: i32 = i32::max; + | --- ^^^^^^^^ expected `i32`, found fn item + | | + | expected due to this + | + = note: expected type `i32` + found fn item `fn(i32, i32) -> i32 {<i32 as Ord>::max}` +help: try referring to the associated const `MAX` instead + | +LL | let z: i32 = i32::MAX; + | ~~~ + +error[E0369]: cannot subtract `{integer}` from `fn(i32, i32) -> i32 {<i32 as Ord>::max}` + --> $DIR/assoc-ct-for-assoc-method.rs:22:27 + | +LL | let y: i32 = i32::max - 42; + | -------- ^ -- {integer} + | | + | fn(i32, i32) -> i32 {<i32 as Ord>::max} + | +help: use parentheses to call this associated function + | +LL | let y: i32 = i32::max(/* i32 */, /* i32 */) - 42; + | ++++++++++++++++++++++ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0369. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed new file mode 100644 index 00000000000..4f9e93a47ed --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed @@ -0,0 +1,16 @@ +// run-rustfix +fn wat<T: Clone>(t: &T) -> T { + t.clone() //~ ERROR E0308 +} + +#[derive(Clone)] +struct Foo; + +fn wut(t: &Foo) -> Foo { + t.clone() //~ ERROR E0308 +} + +fn main() { + wat(&42); + wut(&Foo); +} diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs new file mode 100644 index 00000000000..89b077d671a --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs @@ -0,0 +1,15 @@ +// run-rustfix +fn wat<T>(t: &T) -> T { + t.clone() //~ ERROR E0308 +} + +struct Foo; + +fn wut(t: &Foo) -> Foo { + t.clone() //~ ERROR E0308 +} + +fn main() { + wat(&42); + wut(&Foo); +} diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr new file mode 100644 index 00000000000..26ab515d9b4 --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr @@ -0,0 +1,43 @@ +error[E0308]: mismatched types + --> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5 + | +LL | fn wat<T>(t: &T) -> T { + | - - expected `T` because of return type + | | + | this type parameter +LL | t.clone() + | ^^^^^^^^^ expected type parameter `T`, found `&T` + | + = note: expected type parameter `T` + found reference `&T` +note: `T` does not implement `Clone`, so `&T` was cloned instead + --> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5 + | +LL | t.clone() + | ^ +help: consider restricting type parameter `T` + | +LL | fn wat<T: Clone>(t: &T) -> T { + | +++++++ + +error[E0308]: mismatched types + --> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5 + | +LL | fn wut(t: &Foo) -> Foo { + | --- expected `Foo` because of return type +LL | t.clone() + | ^^^^^^^^^ expected struct `Foo`, found `&Foo` + | +note: `Foo` does not implement `Clone`, so `&Foo` was cloned instead + --> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5 + | +LL | t.clone() + | ^ +help: consider annotating `Foo` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/enum-variant-arg-mismatch.rs b/src/test/ui/suggestions/enum-variant-arg-mismatch.rs new file mode 100644 index 00000000000..8de5bae92fc --- /dev/null +++ b/src/test/ui/suggestions/enum-variant-arg-mismatch.rs @@ -0,0 +1,10 @@ +pub enum Sexpr<'a> { + Ident(&'a str), +} + +fn map<'a, F: Fn(String) -> Sexpr<'a>>(f: F) {} + +fn main() { + map(Sexpr::Ident); + //~^ ERROR type mismatch in function arguments +} diff --git a/src/test/ui/suggestions/enum-variant-arg-mismatch.stderr b/src/test/ui/suggestions/enum-variant-arg-mismatch.stderr new file mode 100644 index 00000000000..f76019b7000 --- /dev/null +++ b/src/test/ui/suggestions/enum-variant-arg-mismatch.stderr @@ -0,0 +1,22 @@ +error[E0631]: type mismatch in function arguments + --> $DIR/enum-variant-arg-mismatch.rs:8:9 + | +LL | Ident(&'a str), + | ----- found signature defined here +... +LL | map(Sexpr::Ident); + | --- ^^^^^^^^^^^^ expected due to this + | | + | required by a bound introduced by this call + | + = note: expected function signature `fn(String) -> _` + found function signature `fn(&str) -> _` +note: required by a bound in `map` + --> $DIR/enum-variant-arg-mismatch.rs:5:15 + | +LL | fn map<'a, F: Fn(String) -> Sexpr<'a>>(f: F) {} + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/suggestions/fn-to-method-deeply-nested.rs b/src/test/ui/suggestions/fn-to-method-deeply-nested.rs new file mode 100644 index 00000000000..58ee3d6409a --- /dev/null +++ b/src/test/ui/suggestions/fn-to-method-deeply-nested.rs @@ -0,0 +1,13 @@ +fn main() -> Result<(), ()> { + a(b(c(d(e( + //~^ ERROR cannot find function `a` in this scope + //~| ERROR cannot find function `b` in this scope + //~| ERROR cannot find function `c` in this scope + //~| ERROR cannot find function `d` in this scope + //~| ERROR cannot find function `e` in this scope + z???????????????????????????????????????????????????????????????????????????????????????? + ????????????????????????????????????????????????????????????????????????????????????????? + ?????????????????????????????????????????????????????????????????? + //~^^^ ERROR cannot find value `z` in this scope + ))))) +} diff --git a/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr b/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr new file mode 100644 index 00000000000..ce813ea7aba --- /dev/null +++ b/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr @@ -0,0 +1,39 @@ +error[E0425]: cannot find value `z` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:8:9 + | +LL | z???????????????????????????????????????????????????????????????????????????????????????? + | ^ not found in this scope + +error[E0425]: cannot find function `e` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:2:13 + | +LL | a(b(c(d(e( + | ^ not found in this scope + +error[E0425]: cannot find function `d` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:2:11 + | +LL | a(b(c(d(e( + | ^ not found in this scope + +error[E0425]: cannot find function `c` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:2:9 + | +LL | a(b(c(d(e( + | ^ not found in this scope + +error[E0425]: cannot find function `b` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:2:7 + | +LL | a(b(c(d(e( + | ^ not found in this scope + +error[E0425]: cannot find function `a` in this scope + --> $DIR/fn-to-method-deeply-nested.rs:2:5 + | +LL | a(b(c(d(e( + | ^ not found in this scope + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/suggestions/issue-104327.rs b/src/test/ui/suggestions/issue-104327.rs new file mode 100644 index 00000000000..dd621ae7100 --- /dev/null +++ b/src/test/ui/suggestions/issue-104327.rs @@ -0,0 +1,12 @@ +trait Bar {} + +trait Foo { + fn f() {} +} + +impl Foo for dyn Bar {} + +fn main() { + Foo::f(); + //~^ ERROR cannot call associated function on trait without specifying the corresponding `impl` type +} diff --git a/src/test/ui/suggestions/issue-104327.stderr b/src/test/ui/suggestions/issue-104327.stderr new file mode 100644 index 00000000000..acec3a55d52 --- /dev/null +++ b/src/test/ui/suggestions/issue-104327.stderr @@ -0,0 +1,17 @@ +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> $DIR/issue-104327.rs:10:5 + | +LL | fn f() {} + | --------- `Foo::f` defined here +... +LL | Foo::f(); + | ^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | <(dyn Bar + 'static) as Foo>::f(); + | +++++++++++++++++++++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0790`. diff --git a/src/test/ui/suggestions/issue-104328.rs b/src/test/ui/suggestions/issue-104328.rs new file mode 100644 index 00000000000..c3707baf79f --- /dev/null +++ b/src/test/ui/suggestions/issue-104328.rs @@ -0,0 +1,12 @@ +#![feature(object_safe_for_dispatch)] + +trait Foo { + fn f() {} +} + +impl Foo for dyn Sized {} + +fn main() { + Foo::f(); + //~^ ERROR cannot call associated function on trait without specifying the corresponding `impl` type +} diff --git a/src/test/ui/suggestions/issue-104328.stderr b/src/test/ui/suggestions/issue-104328.stderr new file mode 100644 index 00000000000..b31b84781ba --- /dev/null +++ b/src/test/ui/suggestions/issue-104328.stderr @@ -0,0 +1,17 @@ +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> $DIR/issue-104328.rs:10:5 + | +LL | fn f() {} + | --------- `Foo::f` defined here +... +LL | Foo::f(); + | ^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | <(dyn Sized + 'static) as Foo>::f(); + | +++++++++++++++++++++++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0790`. diff --git a/src/test/ui/suggestions/issue-105494.rs b/src/test/ui/suggestions/issue-105494.rs new file mode 100644 index 00000000000..8b409232c20 --- /dev/null +++ b/src/test/ui/suggestions/issue-105494.rs @@ -0,0 +1,22 @@ +fn test1() { + let _v: i32 = (1 as i32).to_string(); //~ ERROR mismatched types + + // won't suggestion + let _v: i32 = (1 as i128).to_string(); //~ ERROR mismatched types + + let _v: &str = "foo".to_string(); //~ ERROR mismatched types +} + +fn test2() { + let mut path: String = "/usr".to_string(); + let folder: String = "lib".to_string(); + + path = format!("{}/{}", path, folder).as_str(); //~ ERROR mismatched types + + println!("{}", &path); +} + +fn main() { + test1(); + test2(); +} diff --git a/src/test/ui/suggestions/issue-105494.stderr b/src/test/ui/suggestions/issue-105494.stderr new file mode 100644 index 00000000000..5aa3f2af738 --- /dev/null +++ b/src/test/ui/suggestions/issue-105494.stderr @@ -0,0 +1,54 @@ +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:2:19 + | +LL | let _v: i32 = (1 as i32).to_string(); + | --- ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String` + | | + | expected due to this + | +help: try removing the method call + | +LL - let _v: i32 = (1 as i32).to_string(); +LL + let _v: i32 = (1 as i32); + | + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:5:19 + | +LL | let _v: i32 = (1 as i128).to_string(); + | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String` + | | + | expected due to this + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:7:20 + | +LL | let _v: &str = "foo".to_string(); + | ---- ^^^^^^^^^^^^^^^^^ expected `&str`, found struct `String` + | | + | expected due to this + | +help: try removing the method call + | +LL - let _v: &str = "foo".to_string(); +LL + let _v: &str = "foo"; + | + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:14:12 + | +LL | let mut path: String = "/usr".to_string(); + | ------ expected due to this type +... +LL | path = format!("{}/{}", path, folder).as_str(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&str` + | +help: try removing the method call + | +LL - path = format!("{}/{}", path, folder).as_str(); +LL + path = format!("{}/{}", path, folder); + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr index 2cb53ecce10..6910b77d9bc 100644 --- a/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr +++ b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr @@ -20,11 +20,11 @@ LL | let fp = BufWriter::new(fp); note: required by a bound in `BufWriter` --> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL -error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn std::io::Write>`, but its trait bounds were not satisfied +error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn Write>`, but its trait bounds were not satisfied --> $DIR/mut-borrow-needed-by-trait.rs:21:5 | LL | writeln!(fp, "hello world").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `BufWriter<&dyn std::io::Write>` due to unsatisfied trait bounds + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `BufWriter<&dyn Write>` due to unsatisfied trait bounds --> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL | = note: doesn't satisfy `BufWriter<&dyn std::io::Write>: std::io::Write` diff --git a/src/test/ui/svh/changing-crates.stderr b/src/test/ui/svh/changing-crates.stderr index 7244919e86d..caefdfc96f0 100644 --- a/src/test/ui/svh/changing-crates.stderr +++ b/src/test/ui/svh/changing-crates.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-lit.stderr b/src/test/ui/svh/svh-change-lit.stderr index 1e97e9d0557..5e890c6aa57 100644 --- a/src/test/ui/svh/svh-change-lit.stderr +++ b/src/test/ui/svh/svh-change-lit.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-significant-cfg.stderr b/src/test/ui/svh/svh-change-significant-cfg.stderr index f04046f4c87..dcc250d5216 100644 --- a/src/test/ui/svh/svh-change-significant-cfg.stderr +++ b/src/test/ui/svh/svh-change-significant-cfg.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-trait-bound.stderr b/src/test/ui/svh/svh-change-trait-bound.stderr index a778c61806a..2035993d218 100644 --- a/src/test/ui/svh/svh-change-trait-bound.stderr +++ b/src/test/ui/svh/svh-change-trait-bound.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-type-arg.stderr b/src/test/ui/svh/svh-change-type-arg.stderr index f09babf93fd..eef85aa9546 100644 --- a/src/test/ui/svh/svh-change-type-arg.stderr +++ b/src/test/ui/svh/svh-change-type-arg.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-type-ret.stderr b/src/test/ui/svh/svh-change-type-ret.stderr index 0998cd4b549..247f74e50df 100644 --- a/src/test/ui/svh/svh-change-type-ret.stderr +++ b/src/test/ui/svh/svh-change-type-ret.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-change-type-static.stderr b/src/test/ui/svh/svh-change-type-static.stderr index 9c48cbd30a5..78b54f227f0 100644 --- a/src/test/ui/svh/svh-change-type-static.stderr +++ b/src/test/ui/svh/svh-change-type-static.stderr @@ -11,3 +11,4 @@ LL | extern crate b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/svh/svh-use-trait.stderr b/src/test/ui/svh/svh-use-trait.stderr index 5780cfef357..d8a81864dca 100644 --- a/src/test/ui/svh/svh-use-trait.stderr +++ b/src/test/ui/svh/svh-use-trait.stderr @@ -11,3 +11,4 @@ LL | extern crate utb; error: aborting due to previous error +For more information about this error, try `rustc --explain E0460`. diff --git a/src/test/ui/issues/issue-52557.rs b/src/test/ui/test-attrs/issue-52557.rs index 09f7a8c5131..09f7a8c5131 100644 --- a/src/test/ui/issues/issue-52557.rs +++ b/src/test/ui/test-attrs/issue-52557.rs diff --git a/src/test/ui/traits/assoc-type-in-superbad.rs b/src/test/ui/traits/assoc-type-in-superbad.rs index d7d6241ef70..65340b2a209 100644 --- a/src/test/ui/traits/assoc-type-in-superbad.rs +++ b/src/test/ui/traits/assoc-type-in-superbad.rs @@ -10,7 +10,7 @@ pub trait Foo: Iterator<Item = <Self as Foo>::Key> { impl Foo for IntoIter<i32> { type Key = u32; - //~^ ERROR expected `std::vec::IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32` + //~^ ERROR expected `IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32` } fn main() {} diff --git a/src/test/ui/traits/assoc-type-in-superbad.stderr b/src/test/ui/traits/assoc-type-in-superbad.stderr index 3e2d9d9038a..7fa1d2c2eed 100644 --- a/src/test/ui/traits/assoc-type-in-superbad.stderr +++ b/src/test/ui/traits/assoc-type-in-superbad.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `std::vec::IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32` +error[E0271]: expected `IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32` --> $DIR/assoc-type-in-superbad.rs:12:16 | LL | type Key = u32; diff --git a/src/test/ui/traits/bound/not-on-bare-trait.stderr b/src/test/ui/traits/bound/not-on-bare-trait.stderr index 8da0b6d6b85..36b08a7d309 100644 --- a/src/test/ui/traits/bound/not-on-bare-trait.stderr +++ b/src/test/ui/traits/bound/not-on-bare-trait.stderr @@ -20,6 +20,10 @@ LL | fn foo(_x: Foo + Send) { | = help: the trait `Sized` is not implemented for `(dyn Foo + Send + 'static)` = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn foo(_x: impl Foo + Send) { + | ++++ help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn foo(_x: &Foo + Send) { diff --git a/src/test/ui/traits/issue-77982.stderr b/src/test/ui/traits/issue-77982.stderr index 8ab6414d4d8..0b57a8212bd 100644 --- a/src/test/ui/traits/issue-77982.stderr +++ b/src/test/ui/traits/issue-77982.stderr @@ -43,7 +43,15 @@ LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect( | | | required by a bound introduced by this call | - = note: cannot satisfy `u32: From<_>` + = note: multiple `impl`s satisfying `u32: From<_>` found in the following crates: `core`, `std`: + - impl From<Ipv4Addr> for u32; + - impl From<NonZeroU32> for u32; + - impl From<bool> for u32; + - impl From<char> for u32; + - impl From<u16> for u32; + - impl From<u8> for u32; + - impl<T> From<!> for T; + - impl<T> From<T> for T; help: try using a fully qualified path to specify the expected types | LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect(); diff --git a/src/test/ui/traits/issue-85735.stderr b/src/test/ui/traits/issue-85735.stderr index fa280135beb..9e80497ca6e 100644 --- a/src/test/ui/traits/issue-85735.stderr +++ b/src/test/ui/traits/issue-85735.stderr @@ -4,7 +4,14 @@ error[E0283]: type annotations needed: cannot satisfy `T: FnMut<(&'a (),)>` LL | T: FnMut(&'a ()), | ^^^^^^^^^^^^^ | - = note: cannot satisfy `T: FnMut<(&'a (),)>` +note: multiple `impl`s or `where` clauses satisfying `T: FnMut<(&'a (),)>` found + --> $DIR/issue-85735.rs:7:8 + | +LL | T: FnMut(&'a ()), + | ^^^^^^^^^^^^^ +LL | +LL | T: FnMut(&'b ()), + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs new file mode 100644 index 00000000000..a3bb76d7e3b --- /dev/null +++ b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs @@ -0,0 +1,28 @@ +// known-bug + +// This should compile but fails with the current solver. +// +// This checks that the new solver uses `Ambiguous` when hitting the +// inductive cycle here when proving `exists<^0, ^1> (): Trait<^0, ^1>` +// which requires proving `Trait<?1, ?0>` but that has the same +// canonical representation. +trait Trait<T, U> {} + +impl<T, U> Trait<T, U> for () +where + (): Trait<U, T>, + T: OtherTrait, +{} + +trait OtherTrait {} +impl OtherTrait for u32 {} + +fn require_trait<T, U>() +where + (): Trait<T, U> +{} + +fn main() { + require_trait::<_, _>(); + //~^ ERROR overflow evaluating +} diff --git a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr new file mode 100644 index 00000000000..e4b84e07822 --- /dev/null +++ b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr @@ -0,0 +1,26 @@ +error[E0275]: overflow evaluating the requirement `_: Sized` + --> $DIR/inductive-canonical-cycle.rs:26:5 + | +LL | require_trait::<_, _>(); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_canonical_cycle`) +note: required for `()` to implement `Trait<_, _>` + --> $DIR/inductive-canonical-cycle.rs:11:12 + | +LL | impl<T, U> Trait<T, U> for () + | ^^^^^^^^^^^ ^^ + = note: 128 redundant requirements hidden + = note: required for `()` to implement `Trait<_, _>` +note: required by a bound in `require_trait` + --> $DIR/inductive-canonical-cycle.rs:22:9 + | +LL | fn require_trait<T, U>() + | ------------- required by a bound in this +LL | where +LL | (): Trait<T, U> + | ^^^^^^^^^^^ required by this bound in `require_trait` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/src/test/ui/traits/static-method-generic-inference.stderr b/src/test/ui/traits/static-method-generic-inference.stderr index 5f74d0c3b92..575ace2374e 100644 --- a/src/test/ui/traits/static-method-generic-inference.stderr +++ b/src/test/ui/traits/static-method-generic-inference.stderr @@ -9,8 +9,8 @@ LL | let _f: base::Foo = base::HasNew::new(); | help: use the fully-qualified path to the only available implementation | -LL | let _f: base::Foo = base::<Foo as HasNew>::new(); - | +++++++ + +LL | let _f: base::Foo = <Foo as base::HasNew>::new(); + | +++++++ + error: aborting due to previous error diff --git a/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed new file mode 100644 index 00000000000..ea3d1bf853a --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed @@ -0,0 +1,14 @@ +// run-rustfix + +struct TargetStruct; + +impl From<usize> for TargetStruct { + fn from(_unchecked: usize) -> Self { + TargetStruct + } +} + +fn main() { + let a = &3; + let _b: TargetStruct = (*a).into(); //~ ERROR the trait bound `TargetStruct: From<&{integer}>` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs new file mode 100644 index 00000000000..9eda68027b2 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs @@ -0,0 +1,14 @@ +// run-rustfix + +struct TargetStruct; + +impl From<usize> for TargetStruct { + fn from(_unchecked: usize) -> Self { + TargetStruct + } +} + +fn main() { + let a = &3; + let _b: TargetStruct = a.into(); //~ ERROR the trait bound `TargetStruct: From<&{integer}>` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr new file mode 100644 index 00000000000..ede31a2c7bc --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `TargetStruct: From<&{integer}>` is not satisfied + --> $DIR/suggest-dereferencing-receiver-argument.rs:13:30 + | +LL | let _b: TargetStruct = a.into(); + | ^^^^ the trait `From<&{integer}>` is not implemented for `TargetStruct` + | + = note: required for `&{integer}` to implement `Into<TargetStruct>` +help: consider dereferencing here + | +LL | let _b: TargetStruct = (*a).into(); + | ++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs b/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs new file mode 100644 index 00000000000..712ed55438e --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs @@ -0,0 +1,9 @@ +pub trait SomeTrait {} + +impl SomeTrait for () {} + +// Adding this `impl` would cause errors in this crate's dependent, +// so it would be a breaking change. We explicitly don't add this impl, +// as the dependent crate already assumes this impl exists and thus already +// does not compile. +//impl SomeTrait for i32 {} diff --git a/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr index 48b7946ea82..9cc15f14a99 100644 --- a/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr +++ b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr @@ -6,8 +6,8 @@ LL | |x| x.len() | help: consider giving this closure parameter an explicit type | -LL | |x: _| x.len() - | +++ +LL | |x: /* Type */| x.len() + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:21:10 @@ -17,8 +17,8 @@ LL | |x| x.len() | help: consider giving this closure parameter an explicit type | -LL | |x: _| x.len() - | +++ +LL | |x: /* Type */| x.len() + | ++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/type-alias-impl-trait/coherence.stderr b/src/test/ui/type-alias-impl-trait/coherence.stderr index c923eb08ab3..00b0dbbb583 100644 --- a/src/test/ui/type-alias-impl-trait/coherence.stderr +++ b/src/test/ui/type-alias-impl-trait/coherence.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------- | | | - | | `AliasOfForeignType<T>` is not defined in the current crate + | | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate | impl doesn't use only types from inside the current crate | = note: define and implement a trait or new type instead diff --git a/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs new file mode 100644 index 00000000000..a63e0a1ee6f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs @@ -0,0 +1,24 @@ +// aux-build: coherence_cross_crate_trait_decl.rs +// This test ensures that adding an `impl SomeTrait for i32` within +// `coherence_cross_crate_trait_decl` is not a breaking change, by +// making sure that even without such an impl this test fails to compile. + +#![feature(type_alias_impl_trait)] + +extern crate coherence_cross_crate_trait_decl; + +use coherence_cross_crate_trait_decl::SomeTrait; + +trait OtherTrait {} + +type Alias = impl SomeTrait; + +fn constrain() -> Alias { + () +} + +impl OtherTrait for Alias {} +impl OtherTrait for i32 {} +//~^ ERROR: conflicting implementations of trait `OtherTrait` for type `Alias` + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr new file mode 100644 index 00000000000..63a3ce29cc7 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr @@ -0,0 +1,13 @@ +error[E0119]: conflicting implementations of trait `OtherTrait` for type `Alias` + --> $DIR/coherence_cross_crate.rs:21:1 + | +LL | impl OtherTrait for Alias {} + | ------------------------- first implementation here +LL | impl OtherTrait for i32 {} + | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Alias` + | + = note: upstream crates may add a new impl of trait `coherence_cross_crate_trait_decl::SomeTrait` for type `i32` in future versions + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/type-alias-impl-trait/destructuring.rs b/src/test/ui/type-alias-impl-trait/destructuring.rs new file mode 100644 index 00000000000..b752e58380a --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/destructuring.rs @@ -0,0 +1,10 @@ +#![feature(type_alias_impl_trait)] + +// check-pass + +// issue: https://github.com/rust-lang/rust/issues/104551 + +fn main() { + type T = impl Sized; + let (_a, _b): T = (1u32, 2u32); +} diff --git a/src/test/ui/type-alias-impl-trait/issue-57961.rs b/src/test/ui/type-alias-impl-trait/issue-57961.rs index 24b3a045856..4aa5966ff25 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57961.rs +++ b/src/test/ui/type-alias-impl-trait/issue-57961.rs @@ -8,7 +8,7 @@ trait Foo { impl Foo for () { type Bar = std::vec::IntoIter<u32>; - //~^ ERROR expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` + //~^ ERROR expected `IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` } fn incoherent() { diff --git a/src/test/ui/type-alias-impl-trait/issue-57961.stderr b/src/test/ui/type-alias-impl-trait/issue-57961.stderr index fb40895c49f..8d11b488889 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57961.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-57961.stderr @@ -1,4 +1,4 @@ -error[E0271]: expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` +error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` --> $DIR/issue-57961.rs:10:16 | LL | type X = impl Sized; diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index 4af4c22f751..87bba3166be 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -10,7 +10,7 @@ note: required by a bound in `foo` | LL | fn foo<T: Into<String>>(x: i32) {} | ^^^^^^^^^^^^ required by this bound in `foo` -help: consider specifying the type argument in the function call +help: consider specifying the generic argument | LL | foo::<T>(42); | +++++ diff --git a/src/test/ui/type/type-check/issue-40294.stderr b/src/test/ui/type/type-check/issue-40294.stderr index 75feb5698eb..d15fd23418b 100644 --- a/src/test/ui/type/type-check/issue-40294.stderr +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -4,7 +4,13 @@ error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo` LL | where &'a T : Foo, | ^^^ | - = note: cannot satisfy `&'a T: Foo` +note: multiple `impl`s or `where` clauses satisfying `&'a T: Foo` found + --> $DIR/issue-40294.rs:6:19 + | +LL | where &'a T : Foo, + | ^^^ +LL | &'b T : Foo + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/type/type-check/unknown_type_for_closure.stderr b/src/test/ui/type/type-check/unknown_type_for_closure.stderr index 9ae97f390d3..e5e29aabf37 100644 --- a/src/test/ui/type/type-check/unknown_type_for_closure.stderr +++ b/src/test/ui/type/type-check/unknown_type_for_closure.stderr @@ -12,8 +12,8 @@ LL | let x = |_| {}; | help: consider giving this closure parameter an explicit type | -LL | let x = |_: _| {}; - | +++ +LL | let x = |_: /* Type */| {}; + | ++++++++++++ error[E0282]: type annotations needed --> $DIR/unknown_type_for_closure.rs:10:14 diff --git a/src/test/ui/type/type-path-err-node-types.stderr b/src/test/ui/type/type-path-err-node-types.stderr index c1ae10efac4..1aed1dbe4ba 100644 --- a/src/test/ui/type/type-path-err-node-types.stderr +++ b/src/test/ui/type/type-path-err-node-types.stderr @@ -30,8 +30,8 @@ LL | let _ = |a, b: _| -> _ { 0 }; | help: consider giving this closure parameter an explicit type | -LL | let _ = |a: _, b: _| -> _ { 0 }; - | +++ +LL | let _ = |a: /* Type */, b: _| -> _ { 0 }; + | ++++++++++++ error: aborting due to 5 previous errors diff --git a/src/test/ui/typeck/check-args-on-fn-err-2.rs b/src/test/ui/typeck/check-args-on-fn-err-2.rs new file mode 100644 index 00000000000..af57dbe3317 --- /dev/null +++ b/src/test/ui/typeck/check-args-on-fn-err-2.rs @@ -0,0 +1,5 @@ +fn main() { + a((), 1i32 == 2u32); + //~^ ERROR cannot find function `a` in this scope + //~| ERROR mismatched types +} diff --git a/src/test/ui/typeck/check-args-on-fn-err-2.stderr b/src/test/ui/typeck/check-args-on-fn-err-2.stderr new file mode 100644 index 00000000000..301bb88dbac --- /dev/null +++ b/src/test/ui/typeck/check-args-on-fn-err-2.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/check-args-on-fn-err-2.rs:2:19 + | +LL | a((), 1i32 == 2u32); + | ---- ^^^^ expected `i32`, found `u32` + | | + | expected because this is `i32` + | +help: change the type of the numeric literal from `u32` to `i32` + | +LL | a((), 1i32 == 2i32); + | ~~~ + +error[E0425]: cannot find function `a` in this scope + --> $DIR/check-args-on-fn-err-2.rs:2:5 + | +LL | a((), 1i32 == 2u32); + | ^ not found in this scope + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0425. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/check-args-on-fn-err.rs b/src/test/ui/typeck/check-args-on-fn-err.rs new file mode 100644 index 00000000000..04b98ddd952 --- /dev/null +++ b/src/test/ui/typeck/check-args-on-fn-err.rs @@ -0,0 +1,6 @@ +fn main() { + unknown(1, |glyf| { + //~^ ERROR: cannot find function `unknown` in this scope + let actual = glyf; + }); +} diff --git a/src/test/ui/typeck/check-args-on-fn-err.stderr b/src/test/ui/typeck/check-args-on-fn-err.stderr new file mode 100644 index 00000000000..864d33e0e93 --- /dev/null +++ b/src/test/ui/typeck/check-args-on-fn-err.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `unknown` in this scope + --> $DIR/check-args-on-fn-err.rs:2:5 + | +LL | unknown(1, |glyf| { + | ^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/typeck/explain_clone_autoref.stderr b/src/test/ui/typeck/explain_clone_autoref.stderr index faac680ea19..ff36e18d283 100644 --- a/src/test/ui/typeck/explain_clone_autoref.stderr +++ b/src/test/ui/typeck/explain_clone_autoref.stderr @@ -12,6 +12,10 @@ note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead | LL | nc.clone() | ^^ +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-22375.rs b/src/test/ui/typeck/issue-22375.rs index 21a1a4c8380..21a1a4c8380 100644 --- a/src/test/ui/issues/issue-22375.rs +++ b/src/test/ui/typeck/issue-22375.rs diff --git a/src/test/ui/typeck/issue-57404.rs b/src/test/ui/typeck/issue-57404.rs new file mode 100644 index 00000000000..ecabca66a00 --- /dev/null +++ b/src/test/ui/typeck/issue-57404.rs @@ -0,0 +1,7 @@ +#![feature(unboxed_closures)] +#![feature(fn_traits)] + +fn main() { + let handlers: Option<Box<dyn for<'a> FnMut<&'a mut (), Output=()>>> = None; + handlers.unwrap().as_mut().call_mut(&mut ()); //~ ERROR: `&mut ()` is not a tuple +} diff --git a/src/test/ui/typeck/issue-57404.stderr b/src/test/ui/typeck/issue-57404.stderr new file mode 100644 index 00000000000..5065ac32ad2 --- /dev/null +++ b/src/test/ui/typeck/issue-57404.stderr @@ -0,0 +1,16 @@ +error[E0277]: `&mut ()` is not a tuple + --> $DIR/issue-57404.rs:6:41 + | +LL | handlers.unwrap().as_mut().call_mut(&mut ()); + | -------- -^^^^^^ + | | | + | | the trait `Tuple` is not implemented for `&mut ()` + | | help: consider removing the leading `&`-reference + | required by a bound introduced by this call + | +note: required by a bound in `call_mut` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/typeck/issue-92481.rs b/src/test/ui/typeck/issue-92481.rs new file mode 100644 index 00000000000..0a6b1843d99 --- /dev/null +++ b/src/test/ui/typeck/issue-92481.rs @@ -0,0 +1,14 @@ +//check-fail + +#![crate_type="lib"] + +fn r({) { + Ok { //~ ERROR mismatched types [E0308] + d..||_=m + } +} +//~^^^^^ ERROR expected parameter name, found `{` +//~| ERROR expected one of `,`, `:`, or `}`, found `..` +//~^^^^^ ERROR cannot find value `d` in this scope [E0425] +//~| ERROR cannot find value `m` in this scope [E0425] +//~| ERROR variant `Result<_, _>::Ok` has no field named `d` [E0559] diff --git a/src/test/ui/typeck/issue-92481.stderr b/src/test/ui/typeck/issue-92481.stderr new file mode 100644 index 00000000000..cd778a649b6 --- /dev/null +++ b/src/test/ui/typeck/issue-92481.stderr @@ -0,0 +1,60 @@ +error: expected parameter name, found `{` + --> $DIR/issue-92481.rs:5:6 + | +LL | fn r({) { + | ^ expected parameter name + +error: expected one of `,`, `:`, or `}`, found `..` + --> $DIR/issue-92481.rs:5:6 + | +LL | fn r({) { + | ^ unclosed delimiter +LL | Ok { +LL | d..||_=m + | -^ + | | + | help: `}` may belong here + +error[E0425]: cannot find value `d` in this scope + --> $DIR/issue-92481.rs:7:9 + | +LL | d..||_=m + | ^ not found in this scope + +error[E0425]: cannot find value `m` in this scope + --> $DIR/issue-92481.rs:7:16 + | +LL | d..||_=m + | ^ not found in this scope + +error[E0559]: variant `Result<_, _>::Ok` has no field named `d` + --> $DIR/issue-92481.rs:7:9 + | +LL | d..||_=m + | ^ field does not exist + --> $SRC_DIR/core/src/result.rs:LL:COL + | + = note: `Result<_, _>::Ok` defined here + | +help: `Result<_, _>::Ok` is a tuple variant, use the appropriate syntax + | +LL | Result<_, _>::Ok(/* fields */) + | + +error[E0308]: mismatched types + --> $DIR/issue-92481.rs:6:5 + | +LL | fn r({) { + | - help: a return type might be missing here: `-> _` +LL | / Ok { +LL | | d..||_=m +LL | | } + | |_____^ expected `()`, found enum `Result` + | + = note: expected unit type `()` + found enum `Result<_, _>` + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0308, E0425, E0559. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/issue-96530.rs b/src/test/ui/typeck/issue-96530.rs new file mode 100644 index 00000000000..4ab93ab4938 --- /dev/null +++ b/src/test/ui/typeck/issue-96530.rs @@ -0,0 +1,20 @@ +struct Person { + first_name: String, + age: u32, +} + +fn first_woman(man: &Person) -> Person { + Person { + first_name: "Eve".to_string(), + ..man.clone() //~ ERROR: mismatched types + } +} + +fn main() { + let adam = Person { + first_name: "Adam".to_string(), + age: 0, + }; + + let eve = first_woman(&adam); +} diff --git a/src/test/ui/typeck/issue-96530.stderr b/src/test/ui/typeck/issue-96530.stderr new file mode 100644 index 00000000000..4b4568b1de9 --- /dev/null +++ b/src/test/ui/typeck/issue-96530.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/issue-96530.rs:9:11 + | +LL | ..man.clone() + | ^^^^^^^^^^^ expected struct `Person`, found `&Person` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/unboxed-closures/non-tupled-call.rs b/src/test/ui/unboxed-closures/non-tupled-call.rs new file mode 100644 index 00000000000..08bea4f1678 --- /dev/null +++ b/src/test/ui/unboxed-closures/non-tupled-call.rs @@ -0,0 +1,17 @@ +#![feature(fn_traits, unboxed_closures, tuple_trait)] + +use std::default::Default; +use std::marker::Tuple; + +fn wrap<P: Tuple + Default, T>(func: impl Fn<P, Output = T>) { + let x: P = Default::default(); + // Should be: `func.call(x);` + func(x); + //~^ ERROR cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit +} + +fn foo() {} + +fn main() { + wrap(foo); +} diff --git a/src/test/ui/unboxed-closures/non-tupled-call.stderr b/src/test/ui/unboxed-closures/non-tupled-call.stderr new file mode 100644 index 00000000000..35ac9ebe291 --- /dev/null +++ b/src/test/ui/unboxed-closures/non-tupled-call.stderr @@ -0,0 +1,9 @@ +error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit + --> $DIR/non-tupled-call.rs:9:5 + | +LL | func(x); + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0059`. diff --git a/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr b/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr index e5ca0edd7a9..99ec5178340 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr @@ -1,8 +1,8 @@ -error[E0599]: no method named `call` found for closure `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:29]` in the current scope +error[E0599]: no method named `call` found for closure `[closure@unboxed-closures-static-call-wrong-trait.rs:6:26]` in the current scope --> $DIR/unboxed-closures-static-call-wrong-trait.rs:7:10 | LL | mut_.call((0, )); - | ^^^^ method not found in `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:29]` + | ^^^^ method not found in `[closure@unboxed-closures-static-call-wrong-trait.rs:6:26]` error: aborting due to previous error |
