about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-14 08:17:19 +0000
committerbors <bors@rust-lang.org>2014-11-14 08:17:19 +0000
commitbb2168c5252adeda1dd35ccf7050df89655233d7 (patch)
tree92a9000b4fbf28afbb55bd93a337bcc9255ed9c3
parent6f7081fad5889c7b41460103fc8abc98f3285c60 (diff)
parent661598cef0ffafb0a5446d4b2b2aea89466102ec (diff)
downloadrust-bb2168c5252adeda1dd35ccf7050df89655233d7.tar.gz
rust-bb2168c5252adeda1dd35ccf7050df89655233d7.zip
auto merge of #18840 : huonw/rust/tweaks, r=alexcrichton
Fix some old papercuts with diagnostics, e.g. tweaking spans, rewording messages. See individual commits.
-rw-r--r--src/librustc/metadata/loader.rs12
-rw-r--r--src/libsyntax/parse/lexer/mod.rs7
-rw-r--r--src/libsyntax/parse/parser.rs64
-rw-r--r--src/test/compile-fail/.gitattributes1
-rw-r--r--src/test/compile-fail/extern-crate-as-no-string-help.rs3
-rw-r--r--src/test/compile-fail/int-literal-too-large-span.rs17
-rw-r--r--src/test/compile-fail/mod_file_not_exist.rs1
-rw-r--r--src/test/compile-fail/trailing-carriage-return-in-string.rs23
-rw-r--r--src/test/run-make/mismatching-target-triples/Makefile11
-rwxr-xr-xsrc/test/run-make/mismatching-target-triples/bar.rs11
-rwxr-xr-xsrc/test/run-make/mismatching-target-triples/foo.rs11
11 files changed, 129 insertions, 32 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 19cc04a20ef..c3d92a19a20 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -307,7 +307,8 @@ impl<'a> Context<'a> {
             format!("found possibly newer version of crate `{}`",
                     self.ident)
         } else if self.rejected_via_triple.len() > 0 {
-            format!("found incorrect triple for crate `{}`", self.ident)
+            format!("couldn't find crate `{}` with expected target triple {}",
+                    self.ident, self.triple)
         } else {
             format!("can't find crate for `{}`", self.ident)
         };
@@ -318,15 +319,12 @@ impl<'a> Context<'a> {
         };
         self.sess.span_err(self.span, message.as_slice());
 
-        let mismatches = self.rejected_via_triple.iter();
         if self.rejected_via_triple.len() > 0 {
-            self.sess.span_note(self.span,
-                                format!("expected triple of {}",
-                                        self.triple).as_slice());
+            let mismatches = self.rejected_via_triple.iter();
             for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
                 self.sess.fileline_note(self.span,
-                    format!("crate `{}` path {}{}, triple {}: {}",
-                            self.ident, "#", i+1, got, path.display()).as_slice());
+                    format!("crate `{}`, path #{}, triple {}: {}",
+                            self.ident, i+1, got, path.display()).as_slice());
             }
         }
         if self.rejected_via_hash.len() > 0 {
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 35d56440b50..01a66243a96 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -806,6 +806,13 @@ impl<'a> StringReader<'a> {
                                     if ascii_only { "unknown byte escape" }
                                     else { "unknown character escape" },
                                     c);
+                                if e == '\r' {
+                                    let sp = codemap::mk_sp(escaped_pos, last_pos);
+                                    self.span_diagnostic.span_help(
+                                        sp,
+                                        "this is an isolated carriage return; consider checking \
+                                         your editor and version control settings.")
+                                }
                                 false
                             }
                         }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 42ec1e80342..db10dc1bc90 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -66,6 +66,7 @@ use ast_util::{as_prec, ident_to_path, operator_prec};
 use ast_util;
 use codemap::{Span, BytePos, Spanned, spanned, mk_sp};
 use codemap;
+use diagnostic;
 use ext::tt::macro_parser;
 use parse;
 use parse::attr::ParserAttr;
@@ -941,6 +942,11 @@ impl<'a> Parser<'a> {
     pub fn span_fatal(&mut self, sp: Span, m: &str) -> ! {
         self.sess.span_diagnostic.span_fatal(sp, m)
     }
+    pub fn span_fatal_help(&mut self, sp: Span, m: &str, help: &str) -> ! {
+        self.span_err(sp, m);
+        self.span_help(sp, help);
+        panic!(diagnostic::FatalError);
+    }
     pub fn span_note(&mut self, sp: Span, m: &str) {
         self.sess.span_diagnostic.span_note(sp, m)
     }
@@ -1641,7 +1647,8 @@ impl<'a> Parser<'a> {
             token::LitByte(i) => LitByte(parse::byte_lit(i.as_str()).val0()),
             token::LitChar(i) => LitChar(parse::char_lit(i.as_str()).val0()),
             token::LitInteger(s) => parse::integer_lit(s.as_str(),
-                                                        &self.sess.span_diagnostic, self.span),
+                                                        &self.sess.span_diagnostic,
+                                                       self.last_span),
             token::LitFloat(s) => parse::float_lit(s.as_str()),
             token::LitStr(s) => {
                 LitStr(token::intern_and_get_ident(parse::str_lit(s.as_str()).as_slice()),
@@ -3710,7 +3717,14 @@ impl<'a> Parser<'a> {
         maybe_whole!(no_clone self, NtBlock);
 
         let lo = self.span.lo;
-        self.expect(&token::OpenDelim(token::Brace));
+
+        if !self.eat(&token::OpenDelim(token::Brace)) {
+            let sp = self.span;
+            let tok = self.this_token_to_string();
+            self.span_fatal_help(sp,
+                                 format!("expected `{{`, found `{}`", tok).as_slice(),
+                                 "place this code inside a block");
+        }
 
         return self.parse_block_tail_(lo, DefaultBlock, Vec::new());
     }
@@ -4701,9 +4715,10 @@ impl<'a> Parser<'a> {
             _ => {
                 let span = self.span;
                 let token_str = self.this_token_to_string();
-                self.span_fatal(span,
-                                format!("expected `,`, or `}}`, found `{}`",
-                                        token_str).as_slice())
+                self.span_fatal_help(span,
+                                     format!("expected `,`, or `}}`, found `{}`",
+                                             token_str).as_slice(),
+                                     "struct fields should be separated by commas")
             }
         }
         a_var
@@ -4905,19 +4920,24 @@ impl<'a> Parser<'a> {
                     (true, false) => (default_path, false),
                     (false, true) => (secondary_path, true),
                     (false, false) => {
-                        self.span_fatal(id_sp,
-                                        format!("file not found for module \
-                                                 `{}`",
-                                                 mod_name).as_slice());
+                        self.span_fatal_help(id_sp,
+                                             format!("file not found for module `{}`",
+                                                     mod_name).as_slice(),
+                                             format!("name the file either {} or {} inside \
+                                                     the directory {}",
+                                                     default_path_str,
+                                                     secondary_path_str,
+                                                     dir_path.display()).as_slice());
                     }
                     (true, true) => {
-                        self.span_fatal(
+                        self.span_fatal_help(
                             id_sp,
                             format!("file for module `{}` found at both {} \
                                      and {}",
                                     mod_name,
                                     default_path_str,
-                                    secondary_path_str).as_slice());
+                                    secondary_path_str).as_slice(),
+                            "delete or rename one of them to remove the ambiguity");
                     }
                 }
             }
@@ -5070,9 +5090,10 @@ impl<'a> Parser<'a> {
                     // skip the ident if there is one
                     if self.token.is_ident() { self.bump(); }
 
-                    self.span_err(span,
-                                  format!("expected `;`, found `as`; perhaps you meant \
-                                          to enclose the crate name `{}` in a string?",
+                    self.span_err(span, "expected `;`, found `as`");
+                    self.span_help(span,
+                                   format!("perhaps you meant to enclose the crate name `{}` in \
+                                           a string?",
                                           the_ident.as_str()).as_slice());
                     None
                 } else {
@@ -5582,16 +5603,12 @@ impl<'a> Parser<'a> {
         }
 
         // FAILURE TO PARSE ITEM
-        if visibility != Inherited {
-            let mut s = String::from_str("unmatched visibility `");
-            if visibility == Public {
-                s.push_str("pub")
-            } else {
-                s.push_str("priv")
+        match visibility {
+            Inherited => {}
+            Public => {
+                let last_span = self.last_span;
+                self.span_fatal(last_span, "unmatched visibility `pub`");
             }
-            s.push('`');
-            let last_span = self.last_span;
-            self.span_fatal(last_span, s.as_slice());
         }
         return IoviNone(attrs);
     }
@@ -5913,4 +5930,3 @@ impl<'a> Parser<'a> {
         }
     }
 }
-
diff --git a/src/test/compile-fail/.gitattributes b/src/test/compile-fail/.gitattributes
new file mode 100644
index 00000000000..825f664bf9f
--- /dev/null
+++ b/src/test/compile-fail/.gitattributes
@@ -0,0 +1 @@
+trailing-carriage-return-in-string.rs -text
\ No newline at end of file
diff --git a/src/test/compile-fail/extern-crate-as-no-string-help.rs b/src/test/compile-fail/extern-crate-as-no-string-help.rs
index 70d4ae9ab03..5cc52f6f6db 100644
--- a/src/test/compile-fail/extern-crate-as-no-string-help.rs
+++ b/src/test/compile-fail/extern-crate-as-no-string-help.rs
@@ -11,4 +11,5 @@
 // Tests that the proper help is displayed in the error message
 
 extern crate foo as bar;
-//~^ ERROR expected `;`, found `as`; perhaps you meant to enclose the crate name `foo` in a string?
+//~^ ERROR expected `;`, found `as`
+//~^^ HELP perhaps you meant to enclose the crate name `foo` in a string?
diff --git a/src/test/compile-fail/int-literal-too-large-span.rs b/src/test/compile-fail/int-literal-too-large-span.rs
new file mode 100644
index 00000000000..8a496c934b9
--- /dev/null
+++ b/src/test/compile-fail/int-literal-too-large-span.rs
@@ -0,0 +1,17 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// issue #17123
+
+fn main() {
+    100000000000000000000000000000000 //~ ERROR int literal is too large
+
+        ; // the span shouldn't point to this.
+}
diff --git a/src/test/compile-fail/mod_file_not_exist.rs b/src/test/compile-fail/mod_file_not_exist.rs
index 8391ff6fa39..bbf2152d5b7 100644
--- a/src/test/compile-fail/mod_file_not_exist.rs
+++ b/src/test/compile-fail/mod_file_not_exist.rs
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
+//~^ HELP name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory
 
 fn main() {
     assert_eq!(mod_file_aux::bar(), 10);
diff --git a/src/test/compile-fail/trailing-carriage-return-in-string.rs b/src/test/compile-fail/trailing-carriage-return-in-string.rs
new file mode 100644
index 00000000000..81098333261
--- /dev/null
+++ b/src/test/compile-fail/trailing-carriage-return-in-string.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// ignore-tidy-cr
+// Issue #11669
+
+fn main() {
+    // \r\n
+    let ok = "This is \
+ a test";
+    // \r only
+    let bad = "This is \
 a test";
+    //~^ ERROR unknown character escape: \r
+    //~^^ HELP this is an isolated carriage return
+
+}
diff --git a/src/test/run-make/mismatching-target-triples/Makefile b/src/test/run-make/mismatching-target-triples/Makefile
new file mode 100644
index 00000000000..e79abf82233
--- /dev/null
+++ b/src/test/run-make/mismatching-target-triples/Makefile
@@ -0,0 +1,11 @@
+-include ../tools.mk
+
+# Issue #10814
+#
+# these are no_std to avoid having to have the standard library or any
+# linkers/assemblers for the relevant platform
+
+all:
+	$(RUSTC) foo.rs --target=i686-unknown-linux-gnu
+	$(RUSTC) bar.rs --target=x86_64-unknown-linux-gnu 2>&1 \
+		| grep "couldn't find crate .foo. with expected target triple x86_64-unknown-linux-gnu"
diff --git a/src/test/run-make/mismatching-target-triples/bar.rs b/src/test/run-make/mismatching-target-triples/bar.rs
new file mode 100755
index 00000000000..ed15e5d880a
--- /dev/null
+++ b/src/test/run-make/mismatching-target-triples/bar.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![no_std]
+extern crate foo;
diff --git a/src/test/run-make/mismatching-target-triples/foo.rs b/src/test/run-make/mismatching-target-triples/foo.rs
new file mode 100755
index 00000000000..8afa43710dd
--- /dev/null
+++ b/src/test/run-make/mismatching-target-triples/foo.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![no_std]
+#![crate_type = "lib"]