From deb1eb6134a8ac22c55dc3e9713d667ff352ecf5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 9 Jun 2017 22:04:29 +0200 Subject: [PATCH] wording improvement --- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/diagnostics.rs | 27 ++++++++++--------- src/test/compile-fail/cast-from-nil.rs | 2 +- src/test/compile-fail/cast-to-bare-fn.rs | 4 +-- src/test/compile-fail/cast-to-nil.rs | 2 +- src/test/compile-fail/closure-no-fn-3.rs | 2 +- src/test/compile-fail/coerce-to-bang-cast.rs | 2 +- src/test/compile-fail/fat-ptr-cast.rs | 2 +- src/test/compile-fail/issue-10991.rs | 2 +- src/test/compile-fail/issue-22289.rs | 2 +- src/test/compile-fail/issue-22312.rs | 2 +- src/test/compile-fail/issue-2995.rs | 2 +- src/test/compile-fail/nonscalar-cast.rs | 4 +-- .../tag-variant-cast-non-nullary.rs | 4 +-- .../compile-fail/uninhabited-enum-cast.rs | 2 +- .../ui/mismatched_types/cast-rfc0401.stderr | 10 +++---- .../ui/mismatched_types/issue-26480.stderr | 2 +- 17 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 52962e1e478c..aec9d6f16d24 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -217,7 +217,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } CastError::NonScalar => { struct_span_err!(fcx.tcx.sess, self.span, E0605, - "non-scalar cast: `{}` as `{}`", + "non-primitive cast: `{}` as `{}`", self.expr_ty, fcx.ty_to_string(self.cast_ty)) .note("an `as` expression can only be used to convert between \ diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index ae13e236743d..f9b44f0395fc 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4209,7 +4209,7 @@ println!("{}", v[2]); "##, E0604: r##" -A cast to `char` was attempted on another type than `u8`. +A cast to `char` was attempted on a type other than `u8`. Erroneous code example: @@ -4217,11 +4217,11 @@ Erroneous code example: 0u32 as char; // error: only `u8` can be cast as `char`, not `u32` ``` -As the error message indicates, only `u8` can be casted into `char`. Example: +As the error message indicates, only `u8` can be cast into `char`. Example: ``` let c = 86u8 as char; // ok! -assert!(c, 'V'); +assert_eq!(c, 'V'); ``` "##, @@ -4232,15 +4232,15 @@ Erroneous code examples: ```compile_fail,E0605 let x = 0u8; -x as Vec; // error: non-scalar cast: `u8` as `std::vec::Vec` +x as Vec; // error: non-primitive cast: `u8` as `std::vec::Vec` // Another example let v = 0 as *const u8; // So here, `v` is a `*const u8`. -v as &u8; // error: non-scalar cast: `*const u8` as `&u8` +v as &u8; // error: non-primitive cast: `*const u8` as `&u8` ``` -Only primitive types cast be casted into each others. Examples: +Only primitive types can be cast into each other. Examples: ``` let x = 0u8; @@ -4261,8 +4261,8 @@ let x = &0u8; // Here, `x` is a `&u8`. let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid ``` -When casting, keep in mind that only primitive types cast be casted into each -others. Example: +When casting, keep in mind that only primitive types can be cast into each +other. Example: ``` let x = &0u8; @@ -4282,15 +4282,16 @@ v as *const [u8]; First: what are thin and fat pointers? -Thin pointers are "simple" pointers that simply reference a memory address. +Thin pointers are "simple" pointers: they are purely a reference to a memory +address. Fat pointers are pointers referencing Dynamically Sized Types (also called DST). -They don't have a statically known size, therefore they can only exist behind +DST don't have a statically known size, therefore they can only exist behind some kind of pointers that contain additional information. Slices and trait -objects are DSTs. +objects are DSTs. In the case of slices, the additional information the fat +pointer holds is their size. -So in order to fix this error, don't try to cast directly between thin and fat -pointers. +To fix this error, don't try to cast directly between thin and fat pointers. "##, E0609: r##" diff --git a/src/test/compile-fail/cast-from-nil.rs b/src/test/compile-fail/cast-from-nil.rs index 4c6dcaccc9ae..ab22d3524807 100644 --- a/src/test/compile-fail/cast-from-nil.rs +++ b/src/test/compile-fail/cast-from-nil.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: non-scalar cast: `()` as `u32` +// error-pattern: non-primitive cast: `()` as `u32` fn main() { let u = (assert!(true) as u32); } diff --git a/src/test/compile-fail/cast-to-bare-fn.rs b/src/test/compile-fail/cast-to-bare-fn.rs index 7cc5c727bc7d..d5a998c6e4b6 100644 --- a/src/test/compile-fail/cast-to-bare-fn.rs +++ b/src/test/compile-fail/cast-to-bare-fn.rs @@ -13,8 +13,8 @@ fn foo(_x: isize) { } fn main() { let v: u64 = 5; let x = foo as extern "C" fn() -> isize; - //~^ ERROR non-scalar cast + //~^ ERROR non-primitive cast let y = v as extern "Rust" fn(isize) -> (isize, isize); - //~^ ERROR non-scalar cast + //~^ ERROR non-primitive cast y(x()); } diff --git a/src/test/compile-fail/cast-to-nil.rs b/src/test/compile-fail/cast-to-nil.rs index e5fd5bb33eb9..27d9e8a42b18 100644 --- a/src/test/compile-fail/cast-to-nil.rs +++ b/src/test/compile-fail/cast-to-nil.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: non-scalar cast: `u32` as `()` +// error-pattern: non-primitive cast: `u32` as `()` fn main() { let u = 0u32 as (); } diff --git a/src/test/compile-fail/closure-no-fn-3.rs b/src/test/compile-fail/closure-no-fn-3.rs index 85dbc899208f..6584c16c9dec 100644 --- a/src/test/compile-fail/closure-no-fn-3.rs +++ b/src/test/compile-fail/closure-no-fn-3.rs @@ -14,5 +14,5 @@ fn main() { let b = 0u8; let baz: fn() -> u8 = (|| { b }) as fn() -> u8; - //~^ ERROR non-scalar cast + //~^ ERROR non-primitive cast } diff --git a/src/test/compile-fail/coerce-to-bang-cast.rs b/src/test/compile-fail/coerce-to-bang-cast.rs index 57d2192e6356..0479f5cce653 100644 --- a/src/test/compile-fail/coerce-to-bang-cast.rs +++ b/src/test/compile-fail/coerce-to-bang-cast.rs @@ -17,7 +17,7 @@ fn cast_a() { } fn cast_b() { - let y = 22 as !; //~ ERROR non-scalar cast + let y = 22 as !; //~ ERROR non-primitive cast } fn main() { } diff --git a/src/test/compile-fail/fat-ptr-cast.rs b/src/test/compile-fail/fat-ptr-cast.rs index c62987a5b900..bc2dc1cc5d4c 100644 --- a/src/test/compile-fail/fat-ptr-cast.rs +++ b/src/test/compile-fail/fat-ptr-cast.rs @@ -22,7 +22,7 @@ fn main() { a as isize; //~ ERROR casting a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid - b as usize; //~ ERROR non-scalar cast + b as usize; //~ ERROR non-primitive cast p as usize; //~^ ERROR casting //~^^ HELP cast through a thin pointer diff --git a/src/test/compile-fail/issue-10991.rs b/src/test/compile-fail/issue-10991.rs index 25060b94dcf3..2d00f339f33a 100644 --- a/src/test/compile-fail/issue-10991.rs +++ b/src/test/compile-fail/issue-10991.rs @@ -10,5 +10,5 @@ fn main() { let nil = (); - let _t = nil as usize; //~ ERROR: non-scalar cast: `()` as `usize` + let _t = nil as usize; //~ ERROR: non-primitive cast: `()` as `usize` } diff --git a/src/test/compile-fail/issue-22289.rs b/src/test/compile-fail/issue-22289.rs index bcbc414d3534..c23fc4f33447 100644 --- a/src/test/compile-fail/issue-22289.rs +++ b/src/test/compile-fail/issue-22289.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - 0 as &std::any::Any; //~ ERROR non-scalar cast + 0 as &std::any::Any; //~ ERROR non-primitive cast } diff --git a/src/test/compile-fail/issue-22312.rs b/src/test/compile-fail/issue-22312.rs index 4d6e6eded211..2128c4206301 100644 --- a/src/test/compile-fail/issue-22312.rs +++ b/src/test/compile-fail/issue-22312.rs @@ -19,7 +19,7 @@ pub trait Array2D: Index { } let i = y * self.columns() + x; let indexer = &(*self as &Index>::Output>); - //~^ERROR non-scalar cast + //~^ERROR non-primitive cast Some(indexer.index(i)) } } diff --git a/src/test/compile-fail/issue-2995.rs b/src/test/compile-fail/issue-2995.rs index 8fbf97411cc7..d735e184d5cd 100644 --- a/src/test/compile-fail/issue-2995.rs +++ b/src/test/compile-fail/issue-2995.rs @@ -9,7 +9,7 @@ // except according to those terms. fn bad (p: *const isize) { - let _q: &isize = p as &isize; //~ ERROR non-scalar cast + let _q: &isize = p as &isize; //~ ERROR non-primitive cast } fn main() { } diff --git a/src/test/compile-fail/nonscalar-cast.rs b/src/test/compile-fail/nonscalar-cast.rs index d6f274da967d..0abbc05eef05 100644 --- a/src/test/compile-fail/nonscalar-cast.rs +++ b/src/test/compile-fail/nonscalar-cast.rs @@ -8,13 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:non-scalar cast - #[derive(Debug)] struct foo { x: isize } fn main() { - println!("{}", foo{ x: 1 } as isize); + println!("{}", foo{ x: 1 } as isize); //~ non-primitive cast: `foo` as `isize` [E0605] } diff --git a/src/test/compile-fail/tag-variant-cast-non-nullary.rs b/src/test/compile-fail/tag-variant-cast-non-nullary.rs index b01063291266..220537633eaf 100644 --- a/src/test/compile-fail/tag-variant-cast-non-nullary.rs +++ b/src/test/compile-fail/tag-variant-cast-non-nullary.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//error-pattern: non-scalar cast - enum non_nullary { nullary, other(isize), @@ -17,5 +15,5 @@ enum non_nullary { fn main() { let v = non_nullary::nullary; - let val = v as isize; + let val = v as isize; //~ ERROR non-primitive cast: `non_nullary` as `isize` [E0605] } diff --git a/src/test/compile-fail/uninhabited-enum-cast.rs b/src/test/compile-fail/uninhabited-enum-cast.rs index b4df5fb1e2ac..2a5d25e6b98d 100644 --- a/src/test/compile-fail/uninhabited-enum-cast.rs +++ b/src/test/compile-fail/uninhabited-enum-cast.rs @@ -11,7 +11,7 @@ enum E {} fn f(e: E) { - println!("{}", (e as isize).to_string()); //~ ERROR non-scalar cast + println!("{}", (e as isize).to_string()); //~ ERROR non-primitive cast } fn main() {} diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index 50e181505792..879acbcf9d9d 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -20,7 +20,7 @@ error[E0609]: no field `f` on type `fn() {main}` 75 | let _ = main.f as *const u32; | ^ -error[E0605]: non-scalar cast: `*const u8` as `&u8` +error[E0605]: non-primitive cast: `*const u8` as `&u8` --> $DIR/cast-rfc0401.rs:39:13 | 39 | let _ = v as &u8; @@ -28,7 +28,7 @@ error[E0605]: non-scalar cast: `*const u8` as `&u8` | = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait -error[E0605]: non-scalar cast: `*const u8` as `E` +error[E0605]: non-primitive cast: `*const u8` as `E` --> $DIR/cast-rfc0401.rs:40:13 | 40 | let _ = v as E; @@ -36,7 +36,7 @@ error[E0605]: non-scalar cast: `*const u8` as `E` | = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait -error[E0605]: non-scalar cast: `*const u8` as `fn()` +error[E0605]: non-primitive cast: `*const u8` as `fn()` --> $DIR/cast-rfc0401.rs:41:13 | 41 | let _ = v as fn(); @@ -44,7 +44,7 @@ error[E0605]: non-scalar cast: `*const u8` as `fn()` | = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait -error[E0605]: non-scalar cast: `*const u8` as `(u32,)` +error[E0605]: non-primitive cast: `*const u8` as `(u32,)` --> $DIR/cast-rfc0401.rs:42:13 | 42 | let _ = v as (u32,); @@ -52,7 +52,7 @@ error[E0605]: non-scalar cast: `*const u8` as `(u32,)` | = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait -error[E0605]: non-scalar cast: `std::option::Option<&*const u8>` as `*const u8` +error[E0605]: non-primitive cast: `std::option::Option<&*const u8>` as `*const u8` --> $DIR/cast-rfc0401.rs:43:13 | 43 | let _ = Some(&v) as *const u8; diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr index 06b880690029..9da9042e78ed 100644 --- a/src/test/ui/mismatched_types/issue-26480.stderr +++ b/src/test/ui/mismatched_types/issue-26480.stderr @@ -7,7 +7,7 @@ error[E0308]: mismatched types 37 | write!(hello); | -------------- in this macro invocation -error[E0605]: non-scalar cast: `{integer}` as `()` +error[E0605]: non-primitive cast: `{integer}` as `()` --> $DIR/issue-26480.rs:32:19 | 32 | ($x:expr) => ($x as ())