diff options
Diffstat (limited to 'tests')
168 files changed, 2046 insertions, 624 deletions
diff --git a/tests/auxiliary/rust_test_helpers.c b/tests/auxiliary/rust_test_helpers.c index 965df44c676..34cc7fd5dfb 100644 --- a/tests/auxiliary/rust_test_helpers.c +++ b/tests/auxiliary/rust_test_helpers.c @@ -27,10 +27,10 @@ rust_dbg_extern_identity_u8(char u) { return u; } -typedef void *(*dbg_callback)(void*); +typedef uint64_t (*dbg_callback)(uint64_t); -void * -rust_dbg_call(dbg_callback cb, void *data) { +uint64_t +rust_dbg_call(dbg_callback cb, uint64_t data) { return cb(data); } diff --git a/tests/codegen/mir-aggregate-no-alloca.rs b/tests/codegen/mir-aggregate-no-alloca.rs new file mode 100644 index 00000000000..a7752d714fe --- /dev/null +++ b/tests/codegen/mir-aggregate-no-alloca.rs @@ -0,0 +1,123 @@ +//@ compile-flags: -O -C no-prepopulate-passes -Z randomize-layout=no + +#![crate_type = "lib"] + +#[repr(transparent)] +pub struct Transparent32(u32); + +// CHECK: i32 @make_transparent(i32 noundef %x) +#[no_mangle] +pub fn make_transparent(x: u32) -> Transparent32 { + // CHECK-NOT: alloca + // CHECK: ret i32 %x + let a = Transparent32(x); + a +} + +// CHECK: i32 @make_closure(i32 noundef %x) +#[no_mangle] +pub fn make_closure(x: i32) -> impl Fn(i32) -> i32 { + // CHECK-NOT: alloca + // CHECK: ret i32 %x + move |y| x + y +} + +#[repr(transparent)] +pub struct TransparentPair((), (u16, u16), ()); + +// CHECK: { i16, i16 } @make_transparent_pair(i16 noundef %x.0, i16 noundef %x.1) +#[no_mangle] +pub fn make_transparent_pair(x: (u16, u16)) -> TransparentPair { + // CHECK-NOT: alloca + // CHECK: %[[TEMP0:.+]] = insertvalue { i16, i16 } poison, i16 %x.0, 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i16, i16 } %[[TEMP0]], i16 %x.1, 1 + // CHECK: ret { i16, i16 } %[[TEMP1]] + let a = TransparentPair((), x, ()); + a +} + +// CHECK-LABEL: { i32, i32 } @make_2_tuple(i32 noundef %x) +#[no_mangle] +pub fn make_2_tuple(x: u32) -> (u32, u32) { + // CHECK-NOT: alloca + // CHECK: %[[TEMP0:.+]] = insertvalue { i32, i32 } poison, i32 %x, 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i32, i32 } %[[TEMP0]], i32 %x, 1 + // CHECK: ret { i32, i32 } %[[TEMP1]] + let pair = (x, x); + pair +} + +// CHECK-LABEL: i8 @make_cell_of_bool(i1 noundef zeroext %b) +#[no_mangle] +pub fn make_cell_of_bool(b: bool) -> std::cell::Cell<bool> { + // CHECK: %[[BYTE:.+]] = zext i1 %b to i8 + // CHECK: ret i8 %[[BYTE]] + std::cell::Cell::new(b) +} + +// CHECK-LABLE: { i8, i16 } @make_cell_of_bool_and_short(i1 noundef zeroext %b, i16 noundef %s) +#[no_mangle] +pub fn make_cell_of_bool_and_short(b: bool, s: u16) -> std::cell::Cell<(bool, u16)> { + // CHECK-NOT: alloca + // CHECK: %[[BYTE:.+]] = zext i1 %b to i8 + // CHECK: %[[TEMP0:.+]] = insertvalue { i8, i16 } poison, i8 %[[BYTE]], 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i8, i16 } %[[TEMP0]], i16 %s, 1 + // CHECK: ret { i8, i16 } %[[TEMP1]] + std::cell::Cell::new((b, s)) +} + +// CHECK-LABEL: { i1, i1 } @make_tuple_of_bools(i1 noundef zeroext %a, i1 noundef zeroext %b) +#[no_mangle] +pub fn make_tuple_of_bools(a: bool, b: bool) -> (bool, bool) { + // CHECK-NOT: alloca + // CHECK: %[[TEMP0:.+]] = insertvalue { i1, i1 } poison, i1 %a, 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i1, i1 } %[[TEMP0]], i1 %b, 1 + // CHECK: ret { i1, i1 } %[[TEMP1]] + (a, b) +} + +pub struct Struct0(); + +// CHECK-LABEL: void @make_struct_0() +#[no_mangle] +pub fn make_struct_0() -> Struct0 { + // CHECK: ret void + let s = Struct0(); + s +} + +pub struct Struct1(i32); + +// CHECK-LABEL: i32 @make_struct_1(i32 noundef %a) +#[no_mangle] +pub fn make_struct_1(a: i32) -> Struct1 { + // CHECK: ret i32 %a + let s = Struct1(a); + s +} + +pub struct Struct2Asc(i16, i64); + +// CHECK-LABEL: { i64, i16 } @make_struct_2_asc(i16 noundef %a, i64 noundef %b) +#[no_mangle] +pub fn make_struct_2_asc(a: i16, b: i64) -> Struct2Asc { + // CHECK-NOT: alloca + // CHECK: %[[TEMP0:.+]] = insertvalue { i64, i16 } poison, i64 %b, 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i64, i16 } %[[TEMP0]], i16 %a, 1 + // CHECK: ret { i64, i16 } %[[TEMP1]] + let s = Struct2Asc(a, b); + s +} + +pub struct Struct2Desc(i64, i16); + +// CHECK-LABEL: { i64, i16 } @make_struct_2_desc(i64 noundef %a, i16 noundef %b) +#[no_mangle] +pub fn make_struct_2_desc(a: i64, b: i16) -> Struct2Desc { + // CHECK-NOT: alloca + // CHECK: %[[TEMP0:.+]] = insertvalue { i64, i16 } poison, i64 %a, 0 + // CHECK: %[[TEMP1:.+]] = insertvalue { i64, i16 } %[[TEMP0]], i16 %b, 1 + // CHECK: ret { i64, i16 } %[[TEMP1]] + let s = Struct2Desc(a, b); + s +} diff --git a/tests/codegen/option-niche-eq.rs b/tests/codegen/option-niche-eq.rs index 7b955332fd3..25ea5dd595c 100644 --- a/tests/codegen/option-niche-eq.rs +++ b/tests/codegen/option-niche-eq.rs @@ -7,7 +7,7 @@ use core::cmp::Ordering; use core::ptr::NonNull; use core::num::NonZero; -// CHECK-lABEL: @non_zero_eq +// CHECK-LABEL: @non_zero_eq #[no_mangle] pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool { // CHECK: start: @@ -16,7 +16,7 @@ pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool { l == r } -// CHECK-lABEL: @non_zero_signed_eq +// CHECK-LABEL: @non_zero_signed_eq #[no_mangle] pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> bool { // CHECK: start: @@ -25,7 +25,7 @@ pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> b l == r } -// CHECK-lABEL: @non_null_eq +// CHECK-LABEL: @non_null_eq #[no_mangle] pub fn non_null_eq(l: Option<NonNull<u8>>, r: Option<NonNull<u8>>) -> bool { // CHECK: start: @@ -34,7 +34,7 @@ pub fn non_null_eq(l: Option<NonNull<u8>>, r: Option<NonNull<u8>>) -> bool { l == r } -// CHECK-lABEL: @ordering_eq +// CHECK-LABEL: @ordering_eq #[no_mangle] pub fn ordering_eq(l: Option<Ordering>, r: Option<Ordering>) -> bool { // CHECK: start: @@ -54,7 +54,7 @@ pub enum EnumWithNiche { G, } -// CHECK-lABEL: @niche_eq +// CHECK-LABEL: @niche_eq #[no_mangle] pub fn niche_eq(l: Option<EnumWithNiche>, r: Option<EnumWithNiche>) -> bool { // CHECK: start: @@ -64,7 +64,7 @@ pub fn niche_eq(l: Option<EnumWithNiche>, r: Option<EnumWithNiche>) -> bool { } // FIXME: This should work too -// // FIXME-CHECK-lABEL: @bool_eq +// // FIXME-CHECK-LABEL: @bool_eq // #[no_mangle] // pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool { // // FIXME-CHECK: start: diff --git a/tests/codegen/sanitizer/no-sanitize-inlining.rs b/tests/codegen/sanitizer/no-sanitize-inlining.rs index 623bfa608ca..d5e47884f85 100644 --- a/tests/codegen/sanitizer/no-sanitize-inlining.rs +++ b/tests/codegen/sanitizer/no-sanitize-inlining.rs @@ -16,7 +16,7 @@ // ASAN: } // // LSAN-LABEL: define void @test -// LSAN-NO: call +// LSAN-NOT: call // LSAN: } #[no_mangle] pub fn test(n: &mut u32) { diff --git a/tests/codegen/simd/issue-120720-reduce-nan.rs b/tests/codegen/simd/issue-120720-reduce-nan.rs index 2c6098c0489..0372582bf7f 100644 --- a/tests/codegen/simd/issue-120720-reduce-nan.rs +++ b/tests/codegen/simd/issue-120720-reduce-nan.rs @@ -8,7 +8,7 @@ #![feature(stdarch_x86_avx512, avx512_target_feature)] use std::arch::x86_64::*; -// CHECK-label: @demo( +// CHECK-LABEL: @demo( #[no_mangle] #[target_feature(enable = "avx512f")] // Function-level target feature mismatches inhibit inlining pub unsafe fn demo() -> bool { diff --git a/tests/crashes/123911.rs b/tests/crashes/123911.rs deleted file mode 100644 index 1a4d6a79512..00000000000 --- a/tests/crashes/123911.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ known-bug: #123911 - -macro_rules! m { - ($attr_path: path) => { - #[$attr_path] - fn f() {} - } -} - -m!(inline<{ - let a = CharCharFloat { a: 1 }; - let b = rustrt::rust_dbg_abi_4(a); - println!("a: {}", b.a); -}>); - -fn main() {} diff --git a/tests/crashes/123912.rs b/tests/crashes/123912.rs deleted file mode 100644 index 35216caabcd..00000000000 --- a/tests/crashes/123912.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ known-bug: #123912 - -macro_rules! m { - ($attr_path: path) => { - #[$attr_path] - fn f() {} - } -} - -m!(inline<{ - let a = CharCharFloat { a: 1 }; - println!("a: {}", a); -}>); - -fn main() {} diff --git a/tests/crashes/124436.rs b/tests/crashes/124436.rs new file mode 100644 index 00000000000..aed830e8f0e --- /dev/null +++ b/tests/crashes/124436.rs @@ -0,0 +1,7 @@ +//@ known-bug: rust-lang/rust#124436 +//@ compile-flags: -Zdump-mir=all -Zpolymorphize=on + +pub trait TraitCat {} +pub trait TraitDog {} + +pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {} diff --git a/tests/crashes/124440.rs b/tests/crashes/124440.rs new file mode 100644 index 00000000000..431c4e444f1 --- /dev/null +++ b/tests/crashes/124440.rs @@ -0,0 +1,23 @@ +//@ known-bug: rust-lang/rust#124440 + +#![allow(warnings)] + +trait Foo {} + +impl<F> Foo for F where F: FnMut(&()) {} + +struct Bar<F> { + f: F, +} + +impl<F> Foo for Bar<F> where F: Foo {} + +fn assert_foo<F>(_: F) +where + Bar<F>: Foo, +{ +} + +fn main() { + assert_foo(|_| ()); +} diff --git a/tests/crashes/124464.rs b/tests/crashes/124464.rs new file mode 100644 index 00000000000..471479f5cf1 --- /dev/null +++ b/tests/crashes/124464.rs @@ -0,0 +1,17 @@ +//@ known-bug: rust-lang/rust #124464 +enum TestOption<T> { + TestSome(T), + TestSome(T), +} + +pub struct Request { + bar: TestOption<u64>, + bar: u8, +} + +fn default_instance() -> &'static Request { + static instance: Request = Request { bar: 17 }; + &instance +} + +pub fn main() {} diff --git a/tests/crashes/124490.rs b/tests/crashes/124490.rs new file mode 100644 index 00000000000..9f605c32cf2 --- /dev/null +++ b/tests/crashes/124490.rs @@ -0,0 +1,16 @@ +//@ known-bug: rust-lang/rust#124490 +use io::{self as std}; +use std::collections::{self as io}; + +mod a { + pub mod b { + pub mod c {} + } +} + +use a::*; + +use b::c; +use c as b; + +fn main() {} diff --git a/tests/crashes/124552.rs b/tests/crashes/124552.rs new file mode 100644 index 00000000000..5320ce27843 --- /dev/null +++ b/tests/crashes/124552.rs @@ -0,0 +1,12 @@ +//@ known-bug: rust-lang/rust#124552 + +struct B; + +struct Foo { + b: u32, + b: B, +} + +static BAR: Foo = Foo { b: B }; + +fn main() {} diff --git a/tests/crashes/124563.rs b/tests/crashes/124563.rs new file mode 100644 index 00000000000..b082739af53 --- /dev/null +++ b/tests/crashes/124563.rs @@ -0,0 +1,46 @@ +//@ known-bug: rust-lang/rust#124563 + +use std::marker::PhantomData; + +pub trait Trait {} + +pub trait Foo { + type Trait: Trait; + type Bar: Bar; + fn foo(&mut self); +} + +pub struct FooImpl<'a, 'b, A: Trait>(PhantomData<&'a &'b A>); + +impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T> +where + T: Trait, +{ + type Trait = T; + type Bar = BarImpl<'a, 'b, T>; + + fn foo(&mut self) { + self.enter_scope(|ctx| { + BarImpl(ctx); + }); + } +} + +impl<'a, 'b, T> FooImpl<'a, 'b, T> +where + T: Trait, +{ + fn enter_scope(&mut self, _scope: impl FnOnce(&mut Self)) {} +} +pub trait Bar { + type Foo: Foo; +} + +pub struct BarImpl<'a, 'b, T: Trait>(&'b mut FooImpl<'a, 'b, T>); + +impl<'a, 'b, T> Bar for BarImpl<'a, 'b, T> +where + T: Trait, +{ + type Foo = FooImpl<'a, 'b, T>; +} diff --git a/tests/crashes/124583.rs b/tests/crashes/124583.rs new file mode 100644 index 00000000000..ffd9d7521ad --- /dev/null +++ b/tests/crashes/124583.rs @@ -0,0 +1,5 @@ +//@ known-bug: rust-lang/rust#124583 + +fn main() { + let _ = -(-0.0f16); +} diff --git a/tests/crashes/124751.rs b/tests/crashes/124751.rs new file mode 100644 index 00000000000..f15e39965d3 --- /dev/null +++ b/tests/crashes/124751.rs @@ -0,0 +1,8 @@ +//@ known-bug: rust-lang/rust#124751 +//@ compile-flags: -Zunstable-options --edition=2024 + +#![feature(gen_blocks)] + +fn main() { + let _ = async gen || {}; +} diff --git a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff index 2a36ccaab11..df873600577 100644 --- a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff @@ -11,10 +11,28 @@ + scope 1 (inlined std::ptr::drop_in_place::<Vec<A>> - shim(Some(Vec<A>))) { + let mut _6: &mut std::vec::Vec<A>; + let mut _7: (); ++ scope 2 (inlined <Vec<A> as Drop>::drop) { ++ let mut _8: *mut [A]; ++ let mut _9: *mut A; ++ let mut _10: usize; ++ scope 3 (inlined Vec::<A>::as_mut_ptr) { ++ let mut _11: &alloc::raw_vec::RawVec<A>; ++ scope 4 (inlined alloc::raw_vec::RawVec::<A>::ptr) { ++ let mut _13: std::ptr::NonNull<A>; ++ scope 5 (inlined Unique::<A>::as_ptr) { ++ scope 6 (inlined NonNull::<A>::as_ptr) { ++ let mut _12: *const A; ++ } ++ } ++ } ++ } ++ scope 7 (inlined slice_from_raw_parts_mut::<A>) { ++ } ++ } + } -+ scope 2 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) { -+ let mut _8: isize; -+ let mut _9: isize; ++ scope 8 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) { ++ let mut _14: isize; ++ let mut _15: isize; + } bb0: { @@ -25,7 +43,24 @@ + StorageLive(_6); + StorageLive(_7); + _6 = &mut (*_4); -+ _7 = <Vec<A> as Drop>::drop(move _6) -> [return: bb2, unwind unreachable]; ++ StorageLive(_8); ++ StorageLive(_9); ++ StorageLive(_11); ++ _11 = &((*_6).0: alloc::raw_vec::RawVec<A>); ++ StorageLive(_13); ++ _13 = ((((*_6).0: alloc::raw_vec::RawVec<A>).0: std::ptr::Unique<A>).0: std::ptr::NonNull<A>); ++ StorageLive(_12); ++ _12 = (_13.0: *const A); ++ _9 = move _12 as *mut A (PtrToPtr); ++ StorageDead(_12); ++ StorageDead(_13); ++ StorageDead(_11); ++ StorageLive(_10); ++ _10 = ((*_6).1: usize); ++ _8 = *mut [A] from (_9, _10); ++ StorageDead(_10); ++ StorageDead(_9); ++ _7 = std::ptr::drop_in_place::<[A]>(move _8) -> [return: bb2, unwind unreachable]; } bb1: { @@ -36,19 +71,20 @@ StorageLive(_5); _5 = _2; - _0 = std::ptr::drop_in_place::<Option<B>>(move _5) -> [return: bb2, unwind unreachable]; -+ StorageLive(_8); -+ StorageLive(_9); -+ _8 = discriminant((*_5)); -+ switchInt(move _8) -> [0: bb3, otherwise: bb4]; ++ StorageLive(_14); ++ StorageLive(_15); ++ _14 = discriminant((*_5)); ++ switchInt(move _14) -> [0: bb3, otherwise: bb4]; } bb2: { ++ StorageDead(_8); + drop(((*_4).0: alloc::raw_vec::RawVec<A>)) -> [return: bb1, unwind unreachable]; + } + + bb3: { -+ StorageDead(_9); -+ StorageDead(_8); ++ StorageDead(_15); ++ StorageDead(_14); StorageDead(_5); return; + } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index ef3f4a21720..62fe1a86857 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -4,20 +4,47 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> debug slice => _1; debug index => _2; let mut _0: &mut [u32]; + let mut _3: usize; + let mut _4: usize; scope 1 (inlined core::slice::<impl [u32]>::get_unchecked_mut::<std::ops::Range<usize>>) { - let mut _3: *mut [u32]; - let mut _4: *mut [u32]; + let mut _5: *mut [u32]; + let mut _9: *mut [u32]; + scope 2 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut) { + let _6: usize; + let mut _7: *mut u32; + let mut _8: *mut u32; + scope 3 { + scope 6 (inlined std::ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { + } + scope 7 (inlined std::ptr::mut_ptr::<impl *mut u32>::add) { + } + scope 8 (inlined slice_from_raw_parts_mut::<u32>) { + } + } + scope 4 (inlined std::ptr::mut_ptr::<impl *mut [u32]>::len) { + scope 5 (inlined std::ptr::metadata::<[u32]>) { + } + } + } } bb0: { - StorageLive(_3); - _3 = &raw mut (*_1); - _4 = <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut(move _2, move _3) -> [return: bb1, unwind unreachable]; - } - - bb1: { - StorageDead(_3); - _0 = &mut (*_4); + _3 = move (_2.0: usize); + _4 = move (_2.1: usize); + StorageLive(_5); + _5 = &raw mut (*_1); + StorageLive(_6); + _6 = SubUnchecked(_4, _3); + StorageLive(_8); + StorageLive(_7); + _7 = _5 as *mut u32 (PtrToPtr); + _8 = Offset(_7, _3); + StorageDead(_7); + _9 = *mut [u32] from (_8, _6); + StorageDead(_8); + StorageDead(_6); + StorageDead(_5); + _0 = &mut (*_9); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 9e93a43ac72..62fe1a86857 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -4,20 +4,47 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> debug slice => _1; debug index => _2; let mut _0: &mut [u32]; + let mut _3: usize; + let mut _4: usize; scope 1 (inlined core::slice::<impl [u32]>::get_unchecked_mut::<std::ops::Range<usize>>) { - let mut _3: *mut [u32]; - let mut _4: *mut [u32]; + let mut _5: *mut [u32]; + let mut _9: *mut [u32]; + scope 2 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut) { + let _6: usize; + let mut _7: *mut u32; + let mut _8: *mut u32; + scope 3 { + scope 6 (inlined std::ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { + } + scope 7 (inlined std::ptr::mut_ptr::<impl *mut u32>::add) { + } + scope 8 (inlined slice_from_raw_parts_mut::<u32>) { + } + } + scope 4 (inlined std::ptr::mut_ptr::<impl *mut [u32]>::len) { + scope 5 (inlined std::ptr::metadata::<[u32]>) { + } + } + } } bb0: { - StorageLive(_3); - _3 = &raw mut (*_1); - _4 = <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut(move _2, move _3) -> [return: bb1, unwind continue]; - } - - bb1: { - StorageDead(_3); - _0 = &mut (*_4); + _3 = move (_2.0: usize); + _4 = move (_2.1: usize); + StorageLive(_5); + _5 = &raw mut (*_1); + StorageLive(_6); + _6 = SubUnchecked(_4, _3); + StorageLive(_8); + StorageLive(_7); + _7 = _5 as *mut u32 (PtrToPtr); + _8 = Offset(_7, _3); + StorageDead(_7); + _9 = *mut [u32] from (_8, _6); + StorageDead(_8); + StorageDead(_6); + StorageDead(_5); + _0 = &mut (*_9); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir index 018ff6c357d..000432ccca7 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir @@ -17,11 +17,6 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) - scope 7 (inlined std::ptr::const_ptr::<impl *const u32>::add) { } scope 8 (inlined slice_from_raw_parts::<u32>) { - let mut _8: *const (); - scope 9 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<()>) { - } - scope 10 (inlined std::ptr::from_raw_parts::<[u32]>) { - } } } scope 4 (inlined std::ptr::const_ptr::<impl *const [u32]>::len) { @@ -41,10 +36,7 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) - _6 = _1 as *const u32 (PtrToPtr); _7 = Offset(_6, _3); StorageDead(_6); - StorageLive(_8); - _8 = _7 as *const () (PtrToPtr); - _0 = *const [u32] from (_8, _5); - StorageDead(_8); + _0 = *const [u32] from (_7, _5); StorageDead(_7); StorageDead(_5); return; diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir index 018ff6c357d..000432ccca7 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir @@ -17,11 +17,6 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) - scope 7 (inlined std::ptr::const_ptr::<impl *const u32>::add) { } scope 8 (inlined slice_from_raw_parts::<u32>) { - let mut _8: *const (); - scope 9 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<()>) { - } - scope 10 (inlined std::ptr::from_raw_parts::<[u32]>) { - } } } scope 4 (inlined std::ptr::const_ptr::<impl *const [u32]>::len) { @@ -41,10 +36,7 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) - _6 = _1 as *const u32 (PtrToPtr); _7 = Offset(_6, _3); StorageDead(_6); - StorageLive(_8); - _8 = _7 as *const () (PtrToPtr); - _0 = *const [u32] from (_8, _5); - StorageDead(_8); + _0 = *const [u32] from (_7, _5); StorageDead(_7); StorageDead(_5); return; diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir index 18728d543ad..eabecaed051 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir @@ -25,7 +25,7 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { scope 6 (inlined std::slice::from_raw_parts::<'_, u8>) { debug data => _4; debug len => _5; - let _7: *const [u8]; + let _6: *const [u8]; scope 7 (inlined core::ub_checks::check_language_ub) { scope 8 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -37,14 +37,6 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { scope 11 (inlined slice_from_raw_parts::<u8>) { debug data => _4; debug len => _5; - let mut _6: *const (); - scope 12 (inlined std::ptr::const_ptr::<impl *const u8>::cast::<()>) { - debug self => _4; - } - scope 13 (inlined std::ptr::from_raw_parts::<[u8]>) { - debug data_pointer => _6; - debug metadata => _5; - } } } } @@ -60,13 +52,10 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { StorageDead(_2); StorageLive(_5); _5 = ((*_1).1: usize); - StorageLive(_6); - _6 = _4 as *const () (PtrToPtr); - _7 = *const [u8] from (_6, _5); - StorageDead(_6); + _6 = *const [u8] from (_4, _5); StorageDead(_5); StorageDead(_4); - _0 = &(*_7); + _0 = &(*_6); return; } } diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir index 18728d543ad..eabecaed051 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir @@ -25,7 +25,7 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { scope 6 (inlined std::slice::from_raw_parts::<'_, u8>) { debug data => _4; debug len => _5; - let _7: *const [u8]; + let _6: *const [u8]; scope 7 (inlined core::ub_checks::check_language_ub) { scope 8 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -37,14 +37,6 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { scope 11 (inlined slice_from_raw_parts::<u8>) { debug data => _4; debug len => _5; - let mut _6: *const (); - scope 12 (inlined std::ptr::const_ptr::<impl *const u8>::cast::<()>) { - debug self => _4; - } - scope 13 (inlined std::ptr::from_raw_parts::<[u8]>) { - debug data_pointer => _6; - debug metadata => _5; - } } } } @@ -60,13 +52,10 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] { StorageDead(_2); StorageLive(_5); _5 = ((*_1).1: usize); - StorageLive(_6); - _6 = _4 as *const () (PtrToPtr); - _7 = *const [u8] from (_6, _5); - StorageDead(_6); + _6 = *const [u8] from (_4, _5); StorageDead(_5); StorageDead(_4); - _0 = &(*_7); + _0 = &(*_6); return; } } diff --git a/tests/run-make/alloc-no-oom-handling/Makefile b/tests/run-make/alloc-no-oom-handling/Makefile index 87f74c69c79..7c3ae90b58d 100644 --- a/tests/run-make/alloc-no-oom-handling/Makefile +++ b/tests/run-make/alloc-no-oom-handling/Makefile @@ -1,3 +1,6 @@ +# This test checks that alloc can still compile correctly when the unstable no_global_oom_handling feature is turned on. +# See https://github.com/rust-lang/rust/pull/84266 + include ../tools.mk all: diff --git a/tests/run-make/alloc-no-rc/Makefile b/tests/run-make/alloc-no-rc/Makefile index 9824b17e6c2..fcfe1603b6c 100644 --- a/tests/run-make/alloc-no-rc/Makefile +++ b/tests/run-make/alloc-no-rc/Makefile @@ -1,3 +1,6 @@ +# This test checks that alloc can still compile correctly when the unstable no_rc feature is turned on. +# See https://github.com/rust-lang/rust/pull/89891 + include ../tools.mk all: diff --git a/tests/run-make/alloc-no-sync/Makefile b/tests/run-make/alloc-no-sync/Makefile index 04ec4c7d8bc..997dbcf6603 100644 --- a/tests/run-make/alloc-no-sync/Makefile +++ b/tests/run-make/alloc-no-sync/Makefile @@ -1,3 +1,6 @@ +# This test checks that alloc can still compile correctly when the unstable no_sync feature is turned on. +# See https://github.com/rust-lang/rust/pull/89891 + include ../tools.mk all: diff --git a/tests/run-make/allocator-shim-circular-deps/Makefile b/tests/run-make/allocator-shim-circular-deps/Makefile index 4624b846803..f667e2e2ec2 100644 --- a/tests/run-make/allocator-shim-circular-deps/Makefile +++ b/tests/run-make/allocator-shim-circular-deps/Makefile @@ -1,3 +1,8 @@ +# This test is designed to intentionally introduce a circular dependency scenario to check that a specific compiler bug doesn't make a resurgence. +# The bug in question arose when at least one crate required a global allocator, and that crate was placed after the one defining it in the linker order. +# The generated symbols.o should not result in any linker errors. +# See https://github.com/rust-lang/rust/issues/112715 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/archive-duplicate-names/Makefile b/tests/run-make/archive-duplicate-names/Makefile index 5433a42d252..207eee39299 100644 --- a/tests/run-make/archive-duplicate-names/Makefile +++ b/tests/run-make/archive-duplicate-names/Makefile @@ -1,3 +1,7 @@ +# When two object archives with the same filename are present, an iterator is supposed to inspect each object, recognize the duplication and extract each one to a different directory. +# This test checks that this duplicate handling behaviour has not been broken. +# See https://github.com/rust-lang/rust/pull/24439 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/bare-outfile/Makefile b/tests/run-make/bare-outfile/Makefile index 23b619ea0ba..ad6fe4bd167 100644 --- a/tests/run-make/bare-outfile/Makefile +++ b/tests/run-make/bare-outfile/Makefile @@ -1,3 +1,5 @@ +# This test checks that manually setting the output file as a bare file with no file extension still results in successful compilation. + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-dynamic-dylib/Makefile b/tests/run-make/c-dynamic-dylib/Makefile index b5bfbc76539..0d409640486 100644 --- a/tests/run-make/c-dynamic-dylib/Makefile +++ b/tests/run-make/c-dynamic-dylib/Makefile @@ -1,3 +1,6 @@ +# This test checks that dynamic Rust linking with C does not encounter any errors, with dynamic dependencies given preference over static. +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-dynamic-rlib/Makefile b/tests/run-make/c-dynamic-rlib/Makefile index 0475bd8acae..a64e89cc0dc 100644 --- a/tests/run-make/c-dynamic-rlib/Makefile +++ b/tests/run-make/c-dynamic-rlib/Makefile @@ -1,3 +1,6 @@ +# This test checks that dynamic Rust linking with C does not encounter any errors, with static dependencies given preference over dynamic. (This is the default behaviour.) +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-link-to-rust-dylib/Makefile b/tests/run-make/c-link-to-rust-dylib/Makefile index 2763cb6ed1d..201f717ece4 100644 --- a/tests/run-make/c-link-to-rust-dylib/Makefile +++ b/tests/run-make/c-link-to-rust-dylib/Makefile @@ -1,3 +1,6 @@ +# This test checks that C linking with Rust does not encounter any errors, with dynamic libraries. +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-link-to-rust-staticlib/Makefile b/tests/run-make/c-link-to-rust-staticlib/Makefile index e14775f5c18..d36cc421c46 100644 --- a/tests/run-make/c-link-to-rust-staticlib/Makefile +++ b/tests/run-make/c-link-to-rust-staticlib/Makefile @@ -1,3 +1,6 @@ +# This test checks that C linking with Rust does not encounter any errors, with static libraries. +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-static-dylib/Makefile b/tests/run-make/c-static-dylib/Makefile index 4e23edb6c57..05da1743c83 100644 --- a/tests/run-make/c-static-dylib/Makefile +++ b/tests/run-make/c-static-dylib/Makefile @@ -1,3 +1,6 @@ +# This test checks that static Rust linking with C does not encounter any errors, with dynamic dependencies given preference over static. +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-static-rlib/Makefile b/tests/run-make/c-static-rlib/Makefile index 4e351127cb6..298e432cdb8 100644 --- a/tests/run-make/c-static-rlib/Makefile +++ b/tests/run-make/c-static-rlib/Makefile @@ -1,3 +1,6 @@ +# This test checks that static Rust linking with C does not encounter any errors, with static dependencies given preference over dynamic. (This is the default behaviour.) +# See https://github.com/rust-lang/rust/issues/10434 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile b/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile index b8e0e9483cd..2bb8d42495d 100644 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile @@ -1,3 +1,6 @@ +# Exercise unwinding a panic. This catches a panic across an FFI boundary and downcasts it into an integer. The Rust code that panics is in a separate crate. +# See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb + # ignore-cross-compile # needs-unwind include ../tools.mk diff --git a/tests/run-make/c-unwind-abi-catch-panic/Makefile b/tests/run-make/c-unwind-abi-catch-panic/Makefile index 1760ddb3061..0a38d838e32 100644 --- a/tests/run-make/c-unwind-abi-catch-panic/Makefile +++ b/tests/run-make/c-unwind-abi-catch-panic/Makefile @@ -1,3 +1,6 @@ +# Exercise unwinding a panic. This catches a panic across an FFI boundary and downcasts it into an integer. The Rust code that panics is in the same directory. +# See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb + # ignore-cross-compile # needs-unwind include ../tools.mk diff --git a/tests/run-make/cat-and-grep-sanity-check/Makefile b/tests/run-make/cat-and-grep-sanity-check/Makefile index 82351e22009..8ee69c0a0de 100644 --- a/tests/run-make/cat-and-grep-sanity-check/Makefile +++ b/tests/run-make/cat-and-grep-sanity-check/Makefile @@ -1,3 +1,7 @@ +# grep in run-make tests was partially replaced with a custom script, CGREP. This tests that CGREP does its job correctly. +# See https://github.com/rust-lang/rust/commit/ab788a2ee175c7560f0ca58bbc183ecfd57d2f7a +# FIXME(Oneirical): Note that this test will likely become useless after the port to rmake.rs tests (see https://github.com/rust-lang/rust/issues/121876) + include ../tools.mk all: diff --git a/tests/run-make/cdylib-dylib-linkage/Makefile b/tests/run-make/cdylib-dylib-linkage/Makefile index 51fbfef2d85..db8393d3c05 100644 --- a/tests/run-make/cdylib-dylib-linkage/Makefile +++ b/tests/run-make/cdylib-dylib-linkage/Makefile @@ -1,3 +1,6 @@ +# This test checks that cdylibs can link against dylibs as dependencies, after this restriction was disabled. +# See https://github.com/rust-lang/rust/commit/72aaa3a414d17aa0c4f19feafa5bab5f84b60e63 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/cdylib-fewer-symbols/Makefile b/tests/run-make/cdylib-fewer-symbols/Makefile index 4e08f979c36..d587cece5be 100644 --- a/tests/run-make/cdylib-fewer-symbols/Makefile +++ b/tests/run-make/cdylib-fewer-symbols/Makefile @@ -1,6 +1,8 @@ # ignore-cross-compile + # Test that allocator-related symbols don't show up as exported from a cdylib as # they're internal to Rust and not part of the public ABI. +# See https://github.com/rust-lang/rust/commit/fbf98697021173a30b84d9145df0966a23a2f9d2 include ../tools.mk diff --git a/tests/run-make/cdylib/Makefile b/tests/run-make/cdylib/Makefile index 3c8b5269554..2c6414c3255 100644 --- a/tests/run-make/cdylib/Makefile +++ b/tests/run-make/cdylib/Makefile @@ -1,3 +1,6 @@ +# When the cdylib crate type was added as a variation of dylib, it needed a test to check its function. +# See https://github.com/rust-lang/rust/pull/33553 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/codegen-options-parsing/Makefile b/tests/run-make/codegen-options-parsing/Makefile index 56bb900b7d8..beaf233502b 100644 --- a/tests/run-make/codegen-options-parsing/Makefile +++ b/tests/run-make/codegen-options-parsing/Makefile @@ -1,3 +1,5 @@ +# This test intentionally feeds invalid inputs to codegen and checks if the error message outputs contain specific helpful indications. + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/comment-section/Makefile b/tests/run-make/comment-section/Makefile index 9f810063cc8..d0b98176ffe 100644 --- a/tests/run-make/comment-section/Makefile +++ b/tests/run-make/comment-section/Makefile @@ -1,3 +1,6 @@ +# Both GCC and Clang write by default a `.comment` section with compiler information. Rustc received a similar .comment section, so this tests checks that this section properly appears. +# See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc + include ../tools.mk # only-linux diff --git a/tests/run-make/compile-stdin/Makefile b/tests/run-make/compile-stdin/Makefile index 2a495281c24..b3d7cc777a0 100644 --- a/tests/run-make/compile-stdin/Makefile +++ b/tests/run-make/compile-stdin/Makefile @@ -1,3 +1,6 @@ +# When provided standard input piped directly into rustc, this test checks that the compilation completes successfully and that the output can be executed. +# See https://github.com/rust-lang/rust/pull/28805 + # ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/compiler-lookup-paths-2/Makefile b/tests/run-make/compiler-lookup-paths-2/Makefile index d4ff7d8daab..ecc0577384a 100644 --- a/tests/run-make/compiler-lookup-paths-2/Makefile +++ b/tests/run-make/compiler-lookup-paths-2/Makefile @@ -1,3 +1,6 @@ +# This test checks that extern crate declarations in Cargo without a corresponding declaration in the manifest of a dependency are NOT allowed. +# See https://github.com/rust-lang/rust/pull/21113 + include ../tools.mk all: diff --git a/tests/run-make/compiler-lookup-paths/Makefile b/tests/run-make/compiler-lookup-paths/Makefile index 310d6772c34..fc0cbde4c35 100644 --- a/tests/run-make/compiler-lookup-paths/Makefile +++ b/tests/run-make/compiler-lookup-paths/Makefile @@ -1,3 +1,6 @@ +# rustc supports different types of lookup paths, such as dependency, native or crate. This test checks that these lookup paths are functional and result in functional compilation. +# See https://github.com/rust-lang/rust/pull/19941 + include ../tools.mk # ignore-wasm32 (need a C compiler) diff --git a/tests/run-make/libtest-padding/Makefile b/tests/run-make/libtest-padding/Makefile index 42bc1192925..c8e2fc01f67 100644 --- a/tests/run-make/libtest-padding/Makefile +++ b/tests/run-make/libtest-padding/Makefile @@ -2,7 +2,7 @@ # needs-unwind because #[bench] and -Cpanic=abort requires -Zpanic-abort-tests include ../tools.mk -NORMALIZE=sed 's%[0-9,]\{1,\} ns/iter (+/- [0-9,]\{1,\})%?? ns/iter (+/- ??)%' | sed 's%finished in [0-9\.]\{1,\}%finished in ??%' +NORMALIZE=sed 's%[0-9,\.]\{1,\} ns/iter (+/- [0-9,\.]\{1,\})%?? ns/iter (+/- ??)%' | sed 's%finished in [0-9\.]\{1,\}%finished in ??%' all: $(RUSTC) --test tests.rs diff --git a/tests/run-make/rustdoc-map-file/Makefile b/tests/run-make/rustdoc-map-file/Makefile deleted file mode 100644 index 5cbf7747af6..00000000000 --- a/tests/run-make/rustdoc-map-file/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../tools.mk - -all: - $(RUSTDOC) -Z unstable-options --generate-redirect-map foo.rs -o "$(TMPDIR)/out" - "$(PYTHON)" validate_json.py "$(TMPDIR)/out" diff --git a/tests/run-make/rustdoc-map-file/rmake.rs b/tests/run-make/rustdoc-map-file/rmake.rs new file mode 100644 index 00000000000..aaa7fea0b6b --- /dev/null +++ b/tests/run-make/rustdoc-map-file/rmake.rs @@ -0,0 +1,15 @@ +use run_make_support::{rustdoc, tmp_dir}; +use std::process::Command; + +fn main() { + let out_dir = tmp_dir().join("out"); + rustdoc() + .input("foo.rs") + .arg("-Zunstable-options") + .arg("--generate-redirect-map") + .output(&out_dir) + .run(); + // FIXME (GuillaumeGomez): Port the python script to Rust as well. + let python = std::env::var("PYTHON").unwrap_or("python".into()); + assert!(Command::new(python).arg("validate_json.py").arg(&out_dir).status().unwrap().success()); +} diff --git a/tests/run-make/rustdoc-output-path/Makefile b/tests/run-make/rustdoc-output-path/Makefile deleted file mode 100644 index 8f5cda9e56e..00000000000 --- a/tests/run-make/rustdoc-output-path/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include ../tools.mk - -all: - $(RUSTDOC) -o "$(TMPDIR)/foo/bar/doc" foo.rs diff --git a/tests/run-make/rustdoc-output-path/rmake.rs b/tests/run-make/rustdoc-output-path/rmake.rs new file mode 100644 index 00000000000..74fb0a56ac6 --- /dev/null +++ b/tests/run-make/rustdoc-output-path/rmake.rs @@ -0,0 +1,9 @@ +// Checks that if the output folder doesn't exist, rustdoc will create it. + +use run_make_support::{rustdoc, tmp_dir}; + +fn main() { + let out_dir = tmp_dir().join("foo/bar/doc"); + rustdoc().input("foo.rs").output(&out_dir).run(); + assert!(out_dir.exists()); +} diff --git a/tests/run-make/rustdoc-shared-flags/Makefile b/tests/run-make/rustdoc-shared-flags/Makefile deleted file mode 100644 index a2a7d7b3634..00000000000 --- a/tests/run-make/rustdoc-shared-flags/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -include ../tools.mk - -all: z_help c_help list_passes - -c_help: - $(RUSTC) -C help > $(TMPDIR)/rustc.c_help.txt - $(RUSTDOC) -C help > $(TMPDIR)/rustdoc.c_help.txt - $(DIFF) $(TMPDIR)/rustc.c_help.txt $(TMPDIR)/rustdoc.c_help.txt - -z_help: - $(RUSTC) -Z help > $(TMPDIR)/rustc.z_help.txt - $(RUSTDOC) -Z help > $(TMPDIR)/rustdoc.z_help.txt - $(DIFF) $(TMPDIR)/rustc.z_help.txt $(TMPDIR)/rustdoc.z_help.txt - -list_passes: - $(RUSTC) -C passes=list > $(TMPDIR)/rustc.passes.txt - $(RUSTDOC) -C passes=list > $(TMPDIR)/rustdoc.passes.txt - $(DIFF) $(TMPDIR)/rustc.passes.txt $(TMPDIR)/rustdoc.passes.txt diff --git a/tests/run-make/rustdoc-shared-flags/rmake.rs b/tests/run-make/rustdoc-shared-flags/rmake.rs new file mode 100644 index 00000000000..2db613f7817 --- /dev/null +++ b/tests/run-make/rustdoc-shared-flags/rmake.rs @@ -0,0 +1,14 @@ +use run_make_support::{rustc, rustdoc, Diff}; + +fn compare_outputs(args: &[&str]) { + let rustc_output = String::from_utf8(rustc().args(args).command_output().stdout).unwrap(); + let rustdoc_output = String::from_utf8(rustdoc().args(args).command_output().stdout).unwrap(); + + Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run(); +} + +fn main() { + compare_outputs(&["-C", "help"]); + compare_outputs(&["-Z", "help"]); + compare_outputs(&["-C", "passes=list"]); +} diff --git a/tests/rustdoc-ui/issues/issue-91713.stdout b/tests/rustdoc-ui/issues/issue-91713.stdout index bbea7e5c212..cc3c8385d9a 100644 --- a/tests/rustdoc-ui/issues/issue-91713.stdout +++ b/tests/rustdoc-ui/issues/issue-91713.stdout @@ -1,6 +1,7 @@ Available passes for running rustdoc: check-custom-code-classes - check for custom code classes without the feature-gate enabled check_doc_test_visibility - run various visibility-related lints on doctests +strip-aliased-non-local - strips all non-local private aliased items from the output strip-hidden - strips all `#[doc(hidden)]` items from the output strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports strip-priv-imports - strips all private import statements (`use`, `extern crate`) from a crate @@ -14,6 +15,7 @@ Default passes for rustdoc: check-custom-code-classes collect-trait-impls check_doc_test_visibility +strip-aliased-non-local strip-hidden (when not --document-hidden-items) strip-private (when not --document-private-items) strip-priv-imports (when --document-private-items) diff --git a/tests/rustdoc/private-non-local-fields-2.rs b/tests/rustdoc/private-non-local-fields-2.rs new file mode 100644 index 00000000000..615b957f697 --- /dev/null +++ b/tests/rustdoc/private-non-local-fields-2.rs @@ -0,0 +1,11 @@ +//! This test makes sure that with never show the inner fields in the +//! aliased type view of type alias. + +//@ compile-flags: -Z unstable-options --document-private-items + +#![crate_name = "foo"] + +use std::collections::BTreeMap; + +// @has 'foo/type.FooBar.html' '//*[@class="rust item-decl"]/code' 'struct FooBar { /* private fields */ }' +pub type FooBar = BTreeMap<u32, String>; diff --git a/tests/rustdoc/private-non-local-fields.rs b/tests/rustdoc/private-non-local-fields.rs new file mode 100644 index 00000000000..7922ce074dd --- /dev/null +++ b/tests/rustdoc/private-non-local-fields.rs @@ -0,0 +1,9 @@ +//! This test makes sure that with never show the inner fields in the +//! aliased type view of type alias. + +#![crate_name = "foo"] + +use std::collections::BTreeMap; + +// @has 'foo/type.FooBar.html' '//*[@class="rust item-decl"]/code' 'struct FooBar { /* private fields */ }' +pub type FooBar = BTreeMap<u32, String>; diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 475a69f4ad0..2b1fec94387 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -180,7 +180,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { 18 => { let pat = P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None }); - iter_exprs(depth - 1, &mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, None))) + iter_exprs( + depth - 1, + &mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No)) + ) } _ => panic!("bad counter value in iter_exprs"), } diff --git a/tests/ui-fulldeps/stable-mir/check_abi.rs b/tests/ui-fulldeps/stable-mir/check_abi.rs index 74801e007c4..359dd4146ba 100644 --- a/tests/ui-fulldeps/stable-mir/check_abi.rs +++ b/tests/ui-fulldeps/stable-mir/check_abi.rs @@ -99,7 +99,7 @@ fn check_result(abi: &ArgAbi) { assert_matches!(layout.variants, VariantsShape::Multiple { .. }) } -/// Check the niche information about: `NonZeroU8` +/// Checks the niche information about `NonZero<u8>`. fn check_niche(abi: &ArgAbi) { assert!(abi.ty.kind().is_struct()); assert_matches!(abi.mode, PassMode::Direct { .. }); @@ -150,12 +150,12 @@ fn generate_input(path: &str) -> std::io::Result<()> { #![feature(c_variadic)] #![allow(unused_variables)] - use std::num::NonZeroU8; + use std::num::NonZero; pub fn fn_abi( ignore: [u8; 0], primitive: char, - niche: NonZeroU8, + niche: NonZero<u8>, ) -> Result<usize, &'static str> {{ // We only care about the signature. todo!() diff --git a/tests/ui/abi/debug.stderr b/tests/ui/abi/debug.stderr index 00fc7d1ece1..7365839da89 100644 --- a/tests/ui/abi/debug.stderr +++ b/tests/ui/abi/debug.stderr @@ -576,7 +576,9 @@ error: ABIs are not compatible }, abi: Scalar( Initialized { - value: F32, + value: Float( + F32, + ), valid_range: $FULL, }, ), diff --git a/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs b/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs index 9c61518b941..6b218771096 100644 --- a/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs +++ b/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs @@ -1,28 +1,21 @@ #![crate_name = "externcallback"] #![crate_type = "lib"] -#![feature(rustc_private)] -extern crate libc; - -pub mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern "C" { - pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; - } +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_call( + cb: extern "C" fn(u64) -> u64, + data: u64, + ) -> u64; } -pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +pub fn fact(n: u64) -> u64 { unsafe { println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) + rust_dbg_call(cb, n) } } -pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +pub extern "C" fn cb(data: u64) -> u64 { if data == 1 { data } else { fact(data - 1) * data } } diff --git a/tests/ui/abi/extern/extern-call-deep.rs b/tests/ui/abi/extern/extern-call-deep.rs index 062e70b1b6e..40457ae5720 100644 --- a/tests/ui/abi/extern/extern-call-deep.rs +++ b/tests/ui/abi/extern/extern-call-deep.rs @@ -1,35 +1,27 @@ //@ run-pass //@ ignore-emscripten blows the JS stack -#![feature(rustc_private)] - -extern crate libc; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern "C" { - pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; - } +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_call( + cb: extern "C" fn(u64) -> u64, + data: u64, + ) -> u64; } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: u64) -> u64 { if data == 1 { data } else { count(data - 1) + 1 } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: u64) -> u64 { unsafe { println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) + rust_dbg_call(cb, n) } } pub fn main() { let result = count(1000); - println!("result = {}", result); + println!("result = {:?}", result); assert_eq!(result, 1000); } diff --git a/tests/ui/abi/extern/extern-call-deep2.rs b/tests/ui/abi/extern/extern-call-deep2.rs index c021bc22348..91ca28d80c8 100644 --- a/tests/ui/abi/extern/extern-call-deep2.rs +++ b/tests/ui/abi/extern/extern-call-deep2.rs @@ -1,31 +1,24 @@ //@ run-pass -#![allow(unused_must_use)] //@ needs-threads -#![feature(rustc_private)] -extern crate libc; use std::thread; -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern "C" { - pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; - } +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_call( + cb: extern "C" fn(u64) -> u64, + data: u64, + ) -> u64; } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { data } else { count(data - 1) + 1 } +extern "C" fn cb(data: u64) -> u64 { + if data == 1 { data } else { count(data - 1 ) + 1 } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: u64) -> u64 { unsafe { println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) + rust_dbg_call(cb, n) } } @@ -37,5 +30,5 @@ pub fn main() { println!("result = {}", result); assert_eq!(result, 1000); }) - .join(); + .join().unwrap(); } diff --git a/tests/ui/abi/extern/extern-call-indirect.rs b/tests/ui/abi/extern/extern-call-indirect.rs index 18fb07d8c8b..ef1e8ae5e76 100644 --- a/tests/ui/abi/extern/extern-call-indirect.rs +++ b/tests/ui/abi/extern/extern-call-indirect.rs @@ -1,29 +1,21 @@ //@ run-pass -#![feature(rustc_private)] - -extern crate libc; - -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern "C" { - pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; - } +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_call( + cb: extern "C" fn(u64) -> u64, + data: u64, + ) -> u64; } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: u64) -> u64 { if data == 1 { data } else { fact(data - 1) * data } } -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +fn fact(n: u64) -> u64 { unsafe { println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) + rust_dbg_call(cb, n) } } diff --git a/tests/ui/abi/extern/extern-call-scrub.rs b/tests/ui/abi/extern/extern-call-scrub.rs index 7edf8975ad8..7df3a8f04ef 100644 --- a/tests/ui/abi/extern/extern-call-scrub.rs +++ b/tests/ui/abi/extern/extern-call-scrub.rs @@ -1,35 +1,27 @@ //@ run-pass -#![allow(unused_must_use)] +//@ needs-threads // This time we're testing repeatedly going up and down both stacks to // make sure the stack pointers are maintained properly in both // directions -//@ needs-threads -#![feature(rustc_private)] - -extern crate libc; use std::thread; -mod rustrt { - extern crate libc; - - #[link(name = "rust_test_helpers", kind = "static")] - extern "C" { - pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; - } +#[link(name = "rust_test_helpers", kind = "static")] +extern "C" { + pub fn rust_dbg_call( + cb: extern "C" fn(u64) -> u64, + data: u64, + ) -> u64; } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: u64) -> u64 { if data == 1 { data } else { count(data - 1) + count(data - 1) } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: u64) -> u64 { unsafe { println!("n = {}", n); - rustrt::rust_dbg_call(cb, n) + rust_dbg_call(cb, n) } } @@ -41,5 +33,5 @@ pub fn main() { println!("result = {}", result); assert_eq!(result, 2048); }) - .join(); + .join().unwrap(); } diff --git a/tests/ui/abi/extern/extern-crosscrate.rs b/tests/ui/abi/extern/extern-crosscrate.rs index c283cbe3216..b467d992984 100644 --- a/tests/ui/abi/extern/extern-crosscrate.rs +++ b/tests/ui/abi/extern/extern-crosscrate.rs @@ -1,15 +1,12 @@ //@ run-pass //@ aux-build:extern-crosscrate-source.rs -#![feature(rustc_private)] - extern crate externcallback; -extern crate libc; -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +fn fact(n: u64) -> u64 { unsafe { - println!("n = {}", n); - externcallback::rustrt::rust_dbg_call(externcallback::cb, n) + println!("n = {:?}", n); + externcallback::rust_dbg_call(externcallback::cb, n) } } diff --git a/tests/ui/abi/foreign/foreign-call-no-runtime.rs b/tests/ui/abi/foreign/foreign-call-no-runtime.rs deleted file mode 100644 index fccd62b6100..00000000000 --- a/tests/ui/abi/foreign/foreign-call-no-runtime.rs +++ /dev/null @@ -1,60 +0,0 @@ -//@ run-pass -//@ needs-threads - -#![feature(rustc_private)] - -extern crate libc; - -use std::mem; -use std::thread; - -#[link(name = "rust_test_helpers", kind = "static")] -extern "C" { - fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), data: libc::uintptr_t) -> libc::uintptr_t; -} - -pub fn main() { - unsafe { - thread::spawn(move || { - let i: isize = 100; - rust_dbg_call(callback_isize, mem::transmute(&i)); - }) - .join() - .unwrap(); - - thread::spawn(move || { - let i: i32 = 100; - rust_dbg_call(callback_i32, mem::transmute(&i)); - }) - .join() - .unwrap(); - - thread::spawn(move || { - let i: i64 = 100; - rust_dbg_call(callback_i64, mem::transmute(&i)); - }) - .join() - .unwrap(); - } -} - -extern "C" fn callback_isize(data: libc::uintptr_t) { - unsafe { - let data = data as *const isize; - assert_eq!(*data, 100); - } -} - -extern "C" fn callback_i64(data: libc::uintptr_t) { - unsafe { - let data = data as *const i64; - assert_eq!(*data, 100); - } -} - -extern "C" fn callback_i32(data: libc::uintptr_t) { - unsafe { - let data = data as *const i32; - assert_eq!(*data, 100); - } -} diff --git a/tests/ui/associated-types/bound-lifetime-constrained.ok.stderr b/tests/ui/associated-types/bound-lifetime-constrained.ok.stderr new file mode 100644 index 00000000000..9082044fe06 --- /dev/null +++ b/tests/ui/associated-types/bound-lifetime-constrained.ok.stderr @@ -0,0 +1,8 @@ +error: fatal error triggered by #[rustc_error] + --> $DIR/bound-lifetime-constrained.rs:48:1 + | +LL | fn main() { } + | ^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/associated-types/bound-lifetime-constrained.rs b/tests/ui/associated-types/bound-lifetime-constrained.rs index 880d350bdf6..1dc3b2f5c2b 100644 --- a/tests/ui/associated-types/bound-lifetime-constrained.rs +++ b/tests/ui/associated-types/bound-lifetime-constrained.rs @@ -1,4 +1,4 @@ -//@ revisions: func object clause +//@ revisions: func object clause ok #![allow(dead_code)] #![feature(rustc_attrs)] diff --git a/tests/ui/async-await/async-block-control-flow-static-semantics.rs b/tests/ui/async-await/async-block-control-flow-static-semantics.rs index 0ef7cb7574a..6e04c535cf1 100644 --- a/tests/ui/async-await/async-block-control-flow-static-semantics.rs +++ b/tests/ui/async-await/async-block-control-flow-static-semantics.rs @@ -29,14 +29,14 @@ async fn return_targets_async_block_not_async_fn() -> u8 { fn no_break_in_async_block() { async { - break 0u8; //~ ERROR `break` inside of an `async` block + break 0u8; //~ ERROR `break` inside `async` block }; } fn no_break_in_async_block_even_with_outer_loop() { loop { async { - break 0u8; //~ ERROR `break` inside of an `async` block + break 0u8; //~ ERROR `break` inside `async` block }; } } diff --git a/tests/ui/async-await/async-block-control-flow-static-semantics.stderr b/tests/ui/async-await/async-block-control-flow-static-semantics.stderr index c89671cc481..ce0d003f014 100644 --- a/tests/ui/async-await/async-block-control-flow-static-semantics.stderr +++ b/tests/ui/async-await/async-block-control-flow-static-semantics.stderr @@ -1,18 +1,18 @@ -error[E0267]: `break` inside of an `async` block +error[E0267]: `break` inside `async` block --> $DIR/async-block-control-flow-static-semantics.rs:32:9 | LL | / async { LL | | break 0u8; - | | ^^^^^^^^^ cannot `break` inside of an `async` block + | | ^^^^^^^^^ cannot `break` inside `async` block LL | | }; | |_____- enclosing `async` block -error[E0267]: `break` inside of an `async` block +error[E0267]: `break` inside `async` block --> $DIR/async-block-control-flow-static-semantics.rs:39:13 | LL | / async { LL | | break 0u8; - | | ^^^^^^^^^ cannot `break` inside of an `async` block + | | ^^^^^^^^^ cannot `break` inside `async` block LL | | }; | |_________- enclosing `async` block diff --git a/tests/ui/attributes/nonterminal-expansion.rs b/tests/ui/attributes/nonterminal-expansion.rs index 6db7aea0745..1b2e92a3170 100644 --- a/tests/ui/attributes/nonterminal-expansion.rs +++ b/tests/ui/attributes/nonterminal-expansion.rs @@ -5,7 +5,7 @@ macro_rules! pass_nonterminal { ($n:expr) => { #[repr(align($n))] - //~^ ERROR expected unsuffixed literal or identifier, found `n!()` + //~^ ERROR expected unsuffixed literal, found `n!()` struct S; }; } diff --git a/tests/ui/attributes/nonterminal-expansion.stderr b/tests/ui/attributes/nonterminal-expansion.stderr index 78541495b32..b640575d17d 100644 --- a/tests/ui/attributes/nonterminal-expansion.stderr +++ b/tests/ui/attributes/nonterminal-expansion.stderr @@ -1,4 +1,4 @@ -error: expected unsuffixed literal or identifier, found `n!()` +error: expected unsuffixed literal, found `n!()` --> $DIR/nonterminal-expansion.rs:7:22 | LL | #[repr(align($n))] diff --git a/tests/ui/borrowck/two-phase-activation-sharing-interference.nll_target.stderr b/tests/ui/borrowck/two-phase-activation-sharing-interference.nll_target.stderr index aacf178932e..6cd64c58cab 100644 --- a/tests/ui/borrowck/two-phase-activation-sharing-interference.nll_target.stderr +++ b/tests/ui/borrowck/two-phase-activation-sharing-interference.nll_target.stderr @@ -1,5 +1,5 @@ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-activation-sharing-interference.rs:28:15 + --> $DIR/two-phase-activation-sharing-interference.rs:29:15 | LL | let y = &mut x; | ------ mutable borrow occurs here @@ -10,7 +10,7 @@ LL | *y += 1; | ------- mutable borrow later used here error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-activation-sharing-interference.rs:36:13 + --> $DIR/two-phase-activation-sharing-interference.rs:37:13 | LL | let y = &mut x; | ------ mutable borrow occurs here @@ -32,7 +32,7 @@ LL | *y += 1; | ------- mutable borrow later used here error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-activation-sharing-interference.rs:58:14 + --> $DIR/two-phase-activation-sharing-interference.rs:56:14 | LL | let y = &mut x; | ------ mutable borrow occurs here diff --git a/tests/ui/borrowck/two-phase-activation-sharing-interference.rs b/tests/ui/borrowck/two-phase-activation-sharing-interference.rs index beee9916fca..1b4526a13a8 100644 --- a/tests/ui/borrowck/two-phase-activation-sharing-interference.rs +++ b/tests/ui/borrowck/two-phase-activation-sharing-interference.rs @@ -1,6 +1,7 @@ //@ revisions: nll_target // The following revisions are disabled due to missing support from two-phase beyond autorefs +//@ unused-revision-names: nll_beyond //@[nll_beyond] compile-flags: -Z two-phase-beyond-autoref // This is an important corner case pointed out by Niko: one is @@ -36,8 +37,7 @@ fn not_ok() { let z = &x; //[nll_target]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable *y += 1; - //[lxl_beyond]~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable - //[nll_beyond]~^^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable + //[nll_beyond]~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable read(z); } @@ -48,8 +48,6 @@ fn should_be_ok_with_nll() { //[nll_target]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable read(z); *y += 1; - //[lxl_beyond]~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable - // (okay with (generalized) nll today) } fn should_also_eventually_be_ok_with_nll() { @@ -58,8 +56,6 @@ fn should_also_eventually_be_ok_with_nll() { let _z = &x; //[nll_target]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable *y += 1; - //[lxl_beyond]~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable - // (okay with (generalized) nll today) } fn main() { } diff --git a/tests/ui/borrowck/two-phase-allow-access-during-reservation.nll_target.stderr b/tests/ui/borrowck/two-phase-allow-access-during-reservation.nll_target.stderr index 1356c80493c..b7a1de02a4f 100644 --- a/tests/ui/borrowck/two-phase-allow-access-during-reservation.nll_target.stderr +++ b/tests/ui/borrowck/two-phase-allow-access-during-reservation.nll_target.stderr @@ -1,5 +1,5 @@ error[E0503]: cannot use `i` because it was mutably borrowed - --> $DIR/two-phase-allow-access-during-reservation.rs:26:19 + --> $DIR/two-phase-allow-access-during-reservation.rs:27:19 | LL | /*1*/ let p = &mut i; // (reservation of `i` starts here) | ------ `i` is borrowed here @@ -11,7 +11,7 @@ LL | /*3*/ *p += 1; // (mutable borrow of `i` starts here, since `p` | ------- borrow later used here error[E0503]: cannot use `i` because it was mutably borrowed - --> $DIR/two-phase-allow-access-during-reservation.rs:31:19 + --> $DIR/two-phase-allow-access-during-reservation.rs:32:19 | LL | /*1*/ let p = &mut i; // (reservation of `i` starts here) | ------ `i` is borrowed here diff --git a/tests/ui/borrowck/two-phase-allow-access-during-reservation.rs b/tests/ui/borrowck/two-phase-allow-access-during-reservation.rs index e6b2501c1eb..6b5a2f5e623 100644 --- a/tests/ui/borrowck/two-phase-allow-access-during-reservation.rs +++ b/tests/ui/borrowck/two-phase-allow-access-during-reservation.rs @@ -1,6 +1,7 @@ //@ revisions: nll_target // The following revisions are disabled due to missing support for two_phase_beyond_autoref +//@ unused-revision-names: nll_beyond //@[nll_beyond] compile-flags: -Z two_phase_beyond_autoref // This is the second counter-example from Niko's blog post diff --git a/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr b/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr index e122977b9f2..c9d49b8756d 100644 --- a/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr +++ b/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `*f` as mutable more than once at a time - --> $DIR/two-phase-nonrecv-autoref.rs:50:11 + --> $DIR/two-phase-nonrecv-autoref.rs:51:11 | LL | f(f(10)); | - ^ second mutable borrow occurs here @@ -8,7 +8,7 @@ LL | f(f(10)); | first borrow later used by call error[E0382]: use of moved value: `f` - --> $DIR/two-phase-nonrecv-autoref.rs:57:11 + --> $DIR/two-phase-nonrecv-autoref.rs:58:11 | LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) { | - move occurs because `f` has type `Box<F>`, which does not implement the `Copy` trait @@ -18,7 +18,7 @@ LL | f(f(10)); | value moved here error[E0499]: cannot borrow `*f` as mutable more than once at a time - --> $DIR/two-phase-nonrecv-autoref.rs:62:11 + --> $DIR/two-phase-nonrecv-autoref.rs:63:11 | LL | f(f(10)); | - ^ second mutable borrow occurs here @@ -27,7 +27,7 @@ LL | f(f(10)); | first borrow later used by call error[E0382]: use of moved value: `f` - --> $DIR/two-phase-nonrecv-autoref.rs:69:11 + --> $DIR/two-phase-nonrecv-autoref.rs:70:11 | LL | fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) { | - move occurs because `f` has type `Box<dyn FnOnce(i32) -> i32>`, which does not implement the `Copy` trait @@ -37,7 +37,7 @@ LL | f(f(10)); | value moved here error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-nonrecv-autoref.rs:107:27 + --> $DIR/two-phase-nonrecv-autoref.rs:108:27 | LL | double_access(&mut a, &a); | ------------- ------ ^^ immutable borrow occurs here @@ -46,7 +46,7 @@ LL | double_access(&mut a, &a); | mutable borrow later used by call error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-nonrecv-autoref.rs:132:7 + --> $DIR/two-phase-nonrecv-autoref.rs:133:7 | LL | i[i[3]] = 4; | --^---- @@ -56,18 +56,18 @@ LL | i[i[3]] = 4; | mutable borrow occurs here | help: try adding a local storing this... - --> $DIR/two-phase-nonrecv-autoref.rs:132:8 + --> $DIR/two-phase-nonrecv-autoref.rs:133:8 | LL | i[i[3]] = 4; | ^^^ help: ...and then using that local here - --> $DIR/two-phase-nonrecv-autoref.rs:132:6 + --> $DIR/two-phase-nonrecv-autoref.rs:133:6 | LL | i[i[3]] = 4; | ^^^^^^ error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable - --> $DIR/two-phase-nonrecv-autoref.rs:138:7 + --> $DIR/two-phase-nonrecv-autoref.rs:139:7 | LL | i[i[3]] = i[4]; | --^---- @@ -77,12 +77,12 @@ LL | i[i[3]] = i[4]; | mutable borrow occurs here | help: try adding a local storing this... - --> $DIR/two-phase-nonrecv-autoref.rs:138:8 + --> $DIR/two-phase-nonrecv-autoref.rs:139:8 | LL | i[i[3]] = i[4]; | ^^^ help: ...and then using that local here - --> $DIR/two-phase-nonrecv-autoref.rs:138:6 + --> $DIR/two-phase-nonrecv-autoref.rs:139:6 | LL | i[i[3]] = i[4]; | ^^^^^^ diff --git a/tests/ui/borrowck/two-phase-nonrecv-autoref.rs b/tests/ui/borrowck/two-phase-nonrecv-autoref.rs index f52e9c2e3fd..3a8ab4ef3b0 100644 --- a/tests/ui/borrowck/two-phase-nonrecv-autoref.rs +++ b/tests/ui/borrowck/two-phase-nonrecv-autoref.rs @@ -1,5 +1,6 @@ //@ revisions: base +//@ unused-revision-names: g2p //@[g2p]compile-flags: -Z two-phase-beyond-autoref // the above revision is disabled until two-phase-beyond-autoref support is better diff --git a/tests/ui/borrowck/two-phase-reservation-sharing-interference.nll_target.stderr b/tests/ui/borrowck/two-phase-reservation-sharing-interference.nll_target.stderr index b1e4392989f..5eda4828012 100644 --- a/tests/ui/borrowck/two-phase-reservation-sharing-interference.nll_target.stderr +++ b/tests/ui/borrowck/two-phase-reservation-sharing-interference.nll_target.stderr @@ -1,5 +1,5 @@ error[E0502]: cannot borrow `vec` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference.rs:32:17 + --> $DIR/two-phase-reservation-sharing-interference.rs:33:17 | LL | let shared = &vec; | ---- immutable borrow occurs here diff --git a/tests/ui/borrowck/two-phase-reservation-sharing-interference.rs b/tests/ui/borrowck/two-phase-reservation-sharing-interference.rs index b6bcf7b6617..61446577db2 100644 --- a/tests/ui/borrowck/two-phase-reservation-sharing-interference.rs +++ b/tests/ui/borrowck/two-phase-reservation-sharing-interference.rs @@ -1,6 +1,7 @@ //@ revisions: nll_target // The nll_beyond revision is disabled due to missing support from two-phase beyond autorefs +//@ unused-revision-names: nll_beyond //@[nll_beyond]compile-flags: -Z two-phase-beyond-autoref //@[nll_beyond]should-fail diff --git a/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr b/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr index c196f607376..755373d7b77 100644 --- a/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr +++ b/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr @@ -30,7 +30,7 @@ LL | #[cfg(feature = "unk")] = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration warning: unexpected `cfg` condition name: `feature` - --> $DIR/exhaustive-names-values.rs:25:7 + --> $DIR/exhaustive-names-values.rs:24:7 | LL | #[cfg(feature = "std")] | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/check-cfg/exhaustive-names-values.rs b/tests/ui/check-cfg/exhaustive-names-values.rs index a6190f15dbb..7b2d89b5781 100644 --- a/tests/ui/check-cfg/exhaustive-names-values.rs +++ b/tests/ui/check-cfg/exhaustive-names-values.rs @@ -16,15 +16,13 @@ pub fn f() {} pub fn f() {} #[cfg(feature = "unk")] -//[empty_names_values]~^ WARNING unexpected `cfg` condition name -//[empty_cfg]~^^ WARNING unexpected `cfg` condition name -//[feature]~^^^ WARNING unexpected `cfg` condition value -//[full]~^^^^ WARNING unexpected `cfg` condition value +//[empty_cfg]~^ WARNING unexpected `cfg` condition name +//[feature]~^^ WARNING unexpected `cfg` condition value +//[full]~^^^ WARNING unexpected `cfg` condition value pub fn feat() {} #[cfg(feature = "std")] -//[empty_names_values]~^ WARNING unexpected `cfg` condition name -//[empty_cfg]~^^ WARNING unexpected `cfg` condition name +//[empty_cfg]~^ WARNING unexpected `cfg` condition name pub fn feat() {} #[cfg(windows)] diff --git a/tests/ui/check-cfg/values-none.concat_1.stderr b/tests/ui/check-cfg/values-none.concat_1.stderr new file mode 100644 index 00000000000..b8f0b02b4c5 --- /dev/null +++ b/tests/ui/check-cfg/values-none.concat_1.stderr @@ -0,0 +1,13 @@ +warning: unexpected `cfg` condition value: `bar` + --> $DIR/values-none.rs:16:7 + | +LL | #[cfg(foo = "bar")] + | ^^^^^^^^^^^ + | + = note: expected values for `foo` are: (none), `too` + = help: to expect this configuration use `--check-cfg=cfg(foo, values("bar"))` + = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/check-cfg/values-none.concat_2.stderr b/tests/ui/check-cfg/values-none.concat_2.stderr new file mode 100644 index 00000000000..b8f0b02b4c5 --- /dev/null +++ b/tests/ui/check-cfg/values-none.concat_2.stderr @@ -0,0 +1,13 @@ +warning: unexpected `cfg` condition value: `bar` + --> $DIR/values-none.rs:16:7 + | +LL | #[cfg(foo = "bar")] + | ^^^^^^^^^^^ + | + = note: expected values for `foo` are: (none), `too` + = help: to expect this configuration use `--check-cfg=cfg(foo, values("bar"))` + = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/check-cfg/values-none.rs b/tests/ui/check-cfg/values-none.rs index 6856d2f33af..447fde2bfcc 100644 --- a/tests/ui/check-cfg/values-none.rs +++ b/tests/ui/check-cfg/values-none.rs @@ -1,7 +1,7 @@ //@ check-pass // //@ no-auto-check-cfg -//@ revisions: explicit implicit +//@ revisions: explicit implicit simple concat_1 concat_2 //@ [explicit]compile-flags: --check-cfg=cfg(foo,values(none())) //@ [implicit]compile-flags: --check-cfg=cfg(foo) //@ [simple] compile-flags: --check-cfg=cfg(foo,values(none(),"too")) diff --git a/tests/ui/check-cfg/values-none.simple.stderr b/tests/ui/check-cfg/values-none.simple.stderr new file mode 100644 index 00000000000..b8f0b02b4c5 --- /dev/null +++ b/tests/ui/check-cfg/values-none.simple.stderr @@ -0,0 +1,13 @@ +warning: unexpected `cfg` condition value: `bar` + --> $DIR/values-none.rs:16:7 + | +LL | #[cfg(foo = "bar")] + | ^^^^^^^^^^^ + | + = note: expected values for `foo` are: (none), `too` + = help: to expect this configuration use `--check-cfg=cfg(foo, values("bar"))` + = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs index 408eaffccf7..d8852812492 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -28,8 +28,8 @@ struct S9; macro_rules! generate_s10 { ($expr: expr) => { #[cfg(feature = $expr)] - //~^ ERROR expected unsuffixed literal or identifier, found `concat!("nonexistent")` - //~| ERROR expected unsuffixed literal or identifier, found `concat!("nonexistent")` + //~^ ERROR expected unsuffixed literal, found `concat!("nonexistent")` + //~| ERROR expected unsuffixed literal, found `concat!("nonexistent")` struct S10; } } diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 12557ff6360..3dd0823389c 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -54,7 +54,7 @@ LL | #[cfg(a = b"hi")] | | | help: consider removing the prefix -error: expected unsuffixed literal or identifier, found `concat!("nonexistent")` +error: expected unsuffixed literal, found `concat!("nonexistent")` --> $DIR/cfg-attr-syntax-validation.rs:30:25 | LL | #[cfg(feature = $expr)] @@ -65,7 +65,7 @@ LL | generate_s10!(concat!("nonexistent")); | = note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info) -error: expected unsuffixed literal or identifier, found `concat!("nonexistent")` +error: expected unsuffixed literal, found `concat!("nonexistent")` --> $DIR/cfg-attr-syntax-validation.rs:30:25 | LL | #[cfg(feature = $expr)] diff --git a/tests/ui/consts/offset_from_ub.rs b/tests/ui/consts/offset_from_ub.rs index 51163e650d6..e0dd2707915 100644 --- a/tests/ui/consts/offset_from_ub.rs +++ b/tests/ui/consts/offset_from_ub.rs @@ -42,7 +42,7 @@ pub const DIFFERENT_INT: isize = { // offset_from with two different integers: l let ptr1 = 8 as *const u8; let ptr2 = 16 as *const u8; unsafe { ptr_offset_from(ptr2, ptr1) } //~ERROR evaluation of constant value failed - //~| 0x8[noalloc] is a dangling pointer + //~| different pointers without provenance }; const OUT_OF_BOUNDS_1: isize = { @@ -81,13 +81,13 @@ pub const DIFFERENT_ALLOC_UNSIGNED: usize = { }; pub const TOO_FAR_APART1: isize = { - let ptr1 = ptr::null::<u8>(); + let ptr1 = &0u8 as *const u8; let ptr2 = ptr1.wrapping_add(isize::MAX as usize + 42); unsafe { ptr_offset_from(ptr2, ptr1) } //~ERROR evaluation of constant value failed //~| too far ahead }; pub const TOO_FAR_APART2: isize = { - let ptr1 = ptr::null::<u8>(); + let ptr1 = &0u8 as *const u8; let ptr2 = ptr1.wrapping_add(isize::MAX as usize + 42); unsafe { ptr_offset_from(ptr1, ptr2) } //~ERROR evaluation of constant value failed //~| too far before @@ -100,7 +100,7 @@ const WRONG_ORDER_UNSIGNED: usize = { //~| first pointer has smaller offset than second: 0 < 8 }; pub const TOO_FAR_APART_UNSIGNED: usize = { - let ptr1 = ptr::null::<u8>(); + let ptr1 = &0u8 as *const u8; let ptr2 = ptr1.wrapping_add(isize::MAX as usize + 42); // This would fit into a `usize` but we still don't allow it. unsafe { ptr_offset_from_unsigned(ptr2, ptr1) } //~ERROR evaluation of constant value failed diff --git a/tests/ui/consts/offset_from_ub.stderr b/tests/ui/consts/offset_from_ub.stderr index 4fbb2f00100..e3bac8d5e31 100644 --- a/tests/ui/consts/offset_from_ub.stderr +++ b/tests/ui/consts/offset_from_ub.stderr @@ -33,7 +33,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/offset_from_ub.rs:44:14 | LL | unsafe { ptr_offset_from(ptr2, ptr1) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from`: 0x8[noalloc] is a dangling pointer (it has no provenance) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on different pointers without provenance (i.e., without an associated allocation) error[E0080]: evaluation of constant value failed --> $DIR/offset_from_ub.rs:53:14 @@ -86,7 +86,7 @@ LL | unsafe { ptr_offset_from_unsigned(ptr2, ptr1) } error[E0080]: evaluation of constant value failed --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds `offset_from`: null pointer is a dangling pointer (it has no provenance) + = note: `ptr_offset_from` called on different pointers without provenance (i.e., without an associated allocation) | note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL @@ -99,7 +99,7 @@ LL | unsafe { ptr2.offset_from(ptr1) } error[E0080]: evaluation of constant value failed --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | - = note: out-of-bounds `offset_from`: null pointer is a dangling pointer (it has no provenance) + = note: `ptr_offset_from` called on different pointers without provenance (i.e., without an associated allocation) | note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL diff --git a/tests/ui/coroutine/break-inside-coroutine-issue-124495.rs b/tests/ui/coroutine/break-inside-coroutine-issue-124495.rs new file mode 100644 index 00000000000..5d93db56722 --- /dev/null +++ b/tests/ui/coroutine/break-inside-coroutine-issue-124495.rs @@ -0,0 +1,26 @@ +//@ edition: 2024 +//@ compile-flags: -Z unstable-options + +#![feature(gen_blocks)] +#![feature(async_closure)] + +async fn async_fn() { + break; //~ ERROR `break` inside `async` function +} + +gen fn gen_fn() { + break; //~ ERROR `break` inside `gen` function +} + +async gen fn async_gen_fn() { + break; //~ ERROR `break` inside `async gen` function +} + +fn main() { + let _ = async { break; }; //~ ERROR `break` inside `async` block + let _ = async || { break; }; //~ ERROR `break` inside `async` closure + + let _ = gen { break; }; //~ ERROR `break` inside `gen` block + + let _ = async gen { break; }; //~ ERROR `break` inside `async gen` block +} diff --git a/tests/ui/coroutine/break-inside-coroutine-issue-124495.stderr b/tests/ui/coroutine/break-inside-coroutine-issue-124495.stderr new file mode 100644 index 00000000000..a7f37fad35e --- /dev/null +++ b/tests/ui/coroutine/break-inside-coroutine-issue-124495.stderr @@ -0,0 +1,69 @@ +error[E0267]: `break` inside `async` function + --> $DIR/break-inside-coroutine-issue-124495.rs:8:5 + | +LL | async fn async_fn() { + | _____________________- +LL | | break; + | | ^^^^^ cannot `break` inside `async` function +LL | | } + | |_- enclosing `async` function + +error[E0267]: `break` inside `gen` function + --> $DIR/break-inside-coroutine-issue-124495.rs:12:5 + | +LL | gen fn gen_fn() { + | _________________- +LL | | break; + | | ^^^^^ cannot `break` inside `gen` function +LL | | } + | |_- enclosing `gen` function + +error[E0267]: `break` inside `async gen` function + --> $DIR/break-inside-coroutine-issue-124495.rs:16:5 + | +LL | async gen fn async_gen_fn() { + | _____________________________- +LL | | break; + | | ^^^^^ cannot `break` inside `async gen` function +LL | | } + | |_- enclosing `async gen` function + +error[E0267]: `break` inside `async` block + --> $DIR/break-inside-coroutine-issue-124495.rs:20:21 + | +LL | let _ = async { break; }; + | --------^^^^^--- + | | | + | | cannot `break` inside `async` block + | enclosing `async` block + +error[E0267]: `break` inside `async` closure + --> $DIR/break-inside-coroutine-issue-124495.rs:21:24 + | +LL | let _ = async || { break; }; + | --^^^^^--- + | | | + | | cannot `break` inside `async` closure + | enclosing `async` closure + +error[E0267]: `break` inside `gen` block + --> $DIR/break-inside-coroutine-issue-124495.rs:23:19 + | +LL | let _ = gen { break; }; + | ------^^^^^--- + | | | + | | cannot `break` inside `gen` block + | enclosing `gen` block + +error[E0267]: `break` inside `async gen` block + --> $DIR/break-inside-coroutine-issue-124495.rs:25:25 + | +LL | let _ = async gen { break; }; + | ------------^^^^^--- + | | | + | | cannot `break` inside `async gen` block + | enclosing `async gen` block + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0267`. diff --git a/tests/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr b/tests/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr index 078c766deed..a030da5068c 100644 --- a/tests/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr +++ b/tests/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr @@ -4,7 +4,7 @@ error: expected unsuffixed literal, found `test` LL | #[deprecated(note = test)] | ^^^^ | -help: surround the identifier with quotation marks to parse it as a string +help: surround the identifier with quotation marks to make it into a string literal | LL | #[deprecated(note = "test")] | + + diff --git a/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr b/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr index d0b14ef94c1..e88a523ef4f 100644 --- a/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr +++ b/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr @@ -1,4 +1,4 @@ -error[E0369]: binary operation `==` cannot be applied to type `Error` +error[E0369]: binary operation `==` cannot be applied to type `&Error` --> $DIR/derives-span-PartialEq-enum-struct-variant.rs:9:6 | LL | #[derive(PartialEq)] diff --git a/tests/ui/derives/derives-span-PartialEq-enum.stderr b/tests/ui/derives/derives-span-PartialEq-enum.stderr index f69451ac793..80b225446b4 100644 --- a/tests/ui/derives/derives-span-PartialEq-enum.stderr +++ b/tests/ui/derives/derives-span-PartialEq-enum.stderr @@ -1,4 +1,4 @@ -error[E0369]: binary operation `==` cannot be applied to type `Error` +error[E0369]: binary operation `==` cannot be applied to type `&Error` --> $DIR/derives-span-PartialEq-enum.rs:9:6 | LL | #[derive(PartialEq)] diff --git a/tests/ui/deriving/deriving-all-codegen.rs b/tests/ui/deriving/deriving-all-codegen.rs index 498930fc0c6..6fa4f74f2a5 100644 --- a/tests/ui/deriving/deriving-all-codegen.rs +++ b/tests/ui/deriving/deriving-all-codegen.rs @@ -156,6 +156,20 @@ enum EnumGeneric<T, U> { Two(U), } +// An enum that has variant, which does't implement `Copy`. +#[derive(PartialEq)] +enum NonCopyEnum { + // The `dyn NonCopyTrait` implements `PartialEq`, but it doesn't require `Copy`. + // So we cannot generate `PartialEq` with dereference. + NonCopyField(Box<dyn NonCopyTrait>), +} +trait NonCopyTrait {} +impl PartialEq for dyn NonCopyTrait { + fn eq(&self, _other: &Self) -> bool { + true + } +} + // A union. Most builtin traits are not derivable for unions. #[derive(Clone, Copy)] pub union Union { diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index 9f8a9f30ff6..6b69b57c516 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -876,7 +876,7 @@ impl ::core::cmp::PartialEq for Enum1 { fn eq(&self, other: &Enum1) -> bool { match (self, other) { (Enum1::Single { x: __self_0 }, Enum1::Single { x: __arg1_0 }) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, } } } @@ -1119,10 +1119,10 @@ impl ::core::cmp::PartialEq for Mixed { __self_discr == __arg1_discr && match (self, other) { (Mixed::R(__self_0), Mixed::R(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, (Mixed::S { d1: __self_0, d2: __self_1 }, Mixed::S { d1: __arg1_0, d2: __arg1_1 }) => - *__self_0 == *__arg1_0 && *__self_1 == *__arg1_1, + __self_0 == __arg1_0 && __self_1 == __arg1_1, _ => true, } } @@ -1245,11 +1245,11 @@ impl ::core::cmp::PartialEq for Fielded { __self_discr == __arg1_discr && match (self, other) { (Fielded::X(__self_0), Fielded::X(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, (Fielded::Y(__self_0), Fielded::Y(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, (Fielded::Z(__self_0), Fielded::Z(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, _ => unsafe { ::core::intrinsics::unreachable() } } } @@ -1368,9 +1368,9 @@ impl<T: ::core::cmp::PartialEq, U: ::core::cmp::PartialEq> __self_discr == __arg1_discr && match (self, other) { (EnumGeneric::One(__self_0), EnumGeneric::One(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, (EnumGeneric::Two(__self_0), EnumGeneric::Two(__arg1_0)) => - *__self_0 == *__arg1_0, + __self_0 == __arg1_0, _ => unsafe { ::core::intrinsics::unreachable() } } } @@ -1426,6 +1426,30 @@ impl<T: ::core::cmp::Ord, U: ::core::cmp::Ord> ::core::cmp::Ord for } } +// An enum that has variant, which does't implement `Copy`. +enum NonCopyEnum { + + // The `dyn NonCopyTrait` implements `PartialEq`, but it doesn't require `Copy`. + // So we cannot generate `PartialEq` with dereference. + NonCopyField(Box<dyn NonCopyTrait>), +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for NonCopyEnum { } +#[automatically_derived] +impl ::core::cmp::PartialEq for NonCopyEnum { + #[inline] + fn eq(&self, other: &NonCopyEnum) -> bool { + match (self, other) { + (NonCopyEnum::NonCopyField(__self_0), + NonCopyEnum::NonCopyField(__arg1_0)) => __self_0 == __arg1_0, + } + } +} +trait NonCopyTrait {} +impl PartialEq for dyn NonCopyTrait { + fn eq(&self, _other: &Self) -> bool { true } +} + // A union. Most builtin traits are not derivable for unions. pub union Union { pub b: bool, diff --git a/tests/ui/diagnostic_namespace/auxiliary/bad_on_unimplemented.rs b/tests/ui/diagnostic_namespace/auxiliary/bad_on_unimplemented.rs index 4a5fca43e36..e44c7e4e850 100644 --- a/tests/ui/diagnostic_namespace/auxiliary/bad_on_unimplemented.rs +++ b/tests/ui/diagnostic_namespace/auxiliary/bad_on_unimplemented.rs @@ -1,2 +1,26 @@ #[diagnostic::on_unimplemented(aa = "broken")] -pub trait Test {} +pub trait MissingAttr {} + +#[diagnostic::on_unimplemented(label = "a", label = "b")] +pub trait DuplicateAttr {} + +#[diagnostic::on_unimplemented = "broken"] +pub trait NotMetaList {} + +#[diagnostic::on_unimplemented] +pub trait Empty {} + +#[diagnostic::on_unimplemented {}] +pub trait WrongDelim {} + +#[diagnostic::on_unimplemented(label = "{A:.3}")] +pub trait BadFormatter<A> {} + +#[diagnostic::on_unimplemented(label = "test {}")] +pub trait NoImplicitArgs {} + +#[diagnostic::on_unimplemented(label = "{missing}")] +pub trait MissingArg {} + +#[diagnostic::on_unimplemented(label = "{_}")] +pub trait BadArg {} diff --git a/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.rs b/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.rs new file mode 100644 index 00000000000..8b7467a17d0 --- /dev/null +++ b/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.rs @@ -0,0 +1,31 @@ +//@ edition:2021 +//@ aux-build:bad_on_unimplemented.rs + +// Do not ICE when encountering a malformed `#[diagnostic::on_unimplemented]` annotation in a +// dependency when incorrectly used (#124651). + +extern crate bad_on_unimplemented; + +use bad_on_unimplemented::*; + +fn missing_attr<T: MissingAttr>(_: T) {} +fn duplicate_attr<T: DuplicateAttr>(_: T) {} +fn not_meta_list<T: NotMetaList>(_: T) {} +fn empty<T: Empty>(_: T) {} +fn wrong_delim<T: WrongDelim>(_: T) {} +fn bad_formatter<T: BadFormatter<()>>(_: T) {} +fn no_implicit_args<T: NoImplicitArgs>(_: T) {} +fn missing_arg<T: MissingArg>(_: T) {} +fn bad_arg<T: BadArg>(_: T) {} + +fn main() { + missing_attr(()); //~ ERROR E0277 + duplicate_attr(()); //~ ERROR E0277 + not_meta_list(()); //~ ERROR E0277 + empty(()); //~ ERROR E0277 + wrong_delim(()); //~ ERROR E0277 + bad_formatter(()); //~ ERROR E0277 + no_implicit_args(()); //~ ERROR E0277 + missing_arg(()); //~ ERROR E0277 + bad_arg(()); //~ ERROR E0277 +} diff --git a/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.stderr b/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.stderr new file mode 100644 index 00000000000..c3e56550b70 --- /dev/null +++ b/tests/ui/diagnostic_namespace/malformed_foreign_on_unimplemented.stderr @@ -0,0 +1,134 @@ +error[E0277]: the trait bound `(): bad_on_unimplemented::MissingAttr` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:22:18 + | +LL | missing_attr(()); + | ------------ ^^ the trait `bad_on_unimplemented::MissingAttr` is not implemented for `()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `missing_attr` + --> $DIR/malformed_foreign_on_unimplemented.rs:11:20 + | +LL | fn missing_attr<T: MissingAttr>(_: T) {} + | ^^^^^^^^^^^ required by this bound in `missing_attr` + +error[E0277]: the trait bound `(): bad_on_unimplemented::DuplicateAttr` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:23:20 + | +LL | duplicate_attr(()); + | -------------- ^^ a + | | + | required by a bound introduced by this call + | + = help: the trait `bad_on_unimplemented::DuplicateAttr` is not implemented for `()` +note: required by a bound in `duplicate_attr` + --> $DIR/malformed_foreign_on_unimplemented.rs:12:22 + | +LL | fn duplicate_attr<T: DuplicateAttr>(_: T) {} + | ^^^^^^^^^^^^^ required by this bound in `duplicate_attr` + +error[E0277]: the trait bound `(): bad_on_unimplemented::NotMetaList` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:24:19 + | +LL | not_meta_list(()); + | ------------- ^^ the trait `bad_on_unimplemented::NotMetaList` is not implemented for `()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `not_meta_list` + --> $DIR/malformed_foreign_on_unimplemented.rs:13:21 + | +LL | fn not_meta_list<T: NotMetaList>(_: T) {} + | ^^^^^^^^^^^ required by this bound in `not_meta_list` + +error[E0277]: the trait bound `(): bad_on_unimplemented::Empty` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:25:11 + | +LL | empty(()); + | ----- ^^ the trait `bad_on_unimplemented::Empty` is not implemented for `()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `empty` + --> $DIR/malformed_foreign_on_unimplemented.rs:14:13 + | +LL | fn empty<T: Empty>(_: T) {} + | ^^^^^ required by this bound in `empty` + +error[E0277]: the trait bound `(): bad_on_unimplemented::WrongDelim` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:26:17 + | +LL | wrong_delim(()); + | ----------- ^^ the trait `bad_on_unimplemented::WrongDelim` is not implemented for `()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `wrong_delim` + --> $DIR/malformed_foreign_on_unimplemented.rs:15:19 + | +LL | fn wrong_delim<T: WrongDelim>(_: T) {} + | ^^^^^^^^^^ required by this bound in `wrong_delim` + +error[E0277]: the trait bound `(): bad_on_unimplemented::BadFormatter<()>` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:27:19 + | +LL | bad_formatter(()); + | ------------- ^^ () + | | + | required by a bound introduced by this call + | + = help: the trait `bad_on_unimplemented::BadFormatter<()>` is not implemented for `()` +note: required by a bound in `bad_formatter` + --> $DIR/malformed_foreign_on_unimplemented.rs:16:21 + | +LL | fn bad_formatter<T: BadFormatter<()>>(_: T) {} + | ^^^^^^^^^^^^^^^^ required by this bound in `bad_formatter` + +error[E0277]: the trait bound `(): bad_on_unimplemented::NoImplicitArgs` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:28:22 + | +LL | no_implicit_args(()); + | ---------------- ^^ test {} + | | + | required by a bound introduced by this call + | + = help: the trait `bad_on_unimplemented::NoImplicitArgs` is not implemented for `()` +note: required by a bound in `no_implicit_args` + --> $DIR/malformed_foreign_on_unimplemented.rs:17:24 + | +LL | fn no_implicit_args<T: NoImplicitArgs>(_: T) {} + | ^^^^^^^^^^^^^^ required by this bound in `no_implicit_args` + +error[E0277]: the trait bound `(): bad_on_unimplemented::MissingArg` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:29:17 + | +LL | missing_arg(()); + | ----------- ^^ {missing} + | | + | required by a bound introduced by this call + | + = help: the trait `bad_on_unimplemented::MissingArg` is not implemented for `()` +note: required by a bound in `missing_arg` + --> $DIR/malformed_foreign_on_unimplemented.rs:18:19 + | +LL | fn missing_arg<T: MissingArg>(_: T) {} + | ^^^^^^^^^^ required by this bound in `missing_arg` + +error[E0277]: the trait bound `(): bad_on_unimplemented::BadArg` is not satisfied + --> $DIR/malformed_foreign_on_unimplemented.rs:30:13 + | +LL | bad_arg(()); + | ------- ^^ {_} + | | + | required by a bound introduced by this call + | + = help: the trait `bad_on_unimplemented::BadArg` is not implemented for `()` +note: required by a bound in `bad_arg` + --> $DIR/malformed_foreign_on_unimplemented.rs:19:15 + | +LL | fn bad_arg<T: BadArg>(_: T) {} + | ^^^^^^ required by this bound in `bad_arg` + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/diagnostic_namespace/on_unimplemented_ice.rs b/tests/ui/diagnostic_namespace/on_unimplemented_ice.rs deleted file mode 100644 index 8969f5030e2..00000000000 --- a/tests/ui/diagnostic_namespace/on_unimplemented_ice.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ edition:2021 -//@ compile-flags:--test -//@ aux-build:bad_on_unimplemented.rs - -// Do not ICE when encountering a malformed `#[diagnostic::on_unimplemented]` annotation in a -// dependency when incorrectly used (#124651). - -extern crate bad_on_unimplemented; - -use bad_on_unimplemented::Test; - -fn breakage<T: Test>(_: T) {} - -#[test] -fn test() { - breakage(1); //~ ERROR E0277 -} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented_ice.stderr b/tests/ui/diagnostic_namespace/on_unimplemented_ice.stderr deleted file mode 100644 index 1c0da96abd9..00000000000 --- a/tests/ui/diagnostic_namespace/on_unimplemented_ice.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0277]: the trait bound `{integer}: Test` is not satisfied - --> $DIR/on_unimplemented_ice.rs:16:14 - | -LL | breakage(1); - | -------- ^ the trait `Test` is not implemented for `{integer}` - | | - | required by a bound introduced by this call - | -note: required by a bound in `breakage` - --> $DIR/on_unimplemented_ice.rs:12:16 - | -LL | fn breakage<T: Test>(_: T) {} - | ^^^^ required by this bound in `breakage` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/param-env-region-infer.current.stderr b/tests/ui/dyn-star/param-env-region-infer.current.stderr index b50117c1efb..6e464c17014 100644 --- a/tests/ui/dyn-star/param-env-region-infer.current.stderr +++ b/tests/ui/dyn-star/param-env-region-infer.current.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/param-env-region-infer.rs:19:10 + --> $DIR/param-env-region-infer.rs:20:10 | LL | t as _ | ^ cannot infer type diff --git a/tests/ui/dyn-star/param-env-region-infer.rs b/tests/ui/dyn-star/param-env-region-infer.rs index c53861065c7..842964ad284 100644 --- a/tests/ui/dyn-star/param-env-region-infer.rs +++ b/tests/ui/dyn-star/param-env-region-infer.rs @@ -1,9 +1,10 @@ //@ revisions: current //@ incremental -// FIXME(-Znext-solver): THis currently results in unstable query results: +// FIXME(-Znext-solver): This currently results in unstable query results: // `normalizes-to(opaque, opaque)` changes from `Maybe(Ambiguous)` to `Maybe(Overflow)` // once the hidden type of the opaque is already defined to be itself. +//@ unused-revision-names: next // checks that we don't ICE if there are region inference variables in the environment // when computing `PointerLike` builtin candidates. diff --git a/tests/ui/higher-ranked/trait-bounds/issue-59311.stderr b/tests/ui/higher-ranked/trait-bounds/issue-59311.stderr index f8bed86ccf5..a26c617dc93 100644 --- a/tests/ui/higher-ranked/trait-bounds/issue-59311.stderr +++ b/tests/ui/higher-ranked/trait-bounds/issue-59311.stderr @@ -1,19 +1,33 @@ error: implementation of `Trait` is not general enough --> $DIR/issue-59311.rs:17:5 | -LL | v.t(|| {}); - | ^^^^^^^^^^ implementation of `Trait` is not general enough +LL | / pub fn crash<V>(v: &V) +LL | | where +LL | | for<'a> &'a V: Trait + 'static, + | |____________________-----__________- due to a where-clause on `crash`... + | | + | doesn't satisfy where-clause +LL | { +LL | v.t(|| {}); + | ^^^^^^^^^^ | - = note: `Trait` would have to be implemented for the type `&'a V` + = note: ...`Trait` would have to be implemented for the type `&'a V` = note: ...but `Trait` is actually implemented for the type `&'0 V`, for some specific lifetime `'0` error: implementation of `Trait` is not general enough --> $DIR/issue-59311.rs:17:5 | -LL | v.t(|| {}); - | ^^^^^^^^^^ implementation of `Trait` is not general enough +LL | / pub fn crash<V>(v: &V) +LL | | where +LL | | for<'a> &'a V: Trait + 'static, + | |____________________-----__________- due to a where-clause on `crash`... + | | + | doesn't satisfy where-clause +LL | { +LL | v.t(|| {}); + | ^^^^^^^^^^ | - = note: `Trait` would have to be implemented for the type `&'a V` + = note: ...`Trait` would have to be implemented for the type `&'a V` = note: ...but `Trait` is actually implemented for the type `&'0 V`, for some specific lifetime `'0` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` diff --git a/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.rs b/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.rs new file mode 100644 index 00000000000..fa76686cc8b --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.rs @@ -0,0 +1,11 @@ +// Minimized test from #59311. + +pub fn crash() +where + for<'a> &'a (): 'static, +{ + || {}; + //~^ ERROR higher-ranked lifetime error +} + +fn main() {} diff --git a/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.stderr b/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.stderr new file mode 100644 index 00000000000..9e0d7e4b7be --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/trivial-does-not-hold.stderr @@ -0,0 +1,10 @@ +error: higher-ranked lifetime error + --> $DIR/trivial-does-not-hold.rs:7:5 + | +LL | || {}; + | ^^^^^ + | + = note: could not prove `for<'a> &'a (): 'b` + +error: aborting due to 1 previous error + diff --git a/tests/ui/instrument-coverage/coverage-options.rs b/tests/ui/instrument-coverage/coverage-options.rs index 332da32e435..2a80ce4ab2e 100644 --- a/tests/ui/instrument-coverage/coverage-options.rs +++ b/tests/ui/instrument-coverage/coverage-options.rs @@ -1,5 +1,5 @@ //@ needs-profiler-support -//@ revisions: block branch bad +//@ revisions: block branch mcdc bad //@ compile-flags -Cinstrument-coverage //@ [block] check-pass diff --git a/tests/ui/lint/lint-unnecessary-parens.fixed b/tests/ui/lint/lint-unnecessary-parens.fixed index 973bbd70f25..760897c5143 100644 --- a/tests/ui/lint/lint-unnecessary-parens.fixed +++ b/tests/ui/lint/lint-unnecessary-parens.fixed @@ -46,6 +46,28 @@ pub fn parens_with_keyword(e: &[()]) -> i32 { macro_rules! baz { ($($foo:expr),+) => { ($($foo),*) + }; +} + +macro_rules! unit { + () => { + () + }; +} + +struct One; + +impl std::ops::Sub<One> for () { + type Output = i32; + fn sub(self, _: One) -> Self::Output { + -1 + } +} + +impl std::ops::Neg for One { + type Output = i32; + fn neg(self) -> Self::Output { + -1 } } @@ -94,4 +116,13 @@ fn main() { let _a = baz!(3, 4); let _b = baz!(3); + + let _ = { + unit!() - One //~ ERROR unnecessary parentheses around block return value + } + { + unit![] - One //~ ERROR unnecessary parentheses around block return value + } + { + // FIXME: false positive. This parenthesis is required. + unit! {} - One //~ ERROR unnecessary parentheses around block return value + }; } diff --git a/tests/ui/lint/lint-unnecessary-parens.rs b/tests/ui/lint/lint-unnecessary-parens.rs index 40cd61fcc2c..7cbaac8ae54 100644 --- a/tests/ui/lint/lint-unnecessary-parens.rs +++ b/tests/ui/lint/lint-unnecessary-parens.rs @@ -46,6 +46,28 @@ pub fn parens_with_keyword(e: &[()]) -> i32 { macro_rules! baz { ($($foo:expr),+) => { ($($foo),*) + }; +} + +macro_rules! unit { + () => { + () + }; +} + +struct One; + +impl std::ops::Sub<One> for () { + type Output = i32; + fn sub(self, _: One) -> Self::Output { + -1 + } +} + +impl std::ops::Neg for One { + type Output = i32; + fn neg(self) -> Self::Output { + -1 } } @@ -94,4 +116,13 @@ fn main() { let _a = baz!(3, 4); let _b = baz!(3); + + let _ = { + (unit!() - One) //~ ERROR unnecessary parentheses around block return value + } + { + (unit![] - One) //~ ERROR unnecessary parentheses around block return value + } + { + // FIXME: false positive. This parenthesis is required. + (unit! {} - One) //~ ERROR unnecessary parentheses around block return value + }; } diff --git a/tests/ui/lint/lint-unnecessary-parens.stderr b/tests/ui/lint/lint-unnecessary-parens.stderr index ba7a78b8da1..755dd5fc309 100644 --- a/tests/ui/lint/lint-unnecessary-parens.stderr +++ b/tests/ui/lint/lint-unnecessary-parens.stderr @@ -124,7 +124,7 @@ LL + return 1; | error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:52:31 + --> $DIR/lint-unnecessary-parens.rs:74:31 | LL | pub const CONST_ITEM: usize = (10); | ^ ^ @@ -136,7 +136,7 @@ LL + pub const CONST_ITEM: usize = 10; | error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:53:33 + --> $DIR/lint-unnecessary-parens.rs:75:33 | LL | pub static STATIC_ITEM: usize = (10); | ^ ^ @@ -148,7 +148,7 @@ LL + pub static STATIC_ITEM: usize = 10; | error: unnecessary parentheses around function argument - --> $DIR/lint-unnecessary-parens.rs:57:9 + --> $DIR/lint-unnecessary-parens.rs:79:9 | LL | bar((true)); | ^ ^ @@ -160,7 +160,7 @@ LL + bar(true); | error: unnecessary parentheses around `if` condition - --> $DIR/lint-unnecessary-parens.rs:59:8 + --> $DIR/lint-unnecessary-parens.rs:81:8 | LL | if (true) {} | ^ ^ @@ -172,7 +172,7 @@ LL + if true {} | error: unnecessary parentheses around `while` condition - --> $DIR/lint-unnecessary-parens.rs:60:11 + --> $DIR/lint-unnecessary-parens.rs:82:11 | LL | while (true) {} | ^ ^ @@ -184,7 +184,7 @@ LL + while true {} | error: unnecessary parentheses around `match` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:61:11 + --> $DIR/lint-unnecessary-parens.rs:83:11 | LL | match (true) { | ^ ^ @@ -196,7 +196,7 @@ LL + match true { | error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:64:16 + --> $DIR/lint-unnecessary-parens.rs:86:16 | LL | if let 1 = (1) {} | ^ ^ @@ -208,7 +208,7 @@ LL + if let 1 = 1 {} | error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/lint-unnecessary-parens.rs:65:19 + --> $DIR/lint-unnecessary-parens.rs:87:19 | LL | while let 1 = (2) {} | ^ ^ @@ -220,7 +220,7 @@ LL + while let 1 = 2 {} | error: unnecessary parentheses around method argument - --> $DIR/lint-unnecessary-parens.rs:81:24 + --> $DIR/lint-unnecessary-parens.rs:103:24 | LL | X { y: false }.foo((true)); | ^ ^ @@ -232,7 +232,7 @@ LL + X { y: false }.foo(true); | error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:83:18 + --> $DIR/lint-unnecessary-parens.rs:105:18 | LL | let mut _a = (0); | ^ ^ @@ -244,7 +244,7 @@ LL + let mut _a = 0; | error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:84:10 + --> $DIR/lint-unnecessary-parens.rs:106:10 | LL | _a = (0); | ^ ^ @@ -256,7 +256,7 @@ LL + _a = 0; | error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:85:11 + --> $DIR/lint-unnecessary-parens.rs:107:11 | LL | _a += (1); | ^ ^ @@ -268,7 +268,7 @@ LL + _a += 1; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:87:8 + --> $DIR/lint-unnecessary-parens.rs:109:8 | LL | let(mut _a) = 3; | ^ ^ @@ -280,7 +280,7 @@ LL + let mut _a = 3; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:88:9 + --> $DIR/lint-unnecessary-parens.rs:110:9 | LL | let (mut _a) = 3; | ^ ^ @@ -292,7 +292,7 @@ LL + let mut _a = 3; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:89:8 + --> $DIR/lint-unnecessary-parens.rs:111:8 | LL | let( mut _a) = 3; | ^^ ^ @@ -304,7 +304,7 @@ LL + let mut _a = 3; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:91:8 + --> $DIR/lint-unnecessary-parens.rs:113:8 | LL | let(_a) = 3; | ^ ^ @@ -316,7 +316,7 @@ LL + let _a = 3; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:92:9 + --> $DIR/lint-unnecessary-parens.rs:114:9 | LL | let (_a) = 3; | ^ ^ @@ -328,7 +328,7 @@ LL + let _a = 3; | error: unnecessary parentheses around pattern - --> $DIR/lint-unnecessary-parens.rs:93:8 + --> $DIR/lint-unnecessary-parens.rs:115:8 | LL | let( _a) = 3; | ^^ ^ @@ -339,5 +339,41 @@ LL - let( _a) = 3; LL + let _a = 3; | -error: aborting due to 28 previous errors +error: unnecessary parentheses around block return value + --> $DIR/lint-unnecessary-parens.rs:121:9 + | +LL | (unit!() - One) + | ^ ^ + | +help: remove these parentheses + | +LL - (unit!() - One) +LL + unit!() - One + | + +error: unnecessary parentheses around block return value + --> $DIR/lint-unnecessary-parens.rs:123:9 + | +LL | (unit![] - One) + | ^ ^ + | +help: remove these parentheses + | +LL - (unit![] - One) +LL + unit![] - One + | + +error: unnecessary parentheses around block return value + --> $DIR/lint-unnecessary-parens.rs:126:9 + | +LL | (unit! {} - One) + | ^ ^ + | +help: remove these parentheses + | +LL - (unit! {} - One) +LL + unit! {} - One + | + +error: aborting due to 31 previous errors diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs index 3d0c36ca118..87fa42f9477 100644 --- a/tests/ui/lint/reference_casting.rs +++ b/tests/ui/lint/reference_casting.rs @@ -255,6 +255,19 @@ unsafe fn bigger_layout() { let a3 = a2 as *mut u64; unsafe { *a3 = 3 }; } + + unsafe fn field_access(v: &mut Vec3<i32>) { + let r = &mut v.0; + let ptr = r as *mut i32 as *mut Vec3<i32>; + unsafe { *ptr = Vec3(0, 0, 0) } + } + + unsafe fn deref(v: &mut Vec3<i32>) { + let r = &mut v.0; + let r = &mut *r; + let ptr = &mut *(r as *mut i32 as *mut Vec3<i32>); + unsafe { *ptr = Vec3(0, 0, 0) } + } } const RAW_PTR: *mut u8 = 1 as *mut u8; diff --git a/tests/crashes/97006.rs b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs index c8dfa52ebee..84370fcebbc 100644 --- a/tests/crashes/97006.rs +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs @@ -1,7 +1,6 @@ -//@ known-bug: #97006 //@ compile-flags: -Zunpretty=hir -#![allow(unused)] +// issue#97006 macro_rules! m { ($attr_path: path) => { diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr new file mode 100644 index 00000000000..8fcc7c6fbff --- /dev/null +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr @@ -0,0 +1,8 @@ +error: unexpected generic arguments in path + --> $DIR/genercs-in-path-with-prettry-hir.rs:12:10 + | +LL | m!(inline<u8>); + | ^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout new file mode 100644 index 00000000000..e9ee59abfae --- /dev/null +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout @@ -0,0 +1,15 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +//@ compile-flags: -Zunpretty=hir + +// issue#97006 + +macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } } +#[ + +inline] +fn f() { } + +fn main() { } diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.rs b/tests/ui/macros/macro-expand-within-generics-in-path.rs new file mode 100644 index 00000000000..017d5152221 --- /dev/null +++ b/tests/ui/macros/macro-expand-within-generics-in-path.rs @@ -0,0 +1,19 @@ +// issue#123911 +// issue#123912 + +macro_rules! m { + ($p: path) => { + #[$p] + struct S; + }; +} + +macro_rules! p { + () => {}; +} + +m!(generic<p!()>); +//~^ ERROR: unexpected generic arguments in path +//~| ERROR: cannot find attribute `generic` in this scope + +fn main() {} diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.stderr b/tests/ui/macros/macro-expand-within-generics-in-path.stderr new file mode 100644 index 00000000000..72026c41050 --- /dev/null +++ b/tests/ui/macros/macro-expand-within-generics-in-path.stderr @@ -0,0 +1,14 @@ +error: unexpected generic arguments in path + --> $DIR/macro-expand-within-generics-in-path.rs:15:11 + | +LL | m!(generic<p!()>); + | ^^^^^^ + +error: cannot find attribute `generic` in this scope + --> $DIR/macro-expand-within-generics-in-path.rs:15:4 + | +LL | m!(generic<p!()>); + | ^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 492bd2450b1..472cb4d417b 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -213,6 +213,21 @@ fn test_expr() { "match () { _ => ({ 1 }) - 1, }", "match () { _ => { 1 } - 1 }", ); + c2_match_arm!( + [ m!() - 1 ], + "match () { _ => m!() - 1, }", + "match () { _ => m!() - 1 }", + ); + c2_match_arm!( + [ m![] - 1 ], + "match () { _ => m![] - 1, }", + "match () { _ => m![] - 1 }", + ); + c2_match_arm!( + [ m! {} - 1 ], + "match () { _ => m! {} - 1, }", + "match () { _ => m! {} - 1 }", + ); // ExprKind::Closure c1!(expr, [ || {} ], "|| {}"); @@ -720,6 +735,21 @@ fn test_stmt() { "(loop { break 1; }) - 1;", "loop { break 1; } - 1", ); + c2_minus_one!( + [ m!() ], + "m!() - 1;", + "m!() - 1" + ); + c2_minus_one!( + [ m![] ], + "m![] - 1;", + "m![] - 1" + ); + c2_minus_one!( + [ m! {} ], + "(m! {}) - 1;", + "m! {} - 1" + ); // StmtKind::Empty c1!(stmt, [ ; ], ";"); diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs index f1ac3e340e9..62e4f82a3ff 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs @@ -53,6 +53,12 @@ pub fn main() { if let Some(&Some(Some(&x))) = &Some(Some(&mut Some(0))) { let _: u32 = x; } + if let Some(&Some(&x)) = Some(&Some(&mut 0)) { + let _: u32 = x; + } + if let Some(&Some(x)) = &mut Some(Some(0)) { + let _: u32 = x; + } let &mut x = &&mut 0; let _: &u32 = x; diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs index ec091bb1746..96b4ff77ddb 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs @@ -14,18 +14,20 @@ pub fn main() { let _: &mut u32 = x; //~^ ERROR: mismatched types } - if let Some(&Some(&_)) = Some(&Some(&mut 0)) { - //~^ ERROR: mismatched types - } if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { //~^ ERROR: mismatched types } if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { //~^ ERROR: mismatched types } + if let Some(&mut Some(x)) = &Some(Some(0)) { + //~^ ERROR: mismatched types + } + if let Some(&mut Some(x)) = &Some(Some(0)) { + //~^ ERROR: mismatched types + } - - let &mut _= &&0; + let &mut _ = &&0; //~^ ERROR: mismatched types let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr index be71ee606c7..e06a645fc0d 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr @@ -34,17 +34,6 @@ LL | let _: &mut u32 = x; error[E0308]: mismatched types --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:17:23 | -LL | if let Some(&Some(&_)) = Some(&Some(&mut 0)) { - | ^^ ------------------- this expression has type `Option<&Option<&mut {integer}>>` - | | - | types differ in mutability - | - = note: expected mutable reference `&mut {integer}` - found reference `&_` - -error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:20:23 - | LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { | ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>` | | @@ -54,7 +43,7 @@ LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:23:29 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:20:29 | LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { | ^^^^^^ ------------------------- this expression has type `&Option<Option<&mut Option<{integer}>>>` @@ -65,10 +54,32 @@ LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:28:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:23:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:26:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:30:9 | -LL | let &mut _= &&0; - | ^^^^^^ --- this expression has type `&&{integer}` +LL | let &mut _ = &&0; + | ^^^^^^ --- this expression has type `&&{integer}` | | | expected integer, found `&mut _` | @@ -76,7 +87,7 @@ LL | let &mut _= &&0; found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:31:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:33:9 | LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; | ^^^^^^ ----------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` @@ -86,6 +97,6 @@ LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; = note: expected type `{integer}` found mutable reference `&mut _` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.rs index 36455488407..3cdf47c1dbf 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.rs @@ -8,4 +8,7 @@ pub fn main() { //~^ ERROR: cannot move out of a shared reference [E0507] let _: &u32 = x; } + + let &ref mut x = &0; + //~^ cannot borrow data in a `&` reference as mutable [E0596] } diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.stderr index ccfb5c7a0c0..8b86fa65c4d 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.stderr +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail2.stderr @@ -12,6 +12,13 @@ help: consider borrowing the pattern binding LL | if let Some(&Some(ref x)) = Some(&Some(&mut 0)) { | +++ -error: aborting due to 1 previous error +error[E0596]: cannot borrow data in a `&` reference as mutable + --> $DIR/ref_pat_eat_one_layer_2024_fail2.rs:12:10 + | +LL | let &ref mut x = &0; + | ^^^^^^^^^ cannot borrow as mutable + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0507`. +Some errors have detailed explanations: E0507, E0596. +For more information about an error, try `rustc --explain E0507`. diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.fixed b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.fixed new file mode 100644 index 00000000000..bc7a58a382d --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.fixed @@ -0,0 +1,30 @@ +//@ edition: 2024 +//@ compile-flags: -Zunstable-options +//@ run-rustfix +#![allow(incomplete_features)] +#![feature(ref_pat_eat_one_layer_2024)] + +pub fn main() { + if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) { + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + } + + if let &mut Some(Some(ref mut x)) = &mut Some(Some(0)) { + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + } + + macro_rules! pat { + ($var:ident) => { ref mut $var }; + } + let &mut pat!(x) = &mut 0; + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + + let &mut (ref mut a, ref mut b) = &mut (true, false); + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + //~| ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut bool = a; + let _: &mut bool = b; +} diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs new file mode 100644 index 00000000000..c6d72b0a9d7 --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs @@ -0,0 +1,30 @@ +//@ edition: 2024 +//@ compile-flags: -Zunstable-options +//@ run-rustfix +#![allow(incomplete_features)] +#![feature(ref_pat_eat_one_layer_2024)] + +pub fn main() { + if let Some(&Some(ref mut x)) = &mut Some(Some(0)) { + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + } + + if let &Some(Some(ref mut x)) = &mut Some(Some(0)) { + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + } + + macro_rules! pat { + ($var:ident) => { ref mut $var }; + } + let &pat!(x) = &mut 0; + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut u8 = x; + + let &(ref mut a, ref mut b) = &mut (true, false); + //~^ ERROR: cannot borrow as mutable inside an `&` pattern + //~| ERROR: cannot borrow as mutable inside an `&` pattern + let _: &mut bool = a; + let _: &mut bool = b; +} diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.stderr new file mode 100644 index 00000000000..964e9f36596 --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.stderr @@ -0,0 +1,43 @@ +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:8:31 + | +LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) { + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:13:31 + | +LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) { + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:21:15 + | +LL | let &pat!(x) = &mut 0; + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:25:19 + | +LL | let &(ref mut a, ref mut b) = &mut (true, false); + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:25:30 + | +LL | let &(ref mut a, ref mut b) = &mut (true, false); + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/match/ref_pat_everywhere-mutability-mismatch.rs b/tests/ui/match/ref_pat_everywhere-fail.rs index 9dd7a7893ec..d1b1c04730d 100644 --- a/tests/ui/match/ref_pat_everywhere-mutability-mismatch.rs +++ b/tests/ui/match/ref_pat_everywhere-fail.rs @@ -5,11 +5,7 @@ pub fn main() { //~^ ERROR: mismatched types [E0308] let _: u32 = x; } - if let &Some(x) = &mut Some(0) { - //~^ ERROR: mismatched types [E0308] - let _: u32 = x; - } - if let Some(&x) = &mut Some(0) { + if let Some(&mut x) = Some(&0) { //~^ ERROR: mismatched types [E0308] let _: u32 = x; } diff --git a/tests/ui/match/ref_pat_everywhere-fail.stderr b/tests/ui/match/ref_pat_everywhere-fail.stderr new file mode 100644 index 00000000000..25a01129f4a --- /dev/null +++ b/tests/ui/match/ref_pat_everywhere-fail.stderr @@ -0,0 +1,38 @@ +error[E0308]: mismatched types + --> $DIR/ref_pat_everywhere-fail.rs:4:17 + | +LL | if let Some(&x) = Some(0) { + | ^^ ------- this expression has type `Option<{integer}>` + | | + | expected integer, found `&_` + | + = note: expected type `{integer}` + found reference `&_` +help: consider removing `&` from the pattern + | +LL | if let Some(x) = Some(0) { + | ~ + +error[E0308]: mismatched types + --> $DIR/ref_pat_everywhere-fail.rs:8:17 + | +LL | if let Some(&mut x) = Some(&0) { + | ^^^^^^ -------- this expression has type `Option<&{integer}>` + | | + | types differ in mutability + | + = note: expected reference `&{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/ref_pat_everywhere-fail.rs:8:17 + | +LL | if let Some(&mut x) = Some(&0) { + | ^^^^^^ +help: consider removing `&mut` from the pattern + | +LL | if let Some(x) = Some(&0) { + | ~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/match/ref_pat_everywhere-mutability-mismatch.stderr b/tests/ui/match/ref_pat_everywhere-mutability-mismatch.stderr deleted file mode 100644 index d512ea5f957..00000000000 --- a/tests/ui/match/ref_pat_everywhere-mutability-mismatch.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/ref_pat_everywhere-mutability-mismatch.rs:4:17 - | -LL | if let Some(&x) = Some(0) { - | ^^ ------- this expression has type `Option<{integer}>` - | | - | expected integer, found `&_` - | - = note: expected type `{integer}` - found reference `&_` -help: consider removing `&` from the pattern - | -LL | if let Some(x) = Some(0) { - | ~ - -error[E0308]: mismatched types - --> $DIR/ref_pat_everywhere-mutability-mismatch.rs:8:12 - | -LL | if let &Some(x) = &mut Some(0) { - | ^^^^^^^^ ------------ this expression has type `&mut Option<{integer}>` - | | - | types differ in mutability - | - = note: expected mutable reference `&mut Option<{integer}>` - found reference `&_` - -error[E0308]: mismatched types - --> $DIR/ref_pat_everywhere-mutability-mismatch.rs:12:17 - | -LL | if let Some(&x) = &mut Some(0) { - | ^^ ------------ this expression has type `&mut Option<{integer}>` - | | - | expected integer, found `&_` - | - = note: expected type `{integer}` - found reference `&_` -help: consider removing `&` from the pattern - | -LL | if let Some(x) = &mut Some(0) { - | ~ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/match/ref_pat_everywhere.rs b/tests/ui/match/ref_pat_everywhere.rs index b3daca48409..9a79c548475 100644 --- a/tests/ui/match/ref_pat_everywhere.rs +++ b/tests/ui/match/ref_pat_everywhere.rs @@ -15,4 +15,10 @@ pub fn main() { if let Some(Some(&x)) = &Some(&mut Some(0)) { let _: u32 = x; } + if let &Some(x) = &mut Some(0) { + let _: u32 = x; + } + if let Some(&x) = &mut Some(0) { + let _: u32 = x; + } } diff --git a/tests/ui/meta/meta-expected-error-wrong-rev.a.stderr b/tests/ui/meta/meta-expected-error-wrong-rev.a.stderr index 4221dd04cfa..a489040f32d 100644 --- a/tests/ui/meta/meta-expected-error-wrong-rev.a.stderr +++ b/tests/ui/meta/meta-expected-error-wrong-rev.a.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/meta-expected-error-wrong-rev.rs:13:18 + --> $DIR/meta-expected-error-wrong-rev.rs:14:18 | LL | let x: u32 = 22_usize; | --- ^^^^^^^^ expected `u32`, found `usize` diff --git a/tests/ui/meta/meta-expected-error-wrong-rev.rs b/tests/ui/meta/meta-expected-error-wrong-rev.rs index de276299482..1c3a3fc4923 100644 --- a/tests/ui/meta/meta-expected-error-wrong-rev.rs +++ b/tests/ui/meta/meta-expected-error-wrong-rev.rs @@ -1,6 +1,7 @@ //@ ignore-compare-mode-polonius //@ revisions: a +//@ unused-revision-names: b //@ should-fail // This is a "meta-test" of the compilertest framework itself. In diff --git a/tests/ui/methods/method-lookup-order.rs b/tests/ui/methods/method-lookup-order.rs index f794e5a7241..ad56da96686 100644 --- a/tests/ui/methods/method-lookup-order.rs +++ b/tests/ui/methods/method-lookup-order.rs @@ -17,6 +17,7 @@ // {mutbar_for_foo, valbar_for_etmut_foo} (which are lower precedent than the inherent `&mut self` method on `Foo`; e.g. b10101 *is* included. //@ revisions: b00001 b00010 b00011 b00100 b00101 b00110 b00111 b01000 b01001 b01100 b01101 b10000 b10001 b10010 b10011 b10101 b10111 b11000 b11001 b11101 +//@ unused-revision-names: b01010 b01011 b01110 b01111 b10100 b10110 b11010 b11011 b11100 b11110 b11111 //@ compile-flags: --check-cfg=cfg(inherent_mut,bar_for_foo,mutbar_for_foo) //@ compile-flags: --check-cfg=cfg(valbar_for_et_foo,valbar_for_etmut_foo) diff --git a/tests/ui/mismatched_types/non_zero_assigned_something.rs b/tests/ui/mismatched_types/non_zero_assigned_something.rs index d2adbe01c18..e94d5249d6a 100644 --- a/tests/ui/mismatched_types/non_zero_assigned_something.rs +++ b/tests/ui/mismatched_types/non_zero_assigned_something.rs @@ -1,9 +1,9 @@ fn main() { - let _: std::num::NonZeroU64 = 1; + let _: std::num::NonZero<u64> = 1; //~^ ERROR mismatched types - //~| HELP consider calling `NonZeroU64::new` + //~| HELP consider calling `NonZero::new` - let _: Option<std::num::NonZeroU64> = 1; + let _: Option<std::num::NonZero<u64>> = 1; //~^ ERROR mismatched types - //~| HELP consider calling `NonZeroU64::new` + //~| HELP consider calling `NonZero::new` } diff --git a/tests/ui/mismatched_types/non_zero_assigned_something.stderr b/tests/ui/mismatched_types/non_zero_assigned_something.stderr index f8e86905ab9..aa015bd2efc 100644 --- a/tests/ui/mismatched_types/non_zero_assigned_something.stderr +++ b/tests/ui/mismatched_types/non_zero_assigned_something.stderr @@ -1,32 +1,32 @@ error[E0308]: mismatched types - --> $DIR/non_zero_assigned_something.rs:2:35 + --> $DIR/non_zero_assigned_something.rs:2:37 | -LL | let _: std::num::NonZeroU64 = 1; - | -------------------- ^ expected `NonZero<u64>`, found integer +LL | let _: std::num::NonZero<u64> = 1; + | ---------------------- ^ expected `NonZero<u64>`, found integer | | | expected due to this | = note: expected struct `NonZero<u64>` found type `{integer}` -help: consider calling `NonZeroU64::new` +help: consider calling `NonZero::new` | -LL | let _: std::num::NonZeroU64 = NonZeroU64::new(1).unwrap(); - | ++++++++++++++++ ++++++++++ +LL | let _: std::num::NonZero<u64> = NonZero::new(1).unwrap(); + | +++++++++++++ ++++++++++ error[E0308]: mismatched types - --> $DIR/non_zero_assigned_something.rs:6:43 + --> $DIR/non_zero_assigned_something.rs:6:45 | -LL | let _: Option<std::num::NonZeroU64> = 1; - | ---------------------------- ^ expected `Option<NonZero<u64>>`, found integer +LL | let _: Option<std::num::NonZero<u64>> = 1; + | ------------------------------ ^ expected `Option<NonZero<u64>>`, found integer | | | expected due to this | = note: expected enum `Option<NonZero<u64>>` found type `{integer}` -help: consider calling `NonZeroU64::new` +help: consider calling `NonZero::new` | -LL | let _: Option<std::num::NonZeroU64> = NonZeroU64::new(1); - | ++++++++++++++++ + +LL | let _: Option<std::num::NonZero<u64>> = NonZero::new(1); + | +++++++++++++ + error: aborting due to 2 previous errors diff --git a/tests/ui/parser/attribute/attr-bad-meta-4.rs b/tests/ui/parser/attribute/attr-bad-meta-4.rs index cedbd1d6686..2a69ae5ac06 100644 --- a/tests/ui/parser/attribute/attr-bad-meta-4.rs +++ b/tests/ui/parser/attribute/attr-bad-meta-4.rs @@ -1,12 +1,17 @@ macro_rules! mac { ($attr_item: meta) => { #[cfg($attr_item)] - //~^ ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` - //~| ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` + //~^ ERROR expected unsuffixed literal, found `an(arbitrary token stream)` + //~| ERROR expected unsuffixed literal, found `an(arbitrary token stream)` struct S; } } mac!(an(arbitrary token stream)); +#[cfg(feature = -1)] +//~^ ERROR expected unsuffixed literal, found `-` +//~| ERROR expected unsuffixed literal, found `-` +fn handler() {} + fn main() {} diff --git a/tests/ui/parser/attribute/attr-bad-meta-4.stderr b/tests/ui/parser/attribute/attr-bad-meta-4.stderr index a543bcb692e..192be28db3f 100644 --- a/tests/ui/parser/attribute/attr-bad-meta-4.stderr +++ b/tests/ui/parser/attribute/attr-bad-meta-4.stderr @@ -1,4 +1,10 @@ -error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)` +error: expected unsuffixed literal, found `-` + --> $DIR/attr-bad-meta-4.rs:12:17 + | +LL | #[cfg(feature = -1)] + | ^ + +error: expected unsuffixed literal, found `an(arbitrary token stream)` --> $DIR/attr-bad-meta-4.rs:3:15 | LL | #[cfg($attr_item)] @@ -9,7 +15,7 @@ LL | mac!(an(arbitrary token stream)); | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)` +error: expected unsuffixed literal, found `an(arbitrary token stream)` --> $DIR/attr-bad-meta-4.rs:3:15 | LL | #[cfg($attr_item)] @@ -21,5 +27,13 @@ LL | mac!(an(arbitrary token stream)); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 2 previous errors +error: expected unsuffixed literal, found `-` + --> $DIR/attr-bad-meta-4.rs:12:17 + | +LL | #[cfg(feature = -1)] + | ^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.fixed b/tests/ui/parser/attribute/attr-unquoted-ident.fixed deleted file mode 100644 index bc861ef69fb..00000000000 --- a/tests/ui/parser/attribute/attr-unquoted-ident.fixed +++ /dev/null @@ -1,17 +0,0 @@ -//@ compile-flags: -Zdeduplicate-diagnostics=yes -//@ run-rustfix - -#![allow(unexpected_cfgs)] - -fn main() { - #[cfg(key="foo")] - //~^ ERROR expected unsuffixed literal, found `foo` - //~| HELP surround the identifier with quotation marks to parse it as a string - println!(); - #[cfg(key="bar")] - println!(); - #[cfg(key="foo bar baz")] - //~^ ERROR expected unsuffixed literal, found `foo` - //~| HELP surround the identifier with quotation marks to parse it as a string - println!(); -} diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.rs b/tests/ui/parser/attribute/attr-unquoted-ident.rs index 8bdb8605ebb..5b15b8d69fc 100644 --- a/tests/ui/parser/attribute/attr-unquoted-ident.rs +++ b/tests/ui/parser/attribute/attr-unquoted-ident.rs @@ -1,17 +1,25 @@ //@ compile-flags: -Zdeduplicate-diagnostics=yes -//@ run-rustfix #![allow(unexpected_cfgs)] fn main() { #[cfg(key=foo)] //~^ ERROR expected unsuffixed literal, found `foo` - //~| HELP surround the identifier with quotation marks to parse it as a string + //~| HELP surround the identifier with quotation marks to make it into a string literal println!(); #[cfg(key="bar")] println!(); #[cfg(key=foo bar baz)] //~^ ERROR expected unsuffixed literal, found `foo` - //~| HELP surround the identifier with quotation marks to parse it as a string + //~| HELP surround the identifier with quotation marks to make it into a string literal println!(); } + +// Don't suggest surrounding `$name` or `nickname` with quotes: + +macro_rules! make { + ($name:ident) => { #[doc(alias = $name)] pub struct S; } + //~^ ERROR expected unsuffixed literal, found `nickname` +} + +make!(nickname); //~ NOTE in this expansion diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.stderr b/tests/ui/parser/attribute/attr-unquoted-ident.stderr index 99484a51110..e0f99459c44 100644 --- a/tests/ui/parser/attribute/attr-unquoted-ident.stderr +++ b/tests/ui/parser/attribute/attr-unquoted-ident.stderr @@ -1,24 +1,35 @@ error: expected unsuffixed literal, found `foo` - --> $DIR/attr-unquoted-ident.rs:7:15 + --> $DIR/attr-unquoted-ident.rs:6:15 | LL | #[cfg(key=foo)] | ^^^ | -help: surround the identifier with quotation marks to parse it as a string +help: surround the identifier with quotation marks to make it into a string literal | LL | #[cfg(key="foo")] | + + error: expected unsuffixed literal, found `foo` - --> $DIR/attr-unquoted-ident.rs:13:15 + --> $DIR/attr-unquoted-ident.rs:12:15 | LL | #[cfg(key=foo bar baz)] | ^^^ | -help: surround the identifier with quotation marks to parse it as a string +help: surround the identifier with quotation marks to make it into a string literal | LL | #[cfg(key="foo bar baz")] | + + -error: aborting due to 2 previous errors +error: expected unsuffixed literal, found `nickname` + --> $DIR/attr-unquoted-ident.rs:21:38 + | +LL | ($name:ident) => { #[doc(alias = $name)] pub struct S; } + | ^^^^^ +... +LL | make!(nickname); + | --------------- in this macro invocation + | + = note: this error originates in the macro `make` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors diff --git a/tests/ui/parser/else-no-if.rs b/tests/ui/parser/else-no-if.rs index f0b40ecde66..ad5262cd2cc 100644 --- a/tests/ui/parser/else-no-if.rs +++ b/tests/ui/parser/else-no-if.rs @@ -1,3 +1,7 @@ +macro_rules! falsy { + () => { false }; +} + fn foo() { if true { } else false { @@ -25,6 +29,32 @@ fn foo4() { {} } +fn foo5() { + if true { + } else falsy!() { + //~^ ERROR expected `{`, found `falsy` + } +} + +fn foo6() { + if true { + } else falsy!(); + //~^ ERROR expected `{`, found `falsy` +} + +fn foo7() { + if true { + } else falsy! {} { + //~^ ERROR expected `{`, found `falsy` + } +} + +fn foo8() { + if true { + } else falsy! {}; + //~^ ERROR expected `{`, found `falsy` +} + fn falsy() -> bool { false } diff --git a/tests/ui/parser/else-no-if.stderr b/tests/ui/parser/else-no-if.stderr index b9c1a75276c..2e3e8f6b50e 100644 --- a/tests/ui/parser/else-no-if.stderr +++ b/tests/ui/parser/else-no-if.stderr @@ -1,5 +1,5 @@ error: expected `{`, found keyword `false` - --> $DIR/else-no-if.rs:3:12 + --> $DIR/else-no-if.rs:7:12 | LL | } else false { | ---- ^^^^^ @@ -12,7 +12,7 @@ LL | } else if false { | ++ error: expected `{`, found `falsy` - --> $DIR/else-no-if.rs:10:12 + --> $DIR/else-no-if.rs:14:12 | LL | } else falsy() { | ---- ^^^^^ @@ -25,7 +25,7 @@ LL | } else if falsy() { | ++ error: expected `{`, found `falsy` - --> $DIR/else-no-if.rs:17:12 + --> $DIR/else-no-if.rs:21:12 | LL | } else falsy(); | ^^^^^ expected `{` @@ -36,7 +36,7 @@ LL | } else { falsy() }; | + + error: expected `{`, found keyword `loop` - --> $DIR/else-no-if.rs:23:12 + --> $DIR/else-no-if.rs:27:12 | LL | } else loop{} | ^^^^ expected `{` @@ -46,5 +46,51 @@ help: try placing this code inside a block LL | } else { loop{} } | + + -error: aborting due to 4 previous errors +error: expected `{`, found `falsy` + --> $DIR/else-no-if.rs:34:12 + | +LL | } else falsy!() { + | ---- ^^^^^ + | | + | expected an `if` or a block after this `else` + | +help: add an `if` if this is the condition of a chained `else if` statement + | +LL | } else if falsy!() { + | ++ + +error: expected `{`, found `falsy` + --> $DIR/else-no-if.rs:41:12 + | +LL | } else falsy!(); + | ^^^^^ expected `{` + | +help: try placing this code inside a block + | +LL | } else { falsy!() }; + | + + + +error: expected `{`, found `falsy` + --> $DIR/else-no-if.rs:47:12 + | +LL | } else falsy! {} { + | ^^^^^ expected `{` + | +help: try placing this code inside a block + | +LL | } else { falsy! {} } { + | + + + +error: expected `{`, found `falsy` + --> $DIR/else-no-if.rs:54:12 + | +LL | } else falsy! {}; + | ^^^^^ expected `{` + | +help: try placing this code inside a block + | +LL | } else { falsy! {} }; + | + + + +error: aborting due to 8 previous errors diff --git a/tests/ui/parser/macro/statement-boundaries.rs b/tests/ui/parser/macro/statement-boundaries.rs new file mode 100644 index 00000000000..67a6aa30f0c --- /dev/null +++ b/tests/ui/parser/macro/statement-boundaries.rs @@ -0,0 +1,104 @@ +//@ run-pass +//@ edition:2021 + +// This is a test of several uses of rustc_ast::util::classify::expr_requires_semi_to_be_stmt +// by the Rust parser, which relates to the insertion of statement boundaries +// after certain kinds of expressions if they appear at the head of a statement. + +#![allow(unused_braces, unused_unsafe)] + +macro_rules! unit { + () => { + { () } + }; +} + +#[derive(Copy, Clone)] +struct X; + +fn main() { + let x = X; + + // There is a statement boundary before `|x| x`, so it's a closure. + let _: fn(X) -> X = { if true {} |x| x }; + let _: fn(X) -> X = { if true {} else {} |x| x }; + let _: fn(X) -> X = { match () { () => {} } |x| x }; + let _: fn(X) -> X = { { () } |x| x }; + let _: fn(X) -> X = { unsafe {} |x| x }; + let _: fn(X) -> X = { while false {} |x| x }; + let _: fn(X) -> X = { loop { break; } |x| x }; + let _: fn(X) -> X = { for _ in 0..0 {} |x| x }; + let _: fn(X) -> X = { const {} |x| x }; + let _: fn(X) -> X = { unit! {} |x| x }; + + // No statement boundary, so `|x| x` is 2× BitOr operation. + () = { "" |x| x }; + () = { ("") |x| x }; + () = { [""] |x| x }; + () = { unit!() |x| x }; + () = { unit![] |x| x }; + + // All the same cases, but as a match arm. + () = match x { + // Statement boundary before `| X`, which becomes a new arm with leading vert. + X if false => if true {} | X if false => {} + X if false => if true {} else {} | X if false => {} + X if false => match () { () => {} } | X if false => {} + X if false => { () } | X if false => {} + X if false => unsafe {} | X if false => {} + X if false => while false {} | X if false => {} + X if false => loop { break; } | X if false => {} + X if false => for _ in 0..0 {} | X if false => {} + X if false => const {} | X if false => {} + + // No statement boundary, so `| X` is BitOr. + X if false => "" | X, + X if false => ("") | X, + X if false => [""] | X, + X if false => unit! {} | X, // !! inconsistent with braced mac call in statement position + X if false => unit!() | X, + X if false => unit![] | X, + + X => {} + }; + + // Test how the statement boundary logic interacts with macro metavariables / + // "invisible delimiters". + macro_rules! assert_statement_boundary { + ($expr:expr) => { + let _: fn(X) -> X = { $expr |x| x }; + + () = match X { + X if false => $expr | X if false => {} + X => {} + }; + }; + } + macro_rules! assert_no_statement_boundary { + ($expr:expr) => { + () = { $expr |x| x }; + + () = match x { + X if false => $expr | X, + X => {} + }; + }; + } + assert_statement_boundary!(if true {}); + assert_no_statement_boundary!(""); +} + +impl std::ops::BitOr<X> for () { + type Output = (); + fn bitor(self, _: X) {} +} + +impl std::ops::BitOr<X> for &str { + type Output = (); + fn bitor(self, _: X) {} +} + +impl<T, const N: usize> std::ops::BitOr<X> for [T; N] { + type Output = (); + fn bitor(self, _: X) {} +} diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs new file mode 100644 index 00000000000..32125211a91 --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs @@ -0,0 +1,6 @@ +fn foo() { + let x = Tr<A, A:>; + //~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` +} + +fn main() {} diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr new file mode 100644 index 00000000000..551b2e3ff09 --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr @@ -0,0 +1,14 @@ +error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` + --> $DIR/turbofish-arg-with-stray-colon.rs:2:17 + | +LL | let x = Tr<A, A:>; + | ^ expected one of 8 possible tokens + | + = note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728> +help: maybe write a path separator here + | +LL | let x = Tr<A, A::>; + | ~~ + +error: aborting due to 1 previous error + diff --git a/tests/ui/rust-2018/async-ident.fixed b/tests/ui/rust-2018/async-ident.fixed index 4e31f674435..639a8a245fb 100644 --- a/tests/ui/rust-2018/async-ident.fixed +++ b/tests/ui/rust-2018/async-ident.fixed @@ -9,16 +9,14 @@ fn r#async() {} //~ ERROR async macro_rules! foo { ($foo:ident) => {}; - ($r#async:expr, r#async) => {}; + ($async:expr, r#async) => {}; //~^ ERROR async - //~| ERROR async - //~| WARN this is accepted in the current edition //~| WARN this is accepted in the current edition } foo!(r#async); - //~^ ERROR async - //~| WARN this is accepted in the current edition +//~^ ERROR async +//~| WARN this is accepted in the current edition mod dont_lint_raw { fn r#async() {} diff --git a/tests/ui/rust-2018/async-ident.rs b/tests/ui/rust-2018/async-ident.rs index 4c5134a2923..7921f05f481 100644 --- a/tests/ui/rust-2018/async-ident.rs +++ b/tests/ui/rust-2018/async-ident.rs @@ -11,14 +11,12 @@ macro_rules! foo { ($foo:ident) => {}; ($async:expr, async) => {}; //~^ ERROR async - //~| ERROR async - //~| WARN this is accepted in the current edition //~| WARN this is accepted in the current edition } foo!(async); - //~^ ERROR async - //~| WARN this is accepted in the current edition +//~^ ERROR async +//~| WARN this is accepted in the current edition mod dont_lint_raw { fn r#async() {} diff --git a/tests/ui/rust-2018/async-ident.stderr b/tests/ui/rust-2018/async-ident.stderr index 5b8d8184f4f..4ab061dd6f5 100644 --- a/tests/ui/rust-2018/async-ident.stderr +++ b/tests/ui/rust-2018/async-ident.stderr @@ -14,15 +14,6 @@ LL | #![deny(keyword_idents)] = note: `#[deny(keyword_idents_2018)]` implied by `#[deny(keyword_idents)]` error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:12:7 - | -LL | ($async:expr, async) => {}; - | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! - = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> - -error: `async` is a keyword in the 2018 edition --> $DIR/async-ident.rs:12:19 | LL | ($async:expr, async) => {}; @@ -32,7 +23,7 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:19:6 + --> $DIR/async-ident.rs:17:6 | LL | foo!(async); | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -41,7 +32,7 @@ LL | foo!(async); = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:28:11 + --> $DIR/async-ident.rs:26:11 | LL | trait async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -50,7 +41,7 @@ LL | trait async {} = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:32:10 + --> $DIR/async-ident.rs:30:10 | LL | impl async for MyStruct {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -59,7 +50,7 @@ LL | impl async for MyStruct {} = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:38:12 + --> $DIR/async-ident.rs:36:12 | LL | static async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -68,7 +59,7 @@ LL | static async: u32 = 0; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:44:11 + --> $DIR/async-ident.rs:42:11 | LL | const async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -77,7 +68,7 @@ LL | const async: u32 = 0; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:50:15 + --> $DIR/async-ident.rs:48:15 | LL | impl Foo { fn async() {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -86,7 +77,7 @@ LL | impl Foo { fn async() {} } = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:55:12 + --> $DIR/async-ident.rs:53:12 | LL | struct async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -95,7 +86,7 @@ LL | struct async {} = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:58:9 + --> $DIR/async-ident.rs:56:9 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -104,7 +95,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:58:16 + --> $DIR/async-ident.rs:56:16 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -113,7 +104,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:58:24 + --> $DIR/async-ident.rs:56:24 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -122,7 +113,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:69:19 + --> $DIR/async-ident.rs:67:19 | LL | () => (pub fn async() {}) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -131,7 +122,7 @@ LL | () => (pub fn async() {}) = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:76:6 + --> $DIR/async-ident.rs:74:6 | LL | (async) => (1) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -139,5 +130,5 @@ LL | (async) => (1) = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> -error: aborting due to 15 previous errors +error: aborting due to 14 previous errors diff --git a/tests/ui/rust-2024/gen-kw-in-macro.rs b/tests/ui/rust-2024/gen-kw-in-macro.rs new file mode 100644 index 00000000000..3ccbe05b226 --- /dev/null +++ b/tests/ui/rust-2024/gen-kw-in-macro.rs @@ -0,0 +1,13 @@ +//@ check-pass + +#![deny(keyword_idents_2024)] + +macro_rules! foo { + ($gen:expr) => { + $gen + }; +} + +fn main() { + foo!(println!("hello, world")); +} diff --git a/tests/ui/rust-2024/gen-kw.e2015.stderr b/tests/ui/rust-2024/gen-kw.e2015.stderr index b12363184b7..b1074f77e00 100644 --- a/tests/ui/rust-2024/gen-kw.e2015.stderr +++ b/tests/ui/rust-2024/gen-kw.e2015.stderr @@ -22,5 +22,14 @@ LL | let gen = r#gen; = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> -error: aborting due to 2 previous errors +error: `gen` is a keyword in the 2024 edition + --> $DIR/gen-kw.rs:19:27 + | +LL | () => { mod test { fn gen() {} } } + | ^^^ help: you can use a raw identifier to stay compatible: `r#gen` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: aborting due to 3 previous errors diff --git a/tests/ui/rust-2024/gen-kw.e2018.stderr b/tests/ui/rust-2024/gen-kw.e2018.stderr index e10fc4c4512..b902cff7fdb 100644 --- a/tests/ui/rust-2024/gen-kw.e2018.stderr +++ b/tests/ui/rust-2024/gen-kw.e2018.stderr @@ -22,5 +22,14 @@ LL | let gen = r#gen; = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024! = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> -error: aborting due to 2 previous errors +error: `gen` is a keyword in the 2024 edition + --> $DIR/gen-kw.rs:19:27 + | +LL | () => { mod test { fn gen() {} } } + | ^^^ help: you can use a raw identifier to stay compatible: `r#gen` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: aborting due to 3 previous errors diff --git a/tests/ui/rust-2024/gen-kw.rs b/tests/ui/rust-2024/gen-kw.rs index 3d2a3f95165..04251cbcac4 100644 --- a/tests/ui/rust-2024/gen-kw.rs +++ b/tests/ui/rust-2024/gen-kw.rs @@ -14,3 +14,12 @@ fn main() { //[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! //[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024! } + +macro_rules! t { + () => { mod test { fn gen() {} } } + //~^ ERROR `gen` is a keyword in the 2024 edition + //[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! + //[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024! +} + +t!(); diff --git a/tests/ui/span/macro-ty-params.rs b/tests/ui/span/macro-ty-params.rs index cf28b0255d1..c7ce9b9faed 100644 --- a/tests/ui/span/macro-ty-params.rs +++ b/tests/ui/span/macro-ty-params.rs @@ -11,5 +11,4 @@ fn main() { foo::<>!(); //~ ERROR generic arguments in macro path m!(Default<>); //~^ ERROR unexpected generic arguments in path - //~^^ ERROR generic arguments in macro path } diff --git a/tests/ui/span/macro-ty-params.stderr b/tests/ui/span/macro-ty-params.stderr index 7023ef8cd1c..138cd2598a1 100644 --- a/tests/ui/span/macro-ty-params.stderr +++ b/tests/ui/span/macro-ty-params.stderr @@ -16,11 +16,5 @@ error: unexpected generic arguments in path LL | m!(Default<>); | ^^ -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:12:15 - | -LL | m!(Default<>); - | ^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/suggestions/unused-imports.fixed b/tests/ui/suggestions/unused-imports.fixed new file mode 100644 index 00000000000..57dd091c043 --- /dev/null +++ b/tests/ui/suggestions/unused-imports.fixed @@ -0,0 +1,35 @@ +//@ run-rustfix +//@ check-pass + +#![warn(unused_imports)] + +pub mod nested { + pub struct A; + pub struct B; + pub struct C; + pub struct D; + pub mod even_more { + pub struct E; + pub struct F; + pub struct G; + } + pub mod another { + pub struct H; + pub struct I; + } +} + +use nested::B; +//~^ WARN unused import + +use nested::even_more::F; +//~^^^^^^^ WARN unused import + +// Note that the following fix should result in `::{self}`, not `::self`. The latter is invalid +// Rust syntax, so the braces should not be removed. +use nested::another::{self}; +//~^ WARN unused import + +fn main() { + let _ = (B, F, another::I); +} diff --git a/tests/ui/suggestions/unused-imports.rs b/tests/ui/suggestions/unused-imports.rs new file mode 100644 index 00000000000..5f9dd243bdd --- /dev/null +++ b/tests/ui/suggestions/unused-imports.rs @@ -0,0 +1,42 @@ +//@ run-rustfix +//@ check-pass + +#![warn(unused_imports)] + +pub mod nested { + pub struct A; + pub struct B; + pub struct C; + pub struct D; + pub mod even_more { + pub struct E; + pub struct F; + pub struct G; + } + pub mod another { + pub struct H; + pub struct I; + } +} + +use nested::{A, B, C}; +//~^ WARN unused import + +use nested::{ + D, + even_more::{ + E, + F, + G, + }, + }; +//~^^^^^^^ WARN unused import + +// Note that the following fix should result in `::{self}`, not `::self`. The latter is invalid +// Rust syntax, so the braces should not be removed. +use nested::another::{self, I}; +//~^ WARN unused import + +fn main() { + let _ = (B, F, another::I); +} diff --git a/tests/ui/suggestions/unused-imports.stderr b/tests/ui/suggestions/unused-imports.stderr new file mode 100644 index 00000000000..bf112608da7 --- /dev/null +++ b/tests/ui/suggestions/unused-imports.stderr @@ -0,0 +1,32 @@ +warning: unused imports: `A`, `C` + --> $DIR/unused-imports.rs:22:14 + | +LL | use nested::{A, B, C}; + | ^ ^ + | +note: the lint level is defined here + --> $DIR/unused-imports.rs:4:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ + +warning: unused imports: `D`, `E`, `G` + --> $DIR/unused-imports.rs:26:5 + | +LL | D, + | ^ +LL | even_more::{ +LL | E, + | ^ +LL | F, +LL | G, + | ^ + +warning: unused import: `I` + --> $DIR/unused-imports.rs:37:29 + | +LL | use nested::another::{self, I}; + | ^ + +warning: 3 warnings emitted + diff --git a/tests/ui/target-feature/tied-features-cli.rs b/tests/ui/target-feature/tied-features-cli.rs index 1168245461f..17c13826ce9 100644 --- a/tests/ui/target-feature/tied-features-cli.rs +++ b/tests/ui/target-feature/tied-features-cli.rs @@ -1,4 +1,4 @@ -//@ revisions: one two three +//@ revisions: one two three four //@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu //@ needs-llvm-components: aarch64 // diff --git a/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-1.rs b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-1.rs new file mode 100644 index 00000000000..151c3b226c1 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-1.rs @@ -0,0 +1,43 @@ +//@ compile-flags: -Znext-solver=coherence +//@ check-pass + +// A regression test for #124791. Computing ambiguity causes +// for the overlap of the `ToString` impls caused an ICE. +#![crate_type = "lib"] +#![feature(min_specialization)] +trait Display {} + +trait ToOwned { + type Owned; +} + +impl<T> ToOwned for T { + type Owned = T; +} + +struct Cow<B: ?Sized>(B); + +impl<B: ?Sized> Display for Cow<B> +where + B: ToOwned, + B::Owned: Display, +{ +} + +impl Display for () {} + +trait ToString { + fn to_string(); +} + +impl<T: Display + ?Sized> ToString for T { + default fn to_string() {} +} + +impl ToString for Cow<str> { + fn to_string() {} +} + +impl ToOwned for str { + type Owned = (); +} diff --git a/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.rs b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.rs new file mode 100644 index 00000000000..b472499cb0b --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.rs @@ -0,0 +1,19 @@ +//@ compile-flags: -Znext-solver=coherence + +// A regression test for #124791. Computing ambiguity causes +// for the overlap of the `ToString` impls caused an ICE. +#![crate_type = "lib"] +trait ToOwned { + type Owned; +} +impl<T> ToOwned for T { + type Owned = u8; +} +impl ToOwned for str { + type Owned = i8; +} + +trait Overlap {} +impl<T: ToOwned<Owned = i8> + ?Sized> Overlap for T {} +impl Overlap for str {} +//~^ ERROR conflicting implementations of trait `Overlap` diff --git a/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.stderr b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.stderr new file mode 100644 index 00000000000..469f7a909b1 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/ambiguity-causes-canonical-state-ice-2.stderr @@ -0,0 +1,11 @@ +error[E0119]: conflicting implementations of trait `Overlap` for type `str` + --> $DIR/ambiguity-causes-canonical-state-ice-2.rs:18:1 + | +LL | impl<T: ToOwned<Owned = i8> + ?Sized> Overlap for T {} + | --------------------------------------------------- first implementation here +LL | impl Overlap for str {} + | ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `str` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs index 8bb4ff46907..7eea81ce03c 100644 --- a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs +++ b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs @@ -61,7 +61,7 @@ where // entering the cycle from `A` fails, but would work if we were to use the cache // result of `B<X>`. impls_trait::<A<X>, _, _, _>(); - //~^ ERROR the trait bound `A<X>: Trait<i32, u8, u8>` is not satisfied + //~^ ERROR the trait bound `A<X>: Trait<_, _, _>` is not satisfied } fn main() { diff --git a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr index cdb4ff4588f..ffa3f29e4bd 100644 --- a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr +++ b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr @@ -1,10 +1,11 @@ -error[E0277]: the trait bound `A<X>: Trait<i32, u8, u8>` is not satisfied +error[E0277]: the trait bound `A<X>: Trait<_, _, _>` is not satisfied --> $DIR/incompleteness-unstable-result.rs:63:19 | LL | impls_trait::<A<X>, _, _, _>(); - | ^^^^ the trait `Trait<i32, u8, u8>` is not implemented for `A<X>`, which is required by `A<X>: Trait<_, _, _>` + | ^^^^ the trait `Trait<_, _, _>` is not implemented for `A<X>`, which is required by `A<X>: Trait<_, _, _>` | -note: required for `A<X>` to implement `Trait<i32, u8, u8>` + = help: the trait `Trait<U, V, D>` is implemented for `A<T>` +note: required for `A<X>` to implement `Trait<_, _, _>` --> $DIR/incompleteness-unstable-result.rs:32:50 | LL | impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T> @@ -13,16 +14,12 @@ LL | impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T> LL | A<T>: Trait<U, D, V>, | -------------- unsatisfied trait bound introduced here = note: 8 redundant requirements hidden - = note: required for `A<X>` to implement `Trait<i32, u8, u8>` + = note: required for `A<X>` to implement `Trait<_, _, _>` note: required by a bound in `impls_trait` --> $DIR/incompleteness-unstable-result.rs:51:28 | LL | fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {} | ^^^^^^^^^^^^^^ required by this bound in `impls_trait` -help: consider extending the `where` clause, but there might be an alternative better way to express this requirement - | -LL | X: IncompleteGuidance<u32, i16>, A<X>: Trait<i32, u8, u8> - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/transmutability/primitives/bool-mut.rs b/tests/ui/transmutability/primitives/bool-mut.rs index 5f3f4f3a8c5..09b6d582d87 100644 --- a/tests/ui/transmutability/primitives/bool-mut.rs +++ b/tests/ui/transmutability/primitives/bool-mut.rs @@ -1,5 +1,4 @@ //@ check-fail -//@[next] compile-flags: -Znext-solver #![feature(transmutability)] mod assert { diff --git a/tests/ui/transmutability/primitives/bool-mut.stderr b/tests/ui/transmutability/primitives/bool-mut.stderr index 464c2755e11..a6cf146659e 100644 --- a/tests/ui/transmutability/primitives/bool-mut.stderr +++ b/tests/ui/transmutability/primitives/bool-mut.stderr @@ -1,11 +1,11 @@ error[E0277]: `u8` cannot be safely transmuted into `bool` - --> $DIR/bool-mut.rs:15:50 + --> $DIR/bool-mut.rs:14:50 | LL | assert::is_transmutable::<&'static mut bool, &'static mut u8>() | ^^^^^^^^^^^^^^^ at least one value of `u8` isn't a bit-valid value of `bool` | note: required by a bound in `is_transmutable` - --> $DIR/bool-mut.rs:10:14 + --> $DIR/bool-mut.rs:9:14 | LL | pub fn is_transmutable<Src, Dst>() | --------------- required by a bound in this function diff --git a/tests/ui/type-alias-impl-trait/static-lifetime-through-closure-issue-122775.rs b/tests/ui/type-alias-impl-trait/static-lifetime-through-closure-issue-122775.rs new file mode 100644 index 00000000000..1bb0acf9b75 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/static-lifetime-through-closure-issue-122775.rs @@ -0,0 +1,17 @@ +//@ check-pass + +#![feature(type_alias_impl_trait)] + +fn spawn<T, F>(future: F) -> impl Sized +where + F: FnOnce() -> T, +{ + future +} + +fn spawn_task(sender: &'static ()) -> impl Sized { + type Tait = impl Sized + 'static; + spawn::<Tait, _>(move || sender) +} + +fn main() {} diff --git a/tests/ui/type/pattern_types/range_patterns_usage.rs b/tests/ui/type/pattern_types/range_patterns_usage.rs index 7fe50423c51..2a9f736ae61 100644 --- a/tests/ui/type/pattern_types/range_patterns_usage.rs +++ b/tests/ui/type/pattern_types/range_patterns_usage.rs @@ -8,7 +8,7 @@ use std::pat::pattern_type; -type X = std::num::NonZeroU32; +type X = std::num::NonZero<u32>; type Y = pattern_type!(u32 is 1..); type Z = Option<pattern_type!(u32 is 1..)>; struct NonZeroU32New(pattern_type!(u32 is 1..)); diff --git a/tests/ui/version/version-info-flags.rs b/tests/ui/version/version-info-flags.rs index 612113452c4..96be9c5385b 100644 --- a/tests/ui/version/version-info-flags.rs +++ b/tests/ui/version/version-info-flags.rs @@ -4,6 +4,6 @@ //@ check-pass //@[version] compile-flags: -V //@[verbose-version] compile-flags: -vV -//@[long-verbose-verison] compile-flags: --version --verbose +//@[long-verbose-version] compile-flags: --version --verbose fn main() {} diff --git a/tests/ui/write-fmt-errors.rs b/tests/ui/write-fmt-errors.rs index f194e25b556..1dafb9a784b 100644 --- a/tests/ui/write-fmt-errors.rs +++ b/tests/ui/write-fmt-errors.rs @@ -1,9 +1,11 @@ //@ run-pass +//@ needs-unwind #![feature(io_error_uncategorized)] use std::fmt; use std::io::{self, Error, Write, sink}; +use std::panic::catch_unwind; struct ErrorDisplay; @@ -15,7 +17,6 @@ impl fmt::Display for ErrorDisplay { struct ErrorWriter; -const FORMAT_ERROR: io::ErrorKind = io::ErrorKind::Uncategorized; const WRITER_ERROR: io::ErrorKind = io::ErrorKind::NotConnected; impl Write for ErrorWriter { @@ -27,22 +28,28 @@ impl Write for ErrorWriter { } fn main() { - // Test that the error from the formatter is propagated. - let res = write!(sink(), "{} {} {}", 1, ErrorDisplay, "bar"); - assert!(res.is_err(), "formatter error did not propagate"); - assert_eq!(res.unwrap_err().kind(), FORMAT_ERROR); - // Test that an underlying error is propagated let res = write!(ErrorWriter, "abc"); assert!(res.is_err(), "writer error did not propagate"); - // Writer error + // Test that the error from the formatter is detected. + let res = catch_unwind(|| write!(sink(), "{} {} {}", 1, ErrorDisplay, "bar")); + let err = res.expect_err("formatter error did not lead to panic").downcast::<&str>().unwrap(); + assert!( + err.contains("formatting trait implementation returned an error"), + "unexpected panic: {}", err + ); + + // Writer error when there's some string before the first `{}` let res = write!(ErrorWriter, "abc {}", ErrorDisplay); assert!(res.is_err(), "writer error did not propagate"); assert_eq!(res.unwrap_err().kind(), WRITER_ERROR); - // Formatter error - let res = write!(ErrorWriter, "{} abc", ErrorDisplay); - assert!(res.is_err(), "formatter error did not propagate"); - assert_eq!(res.unwrap_err().kind(), FORMAT_ERROR); + // Formatter error when the `{}` comes first + let res = catch_unwind(|| write!(ErrorWriter, "{} abc", ErrorDisplay)); + let err = res.expect_err("formatter error did not lead to panic").downcast::<&str>().unwrap(); + assert!( + err.contains("formatting trait implementation returned an error"), + "unexpected panic: {}", err + ); } |
