Rollup merge of #59118 - seanmonstar:alias-where-self-ice, r=alexreg

rustc: fix ICE when trait alias has bare Self

Fixes https://github.com/rust-lang/rust/issues/59029
This commit is contained in:
kennytm 2019-03-16 14:56:44 +08:00
commit 464478fbbb
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
4 changed files with 29 additions and 2 deletions

View File

@ -541,7 +541,8 @@ 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))
}
@ -549,7 +550,8 @@ impl<'hir> Map<'hir> {
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)),
}

View File

@ -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() {}

View File

@ -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`.

View File

@ -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() {}