Skip to content

Commit f590a44

Browse files
committed
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

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

+22-17
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

+42-63
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
}

0 commit comments

Comments
 (0)