Skip to content

Commit 0e6b713

Browse files
committed
Auto merge of #52106 - PramodBisht:issue/52049, r=oli-obk
Don't suggest `let` bindings if they don't help with borrows @oli-obk I have added a condition to address #52049, right now, this is on WIP because I think code change is also required on `error_reporting.rs`. Plus I need to check if any test cases fail. I will ping you again if everything passes r? @oli-obk
2 parents 0c0315c + ab767ee commit 0e6b713

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10111011
let node_id = scope.node_id(self.tcx, &self.region_scope_tree);
10121012
match self.tcx.hir.find(node_id) {
10131013
Some(hir_map::NodeStmt(_)) => {
1014-
db.note("consider using a `let` binding to increase its lifetime");
1014+
if *sub_scope != ty::ReStatic {
1015+
db.note("consider using a `let` binding to increase its lifetime");
1016+
}
1017+
10151018
}
10161019
_ => {}
10171020
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/issue-52049.rs:16:10
3+
|
4+
LL | foo(&unpromotable(5u32));
5+
| ^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
6+
LL | }
7+
| - temporary value only lives until here
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0597`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn foo(_: &'static u32) {}
12+
13+
fn unpromotable<T>(t: T) -> T { t }
14+
15+
fn main() {
16+
foo(&unpromotable(5u32));
17+
}
18+
//~^^ ERROR borrowed value does not live long enough
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/issue-52049.rs:16:10
3+
|
4+
LL | foo(&unpromotable(5u32));
5+
| ^^^^^^^^^^^^^^^^^^ - temporary value only lives until here
6+
| |
7+
| temporary value does not live long enough
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)