I’ve been thinking that it would be good to improve the hints/tips that the compiler offers to target the 2018 edition features directly. As a simple example, if one writes:
use foo::bar;
where foo is a global module, then the compiler should suggest use crate::foo::bar as a replacement.
On a more complex note, there have definitely been times when match default bindings can surprise people – e.g., you end up with a reference but don’t expect it. I have some thoughts about how to address that but it would be really helpful to have examples of code that didn’t compile where you had to scratch your head a bit. I assume there may be other features leading to surprises of this kind.
So I am starting this thread to request examples of code snippets where you think an improved error would’ve helped – ideally, with some notes on what you confused you specifically (if it is not obvious) or a suggestion you think would’ve helped.
//#1
trait S {
}
trait R<T> where T: S + Send + Clone {
}
fn main() {
let a : Box<dyn (S + Send)>;
}
the error is:
error: chained comparison operators require parentheses
--> src/main.rs:10:16
|
10 | let a : Box<dyn (S + Send)>;
| ^^^^^^^^^^^^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments
= help: or use `(...)` if you meant to specify fn arguments
error: expected one of `(`, `)`, `::`, or `<`, found `+`
--> src/main.rs:10:24
|
10 | let a : Box<dyn (S + Send)>;
| - ^ expected one of `(`, `)`, `::`, or `<` here
| |
| while parsing the type for `a`
and
// #2
trait S {
}
trait R<T> where T: S + Send + Clone {
}
fn main() {
let a : Box<(dyn S) + Send>;
}
the error is:
error[E0178]: expected a path on the left-hand side of `+`, not `(dyn S)`
--> src/main.rs:10:17
|
10 | let a : Box<(dyn S) + Send>;
| ^^^^^^^^^^^^^^ expected a path
error: aborting due to previous error
I think maybe one of these two is actually correct, but i’m not sure which one.
(I’m on PTO this week, but here’s a note to remind myself: we should look at tweaking the error messages around a case like this:
fn foo(
x: impl IntoIterator<Item = Display>
)
In particular, I think we should now suggest writing either dyn Display or impl Display. We opted not to make this a hard error but we can still change how we report Sized errors for dyn trait objects.