Skip to content

Commit aaa02b3

Browse files
committed
Refactoring
1 parent 95dc7ef commit aaa02b3

File tree

13 files changed

+237
-225
lines changed

13 files changed

+237
-225
lines changed

src/librustc/lint/context.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,18 @@ pub fn raw_emit_lint(sess: &Session,
368368
lvlsrc: LevelSource,
369369
span: Option<Span>,
370370
msg: &str) {
371-
raw_struct_lint(sess, lint, lvlsrc, span, msg).map(|mut e| e.emit());
371+
raw_struct_lint(sess, lint, lvlsrc, span, msg).emit();
372372
}
373373

374374
pub fn raw_struct_lint<'a>(sess: &'a Session,
375375
lint: &'static Lint,
376376
lvlsrc: LevelSource,
377377
span: Option<Span>,
378378
msg: &str)
379-
-> Option<DiagnosticBuilder<'a>> {
379+
-> DiagnosticBuilder<'a> {
380380
let (mut level, source) = lvlsrc;
381381
if level == Allow {
382-
return None;
382+
return sess.diagnostic().struct_dummy();
383383
}
384384

385385
let name = lint.name_lower();
@@ -416,7 +416,8 @@ pub fn raw_struct_lint<'a>(sess: &'a Session,
416416
if let Some(span) = def {
417417
err.span_note(span, "lint level defined here");
418418
}
419-
Some(err)
419+
420+
err
420421
}
421422

422423
pub trait LintContext: Sized {
@@ -456,9 +457,9 @@ pub trait LintContext: Sized {
456457
lint: &'static Lint,
457458
span: Option<Span>,
458459
msg: &str)
459-
-> Option<DiagnosticBuilder> {
460+
-> DiagnosticBuilder {
460461
let (level, src) = match self.level_src(lint) {
461-
None => return None,
462+
None => return self.sess().diagnostic().struct_dummy(),
462463
Some(pair) => pair,
463464
};
464465

@@ -474,17 +475,14 @@ pub trait LintContext: Sized {
474475
lint: &'static Lint,
475476
span: Span,
476477
msg: &str)
477-
-> Option<DiagnosticBuilder> {
478+
-> DiagnosticBuilder {
478479
self.lookup(lint, Some(span), msg)
479480
}
480481

481482
/// Emit a lint and note at the appropriate level, for a particular span.
482483
fn span_lint_note(&self, lint: &'static Lint, span: Span, msg: &str,
483484
note_span: Span, note: &str) {
484-
let mut err = match self.lookup(lint, Some(span), msg) {
485-
Some(e) => e,
486-
None => return
487-
};
485+
let mut err = self.lookup(lint, Some(span), msg);
488486
if self.current_level(lint) != Level::Allow {
489487
if note_span == span {
490488
err.fileline_note(note_span, note);
@@ -498,10 +496,7 @@ pub trait LintContext: Sized {
498496
/// Emit a lint and help at the appropriate level, for a particular span.
499497
fn span_lint_help(&self, lint: &'static Lint, span: Span,
500498
msg: &str, help: &str) {
501-
let mut err = match self.lookup(lint, Some(span), msg) {
502-
Some(e) => e,
503-
None => return
504-
};
499+
let mut err = self.lookup(lint, Some(span), msg);
505500
self.span_lint(lint, span, msg);
506501
if self.current_level(lint) != Level::Allow {
507502
err.span_help(span, help);

src/librustc/middle/infer/error_reporting.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub trait ErrorReporting<'tcx> {
237237
fn report_type_error(&self,
238238
trace: TypeTrace<'tcx>,
239239
terr: &TypeError<'tcx>)
240-
-> Option<DiagnosticBuilder<'tcx>>;
240+
-> DiagnosticBuilder<'tcx>;
241241

242242
fn check_and_note_conflicting_crates(&self,
243243
err: &mut DiagnosticBuilder,
@@ -478,11 +478,11 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
478478
fn report_type_error(&self,
479479
trace: TypeTrace<'tcx>,
480480
terr: &TypeError<'tcx>)
481-
-> Option<DiagnosticBuilder<'tcx>> {
481+
-> DiagnosticBuilder<'tcx> {
482482
let expected_found_str = match self.values_str(&trace.values) {
483483
Some(v) => v,
484484
None => {
485-
return None; /* derived error */
485+
return self.tcx.sess.diagnostic().struct_dummy(); /* derived error */
486486
}
487487
};
488488

@@ -507,7 +507,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
507507
},
508508
_ => ()
509509
}
510-
Some(err)
510+
err
511511
}
512512

513513
/// Adds a note if the types come from similarly named crates
@@ -560,11 +560,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
560560
trace: TypeTrace<'tcx>,
561561
terr: &TypeError<'tcx>) {
562562
let span = trace.origin.span();
563-
let err = self.report_type_error(trace, terr);
564-
err.map(|mut err| {
565-
self.tcx.note_and_explain_type_err(&mut err, terr, span);
566-
err.emit();
567-
});
563+
let mut err = self.report_type_error(trace, terr);
564+
self.tcx.note_and_explain_type_err(&mut err, terr, span);
565+
err.emit();
568566
}
569567

570568
/// Returns a string of the form "expected `{}`, found `{}`", or None if this is a derived

src/librustc/middle/infer/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12811281
mk_msg: M,
12821282
actual_ty: String,
12831283
err: Option<&TypeError<'tcx>>)
1284-
-> Option<DiagnosticBuilder<'tcx>>
1284+
-> DiagnosticBuilder<'tcx>
12851285
where M: FnOnce(Option<String>, String) -> String,
12861286
{
12871287
self.type_error_struct_str_with_expected(sp, mk_msg, None, actual_ty, err)
@@ -1296,7 +1296,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12961296
where M: FnOnce(Option<String>, String) -> String,
12971297
{
12981298
self.type_error_struct_str_with_expected(sp, mk_msg, expected_ty, actual_ty, err)
1299-
.map(|mut e| e.emit());
1299+
.emit();
13001300
}
13011301

13021302
pub fn type_error_struct_str_with_expected<M>(&self,
@@ -1305,7 +1305,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13051305
expected_ty: Option<Ty<'tcx>>,
13061306
actual_ty: String,
13071307
err: Option<&TypeError<'tcx>>)
1308-
-> Option<DiagnosticBuilder<'tcx>>
1308+
-> DiagnosticBuilder<'tcx>
13091309
where M: FnOnce(Option<String>, String) -> String,
13101310
{
13111311
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
@@ -1324,9 +1324,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13241324
if let Some(err) = err {
13251325
self.tcx.note_and_explain_type_err(&mut db, err, sp);
13261326
}
1327-
Some(db)
1327+
db
13281328
} else {
1329-
None
1329+
self.tcx.sess.diagnostic().struct_dummy()
13301330
}
13311331
}
13321332

@@ -1337,22 +1337,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13371337
err: Option<&TypeError<'tcx>>)
13381338
where M: FnOnce(String) -> String,
13391339
{
1340-
self.type_error_struct(sp, mk_msg, actual_ty, err).map(|mut e| e.emit());
1340+
self.type_error_struct(sp, mk_msg, actual_ty, err).emit();
13411341
}
13421342

13431343
pub fn type_error_struct<M>(&self,
13441344
sp: Span,
13451345
mk_msg: M,
13461346
actual_ty: Ty<'tcx>,
13471347
err: Option<&TypeError<'tcx>>)
1348-
-> Option<DiagnosticBuilder<'tcx>>
1348+
-> DiagnosticBuilder<'tcx>
13491349
where M: FnOnce(String) -> String,
13501350
{
13511351
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
13521352

13531353
// Don't report an error if actual type is TyError.
13541354
if actual_ty.references_error() {
1355-
return None;
1355+
return self.tcx.sess.diagnostic().struct_dummy();
13561356
}
13571357

13581358
self.type_error_struct_str(sp,

src/librustc_driver/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct ExpectErrorEmitter {
6060
fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) {
6161
match lvl {
6262
Level::Bug | Level::Fatal | Level::Error => {}
63-
Level::Warning | Level::Note | Level::Help => {
63+
_ => {
6464
return;
6565
}
6666
}

src/librustc_lint/builtin.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,17 @@ impl LateLintPass for UnconditionalRecursion {
754754
if !reached_exit_without_self_call && !self_call_spans.is_empty() {
755755
let mut db = cx.struct_span_lint(UNCONDITIONAL_RECURSION, sp,
756756
"function cannot return without recurring");
757-
let mut db = db.as_mut();
758757

759758
// FIXME #19668: these could be span_lint_note's instead of this manual guard.
760759
if cx.current_level(UNCONDITIONAL_RECURSION) != Level::Allow {
761760
// offer some help to the programmer.
762761
for call in &self_call_spans {
763-
db = db.map(|db| db.span_note(*call, "recursive call site"));
762+
db.span_note(*call, "recursive call site");
764763
}
765-
db = db.map(|db| db.fileline_help(sp, "a `loop` may express intention \
766-
better if this is on purpose"));
764+
db.fileline_help(sp, "a `loop` may express intention \
765+
better if this is on purpose");
767766
}
768-
db.map(|db| db.emit());
767+
db.emit();
769768
}
770769

771770
// all done

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
144144

145145
if let Some(sp) = child[ns].span() {
146146
let note = format!("first definition of {} `{}` here", ns_str, name);
147-
err.as_mut().map(|mut e| e.span_note(sp, &note));
147+
err.span_note(sp, &note);
148148
}
149-
err.as_mut().map(|mut e| e.emit());
149+
err.emit();
150150
child
151151
}
152152
}
@@ -261,10 +261,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
261261
mod_spans[0],
262262
ResolutionError::SelfImportCanOnlyAppearOnceInTheList);
263263
for other_span in mod_spans.iter().skip(1) {
264-
e.as_mut().map(|mut e| e.span_note(*other_span,
265-
"another `self` import appears here"));
264+
e.span_note(*other_span, "another `self` import appears here");
266265
}
267-
e.as_mut().map(|mut e| e.emit());
266+
e.emit();
268267
}
269268

270269
for source_item in source_items {

src/librustc_resolve/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,18 @@ pub enum UnresolvedNameContext {
216216
fn resolve_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
217217
span: syntax::codemap::Span,
218218
resolution_error: ResolutionError<'b>) {
219-
resolve_struct_error(resolver, span, resolution_error).map(|mut e| e.emit());
219+
resolve_struct_error(resolver, span, resolution_error).emit();
220220
}
221221

222222
fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
223223
span: syntax::codemap::Span,
224224
resolution_error: ResolutionError<'b>)
225-
-> Option<DiagnosticBuilder<'a>> {
225+
-> DiagnosticBuilder<'a> {
226226
if !resolver.emit_errors {
227-
return None;
227+
return resolver.session.diagnostic().struct_dummy();
228228
}
229229

230-
Some(match resolution_error {
230+
match resolution_error {
231231
ResolutionError::TypeParametersFromOuterFunction => {
232232
struct_span_err!(resolver.session,
233233
span,
@@ -532,7 +532,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
532532
E0435,
533533
"attempt to use a non-constant value in a constant")
534534
}
535-
})
535+
}
536536
}
537537

538538
#[derive(Copy, Clone)]
@@ -2202,10 +2202,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22022202

22032203
// If it's a typedef, give a note
22042204
if let DefTy(..) = path_res.base_def {
2205-
err.as_mut().map(|mut e| e.span_note(trait_path.span,
2206-
"`type` aliases cannot be used for traits"));
2205+
err.span_note(trait_path.span,
2206+
"`type` aliases cannot be used for traits");
22072207
}
2208-
err.as_mut().map(|mut e| e.emit());
2208+
err.emit();
22092209
Err(())
22102210
}
22112211
} else {
@@ -3493,11 +3493,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
34933493
let msg = format!("did you mean to write: `{} {{ /* fields */ }}`?",
34943494
path_name);
34953495
if self.emit_errors {
3496-
err.as_mut().map(|mut e| e.fileline_help(expr.span, &msg));
3496+
err.fileline_help(expr.span, &msg);
34973497
} else {
3498-
err.as_mut().map(|mut e| e.span_help(expr.span, &msg));
3498+
err.span_help(expr.span, &msg);
34993499
}
3500-
err.as_mut().map(|mut e| e.emit());
3500+
err.emit();
35013501
self.record_def(expr.id, err_path_resolution());
35023502
} else {
35033503
// Write the result into the def map.
@@ -3534,11 +3534,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35343534
let msg = format!("did you mean to write: `{} {{ /* fields */ }}`?",
35353535
path_name);
35363536
if self.emit_errors {
3537-
err.as_mut().map(|mut e| e.fileline_help(expr.span, &msg));
3537+
err.fileline_help(expr.span, &msg);
35383538
} else {
3539-
err.as_mut().map(|mut e| e.span_help(expr.span, &msg));
3539+
err.span_help(expr.span, &msg);
35403540
}
3541-
err.as_mut().map(|mut e| e.emit());
3541+
err.emit();
35423542
}
35433543
_ => {
35443544
// Keep reporting some errors even if they're ignored above.

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,11 +2213,9 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &hir::EnumDef, sp: Span,
22132213
&format!("enum variant is more than three times larger ({} bytes) \
22142214
than the next largest (ignoring padding)",
22152215
largest))
2216-
.map(|mut e| {
2217-
e.span_note(enum_def.variants[largest_index].span,
2216+
.span_note(enum_def.variants[largest_index].span,
22182217
"this variant is the largest")
2219-
.emit();
2220-
});
2218+
.emit();
22212219
}
22222220
}
22232221

src/librustc_typeck/check/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,19 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
232232
let mut err = fcx.type_error_struct(call_expr.span, |actual| {
233233
format!("expected function, found `{}`", actual)
234234
}, callee_ty, None);
235-
let mut err = err.as_mut();
236235

237236
if let hir::ExprCall(ref expr, _) = call_expr.node {
238237
let tcx = fcx.tcx();
239238
if let Some(pr) = tcx.def_map.borrow().get(&expr.id) {
240239
if pr.depth == 0 && pr.base_def != def::DefErr {
241240
if let Some(span) = tcx.map.span_if_local(pr.def_id()) {
242-
err = err.map(|e| e.span_note(span, "defined here"));
241+
err.span_note(span, "defined here");
243242
}
244243
}
245244
}
246245
}
247246

248-
err.map(|e| e.emit());
247+
err.emit();
249248

250249
// This is the "default" function signature, used in case of error.
251250
// In that case, we check each argument against "error" in order to

src/librustc_typeck/check/cast.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,15 @@ impl<'tcx> CastCheck<'tcx> {
132132
actual,
133133
fcx.infcx().ty_to_string(self.cast_ty))
134134
}, self.expr_ty, None)
135-
.map(|mut err| {
136-
err.fileline_help(self.span,
137-
&format!("cast through {} first", match e {
138-
CastError::NeedViaPtr => "a raw pointer",
139-
CastError::NeedViaThinPtr => "a thin pointer",
140-
CastError::NeedViaInt => "an integer",
141-
CastError::NeedViaUsize => "a usize",
142-
_ => unreachable!()
143-
}));
144-
err.emit();
145-
});
135+
.fileline_help(self.span,
136+
&format!("cast through {} first", match e {
137+
CastError::NeedViaPtr => "a raw pointer",
138+
CastError::NeedViaThinPtr => "a thin pointer",
139+
CastError::NeedViaInt => "an integer",
140+
CastError::NeedViaUsize => "a usize",
141+
_ => unreachable!()
142+
}))
143+
.emit();
146144
}
147145
CastError::CastToBool => {
148146
struct_span_err!(fcx.tcx().sess, self.span, E0054, "cannot cast as `bool`")
@@ -174,10 +172,8 @@ impl<'tcx> CastCheck<'tcx> {
174172
actual,
175173
fcx.infcx().ty_to_string(self.cast_ty))
176174
}, self.expr_ty, None)
177-
.map(|mut err| {
178-
err.fileline_note(self.span, "vtable kinds may not match");
179-
err.emit();
180-
});
175+
.fileline_note(self.span, "vtable kinds may not match")
176+
.emit();
181177
}
182178
}
183179
}

0 commit comments

Comments
 (0)