Skip to content

Commit 3005162

Browse files
committed
Extend support to get_generics for all NodeItems
1 parent 5436a5c commit 3005162

10 files changed

+94
-87
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,14 @@ impl<'hir> Map<'hir> {
671671
NodeTraitItem(ref trait_item) => Some(&trait_item.generics),
672672
NodeItem(ref item) => {
673673
match item.node {
674-
ItemFn(_, _, ref generics, _) => Some(generics),
674+
ItemFn(_, _, ref generics, _) |
675+
ItemTy(_, ref generics) |
676+
ItemEnum(_, ref generics) |
677+
ItemStruct(_, ref generics) |
678+
ItemUnion(_, ref generics) |
679+
ItemTrait(_, _, ref generics, ..) |
680+
ItemTraitAlias(ref generics, _) |
681+
ItemImpl(_, _, _, ref generics, ..) => Some(generics),
675682
_ => None,
676683
}
677684
}

src/test/ui/associated-const-impl-wrong-lifetime.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | const NAME: &'a str = "unit";
66
|
77
= note: expected type `&'static str`
88
found type `&'a str`
9-
note: the lifetime 'a as defined on the impl at 17:1...
10-
--> $DIR/associated-const-impl-wrong-lifetime.rs:17:1
9+
note: the lifetime 'a as defined on the impl at 17:6...
10+
--> $DIR/associated-const-impl-wrong-lifetime.rs:17:6
1111
|
1212
LL | impl<'a> Foo for &'a () {
13-
| ^^^^^^^^^^^^^^^^^^^^^^^
13+
| ^^
1414
= note: ...does not necessarily outlive the static lifetime
1515

1616
error: aborting due to previous error

src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5656

5757
error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration
58-
--> $DIR/regions-bound-missing-bound-in-impl.rs:51:5
58+
--> $DIR/regions-bound-missing-bound-in-impl.rs:52:5
5959
|
6060
LL | fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
6161
| ---------------- lifetimes in impl do not match this method in trait
@@ -64,7 +64,7 @@ LL | fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) {
6464
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait
6565

6666
error[E0276]: impl has stricter requirements than trait
67-
--> $DIR/regions-bound-missing-bound-in-impl.rs:58:5
67+
--> $DIR/regions-bound-missing-bound-in-impl.rs:59:5
6868
|
6969
LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
7070
| ------------------------------------------------------- definition of `another_bound` from trait

src/test/ui/error-codes/E0478.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ error[E0478]: lifetime bound not satisfied
44
LL | child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:1
8-
--> $DIR/E0478.rs:13:1
7+
note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:22
8+
--> $DIR/E0478.rs:13:22
99
|
1010
LL | struct Prince<'kiss, 'SnowWhite> {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:1
13-
--> $DIR/E0478.rs:13:1
11+
| ^^^^^^^^^^
12+
note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:15
13+
--> $DIR/E0478.rs:13:15
1414
|
1515
LL | struct Prince<'kiss, 'SnowWhite> {
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
| ^^^^^
1717

1818
error: aborting due to previous error
1919

src/test/ui/issue-27942.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ note: the anonymous lifetime #1 defined on the method body at 15:5...
1111
|
1212
LL | fn select(&self) -> BufferViewHandle<R>;
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:1
15-
--> $DIR/issue-27942.rs:13:1
14+
note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:18
15+
--> $DIR/issue-27942.rs:13:18
1616
|
1717
LL | pub trait Buffer<'a, R: Resources<'a>> {
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
| ^^
1919

2020
error[E0308]: mismatched types
2121
--> $DIR/issue-27942.rs:15:5
@@ -25,11 +25,11 @@ LL | fn select(&self) -> BufferViewHandle<R>;
2525
|
2626
= note: expected type `Resources<'_>`
2727
found type `Resources<'a>`
28-
note: the lifetime 'a as defined on the trait at 13:1...
29-
--> $DIR/issue-27942.rs:13:1
28+
note: the lifetime 'a as defined on the trait at 13:18...
29+
--> $DIR/issue-27942.rs:13:18
3030
|
3131
LL | pub trait Buffer<'a, R: Resources<'a>> {
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
| ^^
3333
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 15:5
3434
--> $DIR/issue-27942.rs:15:5
3535
|

src/test/ui/issue-37884.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ LL | | {
2121
LL | | Some(&mut self.0)
2222
LL | | }
2323
| |_____^
24-
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:1
25-
--> $DIR/issue-37884.rs:13:1
24+
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:6
25+
--> $DIR/issue-37884.rs:13:6
2626
|
2727
LL | impl<'a, T: 'a> Iterator for RepeatMut<'a, T> {
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
| ^^
2929

3030
error: aborting due to previous error
3131

src/test/ui/nll/issue-47470.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | &local //~ ERROR `local` does not live long enough
66
LL | }
77
| - borrowed value only lives until here
88
|
9-
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:1...
10-
--> $DIR/issue-47470.rs:23:1
9+
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:6...
10+
--> $DIR/issue-47470.rs:23:6
1111
|
1212
LL | impl<'a> Bar for Foo<'a> {
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
13+
| ^^
1414

1515
error: aborting due to previous error
1616

src/test/ui/nll/trait-associated-constant.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ LL | const AC: Option<&'c str> = None;
66
|
77
= note: expected type `std::option::Option<&'b str>`
88
found type `std::option::Option<&'c str>`
9-
note: the lifetime 'c as defined on the impl at 30:1...
10-
--> $DIR/trait-associated-constant.rs:30:1
9+
note: the lifetime 'c as defined on the impl at 30:18...
10+
--> $DIR/trait-associated-constant.rs:30:18
1111
|
1212
LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:1
15-
--> $DIR/trait-associated-constant.rs:30:1
13+
| ^^
14+
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:14
15+
--> $DIR/trait-associated-constant.rs:30:14
1616
|
1717
LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
| ^^
1919

2020
error[E0308]: mismatched types
2121
--> $DIR/trait-associated-constant.rs:38:5
@@ -25,16 +25,16 @@ LL | const AC: Option<&'a str> = None;
2525
|
2626
= note: expected type `std::option::Option<&'b str>`
2727
found type `std::option::Option<&'a str>`
28-
note: the lifetime 'a as defined on the impl at 37:1...
29-
--> $DIR/trait-associated-constant.rs:37:1
28+
note: the lifetime 'a as defined on the impl at 37:6...
29+
--> $DIR/trait-associated-constant.rs:37:6
3030
|
3131
LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33-
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:1
34-
--> $DIR/trait-associated-constant.rs:37:1
32+
| ^^
33+
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:14
34+
--> $DIR/trait-associated-constant.rs:37:14
3535
|
3636
LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
| ^^
3838

3939
error: aborting due to 2 previous errors
4040

0 commit comments

Comments
 (0)