Skip to content

Commit

Permalink
rustc: fix ICE when trait alias has bare Self
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Mar 12, 2019
1 parent e68bf8a commit df05fbf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,17 @@ impl<'hir> Map<'hir> {

pub fn ty_param_owner(&self, id: HirId) -> HirId {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id))
}
}

pub fn ty_param_name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => keywords::SelfUpper.name(),
Node::GenericParam(param) => param.name.ident().name,
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-59029-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(trait_alias)]

trait Svc<Req> { type Res; }

trait MkSvc<Target, Req> = Svc<Target> where Self::Res: Svc<Req>;
//~^ ERROR associated type `Res` not found for `Self`

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-59029-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0220]: associated type `Res` not found for `Self`
--> $DIR/issue-59029-1.rs:5:46
|
LL | trait MkSvc<Target, Req> = Svc<Target> where Self::Res: Svc<Req>;
| ^^^^^^^^^ associated type `Res` not found

error: aborting due to previous error

For more information about this error, try `rustc --explain E0220`.
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-59029-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-pass
#![feature(trait_alias)]

trait Svc<Req> { type Res; }

trait MkSvc<Target, Req> = Svc<Target> where <Self as Svc<Target>>::Res: Svc<Req>;

fn main() {}

0 comments on commit df05fbf

Please sign in to comment.