Improve E0477 error message
This commit is contained in:
parent
f3fc547194
commit
cc4afe0f65
3 changed files with 35 additions and 2 deletions
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use infer::{self, InferCtxt, SubregionOrigin};
|
||||
use ty::Region;
|
||||
use ty::{self, Region};
|
||||
use ty::error::TypeError;
|
||||
use errors::DiagnosticBuilder;
|
||||
|
||||
|
|
@ -262,7 +262,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
"the type `{}` does not fulfill the required \
|
||||
lifetime",
|
||||
self.ty_to_string(ty));
|
||||
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
|
||||
match *sub {
|
||||
ty::ReStatic => {
|
||||
self.tcx.note_and_explain_region(&mut err, "type must satisfy ", sub, "")
|
||||
}
|
||||
_ => {
|
||||
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "")
|
||||
}
|
||||
}
|
||||
err
|
||||
}
|
||||
infer::RelateRegionParamBound(span) => {
|
||||
|
|
|
|||
16
src/test/ui/static-lifetime.rs
Normal file
16
src/test/ui/static-lifetime.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
pub trait Arbitrary: Sized + 'static {}
|
||||
|
||||
impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
10
src/test/ui/static-lifetime.stderr
Normal file
10
src/test/ui/static-lifetime.stderr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
error[E0477]: the type `std::borrow::Cow<'a, A>` does not fulfill the required lifetime
|
||||
--> $DIR/static-lifetime.rs:13:20
|
||||
|
|
||||
13 | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: type must satisfy the static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue