From a0ee7c9f55b90a541db1f6f36d18562bdf5ef6bf Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 11 Oct 2014 14:27:37 +1300 Subject: [PATCH 1/5] Remove `unused_extern_crate` and `unused_result` from the `unused` lint group These lints are allow by default because they are sometimes too sensitive. --- src/librustc/lint/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 8e4095df45a..0c9e129ef72 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -221,8 +221,8 @@ impl LintStore { add_lint_group!(sess, "unused", UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE, - UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATES, UNUSED_MUST_USE, - UNUSED_UNSAFE, UNUSED_RESULTS, PATH_STATEMENTS) + UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE, + UNUSED_UNSAFE, PATH_STATEMENTS) // We have one lint pass defined in this module. self.register_pass(sess, false, box GatherNodeLevels as LintPassObject); From 2a7be1b209a4ceea42418f55baf68774571ed9a2 Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 11 Oct 2014 14:34:45 +1300 Subject: [PATCH 2/5] Fix a minor issue with how lint groups are printed by rustc --- src/librustc/driver/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index fbdc0db1665..028d0ec607a 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -255,7 +255,8 @@ Available lint options: for (name, to) in lints.into_iter() { let name = name.chars().map(|x| x.to_lowercase()) .collect::().replace("_", "-"); - let desc = to.into_iter().map(|x| x.as_str()).collect::>().connect(", "); + let desc = to.into_iter().map(|x| x.as_str().replace("_", "-")) + .collect::>().connect(", "); println!(" {} {}", padded(name.as_slice()), desc); } From fb00015246824313e8882935c9ba175ea6daf9d4 Mon Sep 17 00:00:00 2001 From: P1start Date: Sun, 26 Oct 2014 12:07:54 +1300 Subject: [PATCH 3/5] Improve the error message for parenthesised box expressions Closes #15386. --- src/libsyntax/parse/parser.rs | 14 ++++++++++++++ .../compile-fail/parenthesized-box-expr-message.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/compile-fail/parenthesized-box-expr-message.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ef3a559bf4..d9dd37fcb4f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2730,6 +2730,8 @@ impl<'a> Parser<'a> { return self.parse_dot_or_call_expr(); } + let lo = self.span.lo; + self.bump(); // Check for a place: `box(PLACE) EXPR`. @@ -2738,6 +2740,18 @@ impl<'a> Parser<'a> { if !self.eat(&token::RParen) { let place = self.parse_expr(); self.expect(&token::RParen); + // Give a suggestion to use `box()` when a parenthesised expression is used + if !self.token.can_begin_expr() { + let span = self.span; + let this_token_to_string = self.this_token_to_string(); + self.span_err(span, + format!("expected expression, found `{}`", + this_token_to_string).as_slice()); + let box_span = mk_sp(lo, self.last_span.hi); + self.span_help(box_span, + "perhaps you meant `box() (foo)` instead?"); + self.abort_if_errors(); + } let subexpression = self.parse_prefix_expr(); hi = subexpression.span.hi; ex = ExprBox(place, subexpression); diff --git a/src/test/compile-fail/parenthesized-box-expr-message.rs b/src/test/compile-fail/parenthesized-box-expr-message.rs new file mode 100644 index 00000000000..05bbaec37af --- /dev/null +++ b/src/test/compile-fail/parenthesized-box-expr-message.rs @@ -0,0 +1,14 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + box(1 + 1) //~ HELP perhaps you meant `box() (foo)` instead? + ; //~ ERROR expected expression, found `;` +} From 14398f29290b0d96dbe60f329b69062442eefb33 Mon Sep 17 00:00:00 2001 From: P1start Date: Mon, 27 Oct 2014 17:43:38 +1300 Subject: [PATCH 4/5] Add a message for when a `.` follows a macro invocation --- src/libsyntax/parse/parser.rs | 10 ++++++++++ src/test/compile-fail/macro-invocation-dot-help.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/compile-fail/macro-invocation-dot-help.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d9dd37fcb4f..f04f9efd7a7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3592,6 +3592,16 @@ impl<'a> Parser<'a> { let hi = self.span.hi; if id.name == token::special_idents::invalid.name { + if self.token == token::Dot { + let span = self.span; + let token_string = self.this_token_to_string(); + self.span_err(span, + format!("expected statement, found `{}`", + token_string).as_slice()); + let mac_span = mk_sp(lo, hi); + self.span_help(mac_span, "try parenthesizing this macro invocation"); + self.abort_if_errors(); + } P(spanned(lo, hi, StmtMac( spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)), false))) } else { diff --git a/src/test/compile-fail/macro-invocation-dot-help.rs b/src/test/compile-fail/macro-invocation-dot-help.rs new file mode 100644 index 00000000000..bd45b76dd5a --- /dev/null +++ b/src/test/compile-fail/macro-invocation-dot-help.rs @@ -0,0 +1,14 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + foo!() //~ HELP try parenthesizing this macro invocation + .bar //~ ERROR expected statement +} From 737e39696ba0964729f29410cf4e75a061ce120a Mon Sep 17 00:00:00 2001 From: P1start Date: Tue, 28 Oct 2014 21:04:08 +1300 Subject: [PATCH 5/5] Special-case some error messages about `Sized` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error messages still aren’t as good as they were before DST, but they better describe the actual problem, not mentioning `Sized` at all (because that bound is normally implied, not explicitly stated). Closes #17567. Closes #18040. Closes #18159. --- src/librustc/middle/typeck/check/vtable.rs | 28 +++++++++++++++------- src/test/compile-fail/issue-16562.rs | 3 +-- src/test/compile-fail/issue-17551.rs | 2 +- src/test/compile-fail/issue-18159.rs | 13 ++++++++++ 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/test/compile-fail/issue-18159.rs diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a5624dcc2fc..14bb92759d3 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -303,15 +303,25 @@ pub fn maybe_report_ambiguity(fcx: &FnCtxt, obligation: &Obligation) { // has_errors() to be sure that compilation isn't happening // anyway. In that case, why inundate the user. if !fcx.tcx().sess.has_errors() { - fcx.tcx().sess.span_err( - obligation.cause.span, - format!( - "unable to infer enough type information to \ - locate the impl of the trait `{}` for \ - the type `{}`; type annotations required", - trait_ref.user_string(fcx.tcx()), - self_ty.user_string(fcx.tcx())).as_slice()); - note_obligation_cause(fcx, obligation); + if fcx.ccx.tcx.lang_items.sized_trait() + .map_or(false, |sized_id| sized_id == trait_ref.def_id) { + fcx.tcx().sess.span_err( + obligation.cause.span, + format!( + "unable to infer enough type information about `{}`; type annotations \ + required", + self_ty.user_string(fcx.tcx())).as_slice()); + } else { + fcx.tcx().sess.span_err( + obligation.cause.span, + format!( + "unable to infer enough type information to \ + locate the impl of the trait `{}` for \ + the type `{}`; type annotations required", + trait_ref.user_string(fcx.tcx()), + self_ty.user_string(fcx.tcx())).as_slice()); + note_obligation_cause(fcx, obligation); + } } } else if !fcx.tcx().sess.has_errors() { // Ambiguity. Coherence should have reported an error. diff --git a/src/test/compile-fail/issue-16562.rs b/src/test/compile-fail/issue-16562.rs index 1e69fb7bfc9..2207e10add4 100644 --- a/src/test/compile-fail/issue-16562.rs +++ b/src/test/compile-fail/issue-16562.rs @@ -16,8 +16,7 @@ struct Col { } impl Collection for Col { -//~^ ERROR unable to infer enough type information to locate the impl of the trait -//~^^ NOTE the trait `core::kinds::Sized` must be implemented because it is required by +//~^ ERROR unable to infer enough type information fn len(&self) -> uint { unimplemented!() } diff --git a/src/test/compile-fail/issue-17551.rs b/src/test/compile-fail/issue-17551.rs index 197319b6d43..e7f61a4f3ff 100644 --- a/src/test/compile-fail/issue-17551.rs +++ b/src/test/compile-fail/issue-17551.rs @@ -13,6 +13,6 @@ struct B; fn main() { - let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait + let foo = B; //~ ERROR unable to infer enough type information let closure = |:| foo; } diff --git a/src/test/compile-fail/issue-18159.rs b/src/test/compile-fail/issue-18159.rs new file mode 100644 index 00000000000..e46bcf46cc3 --- /dev/null +++ b/src/test/compile-fail/issue-18159.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x; //~ ERROR unable to infer enough type information +}