Skip to content

Commit

Permalink
rollup merge of rust-lang#18417 : P1start/lint-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Oct 30, 2014
2 parents fc3ed0c + 737e396 commit 0966977
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/librustc/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ Available lint options:
for (name, to) in lints.into_iter() {
let name = name.chars().map(|x| x.to_lowercase())
.collect::<String>().replace("_", "-");
let desc = to.into_iter().map(|x| x.as_str()).collect::<Vec<String>>().connect(", ");
let desc = to.into_iter().map(|x| x.as_str().replace("_", "-"))
.collect::<Vec<String>>().connect(", ");
println!(" {} {}",
padded(name.as_slice()), desc);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 19 additions & 9 deletions src/librustc/middle/typeck/check/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,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.
Expand Down
24 changes: 24 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/issue-16562.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ struct Col<D, C> {
}

impl<T, M: MatrixShape> Collection for Col<M, uint> {
//~^ 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!()
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-17551.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
struct B<T>;

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;
}
13 changes: 13 additions & 0 deletions src/test/compile-fail/issue-18159.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

fn main() {
let x; //~ ERROR unable to infer enough type information
}
14 changes: 14 additions & 0 deletions src/test/compile-fail/macro-invocation-dot-help.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

fn main() {
foo!() //~ HELP try parenthesizing this macro invocation
.bar //~ ERROR expected statement
}
14 changes: 14 additions & 0 deletions src/test/compile-fail/parenthesized-box-expr-message.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

fn main() {
box(1 + 1) //~ HELP perhaps you meant `box() (foo)` instead?
; //~ ERROR expected expression, found `;`
}

0 comments on commit 0966977

Please sign in to comment.