Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
| -rw-r--r-- | crates/hir/src/diagnostics.rs | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 64e982c42d..1ed0daa375 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -6,10 +6,11 @@ use cfg::{CfgExpr, CfgOptions}; use either::Either; use hir_def::{ + expr_store::ExprOrPatPtr, hir::ExprOrPatId, path::{hir_segment_to_ast_segment, ModPath}, type_ref::TypesSourceMap, - AssocItemId, DefWithBodyId, SyntheticSyntax, + DefWithBodyId, SyntheticSyntax, }; use hir_expand::{name::Name, HirFileId, InFile}; use hir_ty::{ @@ -24,7 +25,7 @@ use syntax::{ }; use triomphe::Arc; -use crate::{AssocItem, Field, Local, Trait, Type}; +use crate::{AssocItem, Field, Function, Local, Trait, Type}; pub use hir_def::VariantId; pub use hir_ty::{ @@ -111,18 +112,19 @@ diagnostics![ UnusedMut, UnusedVariable, GenericArgsProhibited, + ParenthesizedGenericArgsWithoutFnTrait, ]; #[derive(Debug)] pub struct BreakOutsideOfLoop { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub is_break: bool, pub bad_value_break: bool, } #[derive(Debug)] pub struct TypedHole { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub expected: Type, } @@ -221,26 +223,26 @@ pub struct NoSuchField { #[derive(Debug)] pub struct PrivateAssocItem { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, + pub expr_or_pat: InFile<ExprOrPatPtr>, pub item: AssocItem, } #[derive(Debug)] pub struct MismatchedTupleStructPatArgCount { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, + pub expr_or_pat: InFile<ExprOrPatPtr>, pub expected: usize, pub found: usize, } #[derive(Debug)] pub struct ExpectedFunction { - pub call: InFile<AstPtr<ast::Expr>>, + pub call: InFile<ExprOrPatPtr>, pub found: Type, } #[derive(Debug)] pub struct UnresolvedField { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub receiver: Type, pub name: Name, pub method_with_same_name_exists: bool, @@ -248,26 +250,26 @@ pub struct UnresolvedField { #[derive(Debug)] pub struct UnresolvedMethodCall { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub receiver: Type, pub name: Name, pub field_with_same_name: Option<Type>, - pub assoc_func_with_same_name: Option<AssocItemId>, + pub assoc_func_with_same_name: Option<Function>, } #[derive(Debug)] pub struct UnresolvedAssocItem { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, + pub expr_or_pat: InFile<ExprOrPatPtr>, } #[derive(Debug)] pub struct UnresolvedIdent { - pub node: InFile<(AstPtr<Either<ast::Expr, ast::Pat>>, Option<TextRange>)>, + pub node: InFile<(ExprOrPatPtr, Option<TextRange>)>, } #[derive(Debug)] pub struct PrivateField { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub field: Field, } @@ -280,7 +282,7 @@ pub enum UnsafeLint { #[derive(Debug)] pub struct MissingUnsafe { - pub node: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, + pub node: InFile<ExprOrPatPtr>, pub lint: UnsafeLint, pub reason: UnsafetyReason, } @@ -302,7 +304,7 @@ pub struct ReplaceFilterMapNextWithFindMap { #[derive(Debug)] pub struct MismatchedArgCount { - pub call_expr: InFile<AstPtr<ast::Expr>>, + pub call_expr: InFile<ExprOrPatPtr>, pub expected: usize, pub found: usize, } @@ -321,7 +323,7 @@ pub struct NonExhaustiveLet { #[derive(Debug)] pub struct TypeMismatch { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, + pub expr_or_pat: InFile<ExprOrPatPtr>, pub expected: Type, pub actual: Type, } @@ -395,13 +397,13 @@ pub struct RemoveUnnecessaryElse { #[derive(Debug)] pub struct CastToUnsized { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub cast_ty: Type, } #[derive(Debug)] pub struct InvalidCast { - pub expr: InFile<AstPtr<ast::Expr>>, + pub expr: InFile<ExprOrPatPtr>, pub error: CastError, pub expr_ty: Type, pub cast_ty: Type, @@ -413,6 +415,11 @@ pub struct GenericArgsProhibited { pub reason: GenericArgsProhibitedReason, } +#[derive(Debug)] +pub struct ParenthesizedGenericArgsWithoutFnTrait { + pub args: InFile<AstPtr<ast::ParenthesizedArgList>>, +} + impl AnyDiagnostic { pub(crate) fn body_validation_diagnostic( db: &dyn HirDatabase, @@ -428,9 +435,7 @@ impl AnyDiagnostic { .collect(); let record = match record { - Either::Left(record_expr) => { - source_map.expr_syntax(record_expr).ok()?.map(AstPtr::wrap_left) - } + Either::Left(record_expr) => source_map.expr_syntax(record_expr).ok()?, Either::Right(record_pat) => source_map.pat_syntax(record_pat).ok()?, }; let file = record.file_id; @@ -474,7 +479,7 @@ impl AnyDiagnostic { return Some( ReplaceFilterMapNextWithFindMap { file: next_source_ptr.file_id, - next_expr: next_source_ptr.value, + next_expr: next_source_ptr.value.cast()?, } .into(), ); @@ -484,7 +489,9 @@ impl AnyDiagnostic { match source_map.expr_syntax(match_expr) { Ok(source_ptr) => { let root = source_ptr.file_syntax(db.upcast()); - if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) { + if let Either::Left(ast::Expr::MatchExpr(match_expr)) = + &source_ptr.value.to_node(&root) + { match match_expr.expr() { Some(scrut_expr) if match_expr.match_arm_list().is_some() => { return Some( @@ -561,7 +568,7 @@ impl AnyDiagnostic { let pat_syntax = |pat| source_map.pat_syntax(pat).inspect_err(|_| stdx::never!("synthetic syntax")).ok(); let expr_or_pat_syntax = |id| match id { - ExprOrPatId::ExprId(expr) => expr_syntax(expr).map(|it| it.map(AstPtr::wrap_left)), + ExprOrPatId::ExprId(expr) => expr_syntax(expr), ExprOrPatId::PatId(pat) => pat_syntax(pat), }; Some(match d { @@ -622,7 +629,7 @@ impl AnyDiagnostic { field_with_same_name: field_with_same_name .clone() .map(|ty| Type::new(db, def, ty)), - assoc_func_with_same_name: *assoc_func_with_same_name, + assoc_func_with_same_name: assoc_func_with_same_name.map(Into::into), } .into() } @@ -633,7 +640,7 @@ impl AnyDiagnostic { &InferenceDiagnostic::UnresolvedIdent { id } => { let node = match id { ExprOrPatId::ExprId(id) => match source_map.expr_syntax(id) { - Ok(syntax) => syntax.map(|it| (it.wrap_left(), None)), + Ok(syntax) => syntax.map(|it| (it, None)), Err(SyntheticSyntax) => source_map .format_args_implicit_capture(id)? .map(|(node, range)| (node.wrap_left(), Some(range))), @@ -652,7 +659,7 @@ impl AnyDiagnostic { } &InferenceDiagnostic::MismatchedTupleStructPatArgCount { pat, expected, found } => { let expr_or_pat = match pat { - ExprOrPatId::ExprId(expr) => expr_syntax(expr)?.map(AstPtr::wrap_left), + ExprOrPatId::ExprId(expr) => expr_syntax(expr)?, ExprOrPatId::PatId(pat) => { let InFile { file_id, value } = pat_syntax(pat)?; @@ -702,8 +709,8 @@ impl AnyDiagnostic { diag: &PathLoweringDiagnostic, path: InFile<ast::Path>, ) -> Option<AnyDiagnostic> { - Some(match diag { - &PathLoweringDiagnostic::GenericArgsProhibited { segment, reason } => { + Some(match *diag { + PathLoweringDiagnostic::GenericArgsProhibited { segment, reason } => { let segment = hir_segment_to_ast_segment(&path.value, segment)?; let args = if let Some(generics) = segment.generic_arg_list() { AstPtr::new(&generics).wrap_left() @@ -713,6 +720,12 @@ impl AnyDiagnostic { let args = path.with_value(args); GenericArgsProhibited { args, reason }.into() } + PathLoweringDiagnostic::ParenthesizedGenericArgsWithoutFnTrait { segment } => { + let segment = hir_segment_to_ast_segment(&path.value, segment)?; + let args = AstPtr::new(&segment.parenthesized_arg_list()?); + let args = path.with_value(args); + ParenthesizedGenericArgsWithoutFnTrait { args }.into() + } }) } |