-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Backwards propagation of types leads to unhelpful errors [futures] #46606
Comments
cc @alexcrichton for futures-rs |
So we are pretty much not going to be doing trait-based expected type propagation, which would be required to give an error on the call to |
Building this repo today gives
which is probably because it didn't clamp the crate versions. Changing the |
Ok, this confused me too. Then I realized back in 2017 that I had one remote repo for all tokio-related bugs and different branches for each. The error you are quoting is from the master branch, if you check out I don't do this any more, but it seems that at the time I had a Makefile that captured the output of diff --git a/cargo.out b/cargo.out
index d2607d1..2735df2 100644
--- a/cargo.out
+++ b/cargo.out
@@ -1,25 +1,21 @@
- Compiling futuretest v0.1.0 (file:///mnt/c/Users/Mahmoud/git/futuretest)
-error[E0271]: type mismatch resolving `<futures::FutureResult<(), std::string::String> as futures::IntoFuture>::Error == &str`
+ Compiling futuretest v0.1.0 (/mnt/d/GIT/futuretest)
+error[E0271]: type mismatch resolving `<Failed<(), String> as futures::IntoFuture>::Error == &str`
--> src/main.rs:13:10
|
13 | .and_then(|_|
- | ^^^^^^^^ expected struct `std::string::String`, found &str
- |
- = note: expected type `std::string::String`
- found type `&str`
+ | ^^^^^^^^ expected struct `String`, found `&str`
-error[E0271]: type mismatch resolving `<futures::FutureResult<(), std::string::String> as futures::IntoFuture>::Error == &str`
+error[E0271]: type mismatch resolving `<Failed<(), String> as futures::IntoFuture>::Error == &str`
--> src/main.rs:20:10
|
20 | core.run(f).unwrap();
- | ^^^ expected struct `std::string::String`, found &str
+ | ^^^ expected struct `String`, found `&str`
|
- = note: expected type `std::string::String`
- found type `&str`
- = note: required because of the requirements on the impl of `futures::Future` for `futures::AndThen<futures::Map<futures::MapErr<futures::FutureResult<(), ()>, [closure@src/main.rs:11:18: 11:43]>, [closure@src/main.rs:12:14: 12:67]>, futures::FutureResult<(), std::string::String>, [closure@src/main.rs:13:19: 16:14]>`
+ = note: required because of the requirements on the impl of `futures::Future` for `futures::AndThen<futures::Map<futures::MapErr<Failed<(), ()>, [closure@src/main.rs:11:18: 11:43]>, [closure@src/main.rs:12:14: 12:67]>, Failed<(), String>, [closure@src/main.rs:13:19: 16:14]>`
error: aborting due to 2 previous errors
-error: Could not compile `futuretest`.
+For more information about this error, try `rustc --explain E0271`.
+error: could not compile `futuretest` |
It's a shame to see that the error wasn't improved by any of the changes we've made since then, but at least this is now triaged. Thank you for looking back at what you did 4 years ago to clarify this! |
No problem. I guess we can remove E-needs-mcve? @rustbot label -E-needs-cve |
Minimized example with almost identical first diagnostic (removed second, as it's basically a duplicate): pub trait Foo {
type Assoc;
fn foo<F, B>(&self, _: F)
where
F: FnOnce() -> B,
B: Foo<Assoc = Self::Assoc>,
{}
}
impl<T> Foo for T {
type Assoc = T;
}
fn item<T>(item: T) -> T {
item
}
fn main() {
item("&'static str error")
.foo(|| "String error".to_owned());
} This includes a note about Some variants without the |
In general, and I genuinely wish I had a citation for this, developers likely tend to write their software going from input to output, even if the output is the eventual, fixed "goal" they would like to reach.
For example, the code here (git checkout available): https://git.neosmart.net/mqudsi/futuretest/src/rust-46606
Two conflicting error types are mapped, the first is to
&'static str
and the second is toString
, the compiler output indicates an error with the&'static str
type instead of theString
type usage:In an ideal situation, all types would match up and it wouldn't matter which line the type inference began with. But in the event of a type mismatch, such as here, the reported errors are based off the backwards type propagation, which doesn't seem right (opinion) and leads to an unhelpful error message (fact).
(To make the case a bit clearer, I included several uses of the correct type followed by a final usage of the incorrect type).
The text was updated successfully, but these errors were encountered: