Skip to content

Commit deb1eb6

Browse files
wording improvement
1 parent 7b8c6a2 commit deb1eb6

17 files changed

+35
-38
lines changed

src/librustc_typeck/check/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
217217
}
218218
CastError::NonScalar => {
219219
struct_span_err!(fcx.tcx.sess, self.span, E0605,
220-
"non-scalar cast: `{}` as `{}`",
220+
"non-primitive cast: `{}` as `{}`",
221221
self.expr_ty,
222222
fcx.ty_to_string(self.cast_ty))
223223
.note("an `as` expression can only be used to convert between \

src/librustc_typeck/diagnostics.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,19 +4209,19 @@ println!("{}", v[2]);
42094209
"##,
42104210

42114211
E0604: r##"
4212-
A cast to `char` was attempted on another type than `u8`.
4212+
A cast to `char` was attempted on a type other than `u8`.
42134213
42144214
Erroneous code example:
42154215
42164216
```compile_fail,E0604
42174217
0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
42184218
```
42194219
4220-
As the error message indicates, only `u8` can be casted into `char`. Example:
4220+
As the error message indicates, only `u8` can be cast into `char`. Example:
42214221
42224222
```
42234223
let c = 86u8 as char; // ok!
4224-
assert!(c, 'V');
4224+
assert_eq!(c, 'V');
42254225
```
42264226
"##,
42274227

@@ -4232,15 +4232,15 @@ Erroneous code examples:
42324232
42334233
```compile_fail,E0605
42344234
let x = 0u8;
4235-
x as Vec<u8>; // error: non-scalar cast: `u8` as `std::vec::Vec<u8>`
4235+
x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
42364236
42374237
// Another example
42384238
42394239
let v = 0 as *const u8; // So here, `v` is a `*const u8`.
4240-
v as &u8; // error: non-scalar cast: `*const u8` as `&u8`
4240+
v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
42414241
```
42424242
4243-
Only primitive types cast be casted into each others. Examples:
4243+
Only primitive types can be cast into each other. Examples:
42444244
42454245
```
42464246
let x = 0u8;
@@ -4261,8 +4261,8 @@ let x = &0u8; // Here, `x` is a `&u8`.
42614261
let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid
42624262
```
42634263
4264-
When casting, keep in mind that only primitive types cast be casted into each
4265-
others. Example:
4264+
When casting, keep in mind that only primitive types can be cast into each
4265+
other. Example:
42664266
42674267
```
42684268
let x = &0u8;
@@ -4282,15 +4282,16 @@ v as *const [u8];
42824282
42834283
First: what are thin and fat pointers?
42844284
4285-
Thin pointers are "simple" pointers that simply reference a memory address.
4285+
Thin pointers are "simple" pointers: they are purely a reference to a memory
4286+
address.
42864287
42874288
Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
4288-
They don't have a statically known size, therefore they can only exist behind
4289+
DST don't have a statically known size, therefore they can only exist behind
42894290
some kind of pointers that contain additional information. Slices and trait
4290-
objects are DSTs.
4291+
objects are DSTs. In the case of slices, the additional information the fat
4292+
pointer holds is their size.
42914293
4292-
So in order to fix this error, don't try to cast directly between thin and fat
4293-
pointers.
4294+
To fix this error, don't try to cast directly between thin and fat pointers.
42944295
"##,
42954296

42964297
E0609: r##"

src/test/compile-fail/cast-from-nil.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: non-scalar cast: `()` as `u32`
11+
// error-pattern: non-primitive cast: `()` as `u32`
1212
fn main() { let u = (assert!(true) as u32); }

src/test/compile-fail/cast-to-bare-fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn foo(_x: isize) { }
1313
fn main() {
1414
let v: u64 = 5;
1515
let x = foo as extern "C" fn() -> isize;
16-
//~^ ERROR non-scalar cast
16+
//~^ ERROR non-primitive cast
1717
let y = v as extern "Rust" fn(isize) -> (isize, isize);
18-
//~^ ERROR non-scalar cast
18+
//~^ ERROR non-primitive cast
1919
y(x());
2020
}

src/test/compile-fail/cast-to-nil.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: non-scalar cast: `u32` as `()`
11+
// error-pattern: non-primitive cast: `u32` as `()`
1212
fn main() { let u = 0u32 as (); }

src/test/compile-fail/closure-no-fn-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
fn main() {
1515
let b = 0u8;
1616
let baz: fn() -> u8 = (|| { b }) as fn() -> u8;
17-
//~^ ERROR non-scalar cast
17+
//~^ ERROR non-primitive cast
1818
}

src/test/compile-fail/coerce-to-bang-cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn cast_a() {
1717
}
1818

1919
fn cast_b() {
20-
let y = 22 as !; //~ ERROR non-scalar cast
20+
let y = 22 as !; //~ ERROR non-primitive cast
2121
}
2222

2323
fn main() { }

src/test/compile-fail/fat-ptr-cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
a as isize; //~ ERROR casting
2323
a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid
2424
a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid
25-
b as usize; //~ ERROR non-scalar cast
25+
b as usize; //~ ERROR non-primitive cast
2626
p as usize;
2727
//~^ ERROR casting
2828
//~^^ HELP cast through a thin pointer

src/test/compile-fail/issue-10991.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
let nil = ();
13-
let _t = nil as usize; //~ ERROR: non-scalar cast: `()` as `usize`
13+
let _t = nil as usize; //~ ERROR: non-primitive cast: `()` as `usize`
1414
}

src/test/compile-fail/issue-22289.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
0 as &std::any::Any; //~ ERROR non-scalar cast
12+
0 as &std::any::Any; //~ ERROR non-primitive cast
1313
}

0 commit comments

Comments
 (0)