diff options
Diffstat (limited to 'tests')
50 files changed, 598 insertions, 150 deletions
diff --git a/tests/codegen/intrinsics/typed_swap.rs b/tests/codegen/intrinsics/typed_swap.rs index e73931d1d54..6b55078407a 100644 --- a/tests/codegen/intrinsics/typed_swap.rs +++ b/tests/codegen/intrinsics/typed_swap.rs @@ -8,14 +8,14 @@ #![crate_type = "lib"] #![feature(core_intrinsics)] -use std::intrinsics::typed_swap; +use std::intrinsics::typed_swap_nonoverlapping; // CHECK-LABEL: @swap_unit( #[no_mangle] pub unsafe fn swap_unit(x: &mut (), y: &mut ()) { // CHECK: start // CHECK-NEXT: ret void - typed_swap(x, y) + typed_swap_nonoverlapping(x, y) } // CHECK-LABEL: @swap_i32( @@ -32,7 +32,7 @@ pub unsafe fn swap_i32(x: &mut i32, y: &mut i32) { // OPT3: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 4, i1 false) // CHECK: store i32 %[[TEMP]], ptr %y, align 4 // CHECK: ret void - typed_swap(x, y) + typed_swap_nonoverlapping(x, y) } // CHECK-LABEL: @swap_pair( @@ -47,7 +47,7 @@ pub unsafe fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) { // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 8, i1 false) // CHECK: store i32 // CHECK: store i32 - typed_swap(x, y) + typed_swap_nonoverlapping(x, y) } // CHECK-LABEL: @swap_str( @@ -63,7 +63,7 @@ pub unsafe fn swap_str<'a>(x: &mut &'a str, y: &mut &'a str) { // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 16, i1 false) // CHECK: store ptr // CHECK: store i64 - typed_swap(x, y) + typed_swap_nonoverlapping(x, y) } // OPT0-LABEL: @swap_string( @@ -73,5 +73,5 @@ pub unsafe fn swap_string(x: &mut String, y: &mut String) { // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[TEMP]], ptr align 8 %x, i64 24, i1 false) // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 24, i1 false) // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %y, ptr align 8 %[[TEMP]], i64 24, i1 false) - typed_swap(x, y) + typed_swap_nonoverlapping(x, y) } diff --git a/tests/rustdoc-gui/item-info.goml b/tests/rustdoc-gui/item-info.goml index b5b0052fe61..647a2fd290d 100644 --- a/tests/rustdoc-gui/item-info.goml +++ b/tests/rustdoc-gui/item-info.goml @@ -45,3 +45,26 @@ compare-elements-css: ( "#main-content > .item-info .stab:nth-of-type(2)", ["height"], ) + +// Now checking the text color and the links color. +show-text: true +include: "utils.goml" +go-to: "file://" + |DOC_PATH| + "/lib2/trait.Trait.html" + +call-function: ("switch-theme", {"theme": "ayu"}) +assert-css: (".item-info .stab", {"color": "rgb(197, 197, 197)"}, ALL) +assert-css: (".item-info .stab strong", {"color": "rgb(197, 197, 197)"}, ALL) +assert-css: (".item-info .stab span", {"color": "rgb(197, 197, 197)"}, ALL) +assert-css: (".item-info .stab a", {"color": "rgb(57, 175, 215)"}, ALL) + +call-function: ("switch-theme", {"theme": "dark"}) +assert-css: (".item-info .stab", {"color": "rgb(221, 221, 221)"}, ALL) +assert-css: (".item-info .stab strong", {"color": "rgb(221, 221, 221)"}, ALL) +assert-css: (".item-info .stab span", {"color": "rgb(221, 221, 221)"}, ALL) +assert-css: (".item-info .stab a", {"color": "rgb(210, 153, 29)"}, ALL) + +call-function: ("switch-theme", {"theme": "light"}) +assert-css: (".item-info .stab", {"color": "rgb(0, 0, 0)"}, ALL) +assert-css: (".item-info .stab strong", {"color": "rgb(0, 0, 0)"}, ALL) +assert-css: (".item-info .stab span", {"color": "rgb(0, 0, 0)"}, ALL) +assert-css: (".item-info .stab a", {"color": "rgb(56, 115, 173)"}, ALL) diff --git a/tests/rustdoc-ui/doctest/non-local-defs-impl.rs b/tests/rustdoc-ui/doctest/non-local-defs-impl.rs index 04fdd285506..f2540574f15 100644 --- a/tests/rustdoc-ui/doctest/non-local-defs-impl.rs +++ b/tests/rustdoc-ui/doctest/non-local-defs-impl.rs @@ -21,7 +21,7 @@ /// } /// ``` /// -/// But this shoudln't produce a warning: +/// But this shouldn't produce a warning: /// ```rust,no_run /// # extern crate pub_trait; /// # use pub_trait::Trait; diff --git a/tests/rustdoc/auxiliary/unsafe-binder-dep.rs b/tests/rustdoc/auxiliary/unsafe-binder-dep.rs new file mode 100644 index 00000000000..65aa9032fed --- /dev/null +++ b/tests/rustdoc/auxiliary/unsafe-binder-dep.rs @@ -0,0 +1,4 @@ +#![feature(unsafe_binders)] +#![allow(incomplete_features)] + +pub fn woof() -> unsafe<'a> &'a str { todo!() } diff --git a/tests/rustdoc/type-alias/deeply-nested-112515.rs b/tests/rustdoc/type-alias/deeply-nested-112515.rs index 161188ee576..9530feb78de 100644 --- a/tests/rustdoc/type-alias/deeply-nested-112515.rs +++ b/tests/rustdoc/type-alias/deeply-nested-112515.rs @@ -1,6 +1,6 @@ // Regression test for <https://github.com/rust-lang/rust/issues/112515>. // It's to ensure that this code doesn't have infinite loop in rustdoc when -// trying to retrive type alias implementations. +// trying to retrieve type alias implementations. // ignore-tidy-linelength diff --git a/tests/rustdoc/unsafe-binder.rs b/tests/rustdoc/unsafe-binder.rs new file mode 100644 index 00000000000..621c3dadc72 --- /dev/null +++ b/tests/rustdoc/unsafe-binder.rs @@ -0,0 +1,15 @@ +//@ aux-build:unsafe-binder-dep.rs + +#![feature(unsafe_binders)] +#![allow(incomplete_features)] + +extern crate unsafe_binder_dep; + +//@ has 'unsafe_binder/fn.woof.html' //pre "fn woof() -> unsafe<'a> &'a str" +pub use unsafe_binder_dep::woof; + +//@ has 'unsafe_binder/fn.meow.html' //pre "fn meow() -> unsafe<'a> &'a str" +pub fn meow() -> unsafe<'a> &'a str { todo!() } + +//@ has 'unsafe_binder/fn.meow_squared.html' //pre "fn meow_squared() -> unsafe<'b, 'a> &'a &'b str" +pub fn meow_squared() -> unsafe<'b, 'a> &'a &'b str { todo!() } diff --git a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs new file mode 100644 index 00000000000..e5d70e30eb5 --- /dev/null +++ b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs @@ -0,0 +1,20 @@ +//@ edition: 2021 + +// Ensure that the output of a `fn` pointer that implements `AsyncFn*` is `Sized`, +// like other built-in impls of an fn pointer, like `Fn*`. + +use std::future::Future; + +fn foo() -> fn() -> dyn Future<Output = ()> { + todo!() +} + +async fn is_async_fn(f: impl AsyncFn()) { + f().await; +} + +fn main() { + is_async_fn(foo()); + //~^ ERROR the size for values of type `dyn Future<Output = ()>` cannot be known at compilation time + //~| ERROR the size for values of type `dyn Future<Output = ()>` cannot be known at compilation time +} diff --git a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr new file mode 100644 index 00000000000..f993247d8b9 --- /dev/null +++ b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr @@ -0,0 +1,31 @@ +error[E0277]: the size for values of type `dyn Future<Output = ()>` cannot be known at compilation time + --> $DIR/async-future-out-must-be-sized.rs:17:17 + | +LL | is_async_fn(foo()); + | ----------- ^^^^^ doesn't have a size known at compile-time + | | + | required by a bound introduced by this call + | + = help: the trait `Sized` is not implemented for `dyn Future<Output = ()>` +note: required by a bound in `is_async_fn` + --> $DIR/async-future-out-must-be-sized.rs:12:30 + | +LL | async fn is_async_fn(f: impl AsyncFn()) { + | ^^^^^^^^^ required by this bound in `is_async_fn` + +error[E0277]: the size for values of type `dyn Future<Output = ()>` cannot be known at compilation time + --> $DIR/async-future-out-must-be-sized.rs:17:5 + | +LL | is_async_fn(foo()); + | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `dyn Future<Output = ()>` +note: required by a bound in `is_async_fn` + --> $DIR/async-future-out-must-be-sized.rs:12:30 + | +LL | async fn is_async_fn(f: impl AsyncFn()) { + | ^^^^^^^^^ required by this bound in `is_async_fn` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/borrowck/index-mut-help.stderr b/tests/ui/borrowck/index-mut-help.stderr index fde2b5dc076..c4c9c1c5313 100644 --- a/tests/ui/borrowck/index-mut-help.stderr +++ b/tests/ui/borrowck/index-mut-help.stderr @@ -5,7 +5,10 @@ LL | map["peter"].clear(); | ^^^^^^^^^^^^ cannot borrow as mutable | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>` - = help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API +help: to modify a `HashMap<&str, String>` use `.get_mut()` + | +LL | if let Some(val) = map.get_mut("peter") { val.clear(); }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~ +++ error[E0594]: cannot assign to data in an index of `HashMap<&str, String>` --> $DIR/index-mut-help.rs:11:5 @@ -14,12 +17,12 @@ LL | map["peter"] = "0".to_string(); | ^^^^^^^^^^^^ cannot assign | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>` -help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API +help: use `.insert()` to insert a value into a `HashMap<&str, String>`, `.get_mut()` to modify it, or the entry API for more flexibility | LL | map.insert("peter", "0".to_string()); | ~~~~~~~~ ~ + -LL | map.get_mut("peter").map(|val| { *val = "0".to_string(); }); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ++++ +LL | if let Some(val) = map.get_mut("peter") { *val = "0".to_string(); }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~~ +++ LL | let val = map.entry("peter").or_insert("0".to_string()); | +++++++++ ~~~~~~~ ~~~~~~~~~~~~ + diff --git a/tests/ui/btreemap/btreemap-index-mut-2.stderr b/tests/ui/btreemap/btreemap-index-mut-2.stderr index 0b8c77cb9e1..c42462ee1eb 100644 --- a/tests/ui/btreemap/btreemap-index-mut-2.stderr +++ b/tests/ui/btreemap/btreemap-index-mut-2.stderr @@ -5,12 +5,12 @@ LL | map[&0] = 1; | ^^^^^^^^^^^ cannot assign | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `BTreeMap<u32, u32>` -help: to modify a `BTreeMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API +help: use `.insert()` to insert a value into a `BTreeMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility | LL | map.insert(&0, 1); | ~~~~~~~~ ~ + -LL | map.get_mut(&0).map(|val| { *val = 1; }); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ++++ +LL | if let Some(val) = map.get_mut(&0) { *val = 1; }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~~ +++ LL | let val = map.entry(&0).or_insert(1); | +++++++++ ~~~~~~~ ~~~~~~~~~~~~ + diff --git a/tests/ui/btreemap/btreemap-index-mut.stderr b/tests/ui/btreemap/btreemap-index-mut.stderr index cc465fbf3de..f402f503c15 100644 --- a/tests/ui/btreemap/btreemap-index-mut.stderr +++ b/tests/ui/btreemap/btreemap-index-mut.stderr @@ -5,12 +5,12 @@ LL | map[&0] = 1; | ^^^^^^^^^^^ cannot assign | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `BTreeMap<u32, u32>` -help: to modify a `BTreeMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API +help: use `.insert()` to insert a value into a `BTreeMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility | LL | map.insert(&0, 1); | ~~~~~~~~ ~ + -LL | map.get_mut(&0).map(|val| { *val = 1; }); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ++++ +LL | if let Some(val) = map.get_mut(&0) { *val = 1; }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~~ +++ LL | let val = map.entry(&0).or_insert(1); | +++++++++ ~~~~~~~ ~~~~~~~~~~~~ + diff --git a/tests/ui/closures/2229_closure_analysis/issue-118144.rs b/tests/ui/closures/2229_closure_analysis/issue-118144.rs index 3e5d9f9739a..5747cc75e98 100644 --- a/tests/ui/closures/2229_closure_analysis/issue-118144.rs +++ b/tests/ui/closures/2229_closure_analysis/issue-118144.rs @@ -6,7 +6,7 @@ fn func(func_arg: &mut V) { || { // Declaring `x` separately instead of using // a destructuring binding like `let V(x) = ...` - // becaue only `V(x) = ...` triggers the ICE + // because only `V(x) = ...` triggers the ICE let x; V(x) = func_arg; //~ ERROR: mismatched types func_arg.0 = 0; diff --git a/tests/ui/consts/issue-94371.rs b/tests/ui/consts/issue-94371.rs index ad9ee9a5a3e..b2dd7053c1f 100644 --- a/tests/ui/consts/issue-94371.rs +++ b/tests/ui/consts/issue-94371.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(const_swap)] - #[repr(C)] struct Demo(u64, bool, u64, u32, u64, u64, u64); diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.rs b/tests/ui/consts/qualif-indirect-mutation-fail.rs index c6e08a557c8..0f59a86b7cc 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.rs +++ b/tests/ui/consts/qualif-indirect-mutation-fail.rs @@ -1,6 +1,5 @@ //@ compile-flags: --crate-type=lib #![feature(const_precise_live_drops)] -#![feature(const_swap)] // Mutable borrow of a field with drop impl. pub const fn f() { diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr index f706b7cf699..e76d7d3b670 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr +++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr @@ -1,5 +1,5 @@ error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:13:9 + --> $DIR/qualif-indirect-mutation-fail.rs:12:9 | LL | let mut x = None; | ^^^^^ the destructor for this type cannot be evaluated in constants @@ -19,13 +19,13 @@ note: inside `std::ptr::drop_in_place::<String> - shim(Some(String))` note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: inside `A1` - --> $DIR/qualif-indirect-mutation-fail.rs:19:1 + --> $DIR/qualif-indirect-mutation-fail.rs:18:1 | LL | }; | ^ error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:29:9 + --> $DIR/qualif-indirect-mutation-fail.rs:28:9 | LL | let _z = x; | ^^ the destructor for this type cannot be evaluated in constants @@ -44,13 +44,13 @@ note: inside `std::ptr::drop_in_place::<String> - shim(Some(String))` note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: inside `A2` - --> $DIR/qualif-indirect-mutation-fail.rs:30:1 + --> $DIR/qualif-indirect-mutation-fail.rs:29:1 | LL | }; | ^ error[E0493]: destructor of `(u32, Option<String>)` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:7:9 + --> $DIR/qualif-indirect-mutation-fail.rs:6:9 | LL | let mut a: (u32, Option<String>) = (0, None); | ^^^^^ the destructor for this type cannot be evaluated in constant functions @@ -59,7 +59,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:34:9 + --> $DIR/qualif-indirect-mutation-fail.rs:33:9 | LL | let x: Option<T> = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -68,7 +68,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:42:9 + --> $DIR/qualif-indirect-mutation-fail.rs:41:9 | LL | let _y = x; | ^^ the destructor for this type cannot be evaluated in constant functions @@ -76,7 +76,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:50:9 + --> $DIR/qualif-indirect-mutation-fail.rs:49:9 | LL | let mut y: Option<String> = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions @@ -85,7 +85,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:47:9 + --> $DIR/qualif-indirect-mutation-fail.rs:46:9 | LL | let mut x: Option<String> = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions @@ -94,7 +94,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:60:9 + --> $DIR/qualif-indirect-mutation-fail.rs:59:9 | LL | let y: Option<String> = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -103,7 +103,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:57:9 + --> $DIR/qualif-indirect-mutation-fail.rs:56:9 | LL | let x: Option<String> = None; | ^ the destructor for this type cannot be evaluated in constant functions diff --git a/tests/ui/coroutine/issue-53548.rs b/tests/ui/coroutine/issue-53548.rs index 3b8dff2be28..c70f3e5a0d0 100644 --- a/tests/ui/coroutine/issue-53548.rs +++ b/tests/ui/coroutine/issue-53548.rs @@ -6,7 +6,7 @@ // to process this `'r` region bound. In particular, to be WF, the // region bound must meet the requirements of the trait, and hence we // got `for<'r> { 'r: 'static }`. This would ICE because the `Binder` -// constructor we were using was assering that no higher-ranked +// constructor we were using was asserting that no higher-ranked // regions were involved (because the WF code is supposed to skip // those). The error (if debug-asserions were disabled) came because // we obviously cannot prove that `'r: 'static` for any region `'r`. diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs index 8d36981b41b..72375eb0b3e 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs @@ -1,6 +1,6 @@ // Here, there are two types with the same name. One of these has a `derive` annotation, but in the // expansion these `impl`s are associated to the the *other* type. There is a suggestion to remove -// unneded type parameters, but because we're now point at a type with no type parameters, the +// unneeded type parameters, but because we're now point at a type with no type parameters, the // suggestion would suggest removing code from an empty span, which would ICE in nightly. // // issue: rust-lang/rust#108748 diff --git a/tests/ui/fmt/suggest-wrongly-order-format-parameter.fixed b/tests/ui/fmt/suggest-wrongly-order-format-parameter.fixed new file mode 100644 index 00000000000..a080a65854a --- /dev/null +++ b/tests/ui/fmt/suggest-wrongly-order-format-parameter.fixed @@ -0,0 +1,25 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/129966 +//! +//! Ensure we provide suggestion for wrongly ordered format parameters. + +//@ run-rustfix +#![allow(dead_code)] + +#[derive(Debug)] +struct Foo(u8, u8); + +fn main() { + let f = Foo(1, 2); + + println!("{f:#?}"); + //~^ ERROR invalid format string: expected `}`, found `#` + //~| HELP did you mean `#?`? + + println!("{f:x?}"); + //~^ ERROR invalid format string: expected `}`, found `x` + //~| HELP did you mean `x?`? + + println!("{f:X?}"); + //~^ ERROR invalid format string: expected `}`, found `X` + //~| HELP did you mean `X?`? +} diff --git a/tests/ui/fmt/suggest-wrongly-order-format-parameter.rs b/tests/ui/fmt/suggest-wrongly-order-format-parameter.rs new file mode 100644 index 00000000000..830dafd4479 --- /dev/null +++ b/tests/ui/fmt/suggest-wrongly-order-format-parameter.rs @@ -0,0 +1,25 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/129966 +//! +//! Ensure we provide suggestion for wrongly ordered format parameters. + +//@ run-rustfix +#![allow(dead_code)] + +#[derive(Debug)] +struct Foo(u8, u8); + +fn main() { + let f = Foo(1, 2); + + println!("{f:?#}"); + //~^ ERROR invalid format string: expected `}`, found `#` + //~| HELP did you mean `#?`? + + println!("{f:?x}"); + //~^ ERROR invalid format string: expected `}`, found `x` + //~| HELP did you mean `x?`? + + println!("{f:?X}"); + //~^ ERROR invalid format string: expected `}`, found `X` + //~| HELP did you mean `X?`? +} diff --git a/tests/ui/fmt/suggest-wrongly-order-format-parameter.stderr b/tests/ui/fmt/suggest-wrongly-order-format-parameter.stderr new file mode 100644 index 00000000000..fe693d2e904 --- /dev/null +++ b/tests/ui/fmt/suggest-wrongly-order-format-parameter.stderr @@ -0,0 +1,35 @@ +error: invalid format string: expected `}`, found `#` + --> $DIR/suggest-wrongly-order-format-parameter.rs:14:19 + | +LL | println!("{f:?#}"); + | ^ expected `'}'` in format string + | +help: did you mean `#?`? + | +LL | println!("{f:#?}"); + | ~~ + +error: invalid format string: expected `}`, found `x` + --> $DIR/suggest-wrongly-order-format-parameter.rs:18:19 + | +LL | println!("{f:?x}"); + | ^ expected `'}'` in format string + | +help: did you mean `x?`? + | +LL | println!("{f:x?}"); + | ~~ + +error: invalid format string: expected `}`, found `X` + --> $DIR/suggest-wrongly-order-format-parameter.rs:22:19 + | +LL | println!("{f:?X}"); + | ^ expected `'}'` in format string + | +help: did you mean `X?`? + | +LL | println!("{f:X?}"); + | ~~ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/hashmap/hashmap-index-mut.stderr b/tests/ui/hashmap/hashmap-index-mut.stderr index 2381b8ecb96..ad33c6f9b15 100644 --- a/tests/ui/hashmap/hashmap-index-mut.stderr +++ b/tests/ui/hashmap/hashmap-index-mut.stderr @@ -5,12 +5,12 @@ LL | map[&0] = 1; | ^^^^^^^^^^^ cannot assign | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<u32, u32>` -help: to modify a `HashMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API +help: use `.insert()` to insert a value into a `HashMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility | LL | map.insert(&0, 1); | ~~~~~~~~ ~ + -LL | map.get_mut(&0).map(|val| { *val = 1; }); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ++++ +LL | if let Some(val) = map.get_mut(&0) { *val = 1; }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~~ +++ LL | let val = map.entry(&0).or_insert(1); | +++++++++ ~~~~~~~ ~~~~~~~~~~~~ + diff --git a/tests/ui/incoherent-inherent-impls/no-other-unrelated-errors.rs b/tests/ui/incoherent-inherent-impls/no-other-unrelated-errors.rs index 8eaa0c9194a..cef017e79a4 100644 --- a/tests/ui/incoherent-inherent-impls/no-other-unrelated-errors.rs +++ b/tests/ui/incoherent-inherent-impls/no-other-unrelated-errors.rs @@ -1,4 +1,4 @@ -// E0116 caused other unrelated errors, so check no unrelated errors are emmitted. +// E0116 caused other unrelated errors, so check no unrelated errors are emitted. fn main() { let x = "hello"; diff --git a/tests/ui/indexing/indexing-spans-caller-location.rs b/tests/ui/indexing/indexing-spans-caller-location.rs index 02d8b853734..b01e3894ac1 100644 --- a/tests/ui/indexing/indexing-spans-caller-location.rs +++ b/tests/ui/indexing/indexing-spans-caller-location.rs @@ -20,7 +20,7 @@ impl std::ops::Index<usize> for A { type Output = (); fn index(&self, _idx: usize) -> &() { - // Use the relative number to make it resistent to header changes. + // Use the relative number to make it resistant to header changes. assert_eq!(caller_line(), self.prev_line + 2); &() } diff --git a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs index 7f6758f47f8..3cdb488e7a5 100644 --- a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs +++ b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs @@ -2,7 +2,7 @@ // Regression test for #107745. // Previously need_type_info::update_infer_source will consider expressions originating from -// macro expressions as candiate "previous sources". This unfortunately can mean that +// macro expressions as candidate "previous sources". This unfortunately can mean that // for macros expansions such as `format!()` internal implementation details can leak, such as: // // ``` diff --git a/tests/ui/issues/issue-12567.stderr b/tests/ui/issues/issue-12567.stderr index 3f95f18a967..0b19299ece3 100644 --- a/tests/ui/issues/issue-12567.stderr +++ b/tests/ui/issues/issue-12567.stderr @@ -11,14 +11,16 @@ LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider borrowing the pattern binding +help: consider removing the borrow | -LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) - | +++ -help: consider borrowing the pattern binding +LL - (&[], &[hd, ..]) | (&[hd, ..], &[]) +LL + (&[], [hd, ..]) | (&[hd, ..], &[]) + | +help: consider removing the borrow + | +LL - (&[hd1, ..], &[hd2, ..]) +LL + (&[hd1, ..], [hd2, ..]) | -LL | (&[hd1, ..], &[ref hd2, ..]) - | +++ error[E0508]: cannot move out of type `[T]`, a non-copy slice --> $DIR/issue-12567.rs:2:11 @@ -33,14 +35,16 @@ LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - (&[], &[hd, ..]) | (&[hd, ..], &[]) +LL + (&[], [hd, ..]) | (&[hd, ..], &[]) + | +help: consider removing the borrow | -LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) - | +++ -help: consider borrowing the pattern binding +LL - (&[hd1, ..], &[hd2, ..]) +LL + ([hd1, ..], &[hd2, ..]) | -LL | (&[ref hd1, ..], &[hd2, ..]) - | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-41726.stderr b/tests/ui/issues/issue-41726.stderr index fe7d4df7067..250bba222bf 100644 --- a/tests/ui/issues/issue-41726.stderr +++ b/tests/ui/issues/issue-41726.stderr @@ -5,7 +5,10 @@ LL | things[src.as_str()].sort(); | ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<String, Vec<String>>` - = help: to modify a `HashMap<String, Vec<String>>`, use `.get_mut()`, `.insert()` or the entry API +help: to modify a `HashMap<String, Vec<String>>` use `.get_mut()` + | +LL | if let Some(val) = things.get_mut(src.as_str()) { val.sort(); }; + | ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~ +++ error: aborting due to 1 previous error diff --git a/tests/ui/link-native-libs/issue-70093/issue-70093-link-directives.rs b/tests/ui/link-native-libs/issue-70093/issue-70093-link-directives.rs deleted file mode 100644 index 9c60affbccd..00000000000 --- a/tests/ui/link-native-libs/issue-70093/issue-70093-link-directives.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass -//@ compile-flags: -Zlink-directives=no -//@ ignore-windows - this will probably only work on unixish systems -//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733) -//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling - -#[link(name = "some-random-non-existent-library", kind = "static")] -extern "C" {} - -fn main() {} diff --git a/tests/ui/link-native-libs/issue-70093/issue-70093.rs b/tests/ui/link-native-libs/issue-70093/issue-70093.rs deleted file mode 100644 index 86974239338..00000000000 --- a/tests/ui/link-native-libs/issue-70093/issue-70093.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass -//@ compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes -//@ ignore-windows - this will probably only work on unixish systems -//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733) -//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling - -#[link(name = "some-random-non-existent-library", kind = "static")] -extern "C" {} - -fn main() {} diff --git a/tests/ui/link-native-libs/issue-70093/link-directives.rs b/tests/ui/link-native-libs/issue-70093/link-directives.rs new file mode 100644 index 00000000000..1dc44c996fc --- /dev/null +++ b/tests/ui/link-native-libs/issue-70093/link-directives.rs @@ -0,0 +1,14 @@ +// Ensure that `#[link]` attributes are entirely ignore when using `-Zlink-directives=no`. + +//@ run-pass +//@ compile-flags: -Zlink-directives=no +//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733) +//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling + +// Usually these `#[link]` attribute would cause `libsome-random-non-existent-library` +// to be passed to the linker, causing it to fail because the file doesn't exist. +// However, with -Zlink-directives=no, the `#[link]` is ignored. +#[link(name = "some-random-non-existent-library", kind = "static")] +extern "C" {} + +fn main() {} diff --git a/tests/ui/link-native-libs/issue-70093/link-native-libraries.rs b/tests/ui/link-native-libs/issue-70093/link-native-libraries.rs new file mode 100644 index 00000000000..b4dc9fb5cde --- /dev/null +++ b/tests/ui/link-native-libs/issue-70093/link-native-libraries.rs @@ -0,0 +1,26 @@ +// Ensure that rust does not pass native libraries to the linker when +// `-Zlink-native-libraries=no` is used. + +//@ run-pass +//@ compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes +//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733) +//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling + +//@ revisions: other +//@[other] ignore-msvc + +//@ revisions: msvc +// On Windows MSVC, default-linker-libraries=yes doesn't work because +// rustc drives the linker directly instead of going through another compiler. +// Therefore rustc would need to implement default-linker-libraries itself but doesn't. +// So instead we use -Clink-arg to directly set the required msvcrt.lib as a link arg. +//@[msvc] compile-flags: -Clink-arg=msvcrt.lib +//@[msvc] only-msvc + +// Usually these `#[link]` attribute would cause `libsome-random-non-existent-library` +// to be passed to the linker, causing it to fail because the file doesn't exist. +// However, -Zlink-native-libraries=no disables that. +#[link(name = "some-random-non-existent-library", kind = "static")] +extern "C" {} + +fn main() {} 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 52f4c09e5c0..a8b81394110 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 @@ -7,10 +7,11 @@ LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) { | data moved here | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) { +LL + if let Some(Some(x)) = Some(&Some(&mut 0)) { | -LL | if let Some(&Some(ref x)) = Some(&Some(&mut 0)) { - | +++ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/ref_pat_eat_one_layer_2024_fail2.rs:11:10 diff --git a/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.fixed b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.fixed new file mode 100644 index 00000000000..46b05e4c0a3 --- /dev/null +++ b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.fixed @@ -0,0 +1,10 @@ +//@ run-rustfix +//! diagnostic test for #132806: make sure the suggestion to bind by-reference in patterns doesn't +//! erroneously remove the wrong `&` + +use std::collections::HashMap; + +fn main() { + let _ = HashMap::<String, i32>::new().iter().filter(|&(_k, &_v)| { true }); + //~^ ERROR cannot move out of a shared reference +} diff --git a/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.rs b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.rs new file mode 100644 index 00000000000..1312fd6425b --- /dev/null +++ b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.rs @@ -0,0 +1,10 @@ +//@ run-rustfix +//! diagnostic test for #132806: make sure the suggestion to bind by-reference in patterns doesn't +//! erroneously remove the wrong `&` + +use std::collections::HashMap; + +fn main() { + let _ = HashMap::<String, i32>::new().iter().filter(|&(&_k, &_v)| { true }); + //~^ ERROR cannot move out of a shared reference +} diff --git a/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.stderr b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.stderr new file mode 100644 index 00000000000..ff579f93413 --- /dev/null +++ b/tests/ui/moves/do-not-suggest-removing-wrong-ref-pattern-issue-132806.stderr @@ -0,0 +1,18 @@ +error[E0507]: cannot move out of a shared reference + --> $DIR/do-not-suggest-removing-wrong-ref-pattern-issue-132806.rs:8:58 + | +LL | let _ = HashMap::<String, i32>::new().iter().filter(|&(&_k, &_v)| { true }); + | ^^^--^^^^^^ + | | + | data moved here + | move occurs because `_k` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let _ = HashMap::<String, i32>::new().iter().filter(|&(&_k, &_v)| { true }); +LL + let _ = HashMap::<String, i32>::new().iter().filter(|&(_k, &_v)| { true }); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/nll/move-errors.stderr b/tests/ui/nll/move-errors.stderr index d1384121379..bcb2ab84a23 100644 --- a/tests/ui/nll/move-errors.stderr +++ b/tests/ui/nll/move-errors.stderr @@ -209,10 +209,11 @@ LL | (D(s), &t) => (), | data moved here | move occurs because `t` has type `String`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - (D(s), &t) => (), +LL + (D(s), t) => (), | -LL | (D(s), &ref t) => (), - | +++ error[E0509]: cannot move out of type `F`, which implements the `Drop` trait --> $DIR/move-errors.rs:102:11 diff --git a/tests/ui/no_send-rc.stderr b/tests/ui/no_send-rc.stderr index 3534167870b..1430a7a29ea 100644 --- a/tests/ui/no_send-rc.stderr +++ b/tests/ui/no_send-rc.stderr @@ -12,6 +12,10 @@ note: required by a bound in `bar` | LL | fn bar<T: Send>(_: T) {} | ^^^^ required by this bound in `bar` +help: consider dereferencing here + | +LL | bar(*x); + | + error: aborting due to 1 previous error diff --git a/tests/ui/panics/default-backtrace-ice.rs b/tests/ui/panics/default-backtrace-ice.rs index c47f458f6e9..9933f548758 100644 --- a/tests/ui/panics/default-backtrace-ice.rs +++ b/tests/ui/panics/default-backtrace-ice.rs @@ -17,7 +17,7 @@ // `__rust_{begin,end}_short_backtrace` markers, which only appear in full // backtraces. The rest of the backtrace is filtered out. // -// Ignored on msvc becaue the `__rust_{begin,end}_short_backtrace` symbols +// Ignored on msvc because the `__rust_{begin,end}_short_backtrace` symbols // aren't reliable. fn main() { missing_ident; } diff --git a/tests/ui/parser/unicode-control-codepoints.rs b/tests/ui/parser/unicode-control-codepoints.rs index df099bb62ad..14e1cfe59d3 100644 --- a/tests/ui/parser/unicode-control-codepoints.rs +++ b/tests/ui/parser/unicode-control-codepoints.rs @@ -1,3 +1,5 @@ +//@ edition: 2021 + fn main() { // if access_level != "user" { // Check if admin //~^ ERROR unicode codepoint changing visible direction of text present in comment @@ -25,6 +27,14 @@ fn main() { //~| ERROR non-ASCII character in raw byte string literal println!("{:?}", ''); //~^ ERROR unicode codepoint changing visible direction of text present in literal + + let _ = c""; + //~^ ERROR unicode codepoint changing visible direction of text present in literal + let _ = cr#""#; + //~^ ERROR unicode codepoint changing visible direction of text present in literal + + println!("{{}}"); + //~^ ERROR unicode codepoint changing visible direction of text present in format string } //"/* } if isAdmin begin admins only */" diff --git a/tests/ui/parser/unicode-control-codepoints.stderr b/tests/ui/parser/unicode-control-codepoints.stderr index 28de4ae72ab..2893194308e 100644 --- a/tests/ui/parser/unicode-control-codepoints.stderr +++ b/tests/ui/parser/unicode-control-codepoints.stderr @@ -1,5 +1,5 @@ error: unicode escape in byte string - --> $DIR/unicode-control-codepoints.rs:6:26 + --> $DIR/unicode-control-codepoints.rs:8:26 | LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); | ^^^^^^^^ unicode escape in byte string @@ -7,7 +7,7 @@ LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); = help: unicode escape sequences cannot be used as a byte or in a byte string error: unicode escape in byte string - --> $DIR/unicode-control-codepoints.rs:6:35 + --> $DIR/unicode-control-codepoints.rs:8:35 | LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); | ^^^^^^^^ unicode escape in byte string @@ -15,7 +15,7 @@ LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); = help: unicode escape sequences cannot be used as a byte or in a byte string error: non-ASCII character in byte string literal - --> $DIR/unicode-control-codepoints.rs:16:26 + --> $DIR/unicode-control-codepoints.rs:18:26 | LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{202e}' @@ -26,7 +26,7 @@ LL | println!("{:?}", b"/*\xE2\x80\xAE } �if isAdmin� � begin admins o | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal - --> $DIR/unicode-control-codepoints.rs:16:30 + --> $DIR/unicode-control-codepoints.rs:18:30 | LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{2066}' @@ -37,7 +37,7 @@ LL | println!("{:?}", b"/*� } \xE2\x81\xA6if isAdmin� � begin admins o | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal - --> $DIR/unicode-control-codepoints.rs:16:41 + --> $DIR/unicode-control-codepoints.rs:18:41 | LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{2069}' @@ -48,7 +48,7 @@ LL | println!("{:?}", b"/*� } �if isAdmin\xE2\x81\xA9 � begin admins o | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal - --> $DIR/unicode-control-codepoints.rs:16:43 + --> $DIR/unicode-control-codepoints.rs:18:43 | LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{2066}' @@ -59,31 +59,31 @@ LL | println!("{:?}", b"/*� } �if isAdmin� \xE2\x81\xA6 begin admins o | ~~~~~~~~~~~~ error: non-ASCII character in raw byte string literal - --> $DIR/unicode-control-codepoints.rs:21:29 + --> $DIR/unicode-control-codepoints.rs:23:29 | LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{202e}' error: non-ASCII character in raw byte string literal - --> $DIR/unicode-control-codepoints.rs:21:33 + --> $DIR/unicode-control-codepoints.rs:23:33 | LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{2066}' error: non-ASCII character in raw byte string literal - --> $DIR/unicode-control-codepoints.rs:21:44 + --> $DIR/unicode-control-codepoints.rs:23:44 | LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{2069}' error: non-ASCII character in raw byte string literal - --> $DIR/unicode-control-codepoints.rs:21:46 + --> $DIR/unicode-control-codepoints.rs:23:46 | LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{2066}' error: unicode codepoint changing visible direction of text present in comment - --> $DIR/unicode-control-codepoints.rs:2:5 + --> $DIR/unicode-control-codepoints.rs:4:5 | LL | // if access_level != "us�e�r" { // Check if admin | ^^^^^^^^^^^^^^^^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | // if access_level != "us�e�r" { // Check if admin = help: if their presence wasn't intentional, you can remove them error: unicode codepoint changing visible direction of text present in comment - --> $DIR/unicode-control-codepoints.rs:30:1 + --> $DIR/unicode-control-codepoints.rs:40:1 | LL | //"/*� } �if isAdmin� � begin admins only */" | ^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | //"/*� } �if isAdmin� � begin admins only */" = help: if their presence wasn't intentional, you can remove them error: unicode codepoint changing visible direction of text present in literal - --> $DIR/unicode-control-codepoints.rs:11:22 + --> $DIR/unicode-control-codepoints.rs:13:22 | LL | println!("{:?}", "/*� } �if isAdmin� � begin admins only "); | ^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | println!("{:?}", "/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} begi | ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ error: unicode codepoint changing visible direction of text present in literal - --> $DIR/unicode-control-codepoints.rs:14:22 + --> $DIR/unicode-control-codepoints.rs:16:22 | LL | println!("{:?}", r##"/*� } �if isAdmin� � begin admins only "##); | ^^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ @@ -151,7 +151,7 @@ LL | println!("{:?}", r##"/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} b | ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ error: unicode codepoint changing visible direction of text present in literal - --> $DIR/unicode-control-codepoints.rs:26:22 + --> $DIR/unicode-control-codepoints.rs:28:22 | LL | println!("{:?}", '�'); | ^-^ @@ -166,8 +166,56 @@ help: if you want to keep them but make them visible in your source code, you ca LL | println!("{:?}", '\u{202e}'); | ~~~~~~~~ +error: unicode codepoint changing visible direction of text present in literal + --> $DIR/unicode-control-codepoints.rs:31:13 + | +LL | let _ = c"�"; + | ^^-^ + | | | + | | '\u{202e}' + | this literal contains an invisible unicode text flow control codepoint + | + = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen + = help: if their presence wasn't intentional, you can remove them +help: if you want to keep them but make them visible in your source code, you can escape them + | +LL | let _ = c"\u{202e}"; + | ~~~~~~~~ + +error: unicode codepoint changing visible direction of text present in literal + --> $DIR/unicode-control-codepoints.rs:33:13 + | +LL | let _ = cr#"�"#; + | ^^^^-^^ + | | | + | | '\u{202e}' + | this literal contains an invisible unicode text flow control codepoint + | + = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen + = help: if their presence wasn't intentional, you can remove them +help: if you want to keep them but make them visible in your source code, you can escape them + | +LL | let _ = cr#"\u{202e}"#; + | ~~~~~~~~ + +error: unicode codepoint changing visible direction of text present in format string + --> $DIR/unicode-control-codepoints.rs:36:14 + | +LL | println!("{{�}}"); + | ^^^-^^^ + | | | + | | '\u{202e}' + | this format string contains an invisible unicode text flow control codepoint + | + = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen + = help: if their presence wasn't intentional, you can remove them +help: if you want to keep them but make them visible in your source code, you can escape them + | +LL | println!("{{\u{202e}}}"); + | ~~~~~~~~ + error: unicode codepoint changing visible direction of text present in doc comment - --> $DIR/unicode-control-codepoints.rs:33:1 + --> $DIR/unicode-control-codepoints.rs:43:1 | LL | /** '�'); */fn foo() {} | ^^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint @@ -177,7 +225,7 @@ LL | /** '�'); */fn foo() {} = note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}' error: unicode codepoint changing visible direction of text present in doc comment - --> $DIR/unicode-control-codepoints.rs:36:1 + --> $DIR/unicode-control-codepoints.rs:46:1 | LL | / /** LL | | * @@ -188,5 +236,5 @@ LL | | * '�'); */fn bar() {} = note: if their presence wasn't intentional, you can remove them = note: if you want to keep them but make them visible in your source code, you can escape them: '\u{202e}' -error: aborting due to 17 previous errors +error: aborting due to 20 previous errors diff --git a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr index 108db6d9e4b..2cf435b1179 100644 --- a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr +++ b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr @@ -9,6 +9,11 @@ LL | deref!(x) => x, | | | data moved here | move occurs because `x` has type `Struct`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | deref!(ref x) => x, + | +++ error[E0507]: cannot move out of a shared reference --> $DIR/cant_move_out_of_pattern.rs:17:11 @@ -21,6 +26,11 @@ LL | deref!(x) => x, | | | data moved here | move occurs because `x` has type `Struct`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | deref!(ref x) => x, + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/structs/manual-default-impl-could-be-derived.stderr b/tests/ui/structs/manual-default-impl-could-be-derived.stderr index e8f607fac7e..cf06d5418e1 100644 --- a/tests/ui/structs/manual-default-impl-could-be-derived.stderr +++ b/tests/ui/structs/manual-default-impl-could-be-derived.stderr @@ -31,7 +31,10 @@ LL | | y: 0, LL | | } | |_^ | - = help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` +help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` + | +LL ~ #[derive(Default)] struct B { + | error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:43:1 diff --git a/tests/ui/suggestions/dont-suggest-ref/simple.rs b/tests/ui/suggestions/dont-suggest-ref/simple.rs index 1e40e60a1ce..4dea5319264 100644 --- a/tests/ui/suggestions/dont-suggest-ref/simple.rs +++ b/tests/ui/suggestions/dont-suggest-ref/simple.rs @@ -219,42 +219,42 @@ pub fn main() { let (&X(_t),) = (&x.clone(),); //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the borrow if let (&Either::One(_t),) = (&e.clone(),) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the borrow while let (&Either::One(_t),) = (&e.clone(),) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the borrow match (&e.clone(),) { //~^ ERROR cannot move (&Either::One(_t),) - //~^ HELP consider borrowing the pattern binding + //~^ HELP consider removing the borrow | (&Either::Two(_t),) => (), } fn f3((&X(_t),): (&X,)) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the borrow let (&mut X(_t),) = (&mut xm.clone(),); //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the mutable borrow if let (&mut Either::One(_t),) = (&mut em.clone(),) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the mutable borrow while let (&mut Either::One(_t),) = (&mut em.clone(),) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the mutable borrow match (&mut em.clone(),) { //~^ ERROR cannot move (&mut Either::One(_t),) => (), - //~^ HELP consider borrowing the pattern binding + //~^ HELP consider removing the mutable borrow (&mut Either::Two(_t),) => (), - //~^ HELP consider borrowing the pattern binding + //~^ HELP consider removing the mutable borrow } fn f4((&mut X(_t),): (&mut X,)) { } //~^ ERROR cannot move - //~| HELP consider borrowing the pattern binding + //~| HELP consider removing the mutable borrow // move from &Either/&X value diff --git a/tests/ui/suggestions/dont-suggest-ref/simple.stderr b/tests/ui/suggestions/dont-suggest-ref/simple.stderr index 7d902dbccc4..41571bf9b2c 100644 --- a/tests/ui/suggestions/dont-suggest-ref/simple.stderr +++ b/tests/ui/suggestions/dont-suggest-ref/simple.stderr @@ -578,10 +578,11 @@ LL | let (&X(_t),) = (&x.clone(),); | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - let (&X(_t),) = (&x.clone(),); +LL + let (X(_t),) = (&x.clone(),); | -LL | let (&X(ref _t),) = (&x.clone(),); - | +++ error[E0507]: cannot move out of a shared reference --> $DIR/simple.rs:223:34 @@ -592,10 +593,11 @@ LL | if let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - if let (&Either::One(_t),) = (&e.clone(),) { } +LL + if let (Either::One(_t),) = (&e.clone(),) { } | -LL | if let (&Either::One(ref _t),) = (&e.clone(),) { } - | +++ error[E0507]: cannot move out of a shared reference --> $DIR/simple.rs:226:37 @@ -606,10 +608,11 @@ LL | while let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - while let (&Either::One(_t),) = (&e.clone(),) { } +LL + while let (Either::One(_t),) = (&e.clone(),) { } | -LL | while let (&Either::One(ref _t),) = (&e.clone(),) { } - | +++ error[E0507]: cannot move out of a shared reference --> $DIR/simple.rs:229:11 @@ -623,10 +626,11 @@ LL | (&Either::One(_t),) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - (&Either::One(_t),) +LL + (Either::One(_t),) | -LL | (&Either::One(ref _t),) - | +++ error[E0507]: cannot move out of a mutable reference --> $DIR/simple.rs:239:25 @@ -637,10 +641,11 @@ LL | let (&mut X(_t),) = (&mut xm.clone(),); | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the mutable borrow + | +LL - let (&mut X(_t),) = (&mut xm.clone(),); +LL + let (X(_t),) = (&mut xm.clone(),); | -LL | let (&mut X(ref _t),) = (&mut xm.clone(),); - | +++ error[E0507]: cannot move out of a mutable reference --> $DIR/simple.rs:242:38 @@ -651,10 +656,11 @@ LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the mutable borrow + | +LL - if let (&mut Either::One(_t),) = (&mut em.clone(),) { } +LL + if let (Either::One(_t),) = (&mut em.clone(),) { } | -LL | if let (&mut Either::One(ref _t),) = (&mut em.clone(),) { } - | +++ error[E0507]: cannot move out of a mutable reference --> $DIR/simple.rs:245:41 @@ -665,10 +671,11 @@ LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the mutable borrow + | +LL - while let (&mut Either::One(_t),) = (&mut em.clone(),) { } +LL + while let (Either::One(_t),) = (&mut em.clone(),) { } | -LL | while let (&mut Either::One(ref _t),) = (&mut em.clone(),) { } - | +++ error[E0507]: cannot move out of a mutable reference --> $DIR/simple.rs:248:11 @@ -683,14 +690,16 @@ LL | (&mut Either::Two(_t),) => (), | -- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider borrowing the pattern binding +help: consider removing the mutable borrow | -LL | (&mut Either::One(ref _t),) => (), - | +++ -help: consider borrowing the pattern binding +LL - (&mut Either::One(_t),) => (), +LL + (Either::One(_t),) => (), + | +help: consider removing the mutable borrow + | +LL - (&mut Either::Two(_t),) => (), +LL + (Either::Two(_t),) => (), | -LL | (&mut Either::Two(ref _t),) => (), - | +++ error[E0507]: cannot move out of a shared reference --> $DIR/simple.rs:261:18 @@ -947,10 +956,11 @@ LL | fn f3((&X(_t),): (&X,)) { } | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - fn f3((&X(_t),): (&X,)) { } +LL + fn f3((X(_t),): (&X,)) { } | -LL | fn f3((&X(ref _t),): (&X,)) { } - | +++ error[E0507]: cannot move out of a mutable reference --> $DIR/simple.rs:255:11 @@ -961,10 +971,11 @@ LL | fn f4((&mut X(_t),): (&mut X,)) { } | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the mutable borrow + | +LL - fn f4((&mut X(_t),): (&mut X,)) { } +LL + fn f4((X(_t),): (&mut X,)) { } | -LL | fn f4((&mut X(ref _t),): (&mut X,)) { } - | +++ error[E0507]: cannot move out of `a.a` as enum variant `Some` which is behind a shared reference --> $DIR/simple.rs:331:20 diff --git a/tests/ui/suggestions/issue-84973-blacklist.stderr b/tests/ui/suggestions/issue-84973-blacklist.stderr index a6324a824c1..3db400418c7 100644 --- a/tests/ui/suggestions/issue-84973-blacklist.stderr +++ b/tests/ui/suggestions/issue-84973-blacklist.stderr @@ -86,6 +86,10 @@ note: required by a bound in `f_send` | LL | fn f_send<T: Send>(t: T) {} | ^^^^ required by this bound in `f_send` +help: consider dereferencing here + | +LL | f_send(*rc); + | + error: aborting due to 5 previous errors diff --git a/tests/ui/suggestions/option-content-move-from-tuple-match.stderr b/tests/ui/suggestions/option-content-move-from-tuple-match.stderr index 63314acb87c..c93570c579e 100644 --- a/tests/ui/suggestions/option-content-move-from-tuple-match.stderr +++ b/tests/ui/suggestions/option-content-move-from-tuple-match.stderr @@ -10,10 +10,11 @@ LL | (None, &c) => &c.unwrap(), | data moved here | move occurs because `c` has type `Option<String>`, which does not implement the `Copy` trait | -help: consider borrowing the pattern binding +help: consider removing the borrow + | +LL - (None, &c) => &c.unwrap(), +LL + (None, c) => &c.unwrap(), | -LL | (None, &ref c) => &c.unwrap(), - | +++ error: aborting due to 1 previous error diff --git a/tests/ui/thread-local/thread-local-static.rs b/tests/ui/thread-local/thread-local-static.rs index af30f538366..422dac41002 100644 --- a/tests/ui/thread-local/thread-local-static.rs +++ b/tests/ui/thread-local/thread-local-static.rs @@ -1,7 +1,6 @@ //@ edition:2018 #![feature(thread_local)] -#![feature(const_swap)] #![allow(static_mut_refs)] #[thread_local] diff --git a/tests/ui/thread-local/thread-local-static.stderr b/tests/ui/thread-local/thread-local-static.stderr index 3bc1aec00c1..bb078b79748 100644 --- a/tests/ui/thread-local/thread-local-static.stderr +++ b/tests/ui/thread-local/thread-local-static.stderr @@ -1,5 +1,5 @@ error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/thread-local-static.rs:10:28 + --> $DIR/thread-local-static.rs:9:28 | LL | std::mem::swap(x, &mut STATIC_VAR_2) | ^^^^^^^^^^^^ use of mutable static @@ -7,7 +7,7 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2) = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior error[E0625]: thread-local statics cannot be accessed at compile-time - --> $DIR/thread-local-static.rs:10:28 + --> $DIR/thread-local-static.rs:9:28 | LL | std::mem::swap(x, &mut STATIC_VAR_2) | ^^^^^^^^^^^^ diff --git a/tests/ui/traits/suggest-dereferences/deref-argument.fixed b/tests/ui/traits/suggest-dereferences/deref-argument.fixed new file mode 100644 index 00000000000..8235ae0b628 --- /dev/null +++ b/tests/ui/traits/suggest-dereferences/deref-argument.fixed @@ -0,0 +1,37 @@ +//@ run-rustfix +//! diagnostic test for #90997. +//! test that E0277 suggests dereferences to satisfy bounds when the referent is `Copy` or boxed. +use std::ops::Deref; + +trait Test { + fn test(self); +} +fn consume_test(x: impl Test) { x.test() } + +impl Test for u32 { + fn test(self) {} +} +struct MyRef(u32); +impl Deref for MyRef { + type Target = u32; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +struct NonCopy; +impl Test for NonCopy { + fn test(self) {} +} + +fn main() { + let my_ref = MyRef(0); + consume_test(*my_ref); + //~^ ERROR the trait bound `MyRef: Test` is not satisfied + //~| SUGGESTION * + + let nested_box = Box::new(Box::new(Box::new(NonCopy))); + consume_test(***nested_box); + //~^ ERROR the trait bound `Box<Box<Box<NonCopy>>>: Test` is not satisfied + //~| SUGGESTION *** +} diff --git a/tests/ui/traits/suggest-dereferences/deref-argument.rs b/tests/ui/traits/suggest-dereferences/deref-argument.rs new file mode 100644 index 00000000000..2f96b75c4e4 --- /dev/null +++ b/tests/ui/traits/suggest-dereferences/deref-argument.rs @@ -0,0 +1,37 @@ +//@ run-rustfix +//! diagnostic test for #90997. +//! test that E0277 suggests dereferences to satisfy bounds when the referent is `Copy` or boxed. +use std::ops::Deref; + +trait Test { + fn test(self); +} +fn consume_test(x: impl Test) { x.test() } + +impl Test for u32 { + fn test(self) {} +} +struct MyRef(u32); +impl Deref for MyRef { + type Target = u32; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +struct NonCopy; +impl Test for NonCopy { + fn test(self) {} +} + +fn main() { + let my_ref = MyRef(0); + consume_test(my_ref); + //~^ ERROR the trait bound `MyRef: Test` is not satisfied + //~| SUGGESTION * + + let nested_box = Box::new(Box::new(Box::new(NonCopy))); + consume_test(nested_box); + //~^ ERROR the trait bound `Box<Box<Box<NonCopy>>>: Test` is not satisfied + //~| SUGGESTION *** +} diff --git a/tests/ui/traits/suggest-dereferences/deref-argument.stderr b/tests/ui/traits/suggest-dereferences/deref-argument.stderr new file mode 100644 index 00000000000..3dc92fd6ab6 --- /dev/null +++ b/tests/ui/traits/suggest-dereferences/deref-argument.stderr @@ -0,0 +1,39 @@ +error[E0277]: the trait bound `MyRef: Test` is not satisfied + --> $DIR/deref-argument.rs:29:18 + | +LL | consume_test(my_ref); + | ------------ ^^^^^^ the trait `Test` is not implemented for `MyRef` + | | + | required by a bound introduced by this call + | +note: required by a bound in `consume_test` + --> $DIR/deref-argument.rs:9:25 + | +LL | fn consume_test(x: impl Test) { x.test() } + | ^^^^ required by this bound in `consume_test` +help: consider dereferencing here + | +LL | consume_test(*my_ref); + | + + +error[E0277]: the trait bound `Box<Box<Box<NonCopy>>>: Test` is not satisfied + --> $DIR/deref-argument.rs:34:18 + | +LL | consume_test(nested_box); + | ------------ ^^^^^^^^^^ the trait `Test` is not implemented for `Box<Box<Box<NonCopy>>>` + | | + | required by a bound introduced by this call + | +note: required by a bound in `consume_test` + --> $DIR/deref-argument.rs:9:25 + | +LL | fn consume_test(x: impl Test) { x.test() } + | ^^^^ required by this bound in `consume_test` +help: consider dereferencing here + | +LL | consume_test(***nested_box); + | +++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. |
