diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-05-09 20:51:18 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-05-09 20:51:18 +0200 |
| commit | cc4afe0f6504136ed2adc8cbada32e5429e04757 (patch) | |
| tree | 9f68425dc4ac555689f656faaeaf37a7d9f0b705 | |
| parent | f3fc547194d22dc673274ac20e9a7b1e607cb862 (diff) | |
| download | rust-cc4afe0f6504136ed2adc8cbada32e5429e04757.tar.gz rust-cc4afe0f6504136ed2adc8cbada32e5429e04757.zip | |
Improve E0477 error message
| -rw-r--r-- | src/librustc/infer/error_reporting/note.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/static-lifetime.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/static-lifetime.stderr | 10 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 49952d81cbb..963c14c48c8 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -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) => { diff --git a/src/test/ui/static-lifetime.rs b/src/test/ui/static-lifetime.rs new file mode 100644 index 00000000000..7b1887b2d1a --- /dev/null +++ b/src/test/ui/static-lifetime.rs @@ -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() { +} \ No newline at end of file diff --git a/src/test/ui/static-lifetime.stderr b/src/test/ui/static-lifetime.stderr new file mode 100644 index 00000000000..f73dff4f73d --- /dev/null +++ b/src/test/ui/static-lifetime.stderr @@ -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 + |
