mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 18:43:01 +00:00
Fix completion in when typing integer.|
It should show integer, not floating point methods.
This commit is contained in:
parent
11c7207aa5
commit
0b6df1716d
3 changed files with 50 additions and 1 deletions
|
|
@ -3043,10 +3043,17 @@ pub struct BuiltinType {
|
|||
}
|
||||
|
||||
impl BuiltinType {
|
||||
// Constructors are added on demand, feel free to add more.
|
||||
pub fn str() -> BuiltinType {
|
||||
BuiltinType { inner: hir_def::builtin_type::BuiltinType::Str }
|
||||
}
|
||||
|
||||
pub fn i32() -> BuiltinType {
|
||||
BuiltinType {
|
||||
inner: hir_def::builtin_type::BuiltinType::Int(hir_ty::primitive::BuiltinInt::I32),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> {
|
||||
let core = Crate::core(db).map(|core| core.id).unwrap_or_else(|| db.all_crates()[0]);
|
||||
Type::new_for_crate(core, TyBuilder::builtin(self.inner))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::iter;
|
|||
use hir::{ExpandResult, InFile, Semantics, Type, TypeInfo, Variant};
|
||||
use ide_db::{RootDatabase, active_parameter::ActiveParameter};
|
||||
use itertools::Either;
|
||||
use stdx::always;
|
||||
use syntax::{
|
||||
AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken,
|
||||
T, TextRange, TextSize,
|
||||
|
|
@ -869,8 +870,15 @@ fn classify_name_ref<'db>(
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut receiver_ty = receiver.as_ref().and_then(|it| sema.type_of_expr(it));
|
||||
if receiver_is_ambiguous_float_literal {
|
||||
// `123.|` is parsed as a float but should actually be an integer.
|
||||
always!(receiver_ty.as_ref().is_none_or(|receiver_ty| receiver_ty.original.is_float()));
|
||||
receiver_ty = Some(TypeInfo { original: hir::BuiltinType::i32().ty(sema.db), adjusted: None });
|
||||
}
|
||||
|
||||
let kind = NameRefKind::DotAccess(DotAccess {
|
||||
receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
|
||||
receiver_ty,
|
||||
kind: DotAccessKind::Field { receiver_is_ambiguous_float_literal },
|
||||
receiver,
|
||||
ctx: DotAccessExprCtx { in_block_expr: is_in_block(field.syntax()), in_breakable: is_in_breakable(field.syntax()) }
|
||||
|
|
|
|||
|
|
@ -2241,3 +2241,37 @@ fn main() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ambiguous_float_literal() {
|
||||
check(
|
||||
r#"
|
||||
#![rustc_coherence_is_core]
|
||||
|
||||
impl i32 {
|
||||
pub fn int_method(self) {}
|
||||
}
|
||||
impl f64 {
|
||||
pub fn float_method(self) {}
|
||||
}
|
||||
|
||||
fn foo() {
|
||||
1.$0
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
me int_method() fn(self)
|
||||
sn box Box::new(expr)
|
||||
sn call function(expr)
|
||||
sn const const {}
|
||||
sn dbg dbg!(expr)
|
||||
sn dbgr dbg!(&expr)
|
||||
sn deref *expr
|
||||
sn match match expr {}
|
||||
sn ref &expr
|
||||
sn refm &mut expr
|
||||
sn return return expr
|
||||
sn unsafe unsafe {}
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue