diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index fbdc0db166524..028d0ec607ab6 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); } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 8e4095df45a8f..0c9e129ef72f0 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); diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a5624dcc2fcd3..14bb92759d3ec 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/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ef3a559bf41a..f04f9efd7a761 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); @@ -3578,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/issue-16562.rs b/src/test/compile-fail/issue-16562.rs index 1e69fb7bfc943..2207e10add451 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 197319b6d4340..e7f61a4f3ff5f 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 0000000000000..e46bcf46cc398 --- /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 +} 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 0000000000000..bd45b76dd5afc --- /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 +} 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 0000000000000..05bbaec37af02 --- /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 `;` +}