mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
Merge #2420
2420: Remove last traces of adt from Ty r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
d770f22c53
@ -982,7 +982,7 @@ impl ImplBlock {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Type {
|
||||
pub(crate) krate: CrateId,
|
||||
pub(crate) ty: InEnvironment<Ty>,
|
||||
@ -1104,7 +1104,7 @@ impl Type {
|
||||
|
||||
pub fn as_adt(&self) -> Option<Adt> {
|
||||
let (adt, _subst) = self.ty.value.as_adt()?;
|
||||
Some(adt)
|
||||
Some(adt.into())
|
||||
}
|
||||
|
||||
fn derived(&self, ty: Ty) -> Type {
|
||||
|
@ -12,7 +12,7 @@ use crate::{
|
||||
db::HirDatabase,
|
||||
diagnostics::{MissingFields, MissingOkInTailExpr},
|
||||
ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
|
||||
Adt, Function, Name, Path,
|
||||
Function, Name, Path, Struct,
|
||||
};
|
||||
|
||||
pub use hir_def::{
|
||||
@ -69,7 +69,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||
}
|
||||
|
||||
let struct_def = match self.infer[id].as_adt() {
|
||||
Some((Adt::Struct(s), _)) => s,
|
||||
Some((AdtId::StructId(s), _)) => Struct::from(s),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
@ -22,13 +22,14 @@ use hir_def::{
|
||||
expr::ExprId, generics::GenericParams, type_ref::Mutability, AdtId, ContainerId, DefWithBodyId,
|
||||
GenericDefId, HasModule, Lookup, TraitId, TypeAliasId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
use ra_db::{impl_intern_key, salsa};
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
ty::primitive::{FloatTy, IntTy, Uncertain},
|
||||
util::make_mut_slice,
|
||||
Adt, Crate, Name,
|
||||
Crate,
|
||||
};
|
||||
use display::{HirDisplay, HirFormatter};
|
||||
|
||||
@ -598,10 +599,10 @@ impl Ty {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_adt(&self) -> Option<(Adt, &Substs)> {
|
||||
pub fn as_adt(&self) -> Option<(AdtId, &Substs)> {
|
||||
match self {
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => {
|
||||
Some(((*adt_def).into(), parameters))
|
||||
Some((*adt_def, parameters))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -71,10 +71,11 @@ pub(crate) fn reference_definition(
|
||||
Some(nav) => return Exact(nav),
|
||||
None => return Approximate(vec![]),
|
||||
},
|
||||
Some(SelfType(ty)) => {
|
||||
if let Some((adt, _)) = ty.as_adt() {
|
||||
return Exact(adt.to_nav(db));
|
||||
}
|
||||
Some(SelfType(imp)) => {
|
||||
// FIXME: ideally, this should point to the type in the impl, and
|
||||
// not at the whole impl. And goto **type** definition should bring
|
||||
// us to the actual type
|
||||
return Exact(imp.to_nav(db));
|
||||
}
|
||||
Some(Local(local)) => return Exact(local.to_nav(db)),
|
||||
Some(GenericParam(_)) => {
|
||||
@ -503,7 +504,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)",
|
||||
"impl IMPL_BLOCK FileId(1) [12; 73)",
|
||||
);
|
||||
|
||||
check_goto(
|
||||
@ -516,7 +517,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)",
|
||||
"impl IMPL_BLOCK FileId(1) [12; 73)",
|
||||
);
|
||||
|
||||
check_goto(
|
||||
@ -529,7 +530,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo ENUM_DEF FileId(1) [0; 14) [5; 8)",
|
||||
"impl IMPL_BLOCK FileId(1) [15; 75)",
|
||||
);
|
||||
|
||||
check_goto(
|
||||
@ -541,7 +542,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo ENUM_DEF FileId(1) [0; 14) [5; 8)",
|
||||
"impl IMPL_BLOCK FileId(1) [15; 62)",
|
||||
);
|
||||
}
|
||||
|
||||
@ -560,7 +561,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)",
|
||||
"impl IMPL_BLOCK FileId(1) [49; 115)",
|
||||
);
|
||||
|
||||
check_goto(
|
||||
@ -572,11 +573,11 @@ mod tests {
|
||||
}
|
||||
impl Make for Foo {
|
||||
fn new() -> Self<|> {
|
||||
Self{}
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
",
|
||||
"Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)",
|
||||
"impl IMPL_BLOCK FileId(1) [49; 115)",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -133,20 +133,12 @@ fn hover_text_from_name_kind(
|
||||
hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
|
||||
hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
|
||||
},
|
||||
SelfType(ty) => match ty.as_adt() {
|
||||
Some((adt_def, _)) => match adt_def {
|
||||
hir::Adt::Struct(it) => from_def_source(db, it),
|
||||
hir::Adt::Union(it) => from_def_source(db, it),
|
||||
hir::Adt::Enum(it) => from_def_source(db, it),
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
Local(_) => {
|
||||
// Hover for these shows type names
|
||||
*no_fallback = true;
|
||||
None
|
||||
}
|
||||
GenericParam(_) => {
|
||||
GenericParam(_) | SelfType(_) => {
|
||||
// FIXME: Hover for generic param
|
||||
None
|
||||
}
|
||||
@ -622,49 +614,52 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing"));
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
struct Thing { x: u32 }
|
||||
impl Thing {
|
||||
fn new() -> Self<|> {
|
||||
Self { x: 0 }
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
/* FIXME: revive these tests
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
struct Thing { x: u32 }
|
||||
impl Thing {
|
||||
fn new() -> Self<|> {
|
||||
Self { x: 0 }
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
enum Thing { A }
|
||||
impl Thing {
|
||||
pub fn new() -> Self<|> {
|
||||
Thing::A
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
enum Thing { A }
|
||||
impl Thing {
|
||||
pub fn thing(a: Self<|>) {
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
enum Thing { A }
|
||||
impl Thing {
|
||||
pub fn new() -> Self<|> {
|
||||
Thing::A
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
|
||||
let (analysis, position) = single_file_with_position(
|
||||
"
|
||||
enum Thing { A }
|
||||
impl Thing {
|
||||
pub fn thing(a: Self<|>) {
|
||||
}
|
||||
}
|
||||
",
|
||||
);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||
assert_eq!(hover.info.is_exact(), true);
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -83,10 +83,7 @@ pub(crate) fn find_all_refs(
|
||||
NameKind::Field(field) => field.to_nav(db),
|
||||
NameKind::AssocItem(assoc) => assoc.to_nav(db),
|
||||
NameKind::Def(def) => NavigationTarget::from_def(db, def)?,
|
||||
NameKind::SelfType(ref ty) => match ty.as_adt() {
|
||||
Some((adt, _)) => adt.to_nav(db),
|
||||
None => return None,
|
||||
},
|
||||
NameKind::SelfType(imp) => imp.to_nav(db),
|
||||
NameKind::Local(local) => local.to_nav(db),
|
||||
NameKind::GenericParam(_) => return None,
|
||||
};
|
||||
|
@ -178,8 +178,7 @@ pub(crate) fn classify_name_ref(
|
||||
Some(NameDefinition { kind, container, visibility })
|
||||
}
|
||||
PathResolution::SelfType(impl_block) => {
|
||||
let ty = impl_block.target_ty(db);
|
||||
let kind = NameKind::SelfType(ty);
|
||||
let kind = NameKind::SelfType(impl_block);
|
||||
let container = impl_block.module(db);
|
||||
Some(NameDefinition { kind, container, visibility })
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
//! Note that the reference search is possible for not all of the classified items.
|
||||
|
||||
use hir::{
|
||||
Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty,
|
||||
VariantDef,
|
||||
Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef,
|
||||
StructField, VariantDef,
|
||||
};
|
||||
use ra_syntax::{ast, ast::VisibilityOwner};
|
||||
|
||||
@ -17,7 +17,7 @@ pub enum NameKind {
|
||||
Field(StructField),
|
||||
AssocItem(AssocItem),
|
||||
Def(ModuleDef),
|
||||
SelfType(Ty),
|
||||
SelfType(ImplBlock),
|
||||
Local(Local),
|
||||
GenericParam(GenericParam),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user