From: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:47:01 +0000 (+0000) Subject: Merge #6921 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=eefbae7ed4fca97281bbcd8e5738311be3a31dc6;hp=-c;p=rust.git Merge #6921 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 --- eefbae7ed4fca97281bbcd8e5738311be3a31dc6 diff --combined crates/hir/src/code_model.rs index d6c7e71ea5a,afe229c32fc..73ca6ba9f48 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@@ -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 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)), @@@ -221,7 -221,7 +221,7 @@@ 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))); @@@ -241,7 -241,7 +241,7 @@@ 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 { - db.enum_data(self.id) - .variants - .iter() - .map(|(id, _)| EnumVariant { parent: self, id }) - .collect() + pub fn variants(self, db: &dyn HirDatabase) -> Vec { + db.enum_data(self.id).variants.iter().map(|(id, _)| Variant { parent: self, id }).collect() } pub fn ty(self, db: &dyn HirDatabase) -> Type { @@@ -576,12 -580,12 +576,12 @@@ } #[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 { 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), } } @@@ -675,7 -679,7 +675,7 @@@ 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), } } @@@ -683,7 -687,7 +683,7 @@@ 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), } } @@@ -691,7 -695,7 +691,7 @@@ 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 { + // 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 { 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()); @@@ -1325,7 -1324,6 +1324,7 @@@ 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, } diff --combined crates/ide/src/goto_definition.rs index 7a12e99652f,d75ae447bb0..431da5d9c75 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@@ -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 {} + fn foo() where for<'a> T: Foo<&'a<|> (u8, u16)>, {} + //^^ + "#, + ); + check( + r#"trait Foo {} + fn foo() 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 {} + fn foo() where T: for<'a> Foo<&'a<|> (u8, u16)>, {} + //^^ + "#, + ); + } }