Skip to content

Commit b0c264d

Browse files
committed
Adding new ui test for trait impl
1 parent 0743060 commit b0c264d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/librustc/infer/error_reporting/util.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4040
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
4141
match self.tcx.hir.find(node_id) {
4242
Some(hir_map::NodeItem(..)) |
43-
Some(hir_map::NodeImplItem(..)) |
4443
Some(hir_map::NodeTraitItem(..)) => { /* proceed ahead */ }
4544
_ => return false, // inapplicable
4645
// we target only top-level functions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
trait Foo {
12+
13+
fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32;
14+
15+
}
16+
17+
impl Foo for () {
18+
19+
fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
20+
21+
if x > y { x } else { y }
22+
23+
}
24+
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
2+
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:21:20
3+
|
4+
21 | if x > y { x } else { y }
5+
| ^
6+
|
7+
note: ...the reference is valid for the lifetime 'a as defined on the method body at 19:5...
8+
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5
9+
|
10+
19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
11+
20 | |
12+
21 | | if x > y { x } else { y }
13+
22 | |
14+
23 | | }
15+
| |_____^
16+
note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the method body at 19:5
17+
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5
18+
|
19+
19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
20+
20 | |
21+
21 | | if x > y { x } else { y }
22+
22 | |
23+
23 | | }
24+
| |_____^
25+
26+
error: aborting due to previous error(s)
27+

0 commit comments

Comments
 (0)