Skip to content

tests/ui: A New Order [3/N] #141965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions tests/ui/break-diverging-value.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/cancel-clean-via-immediate-rvalue-ref.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/cannot-mutate-captured-non-mut-var.rs

This file was deleted.

23 changes: 23 additions & 0 deletions tests/ui/closures/closure-immut-capture-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Tests that mutation of captured immutable variables in closures are not permitted.

#![feature(unboxed_closures, tuple_trait)]

use std::io::Read;

fn to_fn_once<A: std::marker::Tuple, F: FnOnce<A>>(f: F) -> F {
f
}

fn main() {
let x = 1;
to_fn_once(move || {
x = 2;
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
});

let s = std::io::stdin();
to_fn_once(move || {
s.read_to_end(&mut Vec::new());
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
});
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
--> $DIR/closure-immut-capture-error.rs:14:9
|
LL | to_fn_once(move|| { x = 2; });
| ^^^^^ cannot assign
LL | x = 2;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut x = 1;
| +++

error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
--> $DIR/closure-immut-capture-error.rs:20:9
|
LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
| ^ cannot borrow as mutable
LL | s.read_to_end(&mut Vec::new());
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/codegen/rvalue-mut-ref-box-drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Tests cleanup of a temporary `Box` rvalue passed as a mutable reference.
//!
//! - Issue: <https://github.com/rust-lang/rust/issues/7972>.

//@ run-pass

fn foo(x: &mut Box<u8>) {
*x = Box::new(5);
}

pub fn main() {
foo(&mut Box::new(4));
}
56 changes: 56 additions & 0 deletions tests/ui/loops/loop-break-never-type-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Tests type mismatches with `break` and diverging types in loops

#![feature(never_type)]

fn loop_break_return() -> i32 {
let loop_value = loop {
break return 0;
}; // ok
}

fn loop_break_loop() -> i32 {
let loop_value = loop {
break loop {};
}; // ok
}

fn loop_break_break() -> i32 {
//~^ ERROR mismatched types
let loop_value = loop {
break break;
};
}

fn loop_break_return_2() -> i32 {
let loop_value = loop {
break {
return 0;
()
};
}; // ok
}

enum Void {}

fn get_void() -> Void {
panic!()
}

fn loop_break_void() -> i32 {
//~^ ERROR mismatched types
let loop_value = loop {
break get_void();
};
}

fn get_never() -> ! {
panic!()
}

fn loop_break_never() -> i32 {
let loop_value = loop {
break get_never();
}; // ok
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:11:26
--> $DIR/loop-break-never-type-mismatch.rs:17:26
|
LL | fn loop_break_break() -> i32 {
| ---------------- ^^^ expected `i32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:25:25
--> $DIR/loop-break-never-type-mismatch.rs:39:25
|
LL | fn loop_break_void() -> i32 {
| --------------- ^^^ expected `i32`, found `()`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! Tests cleanup behavior of the built-in `Clone` impl for tuples during unwinding.

//@ run-pass
//@ needs-unwind

#![allow(unused_variables)]
#![allow(unused_imports)]

// Test that builtin implementations of `Clone` cleanup everything
// in case of unwinding.

use std::thread;
use std::rc::Rc;
use std::thread;

struct S(Rc<()>);

Expand All @@ -28,34 +27,20 @@ fn main() {
// Unwinding with tuples...
let ccounter = counter.clone();
let result = std::panic::catch_unwind(move || {
let _ = (
S(ccounter.clone()),
S(ccounter.clone()),
S(ccounter.clone()),
S(ccounter)
).clone();
let _ =
(S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)).clone();
});

assert!(result.is_err());
assert_eq!(
1,
Rc::strong_count(&counter)
);
assert_eq!(1, Rc::strong_count(&counter));

// ... and with arrays.
let ccounter = counter.clone();
let child = std::panic::catch_unwind(move || {
let _ = [
S(ccounter.clone()),
S(ccounter.clone()),
S(ccounter.clone()),
S(ccounter)
].clone();
let _ =
[S(ccounter.clone()), S(ccounter.clone()), S(ccounter.clone()), S(ccounter)].clone();
});

assert!(child.is_err());
assert_eq!(
1,
Rc::strong_count(&counter)
);
assert_eq!(1, Rc::strong_count(&counter));
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Tests that type parameters with the `Copy` are implicitly copyable.

//@ run-pass

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests that type parameters with the `Copy` are implicitly copyable.

#![allow(dead_code)]

fn can_copy_copy<T:Copy>(v: T) {
fn can_copy_copy<T: Copy>(v: T) {
let _a = v;
let _b = v;
}
Expand Down
Loading