]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/ty/error.rs
Auto merge of #30641 - tsion:match-range, r=eddyb
[rust.git] / src / librustc / middle / ty / error.rs
index 61536934aae13cebbae6cd7a8900f7bee6446f76..ab48fd7fb8665f2727903f471f5e872ff5b6f5a8 100644 (file)
@@ -17,6 +17,7 @@
 use syntax::abi;
 use syntax::ast::{self, Name};
 use syntax::codemap::Span;
+use syntax::errors::DiagnosticBuilder;
 
 use rustc_front::hir;
 
@@ -252,27 +253,30 @@ fn sort_string(&self, cx: &ty::ctxt) -> String {
 }
 
 impl<'tcx> ty::ctxt<'tcx> {
-    pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
+    pub fn note_and_explain_type_err(&self,
+                                     db: &mut DiagnosticBuilder,
+                                     err: &TypeError<'tcx>,
+                                     sp: Span) {
         use self::TypeError::*;
 
         match err.clone() {
             RegionsDoesNotOutlive(subregion, superregion) => {
-                self.note_and_explain_region("", subregion, "...");
-                self.note_and_explain_region("...does not necessarily outlive ",
+                self.note_and_explain_region(db, "", subregion, "...");
+                self.note_and_explain_region(db, "...does not necessarily outlive ",
                                            superregion, "");
             }
             RegionsNotSame(region1, region2) => {
-                self.note_and_explain_region("", region1, "...");
-                self.note_and_explain_region("...is not the same lifetime as ",
+                self.note_and_explain_region(db, "", region1, "...");
+                self.note_and_explain_region(db, "...is not the same lifetime as ",
                                            region2, "");
             }
             RegionsNoOverlap(region1, region2) => {
-                self.note_and_explain_region("", region1, "...");
-                self.note_and_explain_region("...does not overlap ",
+                self.note_and_explain_region(db, "", region1, "...");
+                self.note_and_explain_region(db, "...does not overlap ",
                                            region2, "");
             }
             RegionsInsufficientlyPolymorphic(_, conc_region) => {
-                self.note_and_explain_region("concrete lifetime that was found is ",
+                self.note_and_explain_region(db, "concrete lifetime that was found is ",
                                            conc_region, "");
             }
             RegionsOverlyPolymorphic(_, ty::ReVar(_)) => {
@@ -280,65 +284,58 @@ pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
                 // inference variables, it's not very illuminating.
             }
             RegionsOverlyPolymorphic(_, conc_region) => {
-                self.note_and_explain_region("expected concrete lifetime is ",
+                self.note_and_explain_region(db, "expected concrete lifetime is ",
                                            conc_region, "");
             }
             Sorts(values) => {
                 let expected_str = values.expected.sort_string(self);
                 let found_str = values.found.sort_string(self);
                 if expected_str == found_str && expected_str == "closure" {
-                    self.sess.span_note(sp,
-                        &format!("no two closures, even if identical, have the same type"));
-                    self.sess.span_help(sp,
-                        &format!("consider boxing your closure and/or \
-                                  using it as a trait object"));
+                    db.span_note(sp,
+                        "no two closures, even if identical, have the same type");
+                    db.span_help(sp,
+                        "consider boxing your closure and/or using it as a trait object");
                 }
             },
             TyParamDefaultMismatch(values) => {
                 let expected = values.expected;
                 let found = values.found;
-                self.sess.span_note(sp,
-                                    &format!("conflicting type parameter defaults `{}` and `{}`",
-                                             expected.ty,
-                                             found.ty));
+                db.span_note(sp, &format!("conflicting type parameter defaults `{}` and `{}`",
+                                          expected.ty,
+                                          found.ty));
 
                 match
                     self.map.as_local_node_id(expected.def_id)
                             .and_then(|node_id| self.map.opt_span(node_id))
                 {
                     Some(span) => {
-                        self.sess.span_note(span,
-                                            &format!("a default was defined here..."));
+                        db.span_note(span, "a default was defined here...");
                     }
                     None => {
-                        self.sess.note(
-                            &format!("a default is defined on `{}`",
-                                     self.item_path_str(expected.def_id)));
+                        db.note(&format!("a default is defined on `{}`",
+                                         self.item_path_str(expected.def_id)));
                     }
                 }
 
-                self.sess.span_note(
+                db.span_note(
                     expected.origin_span,
-                    &format!("...that was applied to an unconstrained type variable here"));
+                    "...that was applied to an unconstrained type variable here");
 
                 match
                     self.map.as_local_node_id(found.def_id)
                             .and_then(|node_id| self.map.opt_span(node_id))
                 {
                     Some(span) => {
-                        self.sess.span_note(span,
-                                            &format!("a second default was defined here..."));
+                        db.span_note(span, "a second default was defined here...");
                     }
                     None => {
-                        self.sess.note(
-                            &format!("a second default is defined on `{}`",
-                                     self.item_path_str(found.def_id)));
+                        db.note(&format!("a second default is defined on `{}`",
+                                         self.item_path_str(found.def_id)));
                     }
                 }
 
-                self.sess.span_note(
-                    found.origin_span,
-                    &format!("...that also applies to the same type variable here"));
+                db.span_note(found.origin_span,
+                             "...that also applies to the same type variable here");
             }
             _ => {}
         }