Do not report _#nr lifetimes names in errors
This commit is contained in:
parent
29f5c699b1
commit
a17a2e3f83
5 changed files with 128 additions and 6 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
26
src/test/ui/nll/borrowed-local-error.rs
Normal file
26
src/test/ui/nll/borrowed-local-error.rs
Normal file
|
|
@ -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
src/test/ui/nll/borrowed-local-error.stderr
Normal file
17
src/test/ui/nll/borrowed-local-error.stderr
Normal file
|
|
@ -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
src/test/ui/nll/borrowed-temporary-error.rs
Normal file
26
src/test/ui/nll/borrowed-temporary-error.rs
Normal file
|
|
@ -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
src/test/ui/nll/borrowed-temporary-error.stderr
Normal file
14
src/test/ui/nll/borrowed-temporary-error.stderr
Normal file
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue