Skip to content

Commit

Permalink
Auto merge of rust-lang#112549 - jieyouxu:fix-tests-for-unit-bindings…
Browse files Browse the repository at this point in the history
…, r=Nilstrieb

Adjust UI tests for `unit_bindings` lint

- Explicitly annotate `let x: () = expr;` where `x` has unit type, or remove the unit binding to leave only `expr;` instead.
- Use `let () = init;` or `let pat = ();` where appropriate.
- Fix disjoint-capture-in-same-closure test which wasn't actually testing a closure: `tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs`.

Note that unfortunately there's *a lot* of UI tests, there are a couple of places where I may have left something like `let (): ()` (this is not needed but is left over from an ealier version of the lint) which is bad style.

This PR is to help with the `unit_bindings` lint at rust-lang#112380.
  • Loading branch information
bors committed Jun 13, 2023
2 parents 4bd4e2e + edafbaf commit 2ca8d35
Show file tree
Hide file tree
Showing 61 changed files with 117 additions and 117 deletions.
4 changes: 2 additions & 2 deletions tests/ui/assign-assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn test_assign() {
let y: () = x = 10;
assert_eq!(x, 10);
assert_eq!(y, ());
let mut z = x = 11;
let mut z: () = x = 11;
assert_eq!(x, 11);
assert_eq!(z, ());
z = x = 12;
Expand All @@ -19,7 +19,7 @@ fn test_assign_op() {
let y: () = x += 10;
assert_eq!(x, 10);
assert_eq!(y, ());
let mut z = x += 11;
let mut z: () = x += 11;
assert_eq!(x, 21);
assert_eq!(z, ());
z = x += 12;
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/associated-type-bounds/dyn-impl-trait-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fn def_et4() -> Et4 {
pub fn use_et4() { assert_forall_tr2(def_et4().mk()); }

fn main() {
let _ = use_et1();
let _ = use_et2();
let _ = use_et3();
let _ = use_et4();
use_et1();
use_et2();
use_et3();
use_et4();
}
8 changes: 4 additions & 4 deletions tests/ui/associated-type-bounds/dyn-rpit-and-let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fn def_et4() -> Box<dyn Tr1<As1: for<'a> Tr2<'a>>> {
pub fn use_et4() { assert_forall_tr2(def_et4().mk()); }

fn main() {
let _ = use_et1();
let _ = use_et2();
let _ = use_et3();
let _ = use_et4();
use_et1();
use_et2();
use_et3();
use_et4();
}
8 changes: 4 additions & 4 deletions tests/ui/associated-type-bounds/rpit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ fn def_et4() -> impl Tr1<As1: for<'a> Tr2<'a>> {
pub fn use_et4() { assert_forall_tr2(def_et4().mk()); }

fn main() {
let _ = use_et1();
let _ = use_et2();
let _ = use_et3();
let _ = use_et4();
use_et1();
use_et2();
use_et3();
use_et4();
}
8 changes: 4 additions & 4 deletions tests/ui/associated-type-bounds/trait-alias-impl-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub fn use_et4() {
}

fn main() {
let _ = use_et1();
let _ = use_et2();
let _ = use_et3();
let _ = use_et4();
use_et1();
use_et2();
use_et3();
use_et4();
}
4 changes: 2 additions & 2 deletions tests/ui/associated-types/normalization-debruijn-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use std::future::{Future, Ready};
async fn read() {
let _ = connect(&()).await;
connect(&()).await;
}
async fn connect<A: ToSocketAddr>(addr: A) {
let _ = addr.to_socket_addr().await;
addr.to_socket_addr().await;
}
pub trait ToSocketAddr {
type Future: Future<Output = ()>;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/drop-track-field-assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Agent {
let mut info = self.info_result.clone();
info.node = Some("bar".into());
let element = parse_info(info);
let _ = send_element(element).await;
send_element(element).await;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/field-assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Agent {
let mut info = self.info_result.clone();
info.node = Some("bar".into());
let element = parse_info(info);
let _ = send_element(element).await;
send_element(element).await;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ LL | pub fn foo() -> impl Future + Send {
|
= help: the trait `Sync` is not implemented for `(dyn Any + Send + 'static)`
note: future is not `Send` as this value is used across an await
--> $DIR/issue-64130-4-async-move.rs:27:32
--> $DIR/issue-64130-4-async-move.rs:27:23
|
LL | match client.status() {
| ------ has type `&Client` which is not `Send`
LL | 200 => {
LL | let _x = get().await;
| ^^^^^ await occurs here, with `client` maybe used later
LL | get().await;
| ^^^^^ await occurs here, with `client` maybe used later
...
LL | }
| - `client` is later dropped here
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/issue-64130-4-async-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn foo() -> impl Future + Send {
async move {
match client.status() {
200 => {
let _x = get().await;
get().await;
}
_ => (),
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/non-trivial-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![feature(generators)]

fn main() {
let _ = foo();
foo();
}

fn foo() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/cfg_stmt_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn main() {
// check that lints work

#[allow(non_snake_case)]
let FOOBAR = {
let FOOBAR: () = {
fn SYLADEX() {}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Struct {
fn main() {
let mut s = Struct { x: 10, y: 10, s: String::new() };

let mut c = {
let mut c = || {
s.x += 10;
s.y += 42;
s.s = String::from("new");
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/generic_const_exprs/issue-86710.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::marker::PhantomData;

fn main() {
let x = FooImpl::<BarImpl<1>> { phantom: PhantomData };
let _ = x.foo::<BarImpl<1>>();
x.foo::<BarImpl<1>>();
}

trait Foo<T>
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/issues/issue-70273-assoc-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ impl T<0usize> for S {
}

fn main() {
let _err = <S as T<0usize>>::f();
<S as T<0usize>>::f();
}
2 changes: 1 addition & 1 deletion tests/ui/consts/assoc_const_generic_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait ZeroSized: Sized {
impl<T: Sized> ZeroSized for T {
const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; //~ ERROR evaluation of `<u32 as ZeroSized>::I_AM_ZERO_SIZED` failed
fn requires_zero_size(self) {
let () = Self::I_AM_ZERO_SIZED;
Self::I_AM_ZERO_SIZED;
println!("requires_zero_size called");
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-eval/erroneous-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fn no_codegen<T>() {
if false {
// This bad constant is only used in dead code in a no-codegen function... and yet we still
// must make sure that the build fails.
let _ = PrintName::<T>::VOID; //~ constant
PrintName::<T>::VOID; //~ constant
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/const-eval/erroneous-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | const VOID: () = [()][2];
| ^^^^^^^ index out of bounds: the length is 1 but the index is 2

note: erroneous constant used
--> $DIR/erroneous-const.rs:13:17
--> $DIR/erroneous-const.rs:13:13
|
LL | let _ = PrintName::<T>::VOID;
| ^^^^^^^^^^^^^^^^^^^^
LL | PrintName::<T>::VOID;
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-eval/erroneous-const2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub static FOO: () = {
if false {
// This bad constant is only used in dead code in a static initializer... and yet we still
// must make sure that the build fails.
let _ = PrintName::<i32>::VOID; //~ constant
PrintName::<i32>::VOID; //~ constant
}
};

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/const-eval/erroneous-const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | const VOID: () = [()][2];
| ^^^^^^^ index out of bounds: the length is 1 but the index is 2

note: erroneous constant used
--> $DIR/erroneous-const2.rs:13:17
--> $DIR/erroneous-const2.rs:13:9
|
LL | let _ = PrintName::<i32>::VOID;
| ^^^^^^^^^^^^^^^^^^^^^^
LL | PrintName::<i32>::VOID;
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-eval/promoted_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ const Y: () = {
};

fn main() {
let _y = Y;
Y;
}
2 changes: 1 addition & 1 deletion tests/ui/consts/const-eval/unwind-abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ const _: () = foo();
// Ensure that the CTFE engine handles calls to `extern "C"` aborting gracefully

fn main() {
let _ = foo();
foo();
}
4 changes: 2 additions & 2 deletions tests/ui/consts/large_const_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ static FOO2: () = {
};

fn main() {
let _ = FOO;
let _ = FOO2;
FOO;
FOO2;
}
2 changes: 1 addition & 1 deletion tests/ui/empty-allocation-rvalue-non-null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// pretty-expanded FIXME #23616

pub fn main() {
let x = *Box::new(());
let x: () = *Box::new(());
}
2 changes: 1 addition & 1 deletion tests/ui/feature-gates/feature-gate-generic_arg_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ fn bar() {
fn main() {
let _x = foo::<_>([1,2]);
//[normal]~^ ERROR: type provided when a constant was expected
let _y = bar();
bar();
}
10 changes: 5 additions & 5 deletions tests/ui/for-loop-while/loop-break-value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn main() {
};
assert_eq!(trait_unified_3, ["Yes"]);

let regular_break = loop {
let regular_break: () = loop {
if true {
break;
} else {
Expand All @@ -73,7 +73,7 @@ pub fn main() {
};
assert_eq!(regular_break, ());

let regular_break_2 = loop {
let regular_break_2: () = loop {
if true {
break Default::default();
} else {
Expand All @@ -82,7 +82,7 @@ pub fn main() {
};
assert_eq!(regular_break_2, ());

let regular_break_3 = loop {
let regular_break_3: () = loop {
break if true {
Default::default()
} else {
Expand All @@ -91,13 +91,13 @@ pub fn main() {
};
assert_eq!(regular_break_3, ());

let regular_break_4 = loop {
let regular_break_4: () = loop {
break ();
break;
};
assert_eq!(regular_break_4, ());

let regular_break_5 = loop {
let regular_break_5: () = loop {
break;
break ();
};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/generics/post_monomorphization_error_backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn assert_zst<T>() {
//~| NOTE: in this expansion of assert!
//~| NOTE: the evaluated program panicked
}
let _ = F::<T>::V;
F::<T>::V;
}

fn foo<U>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, 'b, U: Unpack<'b>> Backed<'a, U> {
where
F: for<'f> FnOnce(<U as Unpack<'f>>::Unpacked) -> (),
{
let result = f(self.1.unpack());
let result: () = f(self.1.unpack());
Backed(self.0, result)
}
}
2 changes: 1 addition & 1 deletion tests/ui/intrinsics/panic-uninitialized-zeroed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn main() {
let _val = mem::zeroed::<ZeroIsValid>();
let _val = mem::uninitialized::<MaybeUninit<bool>>();
let _val = mem::uninitialized::<[!; 0]>();
let _val = mem::uninitialized::<()>();
let _val: () = mem::uninitialized::<()>();
let _val = mem::uninitialized::<ZeroSized>();
}
}
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-11047.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub mod foo {
fn main() {

type Ham = foo::bar::baz::Qux;
let foo = foo::bar::baz::Qux::new(); // invoke directly
let bar = Ham::new(); // invoke via type alias
let foo: () = foo::bar::baz::Qux::new(); // invoke directly
let bar: () = Ham::new(); // invoke via type alias

type StringVec = Vec<String>;
let sv = StringVec::new();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-11709.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct S {x:()}

fn test(slot: &mut Option<Box<dyn FnMut() -> Box<dyn FnMut()>>>) -> () {
let a = slot.take();
let _a = match a {
let _a: () = match a {
// `{let .. a(); }` would break
Some(mut a) => { let _a = a(); },
None => (),
Expand All @@ -28,7 +28,7 @@ fn not(b: bool) -> bool {

pub fn main() {
// {} would break
let _r = {};
let _r: () = {};
let mut slot = None;
// `{ test(...); }` would break
let _s : S = S{ x: { test(&mut slot); } };
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-11740.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ impl Element {

fn main() {
let element = Element { attrs: Vec::new() };
let _ = unsafe { element.get_attr("foo") };
unsafe { let () = element.get_attr("foo"); };
}
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-20644.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn foo() {
let cwd = env::current_dir().unwrap();
let src = cwd.clone();
let summary = File::open(&src.join("SUMMARY.md")).unwrap();
let _ = parse_summary(summary, &src);
parse_summary(summary, &src);
}

fn main() {}
8 changes: 4 additions & 4 deletions tests/ui/issues/issue-23808.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ impl_Const!(ConstStruct, ConstEnum, AliasedConstStruct, AliasedConstEnum);
impl_StaticFn!(StaticFnStruct, StaticFnEnum, AliasedStaticFnStruct, AliasedStaticFnEnum);

fn main() {
let _ = ConstStruct::C;
let _ = ConstEnum::C;
let () = ConstStruct::C;
let () = ConstEnum::C;

StaticFnStruct::sfn();
StaticFnEnum::sfn();

let _ = AliasConstStruct::C;
let _ = AliasConstEnum::C;
let () = AliasConstStruct::C;
let () = AliasConstEnum::C;

AliasStaticFnStruct::sfn();
AliasStaticFnEnum::sfn();
Expand Down
Loading

0 comments on commit 2ca8d35

Please sign in to comment.