Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f590a44

Browse files
committedJun 27, 2017
Auto merge of #42922 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: #42519, #42871, #42874, #42905, #42917 - Failed merges:
2 parents 77931c2 + d7a5508 commit f590a44

27 files changed

+336
-136
lines changed
 

‎src/librustc/hir/lowering.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,12 +2170,12 @@ impl<'a> LoweringContext<'a> {
21702170
// let result = match ::std::iter::IntoIterator::into_iter(<head>) {
21712171
// mut iter => {
21722172
// [opt_ident]: loop {
2173-
// let mut _next;
2173+
// let mut __next;
21742174
// match ::std::iter::Iterator::next(&mut iter) {
2175-
// ::std::option::Option::Some(val) => _next = val,
2175+
// ::std::option::Option::Some(val) => __next = val,
21762176
// ::std::option::Option::None => break
21772177
// };
2178-
// let <pat> = _next;
2178+
// let <pat> = __next;
21792179
// StmtExpr(<body>);
21802180
// }
21812181
// }
@@ -2188,7 +2188,7 @@ impl<'a> LoweringContext<'a> {
21882188

21892189
let iter = self.str_to_ident("iter");
21902190

2191-
let next_ident = self.str_to_ident("_next");
2191+
let next_ident = self.str_to_ident("__next");
21922192
let next_pat = self.pat_ident_binding_mode(e.span,
21932193
next_ident,
21942194
hir::BindByValue(hir::MutMutable));
@@ -2237,13 +2237,13 @@ impl<'a> LoweringContext<'a> {
22372237

22382238
let next_expr = P(self.expr_ident(e.span, next_ident, next_pat.id));
22392239

2240-
// `let mut _next`
2240+
// `let mut __next`
22412241
let next_let = self.stmt_let_pat(e.span,
22422242
None,
22432243
next_pat,
22442244
hir::LocalSource::ForLoopDesugar);
22452245

2246-
// `let <pat> = _next`
2246+
// `let <pat> = __next`
22472247
let pat = self.lower_pat(pat);
22482248
let pat_let = self.stmt_let_pat(e.span,
22492249
Some(next_expr),

‎src/librustc/lint/context.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,13 @@ impl LintStore {
291291
self.by_name.insert(name.into(), Removed(reason.into()));
292292
}
293293

294-
#[allow(unused_variables)]
295-
fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
296-
-> Result<LintId, FindLintError>
297-
{
294+
fn find_lint(&self, lint_name: &str) -> Result<LintId, FindLintError> {
298295
match self.by_name.get(lint_name) {
299296
Some(&Id(lint_id)) => Ok(lint_id),
300297
Some(&Renamed(_, lint_id)) => {
301298
Ok(lint_id)
302299
},
303-
Some(&Removed(ref reason)) => {
300+
Some(&Removed(_)) => {
304301
Err(FindLintError::Removed)
305302
},
306303
None => Err(FindLintError::NotFound)
@@ -313,7 +310,7 @@ impl LintStore {
313310
&lint_name[..], level);
314311

315312
let lint_flag_val = Symbol::intern(&lint_name);
316-
match self.find_lint(&lint_name[..], sess, None) {
313+
match self.find_lint(&lint_name[..]) {
317314
Ok(lint_id) => self.levels.set(lint_id, (level, CommandLine(lint_flag_val))),
318315
Err(FindLintError::Removed) => { }
319316
Err(_) => {
@@ -724,21 +721,22 @@ pub trait LintContext<'tcx>: Sized {
724721
let mut pushed = 0;
725722

726723
for result in gather_attrs(attrs) {
727-
let v = match result {
724+
let (is_group, lint_level_spans) = match result {
728725
Err(span) => {
729726
span_err!(self.sess(), span, E0452,
730727
"malformed lint attribute");
731728
continue;
732729
}
733730
Ok((lint_name, level, span)) => {
734-
match self.lints().find_lint(&lint_name.as_str(), &self.sess(), Some(span)) {
735-
Ok(lint_id) => vec![(lint_id, level, span)],
731+
match self.lints().find_lint(&lint_name.as_str()) {
732+
Ok(lint_id) => (false, vec![(lint_id, level, span)]),
736733
Err(FindLintError::NotFound) => {
737734
match self.lints().lint_groups.get(&*lint_name.as_str()) {
738-
Some(&(ref v, _)) => v.iter()
735+
Some(&(ref v, _)) => (true,
736+
v.iter()
739737
.map(|lint_id: &LintId|
740738
(*lint_id, level, span))
741-
.collect(),
739+
.collect()),
742740
None => {
743741
// The lint or lint group doesn't exist.
744742
// This is an error, but it was handled
@@ -754,14 +752,18 @@ pub trait LintContext<'tcx>: Sized {
754752

755753
let lint_attr_name = result.expect("lint attribute should be well-formed").0;
756754

757-
for (lint_id, level, span) in v {
755+
for (lint_id, level, span) in lint_level_spans {
758756
let (now, now_source) = self.lint_sess().get_source(lint_id);
759757
if now == Forbid && level != Forbid {
760-
let lint_name = lint_id.to_string();
758+
let forbidden_lint_name = match now_source {
759+
LintSource::Default => lint_id.to_string(),
760+
LintSource::Node(name, _) => name.to_string(),
761+
LintSource::CommandLine(name) => name.to_string(),
762+
};
761763
let mut diag_builder = struct_span_err!(self.sess(), span, E0453,
762764
"{}({}) overruled by outer forbid({})",
763-
level.as_str(), lint_name,
764-
lint_name);
765+
level.as_str(), lint_attr_name,
766+
forbidden_lint_name);
765767
diag_builder.span_label(span, "overruled by previous forbid");
766768
match now_source {
767769
LintSource::Default => &mut diag_builder,
@@ -772,7 +774,10 @@ pub trait LintContext<'tcx>: Sized {
772774
LintSource::CommandLine(_) => {
773775
diag_builder.note("`forbid` lint level was set on command line")
774776
}
775-
}.emit()
777+
}.emit();
778+
if is_group { // don't set a separate error for every lint in the group
779+
break;
780+
}
776781
} else if now != level {
777782
let cx = self.lint_sess_mut();
778783
cx.stack.push((lint_id, (now, now_source)));
@@ -1420,7 +1425,7 @@ impl Decodable for LintId {
14201425
fn decode<D: Decoder>(d: &mut D) -> Result<LintId, D::Error> {
14211426
let s = d.read_str()?;
14221427
ty::tls::with(|tcx| {
1423-
match tcx.sess.lint_store.borrow().find_lint(&s, tcx.sess, None) {
1428+
match tcx.sess.lint_store.borrow().find_lint(&s) {
14241429
Ok(id) => Ok(id),
14251430
Err(_) => panic!("invalid lint-id `{}`", s),
14261431
}

‎src/librustc_typeck/check/cast.rs

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
4141
use super::{Diverges, FnCtxt};
4242

43-
use lint;
43+
use errors::DiagnosticBuilder;
4444
use hir::def_id::DefId;
45+
use lint;
4546
use rustc::hir;
47+
use rustc::session::Session;
4648
use rustc::traits;
4749
use rustc::ty::{self, Ty, TypeFoldable};
4850
use rustc::ty::cast::{CastKind, CastTy};
@@ -112,6 +114,18 @@ enum CastError {
112114
NonScalar,
113115
}
114116

117+
fn make_invalid_casting_error<'a, 'gcx, 'tcx>(sess: &'a Session,
118+
span: Span,
119+
expr_ty: Ty<'tcx>,
120+
cast_ty: Ty<'tcx>,
121+
fcx: &FnCtxt<'a, 'gcx, 'tcx>)
122+
-> DiagnosticBuilder<'a> {
123+
type_error_struct!(sess, span, expr_ty, E0606,
124+
"casting `{}` as `{}` is invalid",
125+
fcx.ty_to_string(expr_ty),
126+
fcx.ty_to_string(cast_ty))
127+
}
128+
115129
impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
116130
pub fn new(fcx: &FnCtxt<'a, 'gcx, 'tcx>,
117131
expr: &'tcx hir::Expr,
@@ -146,14 +160,9 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
146160
match e {
147161
CastError::NeedDeref => {
148162
let error_span = self.span;
163+
let mut err = make_invalid_casting_error(fcx.tcx.sess, self.span, self.expr_ty,
164+
self.cast_ty, fcx);
149165
let cast_ty = fcx.ty_to_string(self.cast_ty);
150-
let mut err = fcx.type_error_struct(error_span,
151-
|actual| {
152-
format!("casting `{}` as `{}` is invalid",
153-
actual,
154-
cast_ty)
155-
},
156-
self.expr_ty);
157166
err.span_label(error_span,
158167
format!("cannot cast `{}` as `{}`",
159168
fcx.ty_to_string(self.expr_ty),
@@ -166,13 +175,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
166175
}
167176
CastError::NeedViaThinPtr |
168177
CastError::NeedViaPtr => {
169-
let mut err = fcx.type_error_struct(self.span,
170-
|actual| {
171-
format!("casting `{}` as `{}` is invalid",
172-
actual,
173-
fcx.ty_to_string(self.cast_ty))
174-
},
175-
self.expr_ty);
178+
let mut err = make_invalid_casting_error(fcx.tcx.sess, self.span, self.expr_ty,
179+
self.cast_ty, fcx);
176180
if self.cast_ty.is_uint() {
177181
err.help(&format!("cast through {} first",
178182
match e {
@@ -184,72 +188,47 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
184188
err.emit();
185189
}
186190
CastError::NeedViaInt => {
187-
fcx.type_error_struct(self.span,
188-
|actual| {
189-
format!("casting `{}` as `{}` is invalid",
190-
actual,
191-
fcx.ty_to_string(self.cast_ty))
192-
},
193-
self.expr_ty)
191+
make_invalid_casting_error(fcx.tcx.sess, self.span, self.expr_ty, self.cast_ty, fcx)
194192
.help(&format!("cast through {} first",
195193
match e {
196194
CastError::NeedViaInt => "an integer",
197195
_ => bug!(),
198196
}))
199197
.emit();
200198
}
199+
CastError::IllegalCast => {
200+
make_invalid_casting_error(fcx.tcx.sess, self.span, self.expr_ty, self.cast_ty, fcx)
201+
.emit();
202+
}
203+
CastError::DifferingKinds => {
204+
make_invalid_casting_error(fcx.tcx.sess, self.span, self.expr_ty, self.cast_ty, fcx)
205+
.note("vtable kinds may not match")
206+
.emit();
207+
}
201208
CastError::CastToBool => {
202209
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`")
203210
.span_label(self.span, "unsupported cast")
204211
.help("compare with zero instead")
205212
.emit();
206213
}
207214
CastError::CastToChar => {
208-
fcx.type_error_message(self.span,
209-
|actual| {
210-
format!("only `u8` can be cast as `char`, not `{}`",
211-
actual)
212-
},
213-
self.expr_ty);
215+
type_error_struct!(fcx.tcx.sess, self.span, self.expr_ty, E0604,
216+
"only `u8` can be cast as `char`, not `{}`", self.expr_ty).emit();
214217
}
215218
CastError::NonScalar => {
216-
fcx.type_error_message(self.span,
217-
|actual| {
218-
format!("non-scalar cast: `{}` as `{}`",
219-
actual,
220-
fcx.ty_to_string(self.cast_ty))
221-
},
222-
self.expr_ty);
223-
}
224-
CastError::IllegalCast => {
225-
fcx.type_error_message(self.span,
226-
|actual| {
227-
format!("casting `{}` as `{}` is invalid",
228-
actual,
229-
fcx.ty_to_string(self.cast_ty))
230-
},
231-
self.expr_ty);
219+
type_error_struct!(fcx.tcx.sess, self.span, self.expr_ty, E0605,
220+
"non-primitive cast: `{}` as `{}`",
221+
self.expr_ty,
222+
fcx.ty_to_string(self.cast_ty))
223+
.note("an `as` expression can only be used to convert between \
224+
primitive types. Consider using the `From` trait")
225+
.emit();
232226
}
233227
CastError::SizedUnsizedCast => {
234-
fcx.type_error_message(self.span,
235-
|actual| {
236-
format!("cannot cast thin pointer `{}` to fat pointer \
237-
`{}`",
238-
actual,
239-
fcx.ty_to_string(self.cast_ty))
240-
},
241-
self.expr_ty)
242-
}
243-
CastError::DifferingKinds => {
244-
fcx.type_error_struct(self.span,
245-
|actual| {
246-
format!("casting `{}` as `{}` is invalid",
247-
actual,
248-
fcx.ty_to_string(self.cast_ty))
249-
},
250-
self.expr_ty)
251-
.note("vtable kinds may not match")
252-
.emit();
228+
type_error_struct!(fcx.tcx.sess, self.span, self.expr_ty, E0607,
229+
"cannot cast thin pointer `{}` to fat pointer `{}`",
230+
self.expr_ty,
231+
fcx.ty_to_string(self.cast_ty)).emit();
253232
}
254233
}
255234
}

‎src/librustc_typeck/diagnostics.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,104 @@ println!("{}", v[2]);
42084208
```
42094209
"##,
42104210

4211+
E0604: r##"
4212+
A cast to `char` was attempted on a type other than `u8`.
4213+
4214+
Erroneous code example:
4215+
4216+
```compile_fail,E0604
4217+
0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
4218+
```
4219+
4220+
As the error message indicates, only `u8` can be cast into `char`. Example:
4221+
4222+
```
4223+
let c = 86u8 as char; // ok!
4224+
assert_eq!(c, 'V');
4225+
```
4226+
4227+
For more information about casts, take a look at The Book:
4228+
https://doc.rust-lang.org/book/first-edition/casting-between-types.html
4229+
"##,
4230+
4231+
E0605: r##"
4232+
An invalid cast was attempted.
4233+
4234+
Erroneous code examples:
4235+
4236+
```compile_fail,E0605
4237+
let x = 0u8;
4238+
x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
4239+
4240+
// Another example
4241+
4242+
let v = 0 as *const u8; // So here, `v` is a `*const u8`.
4243+
v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
4244+
```
4245+
4246+
Only primitive types can be cast into each other. Examples:
4247+
4248+
```
4249+
let x = 0u8;
4250+
x as u32; // ok!
4251+
4252+
let v = 0 as *const u8;
4253+
v as *const i8; // ok!
4254+
```
4255+
4256+
For more information about casts, take a look at The Book:
4257+
https://doc.rust-lang.org/book/first-edition/casting-between-types.html
4258+
"##,
4259+
4260+
E0606: r##"
4261+
An incompatible cast was attempted.
4262+
4263+
Erroneous code example:
4264+
4265+
```compile_fail,E0606
4266+
let x = &0u8; // Here, `x` is a `&u8`.
4267+
let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid
4268+
```
4269+
4270+
When casting, keep in mind that only primitive types can be cast into each
4271+
other. Example:
4272+
4273+
```
4274+
let x = &0u8;
4275+
let y: u32 = *x as u32; // We dereference it first and then cast it.
4276+
```
4277+
4278+
For more information about casts, take a look at The Book:
4279+
https://doc.rust-lang.org/book/first-edition/casting-between-types.html
4280+
"##,
4281+
4282+
E0607: r##"
4283+
A cast between a thin and a fat pointer was attempted.
4284+
4285+
Erroneous code example:
4286+
4287+
```compile_fail,E0607
4288+
let v = 0 as *const u8;
4289+
v as *const [u8];
4290+
```
4291+
4292+
First: what are thin and fat pointers?
4293+
4294+
Thin pointers are "simple" pointers: they are purely a reference to a memory
4295+
address.
4296+
4297+
Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
4298+
DST don't have a statically known size, therefore they can only exist behind
4299+
some kind of pointers that contain additional information. Slices and trait
4300+
objects are DSTs. In the case of slices, the additional information the fat
4301+
pointer holds is their size.
4302+
4303+
To fix this error, don't try to cast directly between thin and fat pointers.
4304+
4305+
For more information about casts, take a look at The Book:
4306+
https://doc.rust-lang.org/book/first-edition/casting-between-types.html
4307+
"##,
4308+
42114309
E0609: r##"
42124310
Attempted to access a non-existent field in a struct.
42134311

‎src/libstd/ffi/os_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use sys_common::{AsInner, IntoInner, FromInner};
2929
/// * On Windows, strings are often arbitrary sequences of non-zero 16-bit
3030
/// values, interpreted as UTF-16 when it is valid to do so.
3131
///
32-
/// * In Rust, strings are always valid UTF-8, but may contain zeros.
32+
/// * In Rust, strings are always valid UTF-8, which may contain zeros.
3333
///
3434
/// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust
3535
/// and platform-native string values, and in particular allowing a Rust string

‎src/test/compile-fail/E0604.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
1u32 as char; //~ ERROR E0604
13+
}

‎src/test/compile-fail/E0605.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = 0u8;
13+
x as Vec<u8>; //~ ERROR E0605
14+
//~| NOTE an `as` expression can only be used to convert between primitive types
15+
16+
let v = 0 as *const u8;
17+
v as &u8; //~ ERROR E0605
18+
//~| NOTE an `as` expression can only be used to convert between primitive types
19+
}

‎src/test/compile-fail/E0606.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
&0u8 as u8; //~ ERROR E0606
13+
}

‎src/test/compile-fail/E0607.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let v = 0 as *const u8;
13+
v as *const [u8]; //~ ERROR E0607
14+
}

‎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
}

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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/lint/outer-forbid.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Forbidding a group (here, `unused`) overrules subsequent allowance of both
12+
// the group, and an individual lint in the group (here, `unused_variables`);
13+
// and, forbidding an individual lint (here, `non_snake_case`) overrules
14+
// subsequent allowance of a lint group containing it (here, `bad_style`). See
15+
// Issue #42873.
16+
17+
#![forbid(unused, non_snake_case)]
18+
19+
#[allow(unused, unused_variables, bad_style)]
20+
fn main() {
21+
println!("hello forbidden world")
22+
}

‎src/test/ui/lint/outer-forbid.stderr

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0453]: allow(unused) overruled by outer forbid(unused)
2+
--> $DIR/outer-forbid.rs:19:9
3+
|
4+
17 | #![forbid(unused, non_snake_case)]
5+
| ------ `forbid` level set here
6+
18 |
7+
19 | #[allow(unused, unused_variables, bad_style)]
8+
| ^^^^^^ overruled by previous forbid
9+
10+
error[E0453]: allow(unused_variables) overruled by outer forbid(unused)
11+
--> $DIR/outer-forbid.rs:19:17
12+
|
13+
17 | #![forbid(unused, non_snake_case)]
14+
| ------ `forbid` level set here
15+
18 |
16+
19 | #[allow(unused, unused_variables, bad_style)]
17+
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
18+
19+
error[E0453]: allow(bad_style) overruled by outer forbid(non_snake_case)
20+
--> $DIR/outer-forbid.rs:19:35
21+
|
22+
17 | #![forbid(unused, non_snake_case)]
23+
| -------------- `forbid` level set here
24+
18 |
25+
19 | #[allow(unused, unused_variables, bad_style)]
26+
| ^^^^^^^^^ overruled by previous forbid
27+
28+
error: aborting due to previous error(s)
29+

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

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: casting `*const U` as `*const V` is invalid
1+
error[E0606]: casting `*const U` as `*const V` is invalid
22
--> $DIR/cast-rfc0401.rs:13:5
33
|
44
13 | u as *const V
55
| ^^^^^^^^^^^^^
66
|
77
= note: vtable kinds may not match
88

9-
error: casting `*const U` as `*const str` is invalid
9+
error[E0606]: casting `*const U` as `*const str` is invalid
1010
--> $DIR/cast-rfc0401.rs:18:5
1111
|
1212
18 | u as *const str
@@ -20,57 +20,67 @@ error[E0609]: no field `f` on type `fn() {main}`
2020
75 | let _ = main.f as *const u32;
2121
| ^
2222

23-
error: 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
| ^^^^^^^^
28+
|
29+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
2830

29-
error: non-scalar cast: `*const u8` as `E`
31+
error[E0605]: non-primitive cast: `*const u8` as `E`
3032
--> $DIR/cast-rfc0401.rs:40:13
3133
|
3234
40 | let _ = v as E;
3335
| ^^^^^^
36+
|
37+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
3438

35-
error: non-scalar cast: `*const u8` as `fn()`
39+
error[E0605]: non-primitive cast: `*const u8` as `fn()`
3640
--> $DIR/cast-rfc0401.rs:41:13
3741
|
3842
41 | let _ = v as fn();
3943
| ^^^^^^^^^
44+
|
45+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
4046

41-
error: non-scalar cast: `*const u8` as `(u32,)`
47+
error[E0605]: non-primitive cast: `*const u8` as `(u32,)`
4248
--> $DIR/cast-rfc0401.rs:42:13
4349
|
4450
42 | let _ = v as (u32,);
4551
| ^^^^^^^^^^^
52+
|
53+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
4654

47-
error: 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`
4856
--> $DIR/cast-rfc0401.rs:43:13
4957
|
5058
43 | let _ = Some(&v) as *const u8;
5159
| ^^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
5262

53-
error: casting `*const u8` as `f32` is invalid
63+
error[E0606]: casting `*const u8` as `f32` is invalid
5464
--> $DIR/cast-rfc0401.rs:45:13
5565
|
5666
45 | let _ = v as f32;
5767
| ^^^^^^^^
5868

59-
error: casting `fn() {main}` as `f64` is invalid
69+
error[E0606]: casting `fn() {main}` as `f64` is invalid
6070
--> $DIR/cast-rfc0401.rs:46:13
6171
|
6272
46 | let _ = main as f64;
6373
| ^^^^^^^^^^^
6474

65-
error: casting `&*const u8` as `usize` is invalid
75+
error[E0606]: casting `&*const u8` as `usize` is invalid
6676
--> $DIR/cast-rfc0401.rs:47:13
6777
|
6878
47 | let _ = &v as usize;
6979
| ^^^^^^^^^^^
7080
|
7181
= help: cast through a raw pointer first
7282

73-
error: casting `f32` as `*const u8` is invalid
83+
error[E0606]: casting `f32` as `*const u8` is invalid
7484
--> $DIR/cast-rfc0401.rs:48:13
7585
|
7686
48 | let _ = f as *const u8;
@@ -92,113 +102,113 @@ error[E0054]: cannot cast as `bool`
92102
|
93103
= help: compare with zero instead
94104

95-
error: only `u8` can be cast as `char`, not `u32`
105+
error[E0604]: only `u8` can be cast as `char`, not `u32`
96106
--> $DIR/cast-rfc0401.rs:51:13
97107
|
98108
51 | let _ = 0x61u32 as char;
99109
| ^^^^^^^^^^^^^^^
100110

101-
error: casting `bool` as `f32` is invalid
111+
error[E0606]: casting `bool` as `f32` is invalid
102112
--> $DIR/cast-rfc0401.rs:53:13
103113
|
104114
53 | let _ = false as f32;
105115
| ^^^^^^^^^^^^
106116
|
107117
= help: cast through an integer first
108118

109-
error: casting `E` as `f32` is invalid
119+
error[E0606]: casting `E` as `f32` is invalid
110120
--> $DIR/cast-rfc0401.rs:54:13
111121
|
112122
54 | let _ = E::A as f32;
113123
| ^^^^^^^^^^^
114124
|
115125
= help: cast through an integer first
116126

117-
error: casting `char` as `f32` is invalid
127+
error[E0606]: casting `char` as `f32` is invalid
118128
--> $DIR/cast-rfc0401.rs:55:13
119129
|
120130
55 | let _ = 'a' as f32;
121131
| ^^^^^^^^^^
122132
|
123133
= help: cast through an integer first
124134

125-
error: casting `bool` as `*const u8` is invalid
135+
error[E0606]: casting `bool` as `*const u8` is invalid
126136
--> $DIR/cast-rfc0401.rs:57:13
127137
|
128138
57 | let _ = false as *const u8;
129139
| ^^^^^^^^^^^^^^^^^^
130140

131-
error: casting `E` as `*const u8` is invalid
141+
error[E0606]: casting `E` as `*const u8` is invalid
132142
--> $DIR/cast-rfc0401.rs:58:13
133143
|
134144
58 | let _ = E::A as *const u8;
135145
| ^^^^^^^^^^^^^^^^^
136146

137-
error: casting `char` as `*const u8` is invalid
147+
error[E0606]: casting `char` as `*const u8` is invalid
138148
--> $DIR/cast-rfc0401.rs:59:13
139149
|
140150
59 | let _ = 'a' as *const u8;
141151
| ^^^^^^^^^^^^^^^^
142152

143-
error: casting `usize` as `*const [u8]` is invalid
153+
error[E0606]: casting `usize` as `*const [u8]` is invalid
144154
--> $DIR/cast-rfc0401.rs:61:13
145155
|
146156
61 | let _ = 42usize as *const [u8];
147157
| ^^^^^^^^^^^^^^^^^^^^^^
148158

149-
error: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
159+
error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
150160
--> $DIR/cast-rfc0401.rs:62:13
151161
|
152162
62 | let _ = v as *const [u8];
153163
| ^^^^^^^^^^^^^^^^
154164

155-
error: casting `&Foo` as `*const str` is invalid
165+
error[E0606]: casting `&Foo` as `*const str` is invalid
156166
--> $DIR/cast-rfc0401.rs:64:13
157167
|
158168
64 | let _ = foo as *const str;
159169
| ^^^^^^^^^^^^^^^^^
160170

161-
error: casting `&Foo` as `*mut str` is invalid
171+
error[E0606]: casting `&Foo` as `*mut str` is invalid
162172
--> $DIR/cast-rfc0401.rs:65:13
163173
|
164174
65 | let _ = foo as *mut str;
165175
| ^^^^^^^^^^^^^^^
166176

167-
error: casting `fn() {main}` as `*mut str` is invalid
177+
error[E0606]: casting `fn() {main}` as `*mut str` is invalid
168178
--> $DIR/cast-rfc0401.rs:66:13
169179
|
170180
66 | let _ = main as *mut str;
171181
| ^^^^^^^^^^^^^^^^
172182

173-
error: casting `&f32` as `*mut f32` is invalid
183+
error[E0606]: casting `&f32` as `*mut f32` is invalid
174184
--> $DIR/cast-rfc0401.rs:67:13
175185
|
176186
67 | let _ = &f as *mut f32;
177187
| ^^^^^^^^^^^^^^
178188

179-
error: casting `&f32` as `*const f64` is invalid
189+
error[E0606]: casting `&f32` as `*const f64` is invalid
180190
--> $DIR/cast-rfc0401.rs:68:13
181191
|
182192
68 | let _ = &f as *const f64;
183193
| ^^^^^^^^^^^^^^^^
184194

185-
error: casting `*const [i8]` as `usize` is invalid
195+
error[E0606]: casting `*const [i8]` as `usize` is invalid
186196
--> $DIR/cast-rfc0401.rs:69:13
187197
|
188198
69 | let _ = fat_sv as usize;
189199
| ^^^^^^^^^^^^^^^
190200
|
191201
= help: cast through a thin pointer first
192202

193-
error: casting `*const Foo` as `*const [u16]` is invalid
203+
error[E0606]: casting `*const Foo` as `*const [u16]` is invalid
194204
--> $DIR/cast-rfc0401.rs:78:13
195205
|
196206
78 | let _ = cf as *const [u16];
197207
| ^^^^^^^^^^^^^^^^^^
198208
|
199209
= note: vtable kinds may not match
200210

201-
error: casting `*const Foo` as `*const Bar` is invalid
211+
error[E0606]: casting `*const Foo` as `*const Bar` is invalid
202212
--> $DIR/cast-rfc0401.rs:79:13
203213
|
204214
79 | let _ = cf as *const Bar;
@@ -224,7 +234,7 @@ error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
224234
= help: the trait `std::marker::Sized` is not implemented for `str`
225235
= note: required for the cast to the object type `Foo`
226236

227-
error: casting `&{float}` as `f32` is invalid
237+
error[E0606]: casting `&{float}` as `f32` is invalid
228238
--> $DIR/cast-rfc0401.rs:81:30
229239
|
230240
81 | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();

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

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

10-
error: 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 ())
1414
| ^^^^^^^^
1515
...
1616
38 | cast!(2);
1717
| --------- in this macro invocation
18+
|
19+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
1820

1921
error: aborting due to previous error(s)
2022

‎src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ actual:\n\
692692
}
693693

694694
if !debugger_run_result.status.success() {
695-
self.fatal("gdb failed to execute");
695+
self.fatal_proc_rec("gdb failed to execute", &debugger_run_result);
696696
}
697697

698698
self.check_debugger_output(&debugger_run_result, &check_lines);

0 commit comments

Comments
 (0)
Please sign in to comment.