Skip to content

Commit b84d25d

Browse files
Fix format-args-temporaries test (fail->pass) & add 2φ-borrows regression tests
1 parent 2310efa commit b84d25d

File tree

2 files changed

+32
-72
lines changed

2 files changed

+32
-72
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1-
// check-fail
1+
// check-pass
2+
#![crate_type = "lib"]
23

34
use std::fmt::{self, Display};
45

56
struct Mutex;
67

78
impl Mutex {
8-
fn lock(&self) -> MutexGuard {
9-
MutexGuard(self)
9+
/// Dependent item with (potential) drop glue to disable NLL.
10+
fn lock(&self) -> impl '_ + Display {
11+
42
1012
}
1113
}
1214

13-
struct MutexGuard<'a>(&'a Mutex);
15+
struct Stderr();
1416

15-
impl<'a> Drop for MutexGuard<'a> {
16-
fn drop(&mut self) {
17-
// Empty but this is a necessary part of the repro. Otherwise borrow
18-
// checker is fine with 'a dangling at the time that MutexGuard goes out
19-
// of scope.
20-
}
21-
}
22-
23-
struct Out;
24-
25-
impl Out {
26-
fn write_fmt(&self, _args: fmt::Arguments) {}
27-
}
28-
29-
impl<'a> Display for MutexGuard<'a> {
30-
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
31-
Ok(())
32-
}
17+
impl Stderr {
18+
/// A "lending" `write_fmt` method. See:
19+
/// https://docs.rs/async-std/1.12.0/async_std/io/prelude/trait.WriteExt.html#method.write_fmt
20+
fn write_fmt(&mut self, _args: fmt::Arguments) -> &() { &() }
3321
}
3422

35-
fn main() {
36-
// FIXME(dtolnay): We actually want both of these to work. I think it's
37-
// sadly unimplementable today though.
23+
fn early_drop_for_format_args_temporaries() {
24+
let mut out = Stderr();
3825

3926
let _write = {
4027
let mutex = Mutex;
41-
write!(Out, "{}", mutex.lock()) /* no semicolon */
42-
//~^ ERROR `mutex` does not live long enough
28+
write!(out, "{}", mutex.lock()) /* no semicolon */
4329
};
4430

4531
let _writeln = {
4632
let mutex = Mutex;
47-
writeln!(Out, "{}", mutex.lock()) /* no semicolon */
48-
//~^ ERROR `mutex` does not live long enough
33+
writeln!(out, "{}", mutex.lock()) /* no semicolon */
4934
};
5035
}
36+
37+
fn late_drop_for_receiver() {
38+
let mutex = Mutex;
39+
drop(write!(&mut Stderr(), "{}", mutex.lock()));
40+
drop(writeln!(&mut Stderr(), "{}", mutex.lock()));
41+
}
42+
43+
fn two_phased_borrows_retrocompat(w: (&mut Stderr, i32)) {
44+
write!(w.0, "{}", w.1);
45+
writeln!(w.0, "{}", w.1);
46+
struct Struct<W> {
47+
w: W,
48+
len: i32
49+
}
50+
let s = (Struct { w: (w.0, ), len: w.1 }, );
51+
write!(s.0.w.0, "{}", s.0.len);
52+
writeln!(s.0.w.0, "{}", s.0.len);
53+
}

src/test/ui/macros/format-args-temporaries-in-write.stderr

-43
This file was deleted.

0 commit comments

Comments
 (0)