Skip to content

Commit 9a592e6

Browse files
committed
Improve feature gate error, and return after emitting errors instead of looping forever
1 parent a3f5866 commit 9a592e6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_typeck/check/wfcheck.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap};
2020
use rustc::middle::lang_items;
2121

2222
use syntax::ast;
23+
use syntax::feature_gate::{self, GateIssue};
2324
use syntax_pos::Span;
2425
use errors::DiagnosticBuilder;
2526

@@ -481,18 +482,26 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
481482
if let Ok(InferOk { obligations, value: () }) = eq(self_ty, potential_self_ty) {
482483
fcx.register_predicates(obligations);
483484
autoderef.finalize();
484-
break;
485+
break
485486
}
486487

487488
} else {
488-
span_err!(fcx.tcx.sess, span, E0307, "invalid `self` type: {:?}", self_arg_ty);
489-
return;
489+
fcx.tcx.sess.diagnostic().mut_span_err(span, &format!("invalid `self` type: {:?}", self_arg_ty))
490+
.note(&format!("type must be `{:?}` or a type that dereferences to it`", self_ty))
491+
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
492+
.code("E0307".into())
493+
.emit();
494+
return
490495
}
491496
}
492497

493498
if let ExplicitSelf::Other = ExplicitSelf::determine(fcx, fcx.param_env, self_ty, self_arg_ty) {
494499
if !fcx.tcx.sess.features.borrow().arbitrary_self_types {
495-
fcx.tcx.sess.span_err(span, "Arbitrary `self` types are experimental");
500+
feature_gate::feature_err(&fcx.tcx.sess.parse_sess, "arbitrary_self_types", span,
501+
GateIssue::Language, "arbitrary `self` types are unstable")
502+
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
503+
.emit();
504+
return
496505
}
497506
}
498507
}

0 commit comments

Comments
 (0)