@@ -36,7 +36,6 @@ use syntax::attr::{AttributeMethods, AttrMetaMethods};
3636
3737#[ derive( Debug , PartialEq , Eq , Hash ) ]
3838pub struct TraitErrorKey < ' tcx > {
39- is_warning : bool ,
4039 span : Span ,
4140 predicate : ty:: Predicate < ' tcx >
4241}
@@ -47,7 +46,6 @@ impl<'tcx> TraitErrorKey<'tcx> {
4746 let predicate =
4847 infcx. resolve_type_vars_if_possible ( & e. obligation . predicate ) ;
4948 TraitErrorKey {
50- is_warning : is_warning ( & e. obligation ) ,
5149 span : e. obligation . cause . span ,
5250 predicate : infcx. tcx . erase_regions ( & predicate)
5351 }
@@ -83,10 +81,6 @@ fn report_fulfillment_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
8381 }
8482}
8583
86- fn is_warning < T > ( obligation : & Obligation < T > ) -> bool {
87- obligation. cause . code . is_rfc1214 ( )
88- }
89-
9084pub fn report_projection_error < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
9185 obligation : & PredicateObligation < ' tcx > ,
9286 error : & MismatchedProjectionTypes < ' tcx > )
@@ -100,8 +94,8 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
10094 // then $X will be unified with TyError, but the error still needs to be
10195 // reported.
10296 if !infcx. tcx . sess . has_errors ( ) || !predicate. references_error ( ) {
103- span_err_or_warn ! (
104- is_warning ( obligation ) , infcx. tcx. sess, obligation. cause. span, E0271 ,
97+ span_err ! (
98+ infcx. tcx. sess, obligation. cause. span, E0271 ,
10599 "type mismatch resolving `{}`: {}" ,
106100 predicate,
107101 error. err) ;
@@ -208,12 +202,11 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
208202 obligation : & PredicateObligation < ' tcx > ,
209203 error : & SelectionError < ' tcx > )
210204{
211- let is_warning = is_warning ( obligation) ;
212205 match * error {
213206 SelectionError :: Unimplemented => {
214207 if let ObligationCauseCode :: CompareImplMethodObligation = obligation. cause . code {
215- span_err_or_warn ! (
216- is_warning , infcx. tcx. sess, obligation. cause. span, E0276 ,
208+ span_err ! (
209+ infcx. tcx. sess, obligation. cause. span, E0276 ,
217210 "the requirement `{}` appears on the impl \
218211 method but not on the corresponding trait method",
219212 obligation. predicate) ;
@@ -225,8 +218,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
225218
226219 if !infcx. tcx . sess . has_errors ( ) || !trait_predicate. references_error ( ) {
227220 let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
228- span_err_or_warn ! (
229- is_warning , infcx. tcx. sess, obligation. cause. span, E0277 ,
221+ span_err ! (
222+ infcx. tcx. sess, obligation. cause. span, E0277 ,
230223 "the trait `{}` is not implemented for the type `{}`" ,
231224 trait_ref, trait_ref. self_ty( ) ) ;
232225
@@ -245,8 +238,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
245238 let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
246239 let err = infcx. equality_predicate ( obligation. cause . span ,
247240 & predicate) . err ( ) . unwrap ( ) ;
248- span_err_or_warn ! (
249- is_warning , infcx. tcx. sess, obligation. cause. span, E0278 ,
241+ span_err ! (
242+ infcx. tcx. sess, obligation. cause. span, E0278 ,
250243 "the requirement `{}` is not satisfied (`{}`)" ,
251244 predicate,
252245 err) ;
@@ -257,8 +250,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
257250 let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
258251 let err = infcx. region_outlives_predicate ( obligation. cause . span ,
259252 & predicate) . err ( ) . unwrap ( ) ;
260- span_err_or_warn ! (
261- is_warning , infcx. tcx. sess, obligation. cause. span, E0279 ,
253+ span_err ! (
254+ infcx. tcx. sess, obligation. cause. span, E0279 ,
262255 "the requirement `{}` is not satisfied (`{}`)" ,
263256 predicate,
264257 err) ;
@@ -268,8 +261,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
268261 ty:: Predicate :: Projection ( ..) | ty:: Predicate :: TypeOutlives ( ..) => {
269262 let predicate =
270263 infcx. resolve_type_vars_if_possible ( & obligation. predicate ) ;
271- span_err_or_warn ! (
272- is_warning , infcx. tcx. sess, obligation. cause. span, E0280 ,
264+ span_err ! (
265+ infcx. tcx. sess, obligation. cause. span, E0280 ,
273266 "the requirement `{}` is not satisfied" ,
274267 predicate) ;
275268 note_obligation_cause ( infcx, obligation) ;
@@ -281,8 +274,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
281274 report_object_safety_error ( infcx. tcx ,
282275 obligation. cause . span ,
283276 trait_def_id,
284- violations,
285- is_warning) ;
277+ violations) ;
286278 note_obligation_cause ( infcx, obligation) ;
287279 }
288280
@@ -304,8 +296,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
304296 let expected_trait_ref = infcx. resolve_type_vars_if_possible ( & * expected_trait_ref) ;
305297 let actual_trait_ref = infcx. resolve_type_vars_if_possible ( & * actual_trait_ref) ;
306298 if !actual_trait_ref. self_ty ( ) . references_error ( ) {
307- span_err_or_warn ! (
308- is_warning , infcx. tcx. sess, obligation. cause. span, E0281 ,
299+ span_err ! (
300+ infcx. tcx. sess, obligation. cause. span, E0281 ,
309301 "type mismatch: the type `{}` implements the trait `{}`, \
310302 but the trait `{}` is required ({})",
311303 expected_trait_ref. self_ty( ) ,
@@ -318,8 +310,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
318310
319311 TraitNotObjectSafe ( did) => {
320312 let violations = object_safety_violations ( infcx. tcx , did) ;
321- report_object_safety_error ( infcx. tcx , obligation. cause . span , did,
322- violations, is_warning) ;
313+ report_object_safety_error ( infcx. tcx , obligation. cause . span , did, violations) ;
323314 note_obligation_cause ( infcx, obligation) ;
324315 }
325316 }
@@ -328,11 +319,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
328319pub fn report_object_safety_error < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
329320 span : Span ,
330321 trait_def_id : DefId ,
331- violations : Vec < ObjectSafetyViolation > ,
332- is_warning : bool )
322+ violations : Vec < ObjectSafetyViolation > )
333323{
334- span_err_or_warn ! (
335- is_warning , tcx. sess, span, E0038 ,
324+ span_err ! (
325+ tcx. sess, span, E0038 ,
336326 "the trait `{}` cannot be made into an object" ,
337327 tcx. item_path_str( trait_def_id) ) ;
338328
@@ -402,7 +392,17 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
402392 let self_ty = trait_ref. self_ty ( ) ;
403393 let all_types = & trait_ref. substs ( ) . types ;
404394 if all_types. references_error ( ) {
405- } else if all_types. needs_infer ( ) {
395+ } else {
396+ // Typically, this ambiguity should only happen if
397+ // there are unresolved type inference variables
398+ // (otherwise it would suggest a coherence
399+ // failure). But given #21974 that is not necessarily
400+ // the case -- we can have multiple where clauses that
401+ // are only distinguished by a region, which results
402+ // in an ambiguity even when all types are fully
403+ // known, since we don't dispatch based on region
404+ // relationships.
405+
406406 // This is kind of a hack: it frequently happens that some earlier
407407 // error prevents types from being fully inferred, and then we get
408408 // a bunch of uninteresting errors saying something like "<generic
@@ -430,16 +430,6 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
430430 note_obligation_cause ( infcx, obligation) ;
431431 }
432432 }
433- } else if !infcx. tcx . sess . has_errors ( ) {
434- // Ambiguity. Coherence should have reported an error.
435- infcx. tcx . sess . span_bug (
436- obligation. cause . span ,
437- & format ! (
438- "coherence failed to report ambiguity: \
439- cannot locate the impl of the trait `{}` for \
440- the type `{}`",
441- trait_ref,
442- self_ty) ) ;
443433 }
444434 }
445435
@@ -491,10 +481,6 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
491481 let tcx = infcx. tcx ;
492482 match * cause_code {
493483 ObligationCauseCode :: MiscObligation => { }
494- ObligationCauseCode :: RFC1214 ( ref subcode) => {
495- tcx. sess . note_rfc_1214 ( cause_span) ;
496- note_obligation_cause_code ( infcx, predicate, cause_span, subcode) ;
497- }
498484 ObligationCauseCode :: SliceOrArrayElem => {
499485 tcx. sess . fileline_note (
500486 cause_span,
0 commit comments