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

Mismatched type returned from log_file #26

Closed
ltfschoen opened this issue Apr 16, 2018 · 5 comments
Closed

Mismatched type returned from log_file #26

ltfschoen opened this issue Apr 16, 2018 · 5 comments
Labels

Comments

@ltfschoen
Copy link

I'm using fern = "0.5" in Cargo.toml

When I use the sample code in CLion IDE, the line .chain(fern::log_file("output.log")?) displays warning mismatched types expected Result<File, Error>, found File

When I go modify the Fern library file fern-0.5.5/src/lib.rs and change the signature from pub fn log_file<P: AsRef<Path>>(path: P) -> io::Result<File> { to pub fn log_file<P: AsRef<Path>>(path: P) -> File { then the warning disappears, and the implementation still outputs to the log file and terminal successfully.

ltfschoen added a commit to ltfschoen/fern that referenced this issue Apr 16, 2018
@daboross
Copy link
Owner

I don't believe it should compile if log_file is changed to return a File directly. Opening a file is an operation that can fail.

Could you elaborate about the mismatched type warnings? This seems like it's possibly an error in the IDE that we could investigate. Provided your function returns a Result, .chain(fern::log_file("output.log")?) should definitely be correct.

Fern's code does currently compile with no warnings from the rust compiler, and the example which uses fern::log_file also compiles without warnings.

@ltfschoen
Copy link
Author

ltfschoen commented Apr 16, 2018

I'm using CLion 2018.1.1 with macOS Sierra 10.12.6
I have Rust language support installed Version: 0.2.0.2092-181
I have installed the IntelliJ-Rust plugin into the CLion IDE https://intellij-rust.github.io/docs/quick-start.html
The Rust type checker is giving me error E0308 https://doc.rust-lang.org/error-index.html#E0308
The code compiles and runs correctly when I run cargo run even if don't change the return value from io::Result<File> to File, but if I make that change the warning in the IDE goes away

Below is a screenshot of what appears in the CLion IDE:

screen shot 2018-04-16 at 3 07 07 pm

Below is screenshot of the lib.rs file with the log_file function that is called by my code:

screen shot 2018-04-16 at 3 17 47 pm

After writing all the above, I decided to set a breakpoint on the line of code that calls log_file, with it changed to the File return type to see what that would do, and it displayed the below error:

screen shot 2018-04-16 at 3 21 28 pm

When I changed it back to io::Result<File> return type and ran with breakpoint set it did not result in error.

When I changed it back to File once again, built the code with cargo build and ran the code with the debugger the same way again (i.e. cargo run), strangely it didn't encounter the same error again, even on subsequent attempts. So I think it may be a bug with the IDE...

@daboross
Copy link
Owner

Hmm, it does seem to be some sort of ide error. The compiling output you show in your second screenshot is exactly what I'd expect if you change that code the way your PR did. It needs to return a Result.

Have you tried clearing all of CLion's caches and restarting? I'm 90% sure there should be an "invalidate caches & restart" option somewhere which could do this. If that doesn't fix it, there's probably some underlying bug in the rust plugin that needs to be reported at https://github.com/intellij-rust/intellij-rust?

@ltfschoen
Copy link
Author

I just tried "File > Invalidate Caches / Restart" from the menu but it still shows the same warning. I tried changing lib.rs to File again to remove the warning, but it still compiles and runs even in debugging mode without showing any errors in the IDE, which is strange. FYI, this is the code where I'm using it in the 'notary' branch, and i'm running the code with cargo run -- -mode b. Drops-of-Diamond/diamond_drops#32.
I'll create an Issue at https://github.com/intellij-rust/intellij-rust.
It appears that there are other similar issues previously raised such as this one: intellij-rust/intellij-rust#2461

@daboross
Copy link
Owner

Closing this as an IDE bug rather than a fern one.

If there's anything else I can do to help resolve this, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants