Skip to content

Commit ecdc6cd

Browse files
Merge #1514
1514: Better completions for floating point primitive types r=flodiebold a=marcogroppo After #1499 completions for (some of) the inherent methods of `f32` and `f64` are now working. Unfortunately during method resolution we were only looking for the `f32` and `f64` language items defined in `libcore` and we were ignoring the methods defined in `libstd`. This PR fixes this issue. Co-authored-by: Marco Groppo <marco.groppo@gmail.com>
2 parents 3210002 + 95d78a8 commit ecdc6cd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

crates/ra_hir/src/ty/method_resolution.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
nameres::CrateModuleId,
1515
resolve::Resolver,
1616
traits::TraitItem,
17-
ty::primitive::{UncertainFloatTy, UncertainIntTy},
17+
ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy},
1818
ty::{Ty, TypeCtor},
1919
Crate, Function, HirDatabase, Module, Name, Trait,
2020
};
@@ -132,9 +132,11 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV
132132
TypeCtor::Adt(def_id) => Some(std::iter::once(def_id.krate(db)?).collect()),
133133
TypeCtor::Bool => lang_item_crate!(db, cur_crate, "bool"),
134134
TypeCtor::Char => lang_item_crate!(db, cur_crate, "char"),
135-
TypeCtor::Float(UncertainFloatTy::Known(f)) => {
136-
lang_item_crate!(db, cur_crate, f.ty_to_string())
137-
}
135+
TypeCtor::Float(UncertainFloatTy::Known(f)) => match f.bitness {
136+
// There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime)
137+
FloatBitness::X32 => lang_item_crate!(db, cur_crate, "f32", "f32_runtime"),
138+
FloatBitness::X64 => lang_item_crate!(db, cur_crate, "f64", "f64_runtime"),
139+
},
138140
TypeCtor::Int(UncertainIntTy::Known(i)) => {
139141
lang_item_crate!(db, cur_crate, i.ty_to_string())
140142
}

0 commit comments

Comments
 (0)