mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer
This commit is contained in:
commit
514df15d9e
15 changed files with 181 additions and 86 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -45,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.41"
|
version = "0.3.42"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
"backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -463,10 +463,10 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.3.0"
|
version = "1.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -730,7 +730,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.11.1"
|
version = "1.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1038,7 +1038,7 @@ dependencies = [
|
||||||
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1114,7 +1114,7 @@ dependencies = [
|
||||||
name = "ra_prof"
|
name = "ra_prof"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
"backtrace 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jemalloc-ctl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jemalloc-ctl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1353,7 +1353,7 @@ dependencies = [
|
||||||
"crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1449,7 +1449,7 @@ version = "0.14.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1631,7 +1631,7 @@ name = "threadpool"
|
||||||
version = "1.7.1"
|
version = "1.7.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1781,7 +1781,7 @@ dependencies = [
|
||||||
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||||
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||||
"checksum backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)" = "a4ed64ae6d9ebfd9893193c4b2532b1292ec97bd8271c9d7d0fa90cd78a34cba"
|
"checksum backtrace 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b4b1549d804b6c73f4817df2ba073709e96e426f12987127c48e6745568c350b"
|
||||||
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
|
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
|
||||||
"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
|
"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
|
||||||
"checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
|
"checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
|
||||||
|
@ -1832,7 +1832,7 @@ dependencies = [
|
||||||
"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772"
|
"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772"
|
||||||
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
||||||
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
|
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
|
||||||
"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
|
"checksum indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b54058f0a6ff80b6803da8faf8997cde53872b38f4023728f6830b06cd3c0dc"
|
||||||
"checksum inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8"
|
"checksum inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8"
|
||||||
"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
|
"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
|
||||||
"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349"
|
"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349"
|
||||||
|
@ -1863,7 +1863,7 @@ dependencies = [
|
||||||
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
||||||
"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
|
"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
|
||||||
"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
|
"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
|
||||||
"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
|
"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6"
|
||||||
"checksum once_cell 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5941ec2d5ee5916c709580d71553b81a633df245bcc73c04dcbd62152ceefc4"
|
"checksum once_cell 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5941ec2d5ee5916c709580d71553b81a633df245bcc73c04dcbd62152ceefc4"
|
||||||
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||||
"checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc"
|
"checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc"
|
||||||
|
|
|
@ -386,11 +386,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
|
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
|
||||||
// FIXME: find implementation of trait corresponding to operation
|
// FIXME: find implementation of trait corresponding to operation
|
||||||
// symbol and resolve associated `Output` type
|
// symbol and resolve associated `Output` type
|
||||||
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty);
|
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
|
||||||
let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
|
let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
|
||||||
|
|
||||||
// FIXME: similar as above, return ty is often associated trait type
|
// FIXME: similar as above, return ty is often associated trait type
|
||||||
op::binary_op_return_ty(*op, rhs_ty)
|
op::binary_op_return_ty(*op, lhs_ty, rhs_ty)
|
||||||
}
|
}
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
//! FIXME: write short doc here
|
//! Helper functions for binary operator type inference.
|
||||||
use hir_def::expr::{BinaryOp, CmpOp};
|
use hir_def::expr::{ArithOp, BinaryOp, CmpOp};
|
||||||
|
|
||||||
use super::{InferTy, Ty, TypeCtor};
|
use super::{InferTy, Ty, TypeCtor};
|
||||||
use crate::ApplicationTy;
|
use crate::ApplicationTy;
|
||||||
|
|
||||||
pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
|
pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
|
||||||
match op {
|
match op {
|
||||||
BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool),
|
BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool),
|
||||||
BinaryOp::Assignment { .. } => Ty::unit(),
|
BinaryOp::Assignment { .. } => Ty::unit(),
|
||||||
|
BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => match lhs_ty {
|
||||||
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||||
|
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
|
||||||
|
_ => Ty::Unknown,
|
||||||
|
},
|
||||||
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
||||||
|
_ => Ty::Unknown,
|
||||||
|
},
|
||||||
BinaryOp::ArithOp(_) => match rhs_ty {
|
BinaryOp::ArithOp(_) => match rhs_ty {
|
||||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||||
TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
|
TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
|
||||||
|
@ -36,6 +44,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown,
|
||||||
BinaryOp::CmpOp(CmpOp::Ord { .. })
|
BinaryOp::CmpOp(CmpOp::Ord { .. })
|
||||||
| BinaryOp::Assignment { op: Some(_) }
|
| BinaryOp::Assignment { op: Some(_) }
|
||||||
| BinaryOp::ArithOp(_) => match lhs_ty {
|
| BinaryOp::ArithOp(_) => match lhs_ty {
|
||||||
|
|
|
@ -613,6 +613,27 @@ fn test() -> bool {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn infer_shift_op() {
|
||||||
|
assert_snapshot!(
|
||||||
|
infer(r#"
|
||||||
|
fn test() {
|
||||||
|
1u32 << 5u8;
|
||||||
|
1u32 >> 5u8;
|
||||||
|
}
|
||||||
|
"#),
|
||||||
|
@r###"
|
||||||
|
[11; 48) '{ ...5u8; }': ()
|
||||||
|
[17; 21) '1u32': u32
|
||||||
|
[17; 28) '1u32 << 5u8': u32
|
||||||
|
[25; 28) '5u8': u8
|
||||||
|
[34; 38) '1u32': u32
|
||||||
|
[34; 45) '1u32 >> 5u8': u32
|
||||||
|
[42; 45) '5u8': u8
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn infer_field_autoderef() {
|
fn infer_field_autoderef() {
|
||||||
assert_snapshot!(
|
assert_snapshot!(
|
||||||
|
|
|
@ -169,9 +169,22 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||||
res.push(self_param.syntax().text().to_string())
|
res.push(self_param.syntax().text().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
res.extend(param_list.params().map(|param| {
|
res.extend(
|
||||||
param.pat().map(|pat| pat.syntax().text().to_string()).unwrap_or_default()
|
param_list
|
||||||
}));
|
.params()
|
||||||
|
.map(|param| {
|
||||||
|
Some(
|
||||||
|
param
|
||||||
|
.pat()?
|
||||||
|
.syntax()
|
||||||
|
.descendants()
|
||||||
|
.find_map(ast::Name::cast)?
|
||||||
|
.text()
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|param| param.unwrap_or_default()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn get_param_name_hints(
|
||||||
let hints = parameters
|
let hints = parameters
|
||||||
.zip(args)
|
.zip(args)
|
||||||
.filter_map(|(param, arg)| {
|
.filter_map(|(param, arg)| {
|
||||||
if arg.syntax().kind() == SyntaxKind::LITERAL {
|
if arg.syntax().kind() == SyntaxKind::LITERAL && !param.is_empty() {
|
||||||
Some((arg.syntax().text_range(), param))
|
Some((arg.syntax().text_range(), param))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -683,12 +683,12 @@ fn main() {
|
||||||
struct Test {}
|
struct Test {}
|
||||||
|
|
||||||
impl Test {
|
impl Test {
|
||||||
fn method(&self, param: i32) -> i32 {
|
fn method(&self, mut param: i32) -> i32 {
|
||||||
param * 2
|
param * 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_func(foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
|
fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
|
||||||
foo + bar
|
foo + bar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,37 +704,32 @@ fn main() {
|
||||||
assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
|
assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
|
||||||
[
|
[
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [207; 218),
|
range: [215; 226),
|
||||||
kind: TypeHint,
|
kind: TypeHint,
|
||||||
label: "i32",
|
label: "i32",
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [251; 252),
|
range: [259; 260),
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: "foo",
|
label: "foo",
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [254; 255),
|
range: [262; 263),
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: "bar",
|
label: "bar",
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [257; 264),
|
range: [265; 272),
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: "msg",
|
label: "msg",
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [266; 267),
|
range: [331; 334),
|
||||||
kind: ParameterHint,
|
|
||||||
label: "_",
|
|
||||||
},
|
|
||||||
InlayHint {
|
|
||||||
range: [323; 326),
|
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: "param",
|
label: "param",
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: [350; 354),
|
range: [358; 362),
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: "param",
|
label: "param",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! This is the actual "grammar" of the Rust language.
|
//! This is the actual "grammar" of the Rust language.
|
||||||
//!
|
//!
|
||||||
//! Each function in this module and its children corresponds
|
//! Each function in this module and its children corresponds
|
||||||
//! to a production of the format grammar. Submodules roughly
|
//! to a production of the formal grammar. Submodules roughly
|
||||||
//! correspond to different *areas* of the grammar. By convention,
|
//! correspond to different *areas* of the grammar. By convention,
|
||||||
//! each submodule starts with `use super::*` import and exports
|
//! each submodule starts with `use super::*` import and exports
|
||||||
//! "public" productions via `pub(super)`.
|
//! "public" productions via `pub(super)`.
|
||||||
|
|
|
@ -19,6 +19,26 @@ pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
||||||
expr_bp(p, r, 1)
|
expr_bp(p, r, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn expr_with_attrs(p: &mut Parser) -> bool {
|
||||||
|
let m = p.start();
|
||||||
|
let has_attrs = p.at(T![#]);
|
||||||
|
attributes::outer_attributes(p);
|
||||||
|
|
||||||
|
let (cm, _block_like) = expr(p);
|
||||||
|
let success = cm.is_some();
|
||||||
|
|
||||||
|
match (has_attrs, cm) {
|
||||||
|
(true, Some(cm)) => {
|
||||||
|
let kind = cm.kind();
|
||||||
|
cm.undo_completion(p).abandon(p);
|
||||||
|
m.complete(p, kind);
|
||||||
|
}
|
||||||
|
_ => m.abandon(p),
|
||||||
|
}
|
||||||
|
|
||||||
|
success
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
||||||
let r = Restrictions { forbid_structs: false, prefer_stmt: true };
|
let r = Restrictions { forbid_structs: false, prefer_stmt: true };
|
||||||
expr_bp(p, r, 1)
|
expr_bp(p, r, 1)
|
||||||
|
@ -540,11 +560,13 @@ fn arg_list(p: &mut Parser) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
p.bump(T!['(']);
|
p.bump(T!['(']);
|
||||||
while !p.at(T![')']) && !p.at(EOF) {
|
while !p.at(T![')']) && !p.at(EOF) {
|
||||||
if !p.at_ts(EXPR_FIRST) {
|
// test arg_with_attr
|
||||||
p.error("expected expression");
|
// fn main() {
|
||||||
|
// foo(#[attr] 92)
|
||||||
|
// }
|
||||||
|
if !expr_with_attrs(p) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
expr(p);
|
|
||||||
if !p.at(T![')']) && !p.expect(T![,]) {
|
if !p.at(T![')']) && !p.expect(T![,]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,19 +191,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
|
||||||
|
|
||||||
// test array_attrs
|
// test array_attrs
|
||||||
// const A: &[i64] = &[1, #[cfg(test)] 2];
|
// const A: &[i64] = &[1, #[cfg(test)] 2];
|
||||||
let m = p.start();
|
if !expr_with_attrs(p) {
|
||||||
let has_attrs = p.at(T![#]);
|
break;
|
||||||
attributes::outer_attributes(p);
|
|
||||||
|
|
||||||
let cm = expr(p).0;
|
|
||||||
|
|
||||||
match (has_attrs, cm) {
|
|
||||||
(true, Some(cm)) => {
|
|
||||||
let kind = cm.kind();
|
|
||||||
cm.undo_completion(p).abandon(p);
|
|
||||||
m.complete(p, kind);
|
|
||||||
}
|
|
||||||
_ => m.abandon(p),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if n_exprs == 1 && p.eat(T![;]) {
|
if n_exprs == 1 && p.eat(T![;]) {
|
||||||
|
|
|
@ -12,8 +12,8 @@ SOURCE_FILE@[0; 112)
|
||||||
BLOCK@[7; 33)
|
BLOCK@[7; 33)
|
||||||
L_CURLY@[7; 8) "{"
|
L_CURLY@[7; 8) "{"
|
||||||
WHITESPACE@[8; 9) " "
|
WHITESPACE@[8; 9) " "
|
||||||
EXPR_STMT@[9; 26)
|
EXPR_STMT@[9; 17)
|
||||||
ARRAY_EXPR@[9; 26)
|
ARRAY_EXPR@[9; 17)
|
||||||
L_BRACK@[9; 10) "["
|
L_BRACK@[9; 10) "["
|
||||||
LITERAL@[10; 11)
|
LITERAL@[10; 11)
|
||||||
INT_NUMBER@[10; 11) "1"
|
INT_NUMBER@[10; 11) "1"
|
||||||
|
@ -25,10 +25,13 @@ SOURCE_FILE@[0; 112)
|
||||||
WHITESPACE@[15; 16) " "
|
WHITESPACE@[15; 16) " "
|
||||||
ERROR@[16; 17)
|
ERROR@[16; 17)
|
||||||
AT@[16; 17) "@"
|
AT@[16; 17) "@"
|
||||||
|
EXPR_STMT@[17; 18)
|
||||||
|
ERROR@[17; 18)
|
||||||
COMMA@[17; 18) ","
|
COMMA@[17; 18) ","
|
||||||
WHITESPACE@[18; 19) " "
|
WHITESPACE@[18; 19) " "
|
||||||
ERROR@[19; 25)
|
STRUCT_DEF@[19; 26)
|
||||||
STRUCT_KW@[19; 25) "struct"
|
STRUCT_KW@[19; 25) "struct"
|
||||||
|
ERROR@[25; 26)
|
||||||
COMMA@[25; 26) ","
|
COMMA@[25; 26) ","
|
||||||
WHITESPACE@[26; 27) " "
|
WHITESPACE@[26; 27) " "
|
||||||
LET_STMT@[27; 31)
|
LET_STMT@[27; 31)
|
||||||
|
@ -51,14 +54,14 @@ SOURCE_FILE@[0; 112)
|
||||||
BLOCK@[41; 68)
|
BLOCK@[41; 68)
|
||||||
L_CURLY@[41; 42) "{"
|
L_CURLY@[41; 42) "{"
|
||||||
WHITESPACE@[42; 43) " "
|
WHITESPACE@[42; 43) " "
|
||||||
EXPR_STMT@[43; 52)
|
EXPR_STMT@[43; 54)
|
||||||
CALL_EXPR@[43; 52)
|
CALL_EXPR@[43; 54)
|
||||||
PATH_EXPR@[43; 46)
|
PATH_EXPR@[43; 46)
|
||||||
PATH@[43; 46)
|
PATH@[43; 46)
|
||||||
PATH_SEGMENT@[43; 46)
|
PATH_SEGMENT@[43; 46)
|
||||||
NAME_REF@[43; 46)
|
NAME_REF@[43; 46)
|
||||||
IDENT@[43; 46) "foo"
|
IDENT@[43; 46) "foo"
|
||||||
ARG_LIST@[46; 52)
|
ARG_LIST@[46; 54)
|
||||||
L_PAREN@[46; 47) "("
|
L_PAREN@[46; 47) "("
|
||||||
LITERAL@[47; 48)
|
LITERAL@[47; 48)
|
||||||
INT_NUMBER@[47; 48) "1"
|
INT_NUMBER@[47; 48) "1"
|
||||||
|
@ -68,7 +71,6 @@ SOURCE_FILE@[0; 112)
|
||||||
INT_NUMBER@[50; 51) "2"
|
INT_NUMBER@[50; 51) "2"
|
||||||
COMMA@[51; 52) ","
|
COMMA@[51; 52) ","
|
||||||
WHITESPACE@[52; 53) " "
|
WHITESPACE@[52; 53) " "
|
||||||
EXPR_STMT@[53; 54)
|
|
||||||
ERROR@[53; 54)
|
ERROR@[53; 54)
|
||||||
AT@[53; 54) "@"
|
AT@[53; 54) "@"
|
||||||
EXPR_STMT@[54; 55)
|
EXPR_STMT@[54; 55)
|
||||||
|
@ -101,8 +103,8 @@ SOURCE_FILE@[0; 112)
|
||||||
BLOCK@[76; 111)
|
BLOCK@[76; 111)
|
||||||
L_CURLY@[76; 77) "{"
|
L_CURLY@[76; 77) "{"
|
||||||
WHITESPACE@[77; 78) " "
|
WHITESPACE@[77; 78) " "
|
||||||
EXPR_STMT@[78; 91)
|
EXPR_STMT@[78; 93)
|
||||||
METHOD_CALL_EXPR@[78; 91)
|
METHOD_CALL_EXPR@[78; 93)
|
||||||
PATH_EXPR@[78; 81)
|
PATH_EXPR@[78; 81)
|
||||||
PATH@[78; 81)
|
PATH@[78; 81)
|
||||||
PATH_SEGMENT@[78; 81)
|
PATH_SEGMENT@[78; 81)
|
||||||
|
@ -111,7 +113,7 @@ SOURCE_FILE@[0; 112)
|
||||||
DOT@[81; 82) "."
|
DOT@[81; 82) "."
|
||||||
NAME_REF@[82; 85)
|
NAME_REF@[82; 85)
|
||||||
IDENT@[82; 85) "bar"
|
IDENT@[82; 85) "bar"
|
||||||
ARG_LIST@[85; 91)
|
ARG_LIST@[85; 93)
|
||||||
L_PAREN@[85; 86) "("
|
L_PAREN@[85; 86) "("
|
||||||
LITERAL@[86; 87)
|
LITERAL@[86; 87)
|
||||||
INT_NUMBER@[86; 87) "1"
|
INT_NUMBER@[86; 87) "1"
|
||||||
|
@ -121,7 +123,6 @@ SOURCE_FILE@[0; 112)
|
||||||
INT_NUMBER@[89; 90) "2"
|
INT_NUMBER@[89; 90) "2"
|
||||||
COMMA@[90; 91) ","
|
COMMA@[90; 91) ","
|
||||||
WHITESPACE@[91; 92) " "
|
WHITESPACE@[91; 92) " "
|
||||||
EXPR_STMT@[92; 93)
|
|
||||||
ERROR@[92; 93)
|
ERROR@[92; 93)
|
||||||
AT@[92; 93) "@"
|
AT@[92; 93) "@"
|
||||||
EXPR_STMT@[93; 94)
|
EXPR_STMT@[93; 94)
|
||||||
|
@ -148,15 +149,14 @@ SOURCE_FILE@[0; 112)
|
||||||
R_CURLY@[110; 111) "}"
|
R_CURLY@[110; 111) "}"
|
||||||
WHITESPACE@[111; 112) "\n"
|
WHITESPACE@[111; 112) "\n"
|
||||||
error 16: expected expression
|
error 16: expected expression
|
||||||
error 19: expected expression
|
error 17: expected R_BRACK
|
||||||
error 26: expected expression
|
error 17: expected SEMI
|
||||||
error 26: expected COMMA
|
error 17: expected expression
|
||||||
error 26: expected R_BRACK
|
error 18: expected SEMI
|
||||||
error 26: expected SEMI
|
error 25: expected a name
|
||||||
|
error 26: expected `;`, `{`, or `(`
|
||||||
error 30: expected pattern
|
error 30: expected pattern
|
||||||
error 31: expected SEMI
|
error 31: expected SEMI
|
||||||
error 52: expected expression
|
|
||||||
error 52: expected SEMI
|
|
||||||
error 53: expected expression
|
error 53: expected expression
|
||||||
error 54: expected SEMI
|
error 54: expected SEMI
|
||||||
error 54: expected expression
|
error 54: expected expression
|
||||||
|
@ -168,8 +168,6 @@ error 61: expected SEMI
|
||||||
error 65: expected pattern
|
error 65: expected pattern
|
||||||
error 65: expected SEMI
|
error 65: expected SEMI
|
||||||
error 65: expected expression
|
error 65: expected expression
|
||||||
error 91: expected expression
|
|
||||||
error 91: expected SEMI
|
|
||||||
error 92: expected expression
|
error 92: expected expression
|
||||||
error 93: expected SEMI
|
error 93: expected SEMI
|
||||||
error 93: expected expression
|
error 93: expected expression
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
foo(#[attr] 92)
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
SOURCE_FILE@[0; 34)
|
||||||
|
FN_DEF@[0; 33)
|
||||||
|
FN_KW@[0; 2) "fn"
|
||||||
|
WHITESPACE@[2; 3) " "
|
||||||
|
NAME@[3; 7)
|
||||||
|
IDENT@[3; 7) "main"
|
||||||
|
PARAM_LIST@[7; 9)
|
||||||
|
L_PAREN@[7; 8) "("
|
||||||
|
R_PAREN@[8; 9) ")"
|
||||||
|
WHITESPACE@[9; 10) " "
|
||||||
|
BLOCK_EXPR@[10; 33)
|
||||||
|
BLOCK@[10; 33)
|
||||||
|
L_CURLY@[10; 11) "{"
|
||||||
|
WHITESPACE@[11; 16) "\n "
|
||||||
|
CALL_EXPR@[16; 31)
|
||||||
|
PATH_EXPR@[16; 19)
|
||||||
|
PATH@[16; 19)
|
||||||
|
PATH_SEGMENT@[16; 19)
|
||||||
|
NAME_REF@[16; 19)
|
||||||
|
IDENT@[16; 19) "foo"
|
||||||
|
ARG_LIST@[19; 31)
|
||||||
|
L_PAREN@[19; 20) "("
|
||||||
|
LITERAL@[20; 30)
|
||||||
|
ATTR@[20; 27)
|
||||||
|
POUND@[20; 21) "#"
|
||||||
|
L_BRACK@[21; 22) "["
|
||||||
|
PATH@[22; 26)
|
||||||
|
PATH_SEGMENT@[22; 26)
|
||||||
|
NAME_REF@[22; 26)
|
||||||
|
IDENT@[22; 26) "attr"
|
||||||
|
R_BRACK@[26; 27) "]"
|
||||||
|
WHITESPACE@[27; 28) " "
|
||||||
|
INT_NUMBER@[28; 30) "92"
|
||||||
|
R_PAREN@[30; 31) ")"
|
||||||
|
WHITESPACE@[31; 32) "\n"
|
||||||
|
R_CURLY@[32; 33) "}"
|
||||||
|
WHITESPACE@[33; 34) "\n"
|
|
@ -210,9 +210,9 @@
|
||||||
;; inlay hints
|
;; inlay hints
|
||||||
(defun rust-analyzer--update-inlay-hints (buffer)
|
(defun rust-analyzer--update-inlay-hints (buffer)
|
||||||
(if (and (rust-analyzer--initialized?) (eq buffer (current-buffer)))
|
(if (and (rust-analyzer--initialized?) (eq buffer (current-buffer)))
|
||||||
(lsp-send-request-async
|
(lsp-request-async
|
||||||
(lsp-make-request "rust-analyzer/inlayHints"
|
"rust-analyzer/inlayHints"
|
||||||
(list :textDocument (lsp--text-document-identifier)))
|
(list :textDocument (lsp--text-document-identifier))
|
||||||
(lambda (res)
|
(lambda (res)
|
||||||
(remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t)
|
(remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t)
|
||||||
(dolist (hint res)
|
(dolist (hint res)
|
||||||
|
@ -221,9 +221,16 @@
|
||||||
(overlay (make-overlay beg end)))
|
(overlay (make-overlay beg end)))
|
||||||
(overlay-put overlay 'rust-analyzer--inlay-hint t)
|
(overlay-put overlay 'rust-analyzer--inlay-hint t)
|
||||||
(overlay-put overlay 'evaporate t)
|
(overlay-put overlay 'evaporate t)
|
||||||
|
(cond
|
||||||
|
((string= kind "TypeHint")
|
||||||
(overlay-put overlay 'after-string (propertize (concat ": " label)
|
(overlay-put overlay 'after-string (propertize (concat ": " label)
|
||||||
'font-lock-face 'font-lock-comment-face)))))
|
'font-lock-face 'font-lock-comment-face)))
|
||||||
'tick))
|
((string= kind "ParameterHint")
|
||||||
|
(overlay-put overlay 'before-string (propertize (concat label ": ")
|
||||||
|
'font-lock-face 'font-lock-comment-face)))
|
||||||
|
)
|
||||||
|
)))
|
||||||
|
:mode 'tick))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defvar-local rust-analyzer--inlay-hints-timer nil)
|
(defvar-local rust-analyzer--inlay-hints-timer nil)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! This module generate AST datatype used by rust-analyzer.
|
//! This module generates AST datatype used by rust-analyzer.
|
||||||
//!
|
//!
|
||||||
//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
|
//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
|
||||||
//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`.
|
//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`.
|
||||||
|
|
|
@ -53,6 +53,7 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> {
|
||||||
write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
|
write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
|
||||||
let output = rustfmt.wait_with_output()?;
|
let output = rustfmt.wait_with_output()?;
|
||||||
let stdout = String::from_utf8(output.stdout)?;
|
let stdout = String::from_utf8(output.stdout)?;
|
||||||
|
// TODO: update the preable: replace ra_tools with the relevant path
|
||||||
let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
|
let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
|
||||||
Ok(format!("//! {}\n\n{}", preamble, stdout))
|
Ok(format!("//! {}\n\n{}", preamble, stdout))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue