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

+1-1
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

+14-13
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub trait Array2D: Index<usize> {
1919
}
2020
let i = y * self.columns() + x;
2121
let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
22-
//~^ERROR non-scalar cast
22+
//~^ERROR non-primitive cast
2323
Some(indexer.index(i))
2424
}
2525
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn bad (p: *const isize) {
12-
let _q: &isize = p as &isize; //~ ERROR non-scalar cast
12+
let _q: &isize = p as &isize; //~ ERROR non-primitive cast
1313
}
1414

1515
fn main() { }

src/test/compile-fail/nonscalar-cast.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:non-scalar cast
12-
1311
#[derive(Debug)]
1412
struct foo {
1513
x: isize
1614
}
1715

1816
fn main() {
19-
println!("{}", foo{ x: 1 } as isize);
17+
println!("{}", foo{ x: 1 } as isize); //~ non-primitive cast: `foo` as `isize` [E0605]
2018
}

src/test/compile-fail/tag-variant-cast-non-nullary.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//error-pattern: non-scalar cast
12-
1311
enum non_nullary {
1412
nullary,
1513
other(isize),
1614
}
1715

1816
fn main() {
1917
let v = non_nullary::nullary;
20-
let val = v as isize;
18+
let val = v as isize; //~ ERROR non-primitive cast: `non_nullary` as `isize` [E0605]
2119
}

src/test/compile-fail/uninhabited-enum-cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
enum E {}
1212

1313
fn f(e: E) {
14-
println!("{}", (e as isize).to_string()); //~ ERROR non-scalar cast
14+
println!("{}", (e as isize).to_string()); //~ ERROR non-primitive cast
1515
}
1616

1717
fn main() {}

src/test/ui/mismatched_types/cast-rfc0401.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,39 @@ error[E0609]: no field `f` on type `fn() {main}`
2020
75 | let _ = main.f as *const u32;
2121
| ^
2222

23-
error[E0605]: non-scalar cast: `*const u8` as `&u8`
23+
error[E0605]: non-primitive cast: `*const u8` as `&u8`
2424
--> $DIR/cast-rfc0401.rs:39:13
2525
|
2626
39 | let _ = v as &u8;
2727
| ^^^^^^^^
2828
|
2929
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
3030

31-
error[E0605]: non-scalar cast: `*const u8` as `E`
31+
error[E0605]: non-primitive cast: `*const u8` as `E`
3232
--> $DIR/cast-rfc0401.rs:40:13
3333
|
3434
40 | let _ = v as E;
3535
| ^^^^^^
3636
|
3737
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
3838

39-
error[E0605]: non-scalar cast: `*const u8` as `fn()`
39+
error[E0605]: non-primitive cast: `*const u8` as `fn()`
4040
--> $DIR/cast-rfc0401.rs:41:13
4141
|
4242
41 | let _ = v as fn();
4343
| ^^^^^^^^^
4444
|
4545
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
4646

47-
error[E0605]: non-scalar cast: `*const u8` as `(u32,)`
47+
error[E0605]: non-primitive cast: `*const u8` as `(u32,)`
4848
--> $DIR/cast-rfc0401.rs:42:13
4949
|
5050
42 | let _ = v as (u32,);
5151
| ^^^^^^^^^^^
5252
|
5353
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
5454

55-
error[E0605]: non-scalar cast: `std::option::Option<&*const u8>` as `*const u8`
55+
error[E0605]: non-primitive cast: `std::option::Option<&*const u8>` as `*const u8`
5656
--> $DIR/cast-rfc0401.rs:43:13
5757
|
5858
43 | let _ = Some(&v) as *const u8;

src/test/ui/mismatched_types/issue-26480.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ error[E0308]: mismatched types
77
37 | write!(hello);
88
| -------------- in this macro invocation
99

10-
error[E0605]: non-scalar cast: `{integer}` as `()`
10+
error[E0605]: non-primitive cast: `{integer}` as `()`
1111
--> $DIR/issue-26480.rs:32:19
1212
|
1313
32 | ($x:expr) => ($x as ())

0 commit comments

Comments
 (0)