Skip to content

Commit 0966977

Browse files
committed
rollup merge of rust-lang#18417 : P1start/lint-fixes
2 parents fc3ed0c + 737e396 commit 0966977

File tree

9 files changed

+90
-15
lines changed

9 files changed

+90
-15
lines changed

src/librustc/driver/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ Available lint options:
255255
for (name, to) in lints.into_iter() {
256256
let name = name.chars().map(|x| x.to_lowercase())
257257
.collect::<String>().replace("_", "-");
258-
let desc = to.into_iter().map(|x| x.as_str()).collect::<Vec<String>>().connect(", ");
258+
let desc = to.into_iter().map(|x| x.as_str().replace("_", "-"))
259+
.collect::<Vec<String>>().connect(", ");
259260
println!(" {} {}",
260261
padded(name.as_slice()), desc);
261262
}

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ impl LintStore {
221221

222222
add_lint_group!(sess, "unused",
223223
UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
224-
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATES, UNUSED_MUST_USE,
225-
UNUSED_UNSAFE, UNUSED_RESULTS, PATH_STATEMENTS)
224+
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
225+
UNUSED_UNSAFE, PATH_STATEMENTS)
226226

227227
// We have one lint pass defined in this module.
228228
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,25 @@ pub fn maybe_report_ambiguity(fcx: &FnCtxt, obligation: &Obligation) {
402402
// has_errors() to be sure that compilation isn't happening
403403
// anyway. In that case, why inundate the user.
404404
if !fcx.tcx().sess.has_errors() {
405-
fcx.tcx().sess.span_err(
406-
obligation.cause.span,
407-
format!(
408-
"unable to infer enough type information to \
409-
locate the impl of the trait `{}` for \
410-
the type `{}`; type annotations required",
411-
trait_ref.user_string(fcx.tcx()),
412-
self_ty.user_string(fcx.tcx())).as_slice());
413-
note_obligation_cause(fcx, obligation);
405+
if fcx.ccx.tcx.lang_items.sized_trait()
406+
.map_or(false, |sized_id| sized_id == trait_ref.def_id) {
407+
fcx.tcx().sess.span_err(
408+
obligation.cause.span,
409+
format!(
410+
"unable to infer enough type information about `{}`; type annotations \
411+
required",
412+
self_ty.user_string(fcx.tcx())).as_slice());
413+
} else {
414+
fcx.tcx().sess.span_err(
415+
obligation.cause.span,
416+
format!(
417+
"unable to infer enough type information to \
418+
locate the impl of the trait `{}` for \
419+
the type `{}`; type annotations required",
420+
trait_ref.user_string(fcx.tcx()),
421+
self_ty.user_string(fcx.tcx())).as_slice());
422+
note_obligation_cause(fcx, obligation);
423+
}
414424
}
415425
} else if !fcx.tcx().sess.has_errors() {
416426
// Ambiguity. Coherence should have reported an error.

src/libsyntax/parse/parser.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,8 @@ impl<'a> Parser<'a> {
27302730
return self.parse_dot_or_call_expr();
27312731
}
27322732

2733+
let lo = self.span.lo;
2734+
27332735
self.bump();
27342736

27352737
// Check for a place: `box(PLACE) EXPR`.
@@ -2738,6 +2740,18 @@ impl<'a> Parser<'a> {
27382740
if !self.eat(&token::RParen) {
27392741
let place = self.parse_expr();
27402742
self.expect(&token::RParen);
2743+
// Give a suggestion to use `box()` when a parenthesised expression is used
2744+
if !self.token.can_begin_expr() {
2745+
let span = self.span;
2746+
let this_token_to_string = self.this_token_to_string();
2747+
self.span_err(span,
2748+
format!("expected expression, found `{}`",
2749+
this_token_to_string).as_slice());
2750+
let box_span = mk_sp(lo, self.last_span.hi);
2751+
self.span_help(box_span,
2752+
"perhaps you meant `box() (foo)` instead?");
2753+
self.abort_if_errors();
2754+
}
27412755
let subexpression = self.parse_prefix_expr();
27422756
hi = subexpression.span.hi;
27432757
ex = ExprBox(place, subexpression);
@@ -3578,6 +3592,16 @@ impl<'a> Parser<'a> {
35783592
let hi = self.span.hi;
35793593

35803594
if id.name == token::special_idents::invalid.name {
3595+
if self.token == token::Dot {
3596+
let span = self.span;
3597+
let token_string = self.this_token_to_string();
3598+
self.span_err(span,
3599+
format!("expected statement, found `{}`",
3600+
token_string).as_slice());
3601+
let mac_span = mk_sp(lo, hi);
3602+
self.span_help(mac_span, "try parenthesizing this macro invocation");
3603+
self.abort_if_errors();
3604+
}
35813605
P(spanned(lo, hi, StmtMac(
35823606
spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)), false)))
35833607
} else {

src/test/compile-fail/issue-16562.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ struct Col<D, C> {
1616
}
1717

1818
impl<T, M: MatrixShape> Collection for Col<M, uint> {
19-
//~^ ERROR unable to infer enough type information to locate the impl of the trait
20-
//~^^ NOTE the trait `core::kinds::Sized` must be implemented because it is required by
19+
//~^ ERROR unable to infer enough type information
2120
fn len(&self) -> uint {
2221
unimplemented!()
2322
}

src/test/compile-fail/issue-17551.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
struct B<T>;
1414

1515
fn main() {
16-
let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait
16+
let foo = B; //~ ERROR unable to infer enough type information
1717
let closure = |:| foo;
1818
}

src/test/compile-fail/issue-18159.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x; //~ ERROR unable to infer enough type information
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
foo!() //~ HELP try parenthesizing this macro invocation
13+
.bar //~ ERROR expected statement
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
box(1 + 1) //~ HELP perhaps you meant `box() (foo)` instead?
13+
; //~ ERROR expected expression, found `;`
14+
}

0 commit comments

Comments
 (0)