Uh oh!
There was an error while loading. Please reload this page.
Remove err methods - #42887
Conversation
rust-highfive
commented
Jun 24, 2017
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
eddyb
commented
Jun 24, 2017
1b59d3a to
fc2b380Compare
nikomatsakis
left a comment
There was a problem hiding this comment.
Left a few suggestions for the wording. What do you think? My sense is that the extended descriptions are a good place to offer a bit more background information.
There was a problem hiding this comment.
This example is simple, but it does conflate an uninitialized value with one where we do not know the type. An alternative might be something like this:
letmut x = vec![];match x.pop(){Some(v) => {// Here, the type of `v` is not (yet) known, so we// cannot resolve this method call:
v.to_uppercase();}None => {}}This could be fixed by annotating x with a type, like x: Vec<String>. To make it more realistic, we'd need a loop or something else.
Another example that I encounter a lot:
let vec1 = vec![1,2,3];let vec2 = vec1.iter().map(|x| x *2).collect();println!("{}", vec2.len());// errorwith the fix:
let vec1 = vec![1,2,3];let vec2:Vec<_> = vec1.iter().map(|x| x *2).collect();println!("{}", vec2.len());// errorthe problem with this one, of course, is that it references the iterator API. But we could probably explain it just by saying that "because collect() can create many kinds of collections, the type is typically inferred from context." or something like that.
There was a problem hiding this comment.
Wo, this example is way better. Great idea!
There was a problem hiding this comment.
I think we could say a bit more here. This message would perhaps be mildly easier to write if we knew what operation was giving it, but anyhow. (As an aside, this is (yet another...) of those messages that would be greatly improved by a "context sensitive" --explain mechanism, I think).
The type-checker needed to know the type of an expression,
but that type had not yet been inferred. This is most often
fixed by adding a type annotation.
We could go on to give more context, but it may be overkill:
Type inference typically proceeds from the top of the
function to the bottom, figuring out types as it goes.
In some cases -- notably method calls and overloadable
operators like `*` -- the type checker may not have enough
information *yet* to make progress. This can be true even if the
rest of the function provides enough context (because the type-checker
hasn't looked that far ahead yet). In this case, type annotations can be
used to help it along. There was a problem hiding this comment.
The first sentence isn't supposed to be an explanation, just a short recap of the error. However this explanation could replace the current one since it's (way) more complete.
There was a problem hiding this comment.
Maybe something like this?
In Rust, some types don't have a don't have a known size at compile-time.
For example, in a slice type like [u32], the number of elements is not known
at compile-time and hence the overall size cannot be computed. As a result,
such types can only be manipulated through a reference (e.g., &T or &mut T)
or other pointer-type (e.g., Box or Rc). Try casting to a reference instead:
let x = &[1_usize, 2] as &[usize]; // ok!
GuillaumeGomez
commented
Jun 27, 2017
Now that the previous one has been merged, I just need to make this one works. |
GuillaumeGomez
commented
Jun 27, 2017
Updated. |
99a8998 to
c831329Comparer=me when fixed |
c831329 to
03eb963CompareGuillaumeGomez
commented
Jun 28, 2017
@bors: r=nikomatsakis |
bors
commented
Jun 28, 2017
📌 Commit 03eb963 has been approved by |
GuillaumeGomez
commented
Jun 29, 2017
@bors: r- |
03eb963 to
5acc1deCompareGuillaumeGomez
commented
Jun 29, 2017
@bors: r=nikomatsakis |
bors
commented
Jun 29, 2017
📌 Commit 5acc1de has been approved by |
bors
commented
Jun 29, 2017
Remove err methods To be merged after #42519. cc @Susurrus@QuietMisdreavus
bors
commented
Jun 29, 2017
☀️ Test successful - status-appveyor, status-travis |
To be merged after #42519.
cc @Susurrus@QuietMisdreavus