aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/diagnostics
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-01 19:50:02 +0000
committerGitHub <[email protected]>2021-01-01 19:50:02 +0000
commitb4a7caedb066a653560dfe9ec005f20b9e2548c0 (patch)
tree225492cb0e0a8292d670c8153a548593831fa5c2 /crates/hir_ty/src/diagnostics
parentc92c9fdc52ee04a88ee2950a93afc34b4870616b (diff)
parent29acd398004555695bbf29eb054b12381e955cbf (diff)
Merge #7125
7125: Don't emit arg count diagnostics for method calls with unknown receiver r=flodiebold a=flodiebold Fixes #7098. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/diagnostics')
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index 849415706..b4e453411 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -156,7 +156,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
156 // FIXME: Due to shortcomings in the current type system implementation, only emit this 156 // FIXME: Due to shortcomings in the current type system implementation, only emit this
157 // diagnostic if there are no type mismatches in the containing function. 157 // diagnostic if there are no type mismatches in the containing function.
158 if self.infer.type_mismatches.iter().next().is_some() { 158 if self.infer.type_mismatches.iter().next().is_some() {
159 return Some(()); 159 return None;
160 } 160 }
161 161
162 let is_method_call = matches!(expr, Expr::MethodCall { .. }); 162 let is_method_call = matches!(expr, Expr::MethodCall { .. });
@@ -170,6 +170,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
170 let mut args = args.clone(); 170 let mut args = args.clone();
171 args.insert(0, *receiver); 171 args.insert(0, *receiver);
172 172
173 let receiver = &self.infer.type_of_expr[*receiver];
174 if receiver.strip_references().is_unknown() {
175 // if the receiver is of unknown type, it's very likely we
176 // don't know enough to correctly resolve the method call.
177 // This is kind of a band-aid for #6975.
178 return None;
179 }
180
173 // FIXME: note that we erase information about substs here. This 181 // FIXME: note that we erase information about substs here. This
174 // is not right, but, luckily, doesn't matter as we care only 182 // is not right, but, luckily, doesn't matter as we care only
175 // about the number of params 183 // about the number of params
@@ -505,6 +513,22 @@ fn f() {
505 } 513 }
506 514
507 #[test] 515 #[test]
516 fn method_unknown_receiver() {
517 // note: this is incorrect code, so there might be errors on this in the
518 // future, but we shouldn't emit an argument count diagnostic here
519 check_diagnostics(
520 r#"
521trait Foo { fn method(&self, arg: usize) {} }
522
523fn f() {
524 let x;
525 x.method();
526}
527"#,
528 );
529 }
530
531 #[test]
508 fn tuple_struct() { 532 fn tuple_struct() {
509 check_diagnostics( 533 check_diagnostics(
510 r#" 534 r#"