Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8713973
std: simplify `NonNull` variance documentation
xizheyin Jun 3, 2025
5f0dd44
avoid `&mut P<T>` in `visit_expr` etc methods
fee1-dead Jun 11, 2025
810d99e
Prepare `rustc-dev` component un-remapping in the compiler
Urgau Jun 10, 2025
268fbfe
Un-remap `rustc-dev` component paths
Urgau Jun 11, 2025
a16b49b
Manually invalidate caches in SimplifyCfg.
cjgillot Jun 15, 2025
0e1db54
Windows: Use anonymous pipes in Command
ChrisDenton Jun 14, 2025
32c0cb0
Add union with default field values case test
jieyouxu Jun 16, 2025
a2d9687
Add comment.
cjgillot Jun 16, 2025
718df66
Two changes: Have BorrowError & BorrowMutError derive Debug and add
nealsid Jun 14, 2025
2fca05a
Rename BorrowFlag type to BorrowCounter
nealsid Jun 14, 2025
994794a
Handle same-crate macro for borrowck semicolon suggestion
Urgau Jun 16, 2025
2dd9cc1
Reject union default field values
jieyouxu Jun 16, 2025
1dbedaf
Refine run-make test ignores due to unpredictable `i686-pc-windows-gn…
jieyouxu Jun 16, 2025
aa8c6f8
Don't match on platform-specific directory not found message
jieyouxu Jun 17, 2025
0348a4a
Make performance of String::insert_str more precise
hkBst Mar 15, 2025
679a1a7
Rollup merge of #138538 - hkBst:patch-4, r=tgross35
workingjubilee Jun 17, 2025
be6b529
Rollup merge of #141946 - xizheyin:141933, r=jhpratt
workingjubilee Jun 17, 2025
4c48468
Rollup merge of #142216 - nealsid:refcell-logging, r=tgross35
workingjubilee Jun 17, 2025
0ab7ae0
Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petr…
workingjubilee Jun 17, 2025
e39823f
Rollup merge of #142377 - Urgau:unremap-rustc-dev, r=jieyouxu
workingjubilee Jun 17, 2025
532edf5
Rollup merge of #142517 - ChrisDenton:anon-pipe, r=Mark-Simulacrum
workingjubilee Jun 17, 2025
540f68e
Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLii
workingjubilee Jun 17, 2025
ac8a2cb
Rollup merge of #142563 - jieyouxu:no-more-i686-mingw, r=mati865
workingjubilee Jun 17, 2025
0945b2b
Rollup merge of #142570 - jieyouxu:disunion, r=estebank
workingjubilee Jun 17, 2025
c79a6c0
Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
workingjubilee Jun 17, 2025
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
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
}
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
let sp = info
.span
.find_ancestor_in_same_ctxt(local_decl.source_info.span)
.unwrap_or(info.span);
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
if info.tail_result_is_ignored {
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
Expand Down
59 changes: 16 additions & 43 deletions tests/ui/borrowck/span-semicolon-issue-139049.fixed
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
// Make sure the generated suggestion suggest editing the user
// code instead of the std macro implementation
// Make sure the generated suggestion suggest editing the user code instead of
// the macro implementation (which might come from an external crate).
// issue: <https://github.com/rust-lang/rust/issues/139049>

//@ run-rustfix

#![allow(dead_code)]

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) {}
}

struct Out;

impl Out {
fn write_fmt(&self, _args: fmt::Arguments) {}
}

impl<'a> Display for MutexGuard<'a> {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}
// You could assume that this comes from an extern crate (it doesn't
// because an aux crate would be overkill for this test).
macro_rules! perform { ($e:expr) => { D(&$e).end() } }
//~^ ERROR does not live long enough
//~| ERROR does not live long enough

fn main() {
let _write = {
let mutex = Mutex;
write!(Out, "{}", mutex.lock());
//~^ ERROR `mutex` does not live long enough
//~| SUGGESTION ;
};

let _write = {
use std::io::Write as _;
{ let l = (); perform!(l); };
//~^ SUGGESTION ;

let mutex = Mutex;
let x = write!(std::io::stdout(), "{}", mutex.lock()); x
//~^ ERROR `mutex` does not live long enough
//~| SUGGESTION let x
};
let _x = { let l = (); let x = perform!(l); x };
//~^ SUGGESTION let x
}

struct D<T>(T);
impl<T> Drop for D<T> { fn drop(&mut self) {} }
impl<T> D<T> { fn end(&self) -> String { String::new() } }
59 changes: 16 additions & 43 deletions tests/ui/borrowck/span-semicolon-issue-139049.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
// Make sure the generated suggestion suggest editing the user
// code instead of the std macro implementation
// Make sure the generated suggestion suggest editing the user code instead of
// the macro implementation (which might come from an external crate).
// issue: <https://github.com/rust-lang/rust/issues/139049>

//@ run-rustfix

#![allow(dead_code)]

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) {}
}

struct Out;

impl Out {
fn write_fmt(&self, _args: fmt::Arguments) {}
}

impl<'a> Display for MutexGuard<'a> {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}
// You could assume that this comes from an extern crate (it doesn't
// because an aux crate would be overkill for this test).
macro_rules! perform { ($e:expr) => { D(&$e).end() } }
//~^ ERROR does not live long enough
//~| ERROR does not live long enough

fn main() {
let _write = {
let mutex = Mutex;
write!(Out, "{}", mutex.lock())
//~^ ERROR `mutex` does not live long enough
//~| SUGGESTION ;
};

let _write = {
use std::io::Write as _;
{ let l = (); perform!(l) };
//~^ SUGGESTION ;

let mutex = Mutex;
write!(std::io::stdout(), "{}", mutex.lock())
//~^ ERROR `mutex` does not live long enough
//~| SUGGESTION let x
};
let _x = { let l = (); perform!(l) };
//~^ SUGGESTION let x
}

struct D<T>(T);
impl<T> Drop for D<T> { fn drop(&mut self) {} }
impl<T> D<T> { fn end(&self) -> String { String::new() } }
62 changes: 32 additions & 30 deletions tests/ui/borrowck/span-semicolon-issue-139049.stderr
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
error[E0597]: `mutex` does not live long enough
--> $DIR/span-semicolon-issue-139049.rs:39:27
error[E0597]: `l` does not live long enough
--> $DIR/span-semicolon-issue-139049.rs:11:41
|
LL | let mutex = Mutex;
| ----- binding `mutex` declared here
LL | write!(Out, "{}", mutex.lock())
| ^^^^^-------
| |
| borrowed value does not live long enough
| a temporary with access to the borrow is created here ...
LL | macro_rules! perform { ($e:expr) => { D(&$e).end() } }
| --^^^-
| | |
| | borrowed value does not live long enough
| a temporary with access to the borrow is created here ...
...
LL | };
| -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard`
| |
| `mutex` dropped here while still borrowed
LL | { let l = (); perform!(l) };
| - ----------- -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
| | | |
| | | `l` dropped here while still borrowed
| | in this macro invocation
| binding `l` declared here
|
= note: this error originates in the macro `perform` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
|
LL | write!(Out, "{}", mutex.lock());
| +
LL | { let l = (); perform!(l); };
| +

error[E0597]: `mutex` does not live long enough
--> $DIR/span-semicolon-issue-139049.rs:48:41
error[E0597]: `l` does not live long enough
--> $DIR/span-semicolon-issue-139049.rs:11:41
|
LL | let mutex = Mutex;
| ----- binding `mutex` declared here
LL | write!(std::io::stdout(), "{}", mutex.lock())
| ^^^^^-------
| |
| borrowed value does not live long enough
| a temporary with access to the borrow is created here ...
LL | macro_rules! perform { ($e:expr) => { D(&$e).end() } }
| --^^^-
| | |
| | borrowed value does not live long enough
| a temporary with access to the borrow is created here ...
...
LL | };
| -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard`
| |
| `mutex` dropped here while still borrowed
LL | let _x = { let l = (); perform!(l) };
| - ----------- -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
| | | |
| | | `l` dropped here while still borrowed
| | in this macro invocation
| binding `l` declared here
|
= note: the temporary is part of an expression at the end of a block;
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
= note: this error originates in the macro `perform` (in Nightly builds, run with -Z macro-backtrace for more info)
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
|
LL | let x = write!(std::io::stdout(), "{}", mutex.lock()); x
| +++++++ +++
LL | let _x = { let l = (); let x = perform!(l); x };
| +++++++ +++

error: aborting due to 2 previous errors

Expand Down