7125: Don't emit arg count diagnostics for method calls with unknown receiver r=flodiebold a=flodiebold

Fixes #7098.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2021-01-01 19:50:02 +00:00 committed by GitHub
commit b4a7caedb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -156,7 +156,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
// FIXME: Due to shortcomings in the current type system implementation, only emit this
// diagnostic if there are no type mismatches in the containing function.
if self.infer.type_mismatches.iter().next().is_some() {
return Some(());
return None;
}
let is_method_call = matches!(expr, Expr::MethodCall { .. });
@ -170,6 +170,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let mut args = args.clone();
args.insert(0, *receiver);
let receiver = &self.infer.type_of_expr[*receiver];
if receiver.strip_references().is_unknown() {
// if the receiver is of unknown type, it's very likely we
// don't know enough to correctly resolve the method call.
// This is kind of a band-aid for #6975.
return None;
}
// FIXME: note that we erase information about substs here. This
// is not right, but, luckily, doesn't matter as we care only
// about the number of params
@ -504,6 +512,22 @@ fn f() {
);
}
#[test]
fn method_unknown_receiver() {
// note: this is incorrect code, so there might be errors on this in the
// future, but we shouldn't emit an argument count diagnostic here
check_diagnostics(
r#"
trait Foo { fn method(&self, arg: usize) {} }
fn f() {
let x;
x.method();
}
"#,
);
}
#[test]
fn tuple_struct() {
check_diagnostics(

View file

@ -791,6 +791,10 @@ impl Ty {
matches!(self, Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }))
}
pub fn is_unknown(&self) -> bool {
matches!(self, Ty::Unknown)
}
/// If this is a `dyn Trait` type, this returns the `Trait` part.
pub fn dyn_trait_ref(&self) -> Option<&TraitRef> {
match self {