Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: fix ICE when trait alias has bare Self #59118

Merged
merged 1 commit into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}