Skip to content

Commit bb8d51c

Browse files
committed
Auto merge of #41862 - GuillaumeGomez:improve-e0477, r=nagisa
Improve E0477 error message Part of #41816. r? @nagisa
2 parents 978d2cf + cc4afe0 commit bb8d51c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/librustc/infer/error_reporting/note.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use infer::{self, InferCtxt, SubregionOrigin};
12-
use ty::Region;
12+
use ty::{self, Region};
1313
use ty::error::TypeError;
1414
use errors::DiagnosticBuilder;
1515

@@ -262,7 +262,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
262262
"the type `{}` does not fulfill the required \
263263
lifetime",
264264
self.ty_to_string(ty));
265-
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
265+
match *sub {
266+
ty::ReStatic => {
267+
self.tcx.note_and_explain_region(&mut err, "type must satisfy ", sub, "")
268+
}
269+
_ => {
270+
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "")
271+
}
272+
}
266273
err
267274
}
268275
infer::RelateRegionParamBound(span) => {

src/test/ui/static-lifetime.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub trait Arbitrary: Sized + 'static {}
12+
13+
impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
14+
15+
fn main() {
16+
}

src/test/ui/static-lifetime.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0477]: the type `std::borrow::Cow<'a, A>` does not fulfill the required lifetime
2+
--> $DIR/static-lifetime.rs:13:20
3+
|
4+
13 | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
5+
| ^^^^^^^^^
6+
|
7+
= note: type must satisfy the static lifetime
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)