Skip to content

Commit a17a2e3

Browse files
committed
Do not report _#nr lifetimes names in errors
1 parent 29f5c69 commit a17a2e3

File tree

5 files changed

+128
-6
lines changed

5 files changed

+128
-6
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,34 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
497497
_proper_span: Span,
498498
_end_span: Option<Span>,
499499
) {
500+
debug!(
501+
"report_unscoped_local_value_does_not_live_long_enough(\
502+
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
503+
)",
504+
context,
505+
name,
506+
scope_tree,
507+
borrow,
508+
drop_span,
509+
borrow_span
510+
);
511+
500512
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
501513
&format!("`{}`", name),
502514
Origin::Mir);
503515
err.span_label(borrow_span, "borrowed value does not live long enough");
504516
err.span_label(drop_span, "borrowed value only lives until here");
505-
self.tcx.note_and_explain_region(scope_tree, &mut err,
506-
"borrowed value must be valid for ",
507-
borrow.region, "...");
517+
518+
if !self.tcx.sess.nll() {
519+
self.tcx.note_and_explain_region(
520+
scope_tree,
521+
&mut err,
522+
"borrowed value must be valid for ",
523+
borrow.region,
524+
"...",
525+
);
526+
}
527+
508528
self.explain_why_borrow_contains_point(context, borrow, &mut err);
509529
err.emit();
510530
}
@@ -519,14 +539,33 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
519539
proper_span: Span,
520540
_end_span: Option<Span>
521541
) {
542+
debug!(
543+
"report_unscoped_temporary_value_does_not_live_long_enough(\
544+
{:?}, {:?}, {:?}, {:?}, {:?}\
545+
)",
546+
context,
547+
scope_tree,
548+
borrow,
549+
drop_span,
550+
proper_span
551+
);
552+
522553
let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
523554
"borrowed value",
524555
Origin::Mir);
525556
err.span_label(proper_span, "temporary value does not live long enough");
526557
err.span_label(drop_span, "temporary value only lives until here");
527-
self.tcx.note_and_explain_region(scope_tree, &mut err,
528-
"borrowed value must be valid for ",
529-
borrow.region, "...");
558+
559+
if !self.tcx.sess.nll() {
560+
self.tcx.note_and_explain_region(
561+
scope_tree,
562+
&mut err,
563+
"borrowed value must be valid for ",
564+
borrow.region,
565+
"...",
566+
);
567+
}
568+
530569
self.explain_why_borrow_contains_point(context, borrow, &mut err);
531570
err.emit();
532571
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// compile-flags: -Znll-dump-cause
12+
13+
#![feature(nll)]
14+
15+
fn gimme(x: &(u32,)) -> &u32 {
16+
&x.0
17+
}
18+
19+
fn main() {
20+
let x = gimme({
21+
let v = (22,);
22+
&v
23+
//~^ ERROR `v` does not live long enough [E0597]
24+
});
25+
println!("{:?}", x);
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0597]: `v` does not live long enough
2+
--> $DIR/borrowed-local-error.rs:22:9
3+
|
4+
LL | let x = gimme({
5+
| _____________-
6+
LL | | let v = (22,);
7+
LL | | &v
8+
| | ^^ borrowed value does not live long enough
9+
LL | | //~^ ERROR `v` does not live long enough [E0597]
10+
LL | | });
11+
| |_____-- borrow later used here
12+
| |
13+
| borrowed value only lives until here
14+
15+
error: aborting due to previous error
16+
17+
If you want more information on this error, try using "rustc --explain E0597"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// compile-flags: -Znll-dump-cause
12+
13+
#![feature(nll)]
14+
15+
fn gimme(x: &(u32,)) -> &u32 {
16+
&x.0
17+
}
18+
19+
fn main() {
20+
let x = gimme({
21+
let v = 22;
22+
&(v,)
23+
//~^ ERROR borrowed value does not live long enough [E0597]
24+
});
25+
println!("{:?}", x);
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/borrowed-temporary-error.rs:22:10
3+
|
4+
LL | &(v,)
5+
| ^^^^ temporary value does not live long enough
6+
LL | //~^ ERROR borrowed value does not live long enough [E0597]
7+
LL | });
8+
| - temporary value only lives until here
9+
LL | println!("{:?}", x);
10+
| - borrow later used here
11+
12+
error: aborting due to previous error
13+
14+
If you want more information on this error, try using "rustc --explain E0597"

0 commit comments

Comments
 (0)