mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 10:50:15 +00:00
Merge pull request #20110 from ChayimFriedman2/ambiguous-float
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
fix: Fix completion in when typing `integer.|`
This commit is contained in:
commit
5b852da4c3
3 changed files with 50 additions and 1 deletions
|
@ -3046,10 +3046,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