Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress follow-up errors in type checking #6975

Closed
flodiebold opened this issue Dec 21, 2020 · 16 comments
Closed

Suppress follow-up errors in type checking #6975

flodiebold opened this issue Dec 21, 2020 · 16 comments
Labels
A-ty type system / type inference / traits / method resolution E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@flodiebold
Copy link
Member

In this situation:

fn foo() {
    let x = something_broken;
    x.max(1);
}

we currently emit a mismatched-arg-count diagnostic because we resolve the max call to Iterator::max. We should avoid emitting diagnostics in such a situation, because x was already of an unknown type.

Doing this isn't easy though and requires some refactoring, so this issue is unactionable for now.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Dec 21, 2020
@flodiebold flodiebold added E-unknown It's unclear if the issue is E-hard or E-easy without digging in E-hard and removed E-unknown It's unclear if the issue is E-hard or E-easy without digging in labels Dec 21, 2020
@lnicola
Copy link
Member

lnicola commented Dec 30, 2020

Just curious, how are we resolving max on an unknown type? Is chalk doing that?

@bjorn3
Copy link
Member

bjorn3 commented Dec 30, 2020

No, that is something rust-analyzer does. Chalk only handles trait solving, not method resolution.

@lnicola
Copy link
Member

lnicola commented Dec 30, 2020

So does this happen for inherent methods too, or only for trait methods? It seems like something is saying "we don't know the type of x, but max must be Iterator::max because it's in scope".

@flodiebold
Copy link
Member Author

During method resolution, we ask Chalk 'does this unknown type implement that trait?' and Chalk says 'maybe', so we select the method.

One easy step that would fix most of the issues already would be to check in the argument count diagnostic whether the receiver is unknown.

@lnicola
Copy link
Member

lnicola commented Dec 30, 2020

Would it make sense to take "maybe" as "no"? I'm not sure how often that happens, but in the long run I'd assume that's what the compiler will do.

@flodiebold
Copy link
Member Author

No, at that point we need to accept 'maybe'; the compiler does the same. When the method is selected, an obligation is registered to make sure it later becomes a 'yes'.

@flodiebold
Copy link
Member Author

One easy step that would fix most of the issues already would be to check in the argument count diagnostic whether the receiver is unknown.

Did that: #7125

@grinapo
Copy link

grinapo commented Feb 11, 2021

I'm not sure this is the same but I get mismatched-arg-count for this (possibly stupid) fragment:

       let r = rows.next(); // rusqlite::Rows
       match r { 
            Some(r) => match r {
               Ok(r) => {
                    println!( "{:20} {:<10}  {:>20}→{:>20} {:15} {:15}⇒{:15} {:15} {:20} (c{})",  
                        r.get::<usize,String>(5), r.get::<usize,String>(1),

while it compiles fine.

@flodiebold
Copy link
Member Author

I assume you get the error on the get calls? What type does RA show for r?

@grinapo
Copy link

grinapo commented Feb 11, 2021

The bold parts are complained at:
r.get::<usize,String>(5), r.get::<usize,String>(1),

r is a Row according to the popup in vscode.

@flodiebold
Copy link
Member Author

That's weird. Can you make a new issue, ideally with a small reproduction?

@Veykril
Copy link
Member

Veykril commented Mar 4, 2023

Is this still relevant? The initial snippet no longer triggers a diagnostic for me

@flodiebold
Copy link
Member Author

I think the general topic is still relevant.

@Ten0
Copy link

Ten0 commented Mar 7, 2023

Since the recent update I'm getting:

no field `xxx` on type `&{unknown}`

errors. Shouldn't we silence such errors when the type involves unknown?

@lnicola
Copy link
Member

lnicola commented Aug 29, 2024

Can we close this after #16583 and the previous changes?

@Veykril
Copy link
Member

Veykril commented Aug 29, 2024

I'd say yes, there are probaly more occasions we should look at but those will pop up when we find them

@Veykril Veykril closed this as completed Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

6 participants