Skip to content

Commit

Permalink
Do not report _#nr lifetimes names in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Feb 28, 2018
1 parent 29f5c69 commit a17a2e3
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 6 deletions.
51 changes: 45 additions & 6 deletions src/librustc_mir/borrow_check/error_reporting.rs
Expand Up @@ -497,14 +497,34 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
_proper_span: Span,
_end_span: Option<Span>,
) {
debug!(
"report_unscoped_local_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
)",
context,
name,
scope_tree,
borrow,
drop_span,
borrow_span
);

let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
&format!("`{}`", name),
Origin::Mir);
err.span_label(borrow_span, "borrowed value does not live long enough");
err.span_label(drop_span, "borrowed value only lives until here");
self.tcx.note_and_explain_region(scope_tree, &mut err,
"borrowed value must be valid for ",
borrow.region, "...");

if !self.tcx.sess.nll() {
self.tcx.note_and_explain_region(
scope_tree,
&mut err,
"borrowed value must be valid for ",
borrow.region,
"...",
);
}

self.explain_why_borrow_contains_point(context, borrow, &mut err);
err.emit();
}
Expand All @@ -519,14 +539,33 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
proper_span: Span,
_end_span: Option<Span>
) {
debug!(
"report_unscoped_temporary_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}\
)",
context,
scope_tree,
borrow,
drop_span,
proper_span
);

let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
"borrowed value",
Origin::Mir);
err.span_label(proper_span, "temporary value does not live long enough");
err.span_label(drop_span, "temporary value only lives until here");
self.tcx.note_and_explain_region(scope_tree, &mut err,
"borrowed value must be valid for ",
borrow.region, "...");

if !self.tcx.sess.nll() {
self.tcx.note_and_explain_region(
scope_tree,
&mut err,
"borrowed value must be valid for ",
borrow.region,
"...",
);
}

self.explain_why_borrow_contains_point(context, borrow, &mut err);
err.emit();
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/nll/borrowed-local-error.rs
@@ -0,0 +1,26 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Znll-dump-cause

#![feature(nll)]

fn gimme(x: &(u32,)) -> &u32 {
&x.0
}

fn main() {
let x = gimme({
let v = (22,);
&v
//~^ ERROR `v` does not live long enough [E0597]
});
println!("{:?}", x);
}
17 changes: 17 additions & 0 deletions src/test/ui/nll/borrowed-local-error.stderr
@@ -0,0 +1,17 @@
error[E0597]: `v` does not live long enough
--> $DIR/borrowed-local-error.rs:22:9
|
LL | let x = gimme({
| _____________-
LL | | let v = (22,);
LL | | &v
| | ^^ borrowed value does not live long enough
LL | | //~^ ERROR `v` does not live long enough [E0597]
LL | | });
| |_____-- borrow later used here
| |
| borrowed value only lives until here

error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0597"
26 changes: 26 additions & 0 deletions src/test/ui/nll/borrowed-temporary-error.rs
@@ -0,0 +1,26 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Znll-dump-cause

#![feature(nll)]

fn gimme(x: &(u32,)) -> &u32 {
&x.0
}

fn main() {
let x = gimme({
let v = 22;
&(v,)
//~^ ERROR borrowed value does not live long enough [E0597]
});
println!("{:?}", x);
}
14 changes: 14 additions & 0 deletions src/test/ui/nll/borrowed-temporary-error.stderr
@@ -0,0 +1,14 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/borrowed-temporary-error.rs:22:10
|
LL | &(v,)
| ^^^^ temporary value does not live long enough
LL | //~^ ERROR borrowed value does not live long enough [E0597]
LL | });
| - temporary value only lives until here
LL | println!("{:?}", x);
| - borrow later used here

error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0597"

0 comments on commit a17a2e3

Please sign in to comment.