@@ -4665,6 +4665,67 @@ i_am_a_function();
4665
4665
```
4666
4666
"## ,
4667
4667
4668
+ E0619 : r##"
4669
+ The type-checker needed to know the type of an expression, but that type had not
4670
+ yet been inferred.
4671
+
4672
+ Erroneous code example:
4673
+
4674
+ ```compile_fail,E0619
4675
+ let mut x = vec![];
4676
+ match x.pop() {
4677
+ Some(v) => {
4678
+ // Here, the type of `v` is not (yet) known, so we
4679
+ // cannot resolve this method call:
4680
+ v.to_uppercase(); // error: the type of this value must be known in
4681
+ // this context
4682
+ }
4683
+ None => {}
4684
+ }
4685
+ ```
4686
+
4687
+ Type inference typically proceeds from the top of the function to the bottom,
4688
+ figuring out types as it goes. In some cases -- notably method calls and
4689
+ overloadable operators like `*` -- the type checker may not have enough
4690
+ information *yet* to make progress. This can be true even if the rest of the
4691
+ function provides enough context (because the type-checker hasn't looked that
4692
+ far ahead yet). In this case, type annotations can be used to help it along.
4693
+
4694
+ To fix this error, just specify the type of the variable. Example:
4695
+
4696
+ ```
4697
+ let mut x: Vec<String> = vec![]; // We precise the type of the vec elements.
4698
+ match x.pop() {
4699
+ Some(v) => {
4700
+ v.to_uppercase(); // Since rustc now knows the type of the vec elements,
4701
+ // we can use `v`'s methods.
4702
+ }
4703
+ None => {}
4704
+ }
4705
+ ```
4706
+ "## ,
4707
+
4708
+ E0620 : r##"
4709
+ A cast to an unsized type was attempted.
4710
+
4711
+ Erroneous code example:
4712
+
4713
+ ```compile_fail,E0620
4714
+ let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]`
4715
+ // as `[usize]`
4716
+ ```
4717
+
4718
+ In Rust, some types don't have a known size at compile-time. For example, in a
4719
+ slice type like `[u32]`, the number of elements is not known at compile-time and
4720
+ hence the overall size cannot be computed. As a result, such types can only be
4721
+ manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type
4722
+ (e.g., `Box` or `Rc`). Try casting to a reference instead:
4723
+
4724
+ ```
4725
+ let x = &[1_usize, 2] as &[usize]; // ok!
4726
+ ```
4727
+ "## ,
4728
+
4668
4729
}
4669
4730
4670
4731
register_diagnostics ! {
@@ -4736,5 +4797,4 @@ register_diagnostics! {
4736
4797
E0568 , // auto-traits can not have predicates,
4737
4798
E0588 , // packed struct cannot transitively contain a `[repr(align)]` struct
4738
4799
E0592 , // duplicate definitions with name `{}`
4739
- E0619 , // intrinsic must be a function
4740
4800
}
0 commit comments