Skip to content

Improve E0477 error message #41862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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