mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
Don't emit two type mismatches for literal pattern mismatches
This commit is contained in:
parent
ec273c3d12
commit
44e2c6ea92
2 changed files with 9 additions and 13 deletions
|
@ -181,8 +181,8 @@ impl<'a> InferenceContext<'a> {
|
||||||
.intern(Interner)
|
.intern(Interner)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn infer_top_pat(&mut self, pat: PatId, expected: &Ty) -> Ty {
|
pub(super) fn infer_top_pat(&mut self, pat: PatId, expected: &Ty) {
|
||||||
self.infer_pat(pat, expected, BindingMode::default())
|
self.infer_pat(pat, expected, BindingMode::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_pat(&mut self, pat: PatId, expected: &Ty, mut default_bm: BindingMode) -> Ty {
|
fn infer_pat(&mut self, pat: PatId, expected: &Ty, mut default_bm: BindingMode) -> Ty {
|
||||||
|
@ -260,7 +260,12 @@ impl<'a> InferenceContext<'a> {
|
||||||
let start_ty = self.infer_expr(*start, &Expectation::has_type(expected.clone()));
|
let start_ty = self.infer_expr(*start, &Expectation::has_type(expected.clone()));
|
||||||
self.infer_expr(*end, &Expectation::has_type(start_ty))
|
self.infer_expr(*end, &Expectation::has_type(start_ty))
|
||||||
}
|
}
|
||||||
&Pat::Lit(expr) => self.infer_lit_pat(expr, &expected),
|
&Pat::Lit(expr) => {
|
||||||
|
// Don't emit type mismatches again, the expression lowering already did that.
|
||||||
|
let ty = self.infer_lit_pat(expr, &expected);
|
||||||
|
self.write_pat_ty(pat, ty.clone());
|
||||||
|
return ty;
|
||||||
|
}
|
||||||
Pat::Box { inner } => match self.resolve_boxed_box() {
|
Pat::Box { inner } => match self.resolve_boxed_box() {
|
||||||
Some(box_adt) => {
|
Some(box_adt) => {
|
||||||
let (inner_ty, alloc_ty) = match expected.as_adt() {
|
let (inner_ty, alloc_ty) = match expected.as_adt() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch) -> Option<Vec<Assi
|
||||||
remove_semicolon(ctx, d, expr_ptr, &mut fixes);
|
remove_semicolon(ctx, d, expr_ptr, &mut fixes);
|
||||||
str_ref_to_owned(ctx, d, expr_ptr, &mut fixes);
|
str_ref_to_owned(ctx, d, expr_ptr, &mut fixes);
|
||||||
}
|
}
|
||||||
Either::Right(_pat_ptr) => (),
|
Either::Right(_pat_ptr) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fixes.is_empty() {
|
if fixes.is_empty() {
|
||||||
|
@ -63,14 +63,6 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch) -> Option<Vec<Assi
|
||||||
Some(fixes)
|
Some(fixes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_reference_pat(
|
|
||||||
ctx: &DiagnosticsContext<'_>,
|
|
||||||
d: &hir::TypeMismatch,
|
|
||||||
expr_ptr: &InFile<AstPtr<ast::Pat>>,
|
|
||||||
acc: &mut Vec<Assist>,
|
|
||||||
) -> Option<()> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_reference(
|
fn add_reference(
|
||||||
ctx: &DiagnosticsContext<'_>,
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
@ -630,7 +622,6 @@ fn f() {
|
||||||
&9 => ()
|
&9 => ()
|
||||||
//^^ error: expected &(), found &i32
|
//^^ error: expected &(), found &i32
|
||||||
//^ error: expected (), found i32
|
//^ error: expected (), found i32
|
||||||
//^ error: expected (), found i32
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
Loading…
Reference in a new issue