From 04d972906d05e6c27452e1ae35970c30e7cf6e6b Mon Sep 17 00:00:00 2001
From: Nick Cameron <ncameron@mozilla.com>
Date: Thu, 24 Dec 2015 10:54:37 +1300
Subject: [PATCH] Rebasing and review comments

---
 src/librustc_metadata/loader.rs  |  9 +++++----
 src/librustc_resolve/lib.rs      | 12 +++++------
 src/librustc_typeck/check/mod.rs |  2 +-
 src/libsyntax/errors/emitter.rs  |  6 +++---
 src/libsyntax/errors/mod.rs      | 34 +++++++++++++-------------------
 src/libsyntax/parse/parser.rs    |  2 +-
 6 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/src/librustc_metadata/loader.rs b/src/librustc_metadata/loader.rs
index b82b76a57c4..40665beaa5a 100644
--- a/src/librustc_metadata/loader.rs
+++ b/src/librustc_metadata/loader.rs
@@ -676,10 +676,11 @@ impl<'a> Context<'a> {
                         return true
                     }
                 }
-                sess.err(&format!("extern location for {} is of an unknown type: {}",
-                                 self.crate_name, loc.display()));
-                sess.help(&format!("file name should be lib*.rlib or {}*.{}",
-                                   dylibname.0, dylibname.1));
+                sess.struct_err(&format!("extern location for {} is of an unknown type: {}",
+                                         self.crate_name, loc.display()))
+                    .help(&format!("file name should be lib*.rlib or {}*.{}",
+                                   dylibname.0, dylibname.1))
+                    .emit();
                 false
             });
 
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index c2dd764f224..5a17f2528c8 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -425,12 +425,12 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
                              argument is missing?")
         }
         ResolutionError::UnresolvedName(path, msg, context) => {
-            let err = struct_span_err!(resolver.session,
-                                       span,
-                                       E0425,
-                                       "unresolved name `{}`{}",
-                                       path,
-                                       msg);
+            let mut err = struct_span_err!(resolver.session,
+                                           span,
+                                           E0425,
+                                           "unresolved name `{}`{}",
+                                           path,
+                                           msg);
 
             match context {
                 UnresolvedNameContext::Other => {} // no help available
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index ea08343bbc0..ca2db8c3def 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -3011,7 +3011,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
         // only find fits with at least one matching letter
         if let Some(name) = find_best_match_for_name(names, &name, Some(name.len())) {
             err.span_help(field.span,
-                          &format!("did you mean `{}`?", n));
+                          &format!("did you mean `{}`?", name));
         }
     }
 
diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs
index 8b9df7aa921..a7bfdedf718 100644
--- a/src/libsyntax/errors/emitter.rs
+++ b/src/libsyntax/errors/emitter.rs
@@ -28,7 +28,7 @@ pub trait Emitter {
     fn emit(&mut self, span: Option<Span>, msg: &str, code: Option<&str>, lvl: Level);
     fn custom_emit(&mut self, sp: RenderSpan, msg: &str, lvl: Level);
 
-    // Emit a structured diagnostic.
+    /// Emit a structured diagnostic.
     fn emit_struct(&mut self, db: &DiagnosticBuilder) {
         self.emit(db.span, &db.message, db.code.as_ref().map(|s| &**s), db.level);
         for child in &db.children {
@@ -60,8 +60,8 @@ impl ColorConfig {
     }
 }
 
-// A basic emitter for when we don't have access to a codemap or registry. Used
-// for reporting very early errors, etc.
+/// A basic emitter for when we don't have access to a codemap or registry. Used
+/// for reporting very early errors, etc.
 pub struct BasicEmitter {
     dst: Destination,
 }
diff --git a/src/libsyntax/errors/mod.rs b/src/libsyntax/errors/mod.rs
index 3cee14538a9..a2fae975148 100644
--- a/src/libsyntax/errors/mod.rs
+++ b/src/libsyntax/errors/mod.rs
@@ -98,7 +98,7 @@ impl error::Error for ExplicitBug {
     }
 }
 
-// Used for emitting structured error messages and other diagnostic information.
+/// Used for emitting structured error messages and other diagnostic information.
 #[must_use]
 pub struct DiagnosticBuilder<'a> {
     emitter: &'a RefCell<Box<Emitter>>,
@@ -109,7 +109,7 @@ pub struct DiagnosticBuilder<'a> {
     children: Vec<SubDiagnostic>,
 }
 
-// For example a note attached to an error.
+/// For example a note attached to an error.
 struct SubDiagnostic {
     level: Level,
     message: String,
@@ -118,7 +118,7 @@ struct SubDiagnostic {
 }
 
 impl<'a> DiagnosticBuilder<'a> {
-    // Emit the diagnostic.
+    /// Emit the diagnostic.
     pub fn emit(&mut self) {
         if self.cancelled() {
             return;
@@ -132,11 +132,11 @@ impl<'a> DiagnosticBuilder<'a> {
         // }
     }
 
-    // Cancel the diagnostic (a structured diagnostic must either be emitted or
-    // cancelled or it will panic when dropped).
-    // BEWARE: if this DiagnosticBuilder is an error, then creating it will
-    // bump the error count on the Handler and cancelling it won't undo that.
-    // If you want to decrement the error count you should use `Handler::cancel`.
+    /// Cancel the diagnostic (a structured diagnostic must either be emitted or
+    /// cancelled or it will panic when dropped).
+    /// BEWARE: if this DiagnosticBuilder is an error, then creating it will
+    /// bump the error count on the Handler and cancelling it won't undo that.
+    /// If you want to decrement the error count you should use `Handler::cancel`.
     pub fn cancel(&mut self) {
         self.level = Level::Cancelled;
     }
@@ -160,12 +160,6 @@ impl<'a> DiagnosticBuilder<'a> {
         self.sub(Level::Note, msg, Some(sp), None);
         self
     }
-    pub fn note_rfc_1214(&mut self , span: Span) -> &mut DiagnosticBuilder<'a>  {
-        self.span_note(span,
-                       "this warning results from recent bug fixes and clarifications; \
-                        it will become a HARD ERROR in the next release. \
-                        See RFC 1214 for details.")
-    }
     pub fn help(&mut self , msg: &str) -> &mut DiagnosticBuilder<'a>  {
         self.sub(Level::Help, msg, None, None);
         self
@@ -220,8 +214,8 @@ impl<'a> DiagnosticBuilder<'a> {
         self
     }
 
-    // Convenience function for internal use, clients should use one of the
-    // struct_* methods on Handler.
+    /// Convenience function for internal use, clients should use one of the
+    /// struct_* methods on Handler.
     fn new(emitter: &'a RefCell<Box<Emitter>>,
            level: Level,
            message: &str) -> DiagnosticBuilder<'a>  {
@@ -235,8 +229,8 @@ impl<'a> DiagnosticBuilder<'a> {
         }
     }
 
-    // Convenience function for internal use, clients should use one of the
-    // public methods above.
+    /// Convenience function for internal use, clients should use one of the
+    /// public methods above.
     fn sub(&mut self,
            level: Level,
            message: &str,
@@ -258,8 +252,8 @@ impl<'a> fmt::Debug for DiagnosticBuilder<'a> {
     }
 }
 
-// Destructor bomb - a DiagnosticBuilder must be either emitted or cancelled or
-// we emit a bug.
+/// Destructor bomb - a DiagnosticBuilder must be either emitted or cancelled or
+/// we emit a bug.
 impl<'a> Drop for DiagnosticBuilder<'a> {
     fn drop(&mut self) {
         if !self.cancelled() {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index f31f24cf249..efd351a632d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -749,7 +749,7 @@ impl<'a> Parser<'a> {
     pub fn parse_seq_to_before_gt_or_return<T, F>(&mut self,
                                                   sep: Option<token::Token>,
                                                   mut f: F)
-                                                  -> PResult<'a, (P<[T]>, bool)> where
+                                                  -> PResult<'a, (P<[T]>, bool)>
         where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
     {
         let mut v = Vec::new();