Skip to content

Commit

Permalink
Rollup merge of rust-lang#41862 - GuillaumeGomez:improve-e0477, r=nagisa
Browse files Browse the repository at this point in the history
Improve E0477 error message

Part of rust-lang#41816.

r? @nagisa
  • Loading branch information
frewsxcv committed May 10, 2017
2 parents 2806ba0 + cc4afe0 commit 75dc416
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) => {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/static-lifetime.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/test/ui/static-lifetime.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 75dc416

Please sign in to comment.