mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
edafbaffb2
- Either explicitly annotate `let x: () = expr;` where `x` has unit type, or remove the unit binding to leave only `expr;` instead. - Fix disjoint-capture-in-same-closure test
55 lines
1.1 KiB
Rust
55 lines
1.1 KiB
Rust
// check-pass
|
|
|
|
use std::fmt::{self, Display};
|
|
|
|
struct Mutex;
|
|
|
|
impl Mutex {
|
|
fn lock(&self) -> MutexGuard {
|
|
MutexGuard(self)
|
|
}
|
|
}
|
|
|
|
struct MutexGuard<'a>(&'a Mutex);
|
|
|
|
impl<'a> Drop for MutexGuard<'a> {
|
|
fn drop(&mut self) {
|
|
// Empty but this is a necessary part of the repro. Otherwise borrow
|
|
// checker is fine with 'a dangling at the time that MutexGuard goes out
|
|
// of scope.
|
|
}
|
|
}
|
|
|
|
impl<'a> Display for MutexGuard<'a> {
|
|
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let _print: () = {
|
|
let mutex = Mutex;
|
|
print!("{}", mutex.lock()) /* no semicolon */
|
|
};
|
|
|
|
let _println: () = {
|
|
let mutex = Mutex;
|
|
println!("{}", mutex.lock()) /* no semicolon */
|
|
};
|
|
|
|
let _eprint: () = {
|
|
let mutex = Mutex;
|
|
eprint!("{}", mutex.lock()) /* no semicolon */
|
|
};
|
|
|
|
let _eprintln: () = {
|
|
let mutex = Mutex;
|
|
eprintln!("{}", mutex.lock()) /* no semicolon */
|
|
};
|
|
|
|
let _panic: () = {
|
|
let mutex = Mutex;
|
|
panic!("{}", mutex.lock()) /* no semicolon */
|
|
};
|
|
}
|