Skip to content

Commit

Permalink
Extend support to get_generics for all NodeItems
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 28, 2018
1 parent 5436a5c commit 3005162
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 87 deletions.
9 changes: 8 additions & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -671,7 +671,14 @@ impl<'hir> Map<'hir> {
NodeTraitItem(ref trait_item) => Some(&trait_item.generics),
NodeItem(ref item) => {
match item.node {
ItemFn(_, _, ref generics, _) => Some(generics),
ItemFn(_, _, ref generics, _) |
ItemTy(_, ref generics) |
ItemEnum(_, ref generics) |
ItemStruct(_, ref generics) |
ItemUnion(_, ref generics) |
ItemTrait(_, _, ref generics, ..) |
ItemTraitAlias(ref generics, _) |
ItemImpl(_, _, _, ref generics, ..) => Some(generics),
_ => None,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/associated-const-impl-wrong-lifetime.stderr
Expand Up @@ -6,11 +6,11 @@ LL | const NAME: &'a str = "unit";
|
= note: expected type `&'static str`
found type `&'a str`
note: the lifetime 'a as defined on the impl at 17:1...
--> $DIR/associated-const-impl-wrong-lifetime.rs:17:1
note: the lifetime 'a as defined on the impl at 17:6...
--> $DIR/associated-const-impl-wrong-lifetime.rs:17:6
|
LL | impl<'a> Foo for &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^
= note: ...does not necessarily outlive the static lifetime

error: aborting due to previous error
Expand Down
Expand Up @@ -55,7 +55,7 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

error[E0276]: impl has stricter requirements than trait
--> $DIR/regions-bound-missing-bound-in-impl.rs:58:5
--> $DIR/regions-bound-missing-bound-in-impl.rs:59:5
|
LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
| ------------------------------------------------------- definition of `another_bound` from trait
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/error-codes/E0478.stderr
Expand Up @@ -4,16 +4,16 @@ error[E0478]: lifetime bound not satisfied
LL | child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:1
--> $DIR/E0478.rs:13:1
note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:22
--> $DIR/E0478.rs:13:22
|
LL | struct Prince<'kiss, 'SnowWhite> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:1
--> $DIR/E0478.rs:13:1
| ^^^^^^^^^^
note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:15
--> $DIR/E0478.rs:13:15
|
LL | struct Prince<'kiss, 'SnowWhite> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^

error: aborting due to previous error

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/issue-27942.stderr
Expand Up @@ -11,11 +11,11 @@ note: the anonymous lifetime #1 defined on the method body at 15:5...
|
LL | fn select(&self) -> BufferViewHandle<R>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:1
--> $DIR/issue-27942.rs:13:1
note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:18
--> $DIR/issue-27942.rs:13:18
|
LL | pub trait Buffer<'a, R: Resources<'a>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^

error[E0308]: mismatched types
--> $DIR/issue-27942.rs:15:5
Expand All @@ -25,11 +25,11 @@ LL | fn select(&self) -> BufferViewHandle<R>;
|
= note: expected type `Resources<'_>`
found type `Resources<'a>`
note: the lifetime 'a as defined on the trait at 13:1...
--> $DIR/issue-27942.rs:13:1
note: the lifetime 'a as defined on the trait at 13:18...
--> $DIR/issue-27942.rs:13:18
|
LL | pub trait Buffer<'a, R: Resources<'a>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 15:5
--> $DIR/issue-27942.rs:15:5
|
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issue-37884.stderr
Expand Up @@ -21,11 +21,11 @@ LL | | {
LL | | Some(&mut self.0)
LL | | }
| |_____^
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:1
--> $DIR/issue-37884.rs:13:1
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:6
--> $DIR/issue-37884.rs:13:6
|
LL | impl<'a, T: 'a> Iterator for RepeatMut<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^

error: aborting due to previous error

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/nll/issue-47470.stderr
Expand Up @@ -6,11 +6,11 @@ LL | &local //~ ERROR `local` does not live long enough
LL | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:1...
--> $DIR/issue-47470.rs:23:1
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:6...
--> $DIR/issue-47470.rs:23:6
|
LL | impl<'a> Bar for Foo<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^

error: aborting due to previous error

Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/nll/trait-associated-constant.stderr
Expand Up @@ -6,16 +6,16 @@ LL | const AC: Option<&'c str> = None;
|
= note: expected type `std::option::Option<&'b str>`
found type `std::option::Option<&'c str>`
note: the lifetime 'c as defined on the impl at 30:1...
--> $DIR/trait-associated-constant.rs:30:1
note: the lifetime 'c as defined on the impl at 30:18...
--> $DIR/trait-associated-constant.rs:30:18
|
LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:1
--> $DIR/trait-associated-constant.rs:30:1
| ^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:14
--> $DIR/trait-associated-constant.rs:30:14
|
LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^

error[E0308]: mismatched types
--> $DIR/trait-associated-constant.rs:38:5
Expand All @@ -25,16 +25,16 @@ LL | const AC: Option<&'a str> = None;
|
= note: expected type `std::option::Option<&'b str>`
found type `std::option::Option<&'a str>`
note: the lifetime 'a as defined on the impl at 37:1...
--> $DIR/trait-associated-constant.rs:37:1
note: the lifetime 'a as defined on the impl at 37:6...
--> $DIR/trait-associated-constant.rs:37:6
|
LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:1
--> $DIR/trait-associated-constant.rs:37:1
| ^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:14
--> $DIR/trait-associated-constant.rs:37:14
|
LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^

error: aborting due to 2 previous errors

Expand Down

0 comments on commit 3005162

Please sign in to comment.