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

Confusing interaction between deref coercion and unknown type #56036

Closed
euclio opened this issue Nov 18, 2018 · 4 comments · Fixed by #106199
Closed

Confusing interaction between deref coercion and unknown type #56036

euclio opened this issue Nov 18, 2018 · 4 comments · Fixed by #106199
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@euclio
Copy link
Contributor

euclio commented Nov 18, 2018

I wrote something like the following code:

// fn function_that_doesnt_exist() -> String {
//    String::new()
// }

fn test(s: &str) {
    println!("{}", s);
}

fn test2(s: String) {
    println!("{}", s);
}

fn main() {
    let s = function_that_doesnt_exist();
    test(&s);
    test2(s);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=4be367b5c1d5a1d3d6eb20001c171825

Notice that the actual error is the missing function_that_doesnt_exist, but the compiler confusingly reports errors about str not having a size known at compile time, presumably because it infers the type of s as str. When I was writing this code, I missed the message about the missing function, so I was left scratching my head for a bit. It might be nice to silence such errors when the type of the variable is unknowable.

@estebank
Copy link
Contributor

CC #50333 #56607

I believe that s should be marked as TyErr, which will cause the knock down errors to be elided.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 19, 2019
@VirrageS
Copy link
Contributor

It seems to be fixed

@euclio
Copy link
Contributor Author

euclio commented Jan 16, 2020

Not fully, there's still a "mismatched types" error that ideally shouldn't be emitted:

error[E0425]: cannot find function `function_that_doesnt_exist` in this scope
  --> src/main.rs:14:13
   |
14 |     let s = function_that_doesnt_exist();
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0308]: mismatched types
  --> src/main.rs:16:11
   |
16 |     test2(s);
   |           ^
   |           |
   |           expected struct `std::string::String`, found `str`
   |           help: try using a conversion method: `s.to_string()`

@VirrageS
Copy link
Contributor

Yup, right. Sorry! I was fixated on "not having a size known at compile time" that I didn't notice that we still produce an error for inferred type.

@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 16, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 26, 2020
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 28, 2022
…, r=compiler-errors

Silence knock-down errors on `[type error]` bindings

Fix rust-lang#56036, fix rust-lang#76589.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 28, 2022
…, r=compiler-errors

Silence knock-down errors on `[type error]` bindings

Fix rust-lang#56036, fix rust-lang#76589.
@bors bors closed this as completed in 8e039b6 Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants