mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
This commit is contained in:
commit
18a5e16483
322 changed files with 1823 additions and 160 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
@ -10,7 +10,7 @@ on:
|
||||||
env:
|
env:
|
||||||
CARGO_INCREMENTAL: 0
|
CARGO_INCREMENTAL: 0
|
||||||
CARGO_NET_RETRY: 10
|
CARGO_NET_RETRY: 10
|
||||||
RUN_SLOW_TESTS: 1
|
CI: 1
|
||||||
RUST_BACKTRACE: short
|
RUST_BACKTRACE: short
|
||||||
RUSTFLAGS: -D warnings
|
RUSTFLAGS: -D warnings
|
||||||
RUSTUP_MAX_RETRIES: 10
|
RUSTUP_MAX_RETRIES: 10
|
||||||
|
|
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
|
@ -60,6 +60,10 @@ jobs:
|
||||||
if: matrix.os != 'ubuntu-latest'
|
if: matrix.os != 'ubuntu-latest'
|
||||||
run: cargo xtask dist
|
run: cargo xtask dist
|
||||||
|
|
||||||
|
- name: Nightly analysis-stats check
|
||||||
|
if: matrix.os == 'ubuntu-latest' && github.ref != 'refs/heads/release'
|
||||||
|
run: ./dist/rust-analyzer-linux analysis-stats .
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -995,6 +995,7 @@ dependencies = [
|
||||||
"ra_prof",
|
"ra_prof",
|
||||||
"ra_syntax",
|
"ra_syntax",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
|
"smallvec",
|
||||||
"stdx",
|
"stdx",
|
||||||
"test_utils",
|
"test_utils",
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
//! certain context. For example, if the cursor is over `,`, a "swap `,`" assist
|
//! certain context. For example, if the cursor is over `,`, a "swap `,`" assist
|
||||||
//! becomes available.
|
//! becomes available.
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! eprintln {
|
||||||
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
||||||
|
}
|
||||||
|
|
||||||
mod assist_ctx;
|
mod assist_ctx;
|
||||||
mod marks;
|
mod marks;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
pub use hir_def::diagnostics::UnresolvedModule;
|
pub use hir_def::diagnostics::UnresolvedModule;
|
||||||
pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
||||||
pub use hir_ty::diagnostics::{MissingFields, MissingOkInTailExpr, NoSuchField};
|
pub use hir_ty::diagnostics::{MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField};
|
||||||
|
|
|
@ -9,6 +9,7 @@ use hir_def::{
|
||||||
AsMacroCall, TraitId,
|
AsMacroCall, TraitId,
|
||||||
};
|
};
|
||||||
use hir_expand::ExpansionInfo;
|
use hir_expand::ExpansionInfo;
|
||||||
|
use itertools::Itertools;
|
||||||
use ra_db::{FileId, FileRange};
|
use ra_db::{FileId, FileRange};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
|
@ -135,7 +136,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextUnit,
|
offset: TextUnit,
|
||||||
) -> impl Iterator<Item = SyntaxNode> + '_ {
|
) -> impl Iterator<Item = SyntaxNode> + '_ {
|
||||||
use itertools::Itertools;
|
|
||||||
node.token_at_offset(offset)
|
node.token_at_offset(offset)
|
||||||
.map(|token| self.ancestors_with_macros(token.parent()))
|
.map(|token| self.ancestors_with_macros(token.parent()))
|
||||||
.kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
|
.kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
|
||||||
|
|
|
@ -208,12 +208,12 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
|
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
|
||||||
let res: GenericDefId = match_ast! {
|
let res: GenericDefId = match_ast! {
|
||||||
match (container.value) {
|
match (container.value) {
|
||||||
ast::FnDef(it) => { self.fn_to_def(container.with_value(it))?.into() },
|
ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(),
|
||||||
ast::StructDef(it) => { self.struct_to_def(container.with_value(it))?.into() },
|
ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(),
|
||||||
ast::EnumDef(it) => { self.enum_to_def(container.with_value(it))?.into() },
|
ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(),
|
||||||
ast::TraitDef(it) => { self.trait_to_def(container.with_value(it))?.into() },
|
ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(),
|
||||||
ast::TypeAliasDef(it) => { self.type_alias_to_def(container.with_value(it))?.into() },
|
ast::TypeAliasDef(it) => self.type_alias_to_def(container.with_value(it))?.into(),
|
||||||
ast::ImplDef(it) => { self.impl_to_def(container.with_value(it))?.into() },
|
ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -226,9 +226,9 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
|
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
|
||||||
let res: DefWithBodyId = match_ast! {
|
let res: DefWithBodyId = match_ast! {
|
||||||
match (container.value) {
|
match (container.value) {
|
||||||
ast::ConstDef(it) => { self.const_to_def(container.with_value(it))?.into() },
|
ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(),
|
||||||
ast::StaticDef(it) => { self.static_to_def(container.with_value(it))?.into() },
|
ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(),
|
||||||
ast::FnDef(it) => { self.fn_to_def(container.with_value(it))?.into() },
|
ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
//! Note that `hir_def` is a work in progress, so not all of the above is
|
//! Note that `hir_def` is a work in progress, so not all of the above is
|
||||||
//! actually true.
|
//! actually true.
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! eprintln {
|
||||||
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
||||||
|
}
|
||||||
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
pub mod attr;
|
pub mod attr;
|
||||||
|
|
|
@ -73,9 +73,9 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, mbe::ExpandError> {
|
||||||
let node = item.syntax();
|
let node = item.syntax();
|
||||||
let (name, params) = match_ast! {
|
let (name, params) = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::StructDef(it) => { (it.name(), it.type_param_list()) },
|
ast::StructDef(it) => (it.name(), it.type_param_list()),
|
||||||
ast::EnumDef(it) => { (it.name(), it.type_param_list()) },
|
ast::EnumDef(it) => (it.name(), it.type_param_list()),
|
||||||
ast::UnionDef(it) => { (it.name(), it.type_param_list()) },
|
ast::UnionDef(it) => (it.name(), it.type_param_list()),
|
||||||
_ => {
|
_ => {
|
||||||
debug!("unexpected node is {:?}", node);
|
debug!("unexpected node is {:?}", node);
|
||||||
return Err(mbe::ExpandError::ConversionError)
|
return Err(mbe::ExpandError::ConversionError)
|
||||||
|
|
|
@ -9,6 +9,7 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.5.1"
|
arrayvec = "0.5.1"
|
||||||
|
smallvec = "1.2.0"
|
||||||
ena = "0.13.1"
|
ena = "0.13.1"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|
1411
crates/ra_hir_ty/src/_match.rs
Normal file
1411
crates/ra_hir_ty/src/_match.rs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
|
||||||
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
|
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
|
||||||
pub use hir_def::diagnostics::UnresolvedModule;
|
pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
|
||||||
pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -62,6 +62,25 @@ impl AstDiagnostic for MissingFields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct MissingMatchArms {
|
||||||
|
pub file: HirFileId,
|
||||||
|
pub match_expr: AstPtr<ast::Expr>,
|
||||||
|
pub arms: AstPtr<ast::MatchArmList>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Diagnostic for MissingMatchArms {
|
||||||
|
fn message(&self) -> String {
|
||||||
|
String::from("Missing match arm")
|
||||||
|
}
|
||||||
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
|
InFile { file_id: self.file, value: self.match_expr.into() }
|
||||||
|
}
|
||||||
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MissingOkInTailExpr {
|
pub struct MissingOkInTailExpr {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
|
|
|
@ -13,9 +13,10 @@ use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
diagnostics::{MissingFields, MissingOkInTailExpr},
|
diagnostics::{MissingFields, MissingMatchArms, MissingOkInTailExpr},
|
||||||
utils::variant_data,
|
utils::variant_data,
|
||||||
ApplicationTy, InferenceResult, Ty, TypeCtor,
|
ApplicationTy, InferenceResult, Ty, TypeCtor,
|
||||||
|
_match::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use hir_def::{
|
pub use hir_def::{
|
||||||
|
@ -51,15 +52,99 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
for e in body.exprs.iter() {
|
for e in body.exprs.iter() {
|
||||||
if let (id, Expr::RecordLit { path, fields, spread }) = e {
|
if let (id, Expr::RecordLit { path, fields, spread }) = e {
|
||||||
self.validate_record_literal(id, path, fields, *spread, db);
|
self.validate_record_literal(id, path, fields, *spread, db);
|
||||||
|
} else if let (id, Expr::Match { expr, arms }) = e {
|
||||||
|
self.validate_match(id, *expr, arms, db, self.infer.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let body_expr = &body[body.body_expr];
|
let body_expr = &body[body.body_expr];
|
||||||
if let Expr::Block { statements: _, tail: Some(t) } = body_expr {
|
if let Expr::Block { tail: Some(t), .. } = body_expr {
|
||||||
self.validate_results_in_tail_expr(body.body_expr, *t, db);
|
self.validate_results_in_tail_expr(body.body_expr, *t, db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_match(
|
||||||
|
&mut self,
|
||||||
|
id: ExprId,
|
||||||
|
match_expr: ExprId,
|
||||||
|
arms: &[MatchArm],
|
||||||
|
db: &dyn HirDatabase,
|
||||||
|
infer: Arc<InferenceResult>,
|
||||||
|
) {
|
||||||
|
let (body, source_map): (Arc<Body>, Arc<BodySourceMap>) =
|
||||||
|
db.body_with_source_map(self.func.into());
|
||||||
|
|
||||||
|
let match_expr_ty = match infer.type_of_expr.get(match_expr) {
|
||||||
|
Some(ty) => ty,
|
||||||
|
// If we can't resolve the type of the match expression
|
||||||
|
// we cannot perform exhaustiveness checks.
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let cx = MatchCheckCtx { body, infer: infer.clone(), db };
|
||||||
|
let pats = arms.iter().map(|arm| arm.pat);
|
||||||
|
|
||||||
|
let mut seen = Matrix::empty();
|
||||||
|
for pat in pats {
|
||||||
|
// We skip any patterns whose type we cannot resolve.
|
||||||
|
//
|
||||||
|
// This could lead to false positives in this diagnostic, so
|
||||||
|
// it might be better to skip the entire diagnostic if we either
|
||||||
|
// cannot resolve a match arm or determine that the match arm has
|
||||||
|
// the wrong type.
|
||||||
|
if let Some(pat_ty) = infer.type_of_pat.get(pat) {
|
||||||
|
// We only include patterns whose type matches the type
|
||||||
|
// of the match expression. If we had a InvalidMatchArmPattern
|
||||||
|
// diagnostic or similar we could raise that in an else
|
||||||
|
// block here.
|
||||||
|
//
|
||||||
|
// When comparing the types, we also have to consider that rustc
|
||||||
|
// will automatically de-reference the match expression type if
|
||||||
|
// necessary.
|
||||||
|
//
|
||||||
|
// FIXME we should use the type checker for this.
|
||||||
|
if pat_ty == match_expr_ty
|
||||||
|
|| match_expr_ty
|
||||||
|
.as_reference()
|
||||||
|
.map(|(match_expr_ty, _)| match_expr_ty == pat_ty)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
// If we had a NotUsefulMatchArm diagnostic, we could
|
||||||
|
// check the usefulness of each pattern as we added it
|
||||||
|
// to the matrix here.
|
||||||
|
let v = PatStack::from_pattern(pat);
|
||||||
|
seen.push(&cx, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match is_useful(&cx, &seen, &PatStack::from_wild()) {
|
||||||
|
Ok(Usefulness::Useful) => (),
|
||||||
|
// if a wildcard pattern is not useful, then all patterns are covered
|
||||||
|
Ok(Usefulness::NotUseful) => return,
|
||||||
|
// this path is for unimplemented checks, so we err on the side of not
|
||||||
|
// reporting any errors
|
||||||
|
_ => return,
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(source_ptr) = source_map.expr_syntax(id) {
|
||||||
|
if let Some(expr) = source_ptr.value.left() {
|
||||||
|
let root = source_ptr.file_syntax(db.upcast());
|
||||||
|
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) {
|
||||||
|
if let (Some(match_expr), Some(arms)) =
|
||||||
|
(match_expr.expr(), match_expr.match_arm_list())
|
||||||
|
{
|
||||||
|
self.sink.push(MissingMatchArms {
|
||||||
|
file: source_ptr.file_id,
|
||||||
|
match_expr: AstPtr::new(&match_expr),
|
||||||
|
arms: AstPtr::new(&arms),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn validate_record_literal(
|
fn validate_record_literal(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: ExprId,
|
id: ExprId,
|
||||||
|
|
|
@ -21,9 +21,13 @@ impl<'a> InferenceContext<'a> {
|
||||||
subpats: &[PatId],
|
subpats: &[PatId],
|
||||||
expected: &Ty,
|
expected: &Ty,
|
||||||
default_bm: BindingMode,
|
default_bm: BindingMode,
|
||||||
|
id: PatId,
|
||||||
) -> Ty {
|
) -> Ty {
|
||||||
let (ty, def) = self.resolve_variant(path);
|
let (ty, def) = self.resolve_variant(path);
|
||||||
let var_data = def.map(|it| variant_data(self.db.upcast(), it));
|
let var_data = def.map(|it| variant_data(self.db.upcast(), it));
|
||||||
|
if let Some(variant) = def {
|
||||||
|
self.write_variant_resolution(id.into(), variant);
|
||||||
|
}
|
||||||
self.unify(&ty, expected);
|
self.unify(&ty, expected);
|
||||||
|
|
||||||
let substs = ty.substs().unwrap_or_else(Substs::empty);
|
let substs = ty.substs().unwrap_or_else(Substs::empty);
|
||||||
|
@ -152,7 +156,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
Ty::apply_one(TypeCtor::Ref(*mutability), subty)
|
Ty::apply_one(TypeCtor::Ref(*mutability), subty)
|
||||||
}
|
}
|
||||||
Pat::TupleStruct { path: p, args: subpats } => {
|
Pat::TupleStruct { path: p, args: subpats } => {
|
||||||
self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm)
|
self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm, pat)
|
||||||
}
|
}
|
||||||
Pat::Record { path: p, args: fields } => {
|
Pat::Record { path: p, args: fields } => {
|
||||||
self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat)
|
self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat)
|
||||||
|
|
|
@ -67,8 +67,16 @@ impl<'a> InferenceContext<'a> {
|
||||||
ValueNs::FunctionId(it) => it.into(),
|
ValueNs::FunctionId(it) => it.into(),
|
||||||
ValueNs::ConstId(it) => it.into(),
|
ValueNs::ConstId(it) => it.into(),
|
||||||
ValueNs::StaticId(it) => it.into(),
|
ValueNs::StaticId(it) => it.into(),
|
||||||
ValueNs::StructId(it) => it.into(),
|
ValueNs::StructId(it) => {
|
||||||
ValueNs::EnumVariantId(it) => it.into(),
|
self.write_variant_resolution(id, it.into());
|
||||||
|
|
||||||
|
it.into()
|
||||||
|
}
|
||||||
|
ValueNs::EnumVariantId(it) => {
|
||||||
|
self.write_variant_resolution(id, it.into());
|
||||||
|
|
||||||
|
it.into()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty = self.db.value_ty(typable);
|
let ty = self.db.value_ty(typable);
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
//! The type system. We currently use this to infer types for completion, hover
|
//! The type system. We currently use this to infer types for completion, hover
|
||||||
//! information and various assists.
|
//! information and various assists.
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! eprintln {
|
||||||
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! impl_froms {
|
macro_rules! impl_froms {
|
||||||
($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
|
($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -38,6 +43,7 @@ mod tests;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_db;
|
mod test_db;
|
||||||
mod marks;
|
mod marks;
|
||||||
|
mod _match;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -855,7 +861,8 @@ pub trait TypeWalk {
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
// /// Shifts up debruijn indices of `Ty::Bound` vars by `n`.
|
|
||||||
|
/// Shifts up debruijn indices of `Ty::Bound` vars by `n`.
|
||||||
fn shift_bound_vars(self, n: DebruijnIndex) -> Self
|
fn shift_bound_vars(self, n: DebruijnIndex) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -105,8 +105,9 @@ impl TestDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: don't duplicate this
|
// FIXME: don't duplicate this
|
||||||
pub fn diagnostics(&self) -> String {
|
pub fn diagnostics(&self) -> (String, u32) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
let mut count = 0;
|
||||||
let crate_graph = self.crate_graph();
|
let crate_graph = self.crate_graph();
|
||||||
for krate in crate_graph.iter() {
|
for krate in crate_graph.iter() {
|
||||||
let crate_def_map = self.crate_def_map(krate);
|
let crate_def_map = self.crate_def_map(krate);
|
||||||
|
@ -133,13 +134,14 @@ impl TestDB {
|
||||||
let infer = self.infer(f.into());
|
let infer = self.infer(f.into());
|
||||||
let mut sink = DiagnosticSink::new(|d| {
|
let mut sink = DiagnosticSink::new(|d| {
|
||||||
format_to!(buf, "{:?}: {}\n", d.syntax_node(self).text(), d.message());
|
format_to!(buf, "{:?}: {}\n", d.syntax_node(self).text(), d.message());
|
||||||
|
count += 1;
|
||||||
});
|
});
|
||||||
infer.add_diagnostics(self, f, &mut sink);
|
infer.add_diagnostics(self, f, &mut sink);
|
||||||
let mut validator = ExprValidator::new(f, infer, &mut sink);
|
let mut validator = ExprValidator::new(f, infer, &mut sink);
|
||||||
validator.validate_body(self);
|
validator.validate_body(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf
|
(buf, count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,8 @@ fn no_such_field_diagnostics() {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.diagnostics();
|
.diagnostics()
|
||||||
|
.0;
|
||||||
|
|
||||||
assert_snapshot!(diagnostics, @r###"
|
assert_snapshot!(diagnostics, @r###"
|
||||||
"baz: 62": no such field
|
"baz: 62": no such field
|
||||||
|
|
|
@ -2021,3 +2021,28 @@ fn main() {
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dyn_trait_through_chalk() {
|
||||||
|
let t = type_at(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
struct Box<T> {}
|
||||||
|
#[lang = "deref"]
|
||||||
|
trait Deref {
|
||||||
|
type Target;
|
||||||
|
}
|
||||||
|
impl<T> Deref for Box<T> {
|
||||||
|
type Target = T;
|
||||||
|
}
|
||||||
|
trait Trait {
|
||||||
|
fn foo(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(x: Box<dyn Trait>) {
|
||||||
|
x.foo()<|>;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
assert_eq!(t, "()");
|
||||||
|
}
|
||||||
|
|
|
@ -427,7 +427,12 @@ impl ToChalk for GenericPredicate {
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
where_clause: chalk_ir::QuantifiedWhereClause<Interner>,
|
where_clause: chalk_ir::QuantifiedWhereClause<Interner>,
|
||||||
) -> GenericPredicate {
|
) -> GenericPredicate {
|
||||||
match where_clause.value {
|
// we don't produce any where clauses with binders and can't currently deal with them
|
||||||
|
match where_clause
|
||||||
|
.value
|
||||||
|
.shifted_out(&Interner)
|
||||||
|
.expect("unexpected bound vars in where clause")
|
||||||
|
{
|
||||||
chalk_ir::WhereClause::Implemented(tr) => {
|
chalk_ir::WhereClause::Implemented(tr) => {
|
||||||
GenericPredicate::Implemented(from_chalk(db, tr))
|
GenericPredicate::Implemented(from_chalk(db, tr))
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl FnCallNode {
|
||||||
syntax.ancestors().find_map(|node| {
|
syntax.ancestors().find_map(|node| {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::CallExpr(it) => { Some(FnCallNode::CallExpr(it)) },
|
ast::CallExpr(it) => Some(FnCallNode::CallExpr(it)),
|
||||||
ast::MethodCallExpr(it) => {
|
ast::MethodCallExpr(it) => {
|
||||||
let arg_list = it.arg_list()?;
|
let arg_list = it.arg_list()?;
|
||||||
if !syntax.text_range().is_subrange(&arg_list.syntax().text_range()) {
|
if !syntax.text_range().is_subrange(&arg_list.syntax().text_range()) {
|
||||||
|
@ -117,8 +117,8 @@ impl FnCallNode {
|
||||||
}
|
}
|
||||||
Some(FnCallNode::MethodCallExpr(it))
|
Some(FnCallNode::MethodCallExpr(it))
|
||||||
},
|
},
|
||||||
ast::MacroCall(it) => { Some(FnCallNode::MacroCallExpr(it)) },
|
ast::MacroCall(it) => Some(FnCallNode::MacroCallExpr(it)),
|
||||||
_ => { None },
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -127,10 +127,10 @@ impl FnCallNode {
|
||||||
pub(crate) fn with_node_exact(node: &SyntaxNode) -> Option<FnCallNode> {
|
pub(crate) fn with_node_exact(node: &SyntaxNode) -> Option<FnCallNode> {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::CallExpr(it) => { Some(FnCallNode::CallExpr(it)) },
|
ast::CallExpr(it) => Some(FnCallNode::CallExpr(it)),
|
||||||
ast::MethodCallExpr(it) => { Some(FnCallNode::MethodCallExpr(it)) },
|
ast::MethodCallExpr(it) => Some(FnCallNode::MethodCallExpr(it)),
|
||||||
ast::MacroCall(it) => { Some(FnCallNode::MacroCallExpr(it)) },
|
ast::MacroCall(it) => Some(FnCallNode::MacroCallExpr(it)),
|
||||||
_ => { None },
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ mod complete_pattern;
|
||||||
mod complete_fn_param;
|
mod complete_fn_param;
|
||||||
mod complete_keyword;
|
mod complete_keyword;
|
||||||
mod complete_snippet;
|
mod complete_snippet;
|
||||||
mod complete_path;
|
mod complete_qualified_path;
|
||||||
mod complete_scope;
|
mod complete_unqualified_path;
|
||||||
mod complete_postfix;
|
mod complete_postfix;
|
||||||
mod complete_macro_in_item_position;
|
mod complete_macro_in_item_position;
|
||||||
mod complete_trait_impl;
|
mod complete_trait_impl;
|
||||||
|
@ -85,8 +85,8 @@ pub(crate) fn completions(
|
||||||
complete_keyword::complete_use_tree_keyword(&mut acc, &ctx);
|
complete_keyword::complete_use_tree_keyword(&mut acc, &ctx);
|
||||||
complete_snippet::complete_expr_snippet(&mut acc, &ctx);
|
complete_snippet::complete_expr_snippet(&mut acc, &ctx);
|
||||||
complete_snippet::complete_item_snippet(&mut acc, &ctx);
|
complete_snippet::complete_item_snippet(&mut acc, &ctx);
|
||||||
complete_path::complete_path(&mut acc, &ctx);
|
complete_qualified_path::complete_qualified_path(&mut acc, &ctx);
|
||||||
complete_scope::complete_scope(&mut acc, &ctx);
|
complete_unqualified_path::complete_unqualified_path(&mut acc, &ctx);
|
||||||
complete_dot::complete_dot(&mut acc, &ctx);
|
complete_dot::complete_dot(&mut acc, &ctx);
|
||||||
complete_record::complete_record(&mut acc, &ctx);
|
complete_record::complete_record(&mut acc, &ctx);
|
||||||
complete_pattern::complete_pattern(&mut acc, &ctx);
|
complete_pattern::complete_pattern(&mut acc, &ctx);
|
||||||
|
|
|
@ -18,8 +18,8 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
for node in ctx.token.parent().ancestors() {
|
for node in ctx.token.parent().ancestors() {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::SourceFile(it) => { process(it, &mut params) },
|
ast::SourceFile(it) => process(it, &mut params),
|
||||||
ast::ItemList(it) => { process(it, &mut params) },
|
ast::ItemList(it) => process(it, &mut params),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,9 +86,9 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool {
|
||||||
}
|
}
|
||||||
let loop_body = match_ast! {
|
let loop_body = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::ForExpr(it) => { it.loop_body() },
|
ast::ForExpr(it) => it.loop_body(),
|
||||||
ast::WhileExpr(it) => { it.loop_body() },
|
ast::WhileExpr(it) => it.loop_body(),
|
||||||
ast::LoopExpr(it) => { it.loop_body() },
|
ast::LoopExpr(it) => it.loop_body(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, Completions};
|
use crate::completion::{CompletionContext, Completions};
|
||||||
|
|
||||||
pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
let path = match &ctx.path_prefix {
|
let path = match &ctx.path_prefix {
|
||||||
Some(path) => path.clone(),
|
Some(path) => path.clone(),
|
||||||
_ => return,
|
_ => return,
|
|
@ -1,12 +1,13 @@
|
||||||
//! Complete fields in record literals and patterns.
|
//! Complete fields in record literals and patterns.
|
||||||
use crate::completion::{CompletionContext, Completions};
|
|
||||||
use ra_syntax::{ast, ast::NameOwner, SmolStr};
|
use ra_syntax::{ast, ast::NameOwner, SmolStr};
|
||||||
|
|
||||||
|
use crate::completion::{CompletionContext, Completions};
|
||||||
|
|
||||||
pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||||
let (ty, variant, already_present_fields) =
|
let (ty, variant, already_present_fields) =
|
||||||
match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) {
|
match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) {
|
||||||
(None, None) => return None,
|
(None, None) => return None,
|
||||||
(Some(_), Some(_)) => panic!("A record cannot be both a literal and a pattern"),
|
(Some(_), Some(_)) => unreachable!("A record cannot be both a literal and a pattern"),
|
||||||
(Some(record_pat), _) => (
|
(Some(record_pat), _) => (
|
||||||
ctx.sema.type_of_pat(&record_pat.clone().into())?,
|
ctx.sema.type_of_pat(&record_pat.clone().into())?,
|
||||||
ctx.sema.resolve_record_pattern(record_pat)?,
|
ctx.sema.resolve_record_pattern(record_pat)?,
|
||||||
|
@ -59,9 +60,10 @@ fn pattern_ascribed_fields(record_pat: &ast::RecordPat) -> Vec<SmolStr> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
mod record_lit_tests {
|
mod record_lit_tests {
|
||||||
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
|
||||||
use insta::assert_debug_snapshot;
|
use insta::assert_debug_snapshot;
|
||||||
|
|
||||||
|
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
||||||
|
|
||||||
fn complete(code: &str) -> Vec<CompletionItem> {
|
fn complete(code: &str) -> Vec<CompletionItem> {
|
||||||
do_completion(code, CompletionKind::Reference)
|
do_completion(code, CompletionKind::Reference)
|
||||||
}
|
}
|
||||||
|
@ -204,9 +206,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod record_pat_tests {
|
mod record_pat_tests {
|
||||||
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
|
||||||
use insta::assert_debug_snapshot;
|
use insta::assert_debug_snapshot;
|
||||||
|
|
||||||
|
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
||||||
|
|
||||||
fn complete(code: &str) -> Vec<CompletionItem> {
|
fn complete(code: &str) -> Vec<CompletionItem> {
|
||||||
do_completion(code, CompletionKind::Reference)
|
do_completion(code, CompletionKind::Reference)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, Completions};
|
use crate::completion::{CompletionContext, Completions};
|
||||||
|
|
||||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const) {
|
if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
|
@ -50,6 +50,8 @@ pub(crate) struct CompletionContext<'a> {
|
||||||
pub(super) dot_receiver_is_ambiguous_float_literal: bool,
|
pub(super) dot_receiver_is_ambiguous_float_literal: bool,
|
||||||
/// If this is a call (method or function) in particular, i.e. the () are already there.
|
/// If this is a call (method or function) in particular, i.e. the () are already there.
|
||||||
pub(super) is_call: bool,
|
pub(super) is_call: bool,
|
||||||
|
/// If this is a macro call, i.e. the () are already there.
|
||||||
|
pub(super) is_macro_call: bool,
|
||||||
pub(super) is_path_type: bool,
|
pub(super) is_path_type: bool,
|
||||||
pub(super) has_type_args: bool,
|
pub(super) has_type_args: bool,
|
||||||
}
|
}
|
||||||
|
@ -102,6 +104,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
is_new_item: false,
|
is_new_item: false,
|
||||||
dot_receiver: None,
|
dot_receiver: None,
|
||||||
is_call: false,
|
is_call: false,
|
||||||
|
is_macro_call: false,
|
||||||
is_path_type: false,
|
is_path_type: false,
|
||||||
has_type_args: false,
|
has_type_args: false,
|
||||||
dot_receiver_is_ambiguous_float_literal: false,
|
dot_receiver_is_ambiguous_float_literal: false,
|
||||||
|
@ -269,6 +272,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
.and_then(ast::PathExpr::cast)
|
.and_then(ast::PathExpr::cast)
|
||||||
.and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
|
.and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
|
||||||
.is_some();
|
.is_some();
|
||||||
|
self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some();
|
||||||
|
|
||||||
self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
|
self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
|
||||||
self.has_type_args = segment.type_arg_list().is_some();
|
self.has_type_args = segment.type_arg_list().is_some();
|
||||||
|
|
|
@ -174,7 +174,8 @@ impl Completions {
|
||||||
.set_deprecated(is_deprecated(macro_, ctx.db))
|
.set_deprecated(is_deprecated(macro_, ctx.db))
|
||||||
.detail(detail);
|
.detail(detail);
|
||||||
|
|
||||||
builder = if ctx.use_item_syntax.is_some() {
|
builder = if ctx.use_item_syntax.is_some() || ctx.is_macro_call {
|
||||||
|
tested_by!(dont_insert_macro_call_parens_unncessary);
|
||||||
builder.insert_text(name)
|
builder.insert_text(name)
|
||||||
} else {
|
} else {
|
||||||
let macro_braces_to_insert =
|
let macro_braces_to_insert =
|
||||||
|
@ -960,7 +961,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dont_insert_macro_call_braces_in_use() {
|
fn dont_insert_macro_call_parens_unncessary() {
|
||||||
|
covers!(dont_insert_macro_call_parens_unncessary);
|
||||||
assert_debug_snapshot!(
|
assert_debug_snapshot!(
|
||||||
do_reference_completion(
|
do_reference_completion(
|
||||||
r"
|
r"
|
||||||
|
@ -986,6 +988,41 @@ mod tests {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"###
|
"###
|
||||||
)
|
);
|
||||||
|
|
||||||
|
assert_debug_snapshot!(
|
||||||
|
do_reference_completion(
|
||||||
|
r"
|
||||||
|
//- /main.rs
|
||||||
|
macro_rules frobnicate {
|
||||||
|
() => ()
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
frob<|>!();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "frobnicate!",
|
||||||
|
source_range: [56; 60),
|
||||||
|
delete: [56; 60),
|
||||||
|
insert: "frobnicate",
|
||||||
|
kind: Macro,
|
||||||
|
detail: "macro_rules! frobnicate",
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "main()",
|
||||||
|
source_range: [56; 60),
|
||||||
|
delete: [56; 60),
|
||||||
|
insert: "main()$0",
|
||||||
|
kind: Function,
|
||||||
|
lookup: "main",
|
||||||
|
detail: "fn main()",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"###
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,14 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
||||||
fix,
|
fix,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.on::<hir::diagnostics::MissingMatchArms, _>(|d| {
|
||||||
|
res.borrow_mut().push(Diagnostic {
|
||||||
|
range: d.highlight_range(),
|
||||||
|
message: d.message(),
|
||||||
|
severity: Severity::Error,
|
||||||
|
fix: None,
|
||||||
|
})
|
||||||
|
})
|
||||||
.on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {
|
.on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {
|
||||||
let node = d.ast(db);
|
let node = d.ast(db);
|
||||||
let replacement = format!("Ok({})", node.syntax());
|
let replacement = format!("Ok({})", node.syntax());
|
||||||
|
@ -291,7 +299,7 @@ mod tests {
|
||||||
fn check_no_diagnostic(content: &str) {
|
fn check_no_diagnostic(content: &str) {
|
||||||
let (analysis, file_id) = single_file(content);
|
let (analysis, file_id) = single_file(content);
|
||||||
let diagnostics = analysis.diagnostics(file_id).unwrap();
|
let diagnostics = analysis.diagnostics(file_id).unwrap();
|
||||||
assert_eq!(diagnostics.len(), 0);
|
assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -399,17 +399,17 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option
|
||||||
|
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::FnDef(it) => { it.doc_comment_text() },
|
ast::FnDef(it) => it.doc_comment_text(),
|
||||||
ast::StructDef(it) => { it.doc_comment_text() },
|
ast::StructDef(it) => it.doc_comment_text(),
|
||||||
ast::EnumDef(it) => { it.doc_comment_text() },
|
ast::EnumDef(it) => it.doc_comment_text(),
|
||||||
ast::TraitDef(it) => { it.doc_comment_text() },
|
ast::TraitDef(it) => it.doc_comment_text(),
|
||||||
ast::Module(it) => { it.doc_comment_text() },
|
ast::Module(it) => it.doc_comment_text(),
|
||||||
ast::TypeAliasDef(it) => { it.doc_comment_text() },
|
ast::TypeAliasDef(it) => it.doc_comment_text(),
|
||||||
ast::ConstDef(it) => { it.doc_comment_text() },
|
ast::ConstDef(it) => it.doc_comment_text(),
|
||||||
ast::StaticDef(it) => { it.doc_comment_text() },
|
ast::StaticDef(it) => it.doc_comment_text(),
|
||||||
ast::RecordFieldDef(it) => { it.doc_comment_text() },
|
ast::RecordFieldDef(it) => it.doc_comment_text(),
|
||||||
ast::EnumVariant(it) => { it.doc_comment_text() },
|
ast::EnumVariant(it) => it.doc_comment_text(),
|
||||||
ast::MacroCall(it) => { it.doc_comment_text() },
|
ast::MacroCall(it) => it.doc_comment_text(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,16 +424,16 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
|
||||||
|
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::FnDef(it) => { it.short_label() },
|
ast::FnDef(it) => it.short_label(),
|
||||||
ast::StructDef(it) => { it.short_label() },
|
ast::StructDef(it) => it.short_label(),
|
||||||
ast::EnumDef(it) => { it.short_label() },
|
ast::EnumDef(it) => it.short_label(),
|
||||||
ast::TraitDef(it) => { it.short_label() },
|
ast::TraitDef(it) => it.short_label(),
|
||||||
ast::Module(it) => { it.short_label() },
|
ast::Module(it) => it.short_label(),
|
||||||
ast::TypeAliasDef(it) => { it.short_label() },
|
ast::TypeAliasDef(it) => it.short_label(),
|
||||||
ast::ConstDef(it) => { it.short_label() },
|
ast::ConstDef(it) => it.short_label(),
|
||||||
ast::StaticDef(it) => { it.short_label() },
|
ast::StaticDef(it) => it.short_label(),
|
||||||
ast::RecordFieldDef(it) => { it.short_label() },
|
ast::RecordFieldDef(it) => it.short_label(),
|
||||||
ast::EnumVariant(it) => { it.short_label() },
|
ast::EnumVariant(it) => it.short_label(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,18 +117,18 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
|
||||||
|
|
||||||
decl_with_detail(it, Some(detail))
|
decl_with_detail(it, Some(detail))
|
||||||
},
|
},
|
||||||
ast::StructDef(it) => { decl(it) },
|
ast::StructDef(it) => decl(it),
|
||||||
ast::EnumDef(it) => { decl(it) },
|
ast::EnumDef(it) => decl(it),
|
||||||
ast::EnumVariant(it) => { decl(it) },
|
ast::EnumVariant(it) => decl(it),
|
||||||
ast::TraitDef(it) => { decl(it) },
|
ast::TraitDef(it) => decl(it),
|
||||||
ast::Module(it) => { decl(it) },
|
ast::Module(it) => decl(it),
|
||||||
ast::TypeAliasDef(it) => {
|
ast::TypeAliasDef(it) => {
|
||||||
let ty = it.type_ref();
|
let ty = it.type_ref();
|
||||||
decl_with_type_ref(it, ty)
|
decl_with_type_ref(it, ty)
|
||||||
},
|
},
|
||||||
ast::RecordFieldDef(it) => { decl_with_ascription(it) },
|
ast::RecordFieldDef(it) => decl_with_ascription(it),
|
||||||
ast::ConstDef(it) => { decl_with_ascription(it) },
|
ast::ConstDef(it) => decl_with_ascription(it),
|
||||||
ast::StaticDef(it) => { decl_with_ascription(it) },
|
ast::StaticDef(it) => decl_with_ascription(it),
|
||||||
ast::ImplDef(it) => {
|
ast::ImplDef(it) => {
|
||||||
let target_type = it.target_type()?;
|
let target_type = it.target_type()?;
|
||||||
let target_trait = it.target_trait();
|
let target_trait = it.target_trait();
|
||||||
|
|
|
@ -18,9 +18,9 @@ pub(crate) fn goto_type_definition(
|
||||||
let (ty, node) = sema.ancestors_with_macros(token.parent()).find_map(|node| {
|
let (ty, node) = sema.ancestors_with_macros(token.parent()).find_map(|node| {
|
||||||
let ty = match_ast! {
|
let ty = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::Expr(expr) => { sema.type_of_expr(&expr)? },
|
ast::Expr(expr) => sema.type_of_expr(&expr)?,
|
||||||
ast::Pat(pat) => { sema.type_of_pat(&pat)? },
|
ast::Pat(pat) => sema.type_of_pat(&pat)?,
|
||||||
_ => { return None },
|
_ => return None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
// For proving that RootDatabase is RefUnwindSafe.
|
// For proving that RootDatabase is RefUnwindSafe.
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
macro_rules! eprintln {
|
||||||
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
||||||
|
}
|
||||||
|
|
||||||
pub mod mock_analysis;
|
pub mod mock_analysis;
|
||||||
mod source_change;
|
mod source_change;
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ test_utils::marks!(
|
||||||
dont_complete_current_use
|
dont_complete_current_use
|
||||||
test_resolve_parent_module_on_module_decl
|
test_resolve_parent_module_on_module_decl
|
||||||
search_filters_by_range
|
search_filters_by_range
|
||||||
|
dont_insert_macro_call_parens_unncessary
|
||||||
);
|
);
|
||||||
|
|
|
@ -49,8 +49,8 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
|
||||||
fn runnable(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> {
|
fn runnable(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match item {
|
match item {
|
||||||
ast::FnDef(it) => { runnable_fn(sema, it) },
|
ast::FnDef(it) => runnable_fn(sema, it),
|
||||||
ast::Module(it) => { runnable_mod(sema, it) },
|
ast::Module(it) => runnable_mod(sema, it),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<Referen
|
||||||
}
|
}
|
||||||
Some(ReferenceAccess::Read)
|
Some(ReferenceAccess::Read)
|
||||||
},
|
},
|
||||||
_ => {None}
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -354,14 +354,14 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
|
||||||
}
|
}
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::FnDef(it) => { decl(it) },
|
ast::FnDef(it) => decl(it),
|
||||||
ast::StructDef(it) => { decl(it) },
|
ast::StructDef(it) => decl(it),
|
||||||
ast::EnumDef(it) => { decl(it) },
|
ast::EnumDef(it) => decl(it),
|
||||||
ast::TraitDef(it) => { decl(it) },
|
ast::TraitDef(it) => decl(it),
|
||||||
ast::Module(it) => { decl(it) },
|
ast::Module(it) => decl(it),
|
||||||
ast::TypeAliasDef(it) => { decl(it) },
|
ast::TypeAliasDef(it) => decl(it),
|
||||||
ast::ConstDef(it) => { decl(it) },
|
ast::ConstDef(it) => decl(it),
|
||||||
ast::StaticDef(it) => { decl(it) },
|
ast::StaticDef(it) => decl(it),
|
||||||
ast::MacroCall(it) => {
|
ast::MacroCall(it) => {
|
||||||
if it.is_macro_rules().is_some() {
|
if it.is_macro_rules().is_some() {
|
||||||
decl(it)
|
decl(it)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
||||||
path::{Component, Path, PathBuf},
|
path::{Component, Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use test_utils::{collect_tests, dir_tests, project_dir, read_text};
|
use test_utils::{collect_rust_files, dir_tests, project_dir, read_text};
|
||||||
|
|
||||||
use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextUnit, Token};
|
use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextUnit, Token};
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ fn lexer_tests() {
|
||||||
// * Add tests for unicode escapes in byte-character and [raw]-byte-string literals
|
// * Add tests for unicode escapes in byte-character and [raw]-byte-string literals
|
||||||
// * Add tests for unescape errors
|
// * Add tests for unescape errors
|
||||||
|
|
||||||
dir_tests(&test_data_dir(), &["lexer/ok"], |text, path| {
|
dir_tests(&test_data_dir(), &["lexer/ok"], "txt", |text, path| {
|
||||||
let (tokens, errors) = tokenize(text);
|
let (tokens, errors) = tokenize(text);
|
||||||
assert_errors_are_absent(&errors, path);
|
assert_errors_are_absent(&errors, path);
|
||||||
dump_tokens_and_errors(&tokens, &errors, text)
|
dump_tokens_and_errors(&tokens, &errors, text)
|
||||||
});
|
});
|
||||||
dir_tests(&test_data_dir(), &["lexer/err"], |text, path| {
|
dir_tests(&test_data_dir(), &["lexer/err"], "txt", |text, path| {
|
||||||
let (tokens, errors) = tokenize(text);
|
let (tokens, errors) = tokenize(text);
|
||||||
assert_errors_are_present(&errors, path);
|
assert_errors_are_present(&errors, path);
|
||||||
dump_tokens_and_errors(&tokens, &errors, text)
|
dump_tokens_and_errors(&tokens, &errors, text)
|
||||||
|
@ -40,13 +40,13 @@ fn main() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parser_tests() {
|
fn parser_tests() {
|
||||||
dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], |text, path| {
|
dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], "rast", |text, path| {
|
||||||
let parse = SourceFile::parse(text);
|
let parse = SourceFile::parse(text);
|
||||||
let errors = parse.errors();
|
let errors = parse.errors();
|
||||||
assert_errors_are_absent(&errors, path);
|
assert_errors_are_absent(&errors, path);
|
||||||
parse.debug_dump()
|
parse.debug_dump()
|
||||||
});
|
});
|
||||||
dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], |text, path| {
|
dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], "rast", |text, path| {
|
||||||
let parse = SourceFile::parse(text);
|
let parse = SourceFile::parse(text);
|
||||||
let errors = parse.errors();
|
let errors = parse.errors();
|
||||||
assert_errors_are_present(&errors, path);
|
assert_errors_are_present(&errors, path);
|
||||||
|
@ -56,14 +56,14 @@ fn parser_tests() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parser_fuzz_tests() {
|
fn parser_fuzz_tests() {
|
||||||
for (_, text) in collect_tests(&test_data_dir(), &["parser/fuzz-failures"]) {
|
for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) {
|
||||||
fuzz::check_parser(&text)
|
fuzz::check_parser(&text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reparse_fuzz_tests() {
|
fn reparse_fuzz_tests() {
|
||||||
for (_, text) in collect_tests(&test_data_dir(), &["reparse/fuzz-failures"]) {
|
for (_, text) in collect_rust_files(&test_data_dir(), &["reparse/fuzz-failures"]) {
|
||||||
let check = fuzz::CheckReparse::from_data(text.as_bytes()).unwrap();
|
let check = fuzz::CheckReparse::from_data(text.as_bytes()).unwrap();
|
||||||
println!("{:?}", check);
|
println!("{:?}", check);
|
||||||
check.run();
|
check.run();
|
||||||
|
|
|
@ -88,12 +88,12 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
|
||||||
for node in root.descendants() {
|
for node in root.descendants() {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::Literal(it) => { validate_literal(it, &mut errors) },
|
ast::Literal(it) => validate_literal(it, &mut errors),
|
||||||
ast::BlockExpr(it) => { block::validate_block_expr(it, &mut errors) },
|
ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
|
||||||
ast::FieldExpr(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
|
||||||
ast::RecordField(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
ast::RecordField(it) => validate_numeric_name(it.name_ref(), &mut errors),
|
||||||
ast::Visibility(it) => { validate_visibility(it, &mut errors) },
|
ast::Visibility(it) => validate_visibility(it, &mut errors),
|
||||||
ast::RangeExpr(it) => { validate_range_expr(it, &mut errors) },
|
ast::RangeExpr(it) => validate_range_expr(it, &mut errors),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue