]> git.lizzy.rs Git - rust.git/commitdiff
Merge #6921
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Sun, 20 Dec 2020 11:47:01 +0000 (11:47 +0000)
committerGitHub <noreply@github.com>
Sun, 20 Dec 2020 11:47:01 +0000 (11:47 +0000)
6921: Higher-ranked trait bounds for where clauses r=flodiebold a=Veykril

There is a slight problem with this which is also noted in a FIXME now but `LifetimeParameters` of these ForLifetime where clauses allocate the lifetimes in the corresponding arena as if they were lifetimes of the item itself and not just the clause they belong to. I wasn't entirely sure what I could do about this but given nothing really uses lifetimes like that currently I figured it might be fine? Open to suggestions for that problem.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
1  2 
crates/hir/src/code_model.rs
crates/ide/src/goto_definition.rs

index d6c7e71ea5a50e8251de19355c117015493dc4ad,afe229c32fc8e7121c45732933ff4d0908ad7ad9..73ca6ba9f481e5555ea6b6534f7e72839a1a3ae6
@@@ -161,7 -161,7 +161,7 @@@ pub enum ModuleDef 
      Function(Function),
      Adt(Adt),
      // Can't be directly declared, but can be imported.
 -    EnumVariant(EnumVariant),
 +    Variant(Variant),
      Const(Const),
      Static(Static),
      Trait(Trait),
@@@ -172,7 -172,7 +172,7 @@@ impl_from!
      Module,
      Function,
      Adt(Struct, Enum, Union),
 -    EnumVariant,
 +    Variant,
      Const,
      Static,
      Trait,
@@@ -186,7 -186,7 +186,7 @@@ impl From<VariantDef> for ModuleDef 
          match var {
              VariantDef::Struct(t) => Adt::from(t).into(),
              VariantDef::Union(t) => Adt::from(t).into(),
 -            VariantDef::EnumVariant(t) => t.into(),
 +            VariantDef::Variant(t) => t.into(),
          }
      }
  }
@@@ -197,7 -197,7 +197,7 @@@ impl ModuleDef 
              ModuleDef::Module(it) => it.parent(db),
              ModuleDef::Function(it) => Some(it.module(db)),
              ModuleDef::Adt(it) => Some(it.module(db)),
 -            ModuleDef::EnumVariant(it) => Some(it.module(db)),
 +            ModuleDef::Variant(it) => Some(it.module(db)),
              ModuleDef::Const(it) => Some(it.module(db)),
              ModuleDef::Static(it) => Some(it.module(db)),
              ModuleDef::Trait(it) => Some(it.module(db)),
              ModuleDef::Module(it) => it.parent(db)?,
              ModuleDef::Function(it) => return Some(it.visibility(db)),
              ModuleDef::Adt(it) => it.module(db),
 -            ModuleDef::EnumVariant(it) => {
 +            ModuleDef::Variant(it) => {
                  let parent = it.parent_enum(db);
                  let module = it.module(db);
                  return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)));
              ModuleDef::Adt(it) => Some(it.name(db)),
              ModuleDef::Trait(it) => Some(it.name(db)),
              ModuleDef::Function(it) => Some(it.name(db)),
 -            ModuleDef::EnumVariant(it) => Some(it.name(db)),
 +            ModuleDef::Variant(it) => Some(it.name(db)),
              ModuleDef::TypeAlias(it) => Some(it.name(db)),
              ModuleDef::Module(it) => it.name(db),
              ModuleDef::Const(it) => it.name(db),
@@@ -455,7 -455,7 +455,7 @@@ impl Field 
          let generic_def_id: GenericDefId = match self.parent {
              VariantDef::Struct(it) => it.id.into(),
              VariantDef::Union(it) => it.id.into(),
 -            VariantDef::EnumVariant(it) => it.parent.id.into(),
 +            VariantDef::Variant(it) => it.parent.id.into(),
          };
          let substs = Substs::type_params(db, generic_def_id);
          let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
@@@ -566,8 -566,12 +566,8 @@@ impl Enum 
          db.enum_data(self.id).name.clone()
      }
  
 -    pub fn variants(self, db: &dyn HirDatabase) -> Vec<EnumVariant> {
 -        db.enum_data(self.id)
 -            .variants
 -            .iter()
 -            .map(|(id, _)| EnumVariant { parent: self, id })
 -            .collect()
 +    pub fn variants(self, db: &dyn HirDatabase) -> Vec<Variant> {
 +        db.enum_data(self.id).variants.iter().map(|(id, _)| Variant { parent: self, id }).collect()
      }
  
      pub fn ty(self, db: &dyn HirDatabase) -> Type {
  }
  
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
 -pub struct EnumVariant {
 +pub struct Variant {
      pub(crate) parent: Enum,
      pub(crate) id: LocalEnumVariantId,
  }
  
 -impl EnumVariant {
 +impl Variant {
      pub fn module(self, db: &dyn HirDatabase) -> Module {
          self.parent.module(db)
      }
@@@ -658,16 -662,16 +658,16 @@@ impl Adt 
  pub enum VariantDef {
      Struct(Struct),
      Union(Union),
 -    EnumVariant(EnumVariant),
 +    Variant(Variant),
  }
 -impl_from!(Struct, Union, EnumVariant for VariantDef);
 +impl_from!(Struct, Union, Variant for VariantDef);
  
  impl VariantDef {
      pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
          match self {
              VariantDef::Struct(it) => it.fields(db),
              VariantDef::Union(it) => it.fields(db),
 -            VariantDef::EnumVariant(it) => it.fields(db),
 +            VariantDef::Variant(it) => it.fields(db),
          }
      }
  
          match self {
              VariantDef::Struct(it) => it.module(db),
              VariantDef::Union(it) => it.module(db),
 -            VariantDef::EnumVariant(it) => it.module(db),
 +            VariantDef::Variant(it) => it.module(db),
          }
      }
  
          match self {
              VariantDef::Struct(s) => s.name(db),
              VariantDef::Union(u) => u.name(db),
 -            VariantDef::EnumVariant(e) => e.name(db),
 +            VariantDef::Variant(e) => e.name(db),
          }
      }
  
          match self {
              VariantDef::Struct(it) => it.variant_data(db),
              VariantDef::Union(it) => it.variant_data(db),
 -            VariantDef::EnumVariant(it) => it.variant_data(db),
 +            VariantDef::Variant(it) => it.variant_data(db),
          }
      }
  }
@@@ -979,12 -983,6 +979,12 @@@ impl MacroDef 
  
      /// XXX: this parses the file
      pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
 +        // FIXME: Currently proc-macro do not have ast-node,
 +        // such that it does not have source
 +        // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
 +        if self.is_proc_macro() {
 +            return None;
 +        }
          self.source(db).value.name().map(|it| it.as_name())
      }
  
@@@ -1091,7 -1089,7 +1091,7 @@@ pub enum GenericDef 
      Impl(Impl),
      // enum variants cannot have generics themselves, but their parent enums
      // can, and this makes some code easier to write
 -    EnumVariant(EnumVariant),
 +    Variant(Variant),
      // consts can have type parameters from their parents (i.e. associated consts of traits)
      Const(Const),
  }
@@@ -1101,7 -1099,7 +1101,7 @@@ impl_from!
      Trait,
      TypeAlias,
      Impl,
 -    EnumVariant,
 +    Variant,
      Const
      for GenericDef
  );
@@@ -1268,7 -1266,6 +1268,6 @@@ impl LifetimeParam 
      }
  }
  
- // FIXME: rename from `ImplDef` to `Impl`
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
  pub struct Impl {
      pub(crate) id: ImplId,
@@@ -1286,12 -1283,14 +1285,12 @@@ impl Impl 
          impls.for_trait(trait_.id).map(Self::from).collect()
      }
  
 +    // FIXME: the return type is wrong. This should be a hir version of
 +    // `TraitRef` (ie, resolved `TypeRef`).
      pub fn target_trait(self, db: &dyn HirDatabase) -> Option<TypeRef> {
          db.impl_data(self.id).target_trait.clone()
      }
  
 -    pub fn target_type(self, db: &dyn HirDatabase) -> TypeRef {
 -        db.impl_data(self.id).target_type.clone()
 -    }
 -
      pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
          let impl_data = db.impl_data(self.id);
          let resolver = self.id.resolver(db.upcast());
          let item = src.file_id.is_builtin_derive(db.upcast())?;
          let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);
  
 +        // FIXME: handle `cfg_attr`
          let attr = item
              .value
              .attrs()
@@@ -1843,7 -1841,7 +1842,7 @@@ pub struct Callable 
  pub enum CallableKind {
      Function(Function),
      TupleStruct(Struct),
 -    TupleEnumVariant(EnumVariant),
 +    TupleEnumVariant(Variant),
      Closure,
  }
  
index 7a12e99652f6a0f4d4eaf572f5dae027701b259f,d75ae447bb0c0bf841ba327156ed504154961b31..431da5d9c75197126314fcd48d2f38fa956a9974
@@@ -9,7 -9,7 +9,7 @@@ use syntax::{ast, match_ast, AstNode, S
  
  use crate::{
      display::{ToNav, TryToNav},
 -    FilePosition, NavigationTarget, RangeInfo,
 +    FilePosition, NavigationTarget, RangeInfo, SymbolKind,
  };
  
  // Feature: Go to Definition
@@@ -86,7 -86,7 +86,7 @@@ fn self_to_nav_target(self_param: ast::
          full_range: self_param.syntax().text_range(),
          focus_range: Some(self_token.text_range()),
          name: self_token.text().clone(),
 -        kind: self_token.kind(),
 +        kind: Some(SymbolKind::SelfParam),
          container_name: None,
          description: None,
          docs: None,
@@@ -1077,4 -1077,32 +1077,32 @@@ fn foo<'foobar>(_: &'foobar ()) 
  }"#,
          )
      }
+     #[test]
+     #[ignore] // requires the HIR to somehow track these hrtb lifetimes
+     fn goto_lifetime_hrtb() {
+         check(
+             r#"trait Foo<T> {}
+ fn foo<T>() where for<'a> T: Foo<&'a<|> (u8, u16)>, {}
+                     //^^
+ "#,
+         );
+         check(
+             r#"trait Foo<T> {}
+ fn foo<T>() where for<'a<|>> T: Foo<&'a (u8, u16)>, {}
+                     //^^
+ "#,
+         );
+     }
+     #[test]
+     #[ignore] // requires ForTypes to be implemented
+     fn goto_lifetime_hrtb_for_type() {
+         check(
+             r#"trait Foo<T> {}
+ fn foo<T>() where T: for<'a> Foo<&'a<|> (u8, u16)>, {}
+                        //^^
+ "#,
+         );
+     }
  }