about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-02 19:21:56 -0700
committerbors <bors@rust-lang.org>2016-05-02 19:21:56 -0700
commit44b3cd8c462a420ab64a44ef8f70c007001a1f44 (patch)
treeafca36813604190e06b0f5a6e01e4389ce796be1 /src/libsyntax/parse
parent9a003b0ef22090e8be5b2705a427d6b08b06eaf9 (diff)
parent9355a91224a6f715b94342c074e5bac1f9e820f3 (diff)
downloadrust-44b3cd8c462a420ab64a44ef8f70c007001a1f44.tar.gz
rust-44b3cd8c462a420ab64a44ef8f70c007001a1f44.zip
Auto merge of #32756 - nikomatsakis:borrowck-snippet, r=nrc
Overhaul borrowck error messages and compiler error formatting generally

This is a major overhaul of how the compiler reports errors. The primary goal is to be able to give many spans within the same overall context, such as this:

```
./borrow-errors.rs:73:17: 73:20: error: cannot borrow `*vec` as immutable because previous closure requires unique access [E0501]
70     let append = |e| {
                    ~~~ closure construction occurs here
71         vec.push(e)
           ~~~ previous borrow occurs due to use of `vec` in closure
72     };
73     let data = &vec[3];
                   ~~~ borrow occurs here
74 }
   ~ borrow from closure ends here
```

However, in the process we made a number of other changes:

- Removed the repetitive filenames from snippets and just give the line number.
- Color the line numbers blue so they "fade away"
- Remove the file name and line number from the error code suggestions since they don't seem to fit anymore. (This should probably happen in more places, like existing notes.)
- Newlines in between errors to help group them better.

This PR is not quite ready to land, but we thought it made sense to stop here and get some feedback from people at large. It'd be great if people can check out the branch and play with it. We'd be especially interested in hearing about cases that don't look good with the new formatting (I suspect they exist).

Here is a checklist of some pending work items for this PR. Some of them may be best left for follow-up PRs:

- [x] Accommodate multiple files in a `MultiSpan` (this should be easy)
  - In this case, we want to print filenames though.
- [x] Remove duplicate E0500 code.
- [x] Make the header message bold, rather than current hack that makes all errors/warnings bold
- [x] Update warning text color (yellow is hard to read w/ a white background)

Moved numerous follow-ups to: https://github.com/rust-lang/rust/issues/33240

Joint work with @jonathandturner.

Fixes https://github.com/rust-lang/rust/issues/3533
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/attr.rs5
-rw-r--r--src/libsyntax/parse/mod.rs10
-rw-r--r--src/libsyntax/parse/parser.rs21
3 files changed, 17 insertions, 19 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs
index b8e320e36e9..3aac12d76ff 100644
--- a/src/libsyntax/parse/attr.rs
+++ b/src/libsyntax/parse/attr.rs
@@ -69,9 +69,8 @@ impl<'a> Parser<'a> {
                         self.diagnostic()
                             .struct_span_err(span,
                                              "an inner attribute is not permitted in this context")
-                            .fileline_help(span,
-                                           "place inner attribute at the top of the module or \
-                                            block")
+                            .help("place inner attribute at the top of the module or \
+                                   block")
                             .emit()
                     }
                     ast::AttrStyle::Inner
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index c2050d2a8f4..2a9bcfd658c 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -445,11 +445,11 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
             if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) {
                 // if it looks like a width, lets try to be helpful.
                 sd.struct_span_err(sp, &format!("invalid width `{}` for float literal", &suf[1..]))
-                 .fileline_help(sp, "valid widths are 32 and 64")
+                 .help("valid widths are 32 and 64")
                  .emit();
             } else {
                 sd.struct_span_err(sp, &format!("invalid suffix `{}` for float literal", suf))
-                  .fileline_help(sp, "valid suffixes are `f32` and `f64`")
+                  .help("valid suffixes are `f32` and `f64`")
                   .emit();
             }
 
@@ -621,12 +621,12 @@ pub fn integer_lit(s: &str,
                 if looks_like_width_suffix(&['i', 'u'], suf) {
                     sd.struct_span_err(sp, &format!("invalid width `{}` for integer literal",
                                              &suf[1..]))
-                      .fileline_help(sp, "valid widths are 8, 16, 32 and 64")
+                      .help("valid widths are 8, 16, 32 and 64")
                       .emit();
                 } else {
                     sd.struct_span_err(sp, &format!("invalid suffix `{}` for numeric literal", suf))
-                      .fileline_help(sp, "the suffix must be one of the integral types \
-                                      (`u32`, `isize`, etc)")
+                      .help("the suffix must be one of the integral types \
+                             (`u32`, `isize`, etc)")
                       .emit();
                 }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 671a11b57de..b9188f5101d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -583,7 +583,7 @@ impl<'a> Parser<'a> {
                 let mut err = self.fatal(&format!("expected identifier, found `{}`",
                                                   self.this_token_to_string()));
                 if self.token == token::Underscore {
-                    err.fileline_note(self.span, "`_` is a wildcard pattern, not an identifier");
+                    err.note("`_` is a wildcard pattern, not an identifier");
                 }
                 Err(err)
             }
@@ -1082,7 +1082,7 @@ impl<'a> Parser<'a> {
     }
     pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
         let mut err = self.sess.span_diagnostic.struct_span_fatal(sp, m);
-        err.fileline_help(sp, help);
+        err.help(help);
         err
     }
     pub fn bug(&self, m: &str) -> ! {
@@ -2622,10 +2622,9 @@ impl<'a> Parser<'a> {
                             Some(f) => f,
                             None => continue,
                         };
-                        err.fileline_help(last_span,
-                            &format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
-                                    float.trunc() as usize,
-                                    format!(".{}", fstr.splitn(2, ".").last().unwrap())));
+                        err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
+                                 float.trunc() as usize,
+                                 format!(".{}", fstr.splitn(2, ".").last().unwrap())));
                     }
                     return Err(err);
 
@@ -3134,7 +3133,7 @@ impl<'a> Parser<'a> {
                 let mut err = self.diagnostic().struct_span_err(op_span,
                     "chained comparison operators require parentheses");
                 if op.node == BinOpKind::Lt && *outer_op == AssocOp::Greater {
-                    err.fileline_help(op_span,
+                    err.help(
                         "use `::<...>` instead of `<...>` if you meant to specify type arguments");
                 }
                 err.emit();
@@ -4951,13 +4950,13 @@ impl<'a> Parser<'a> {
                 if is_macro_rules {
                     self.diagnostic().struct_span_err(span, "can't qualify macro_rules \
                                                              invocation with `pub`")
-                                     .fileline_help(span, "did you mean #[macro_export]?")
+                                     .help("did you mean #[macro_export]?")
                                      .emit();
                 } else {
                     self.diagnostic().struct_span_err(span, "can't qualify macro \
                                                              invocation with `pub`")
-                                     .fileline_help(span, "try adjusting the macro to put `pub` \
-                                                           inside the invocation")
+                                     .help("try adjusting the macro to put `pub` \
+                                            inside the invocation")
                                      .emit();
                 }
             }
@@ -5857,7 +5856,7 @@ impl<'a> Parser<'a> {
             if self.eat_keyword(keywords::Mut) {
                 let last_span = self.last_span;
                 self.diagnostic().struct_span_err(last_span, "const globals cannot be mutable")
-                                 .fileline_help(last_span, "did you mean to declare a static?")
+                                 .help("did you mean to declare a static?")
                                  .emit();
             }
             let (ident, item_, extra_attrs) = self.parse_item_const(None)?;