mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 09:53:26 +00:00
rollup merge of #18417 : P1start/lint-fixes
This commit is contained in:
commit
09669772db
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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!()
|
||||
}
|
||||
|
@ -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
src/test/compile-fail/issue-18159.rs
Normal file
13
src/test/compile-fail/issue-18159.rs
Normal file
@ -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
src/test/compile-fail/macro-invocation-dot-help.rs
Normal file
14
src/test/compile-fail/macro-invocation-dot-help.rs
Normal file
@ -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
src/test/compile-fail/parenthesized-box-expr-message.rs
Normal file
14
src/test/compile-fail/parenthesized-box-expr-message.rs
Normal file
@ -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 `;`
|
||||
}
|
Loading…
Reference in New Issue
Block a user