}
/// Returns an option containing a tuple with the start and end (exclusive) of the range.
-fn to_const_range(start: Option<Option<ConstVal>>, end: Option<Option<ConstVal>>, limits: RangeLimits, array_size: ConstInt)
- -> Option<(ConstInt, ConstInt)> {
+fn to_const_range(
+ start: Option<Option<ConstVal>>,
+ end: Option<Option<ConstVal>>,
+ limits: RangeLimits,
+ array_size: ConstInt
+) -> Option<(ConstInt, ConstInt)> {
let start = match start {
Some(Some(ConstVal::Integral(x))) => x,
Some(_) => return None,
/// Return the list of bindings in a pattern.
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<InternedString, ty::Ty<'tcx>> {
- fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut HashMap<InternedString, ty::Ty<'tcx>>) {
+ fn bindings_impl<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ pat: &Pat,
+ map: &mut HashMap<InternedString, ty::Ty<'tcx>>
+ ) {
match pat.node {
PatKind::Box(ref pat) |
PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
}
/// Implementation of the `DERIVE_HASH_XOR_EQ` lint.
-fn check_hash_peq<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref: &TraitRef, ty: ty::Ty<'tcx>,
- hash_is_automatically_derived: bool) {
+fn check_hash_peq<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ span: Span,
+ trait_ref: &TraitRef,
+ ty: ty::Ty<'tcx>,
+ hash_is_automatically_derived: bool
+) {
if_let_chain! {[
match_path_old(&trait_ref.path, &paths::HASH),
let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait()
}
}
-fn check_cond<'a, 'tcx, 'b>(cx: &'a LateContext<'a, 'tcx>, check: &'b Expr)
- -> Option<(&'static str, &'b Expr, &'b Expr)> {
+fn check_cond<'a, 'tcx, 'b>(
+ cx: &'a LateContext<'a, 'tcx>,
+ check: &'b Expr
+) -> Option<(&'static str, &'b Expr, &'b Expr)> {
if_let_chain! {[
let ExprMethodCall(ref name, _, ref params) = check.node,
params.len() >= 2,
// FIXME: #600
#[allow(while_let_on_iterator)]
-fn check_variant(cx: &EarlyContext, threshold: u64, def: &EnumDef, item_name: &str, item_name_chars: usize, span: Span) {
+fn check_variant(
+ cx: &EarlyContext,
+ threshold: u64,
+ def: &EnumDef,
+ item_name: &str,
+ item_name_chars: usize,
+ span: Span
+) {
if (def.variants.len() as u64) < threshold {
return;
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_fn(
- &mut self, cx: &LateContext<'a, 'tcx>, _: visit::FnKind<'tcx>, decl: &'tcx FnDecl, body: &'tcx Expr, _: Span,
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ _: visit::FnKind<'tcx>,
+ decl: &'tcx FnDecl,
+ body: &'tcx Expr,
+ _: Span,
id: NodeId
) {
let param_env = ty::ParameterEnvironment::for_item(cx.tcx, id);
}
}
- fn borrow(&mut self, borrow_id: NodeId, _: Span, cmt: cmt<'tcx>, _: &ty::Region, _: ty::BorrowKind,
- loan_cause: LoanCause) {
+ fn borrow(
+ &mut self,
+ borrow_id: NodeId,
+ _: Span,
+ cmt: cmt<'tcx>,
+ _: &ty::Region,
+ _: ty::BorrowKind,
+ loan_cause: LoanCause
+ ) {
use rustc::ty::adjustment::Adjust;
if let Categorization::Local(lid) = cmt.cat {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
fn check_fn(
- &mut self, cx: &LateContext<'a, 'tcx>, kind: intravisit::FnKind<'tcx>, decl: &'tcx hir::FnDecl,
- expr: &'tcx hir::Expr, span: Span, nodeid: ast::NodeId
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ kind: intravisit::FnKind<'tcx>,
+ decl: &'tcx hir::FnDecl,
+ expr: &'tcx hir::Expr,
+ span: Span,
+ nodeid: ast::NodeId
) {
use rustc::hir::map::Node::*;
}
fn check_raw_ptr(
- &self, cx: &LateContext<'a, 'tcx>, unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl, expr: &'tcx hir::Expr,
+ &self,
+ cx: &LateContext<'a, 'tcx>,
+ unsafety: hir::Unsafety,
+ decl: &'tcx hir::FnDecl,
+ expr: &'tcx hir::Expr,
nodeid: ast::NodeId
) {
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
}
}
-fn check_assign<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: hir::def_id::DefId, block: &'tcx hir::Block)
- -> Option<&'tcx hir::Expr> {
+fn check_assign<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ decl: hir::def_id::DefId,
+ block: &'tcx hir::Block
+) -> Option<&'tcx hir::Expr> {
if_let_chain! {[
block.expr.is_none(),
let Some(expr) = block.stmts.iter().last(),
report_extra_lifetimes(cx, decl, generics);
}
-fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl, named_lts: &'tcx [LifetimeDef], bounds_lts: T)
- -> bool {
+fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(
+ cx: &LateContext<'a, 'tcx>,
+ func: &'tcx FnDecl,
+ named_lts: &'tcx [LifetimeDef],
+ bounds_lts: T
+) -> bool {
// There are two scenarios where elision works:
// * no output references, all input references have different LT
// * output references, exactly one input reference with same LT
}
}
-fn check_for_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, arg: &'tcx Expr, body: &'tcx Expr,
- expr: &'tcx Expr) {
+fn check_for_loop<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ pat: &'tcx Pat,
+ arg: &'tcx Expr,
+ body: &'tcx Expr,
+ expr: &'tcx Expr
+) {
check_for_loop_range(cx, pat, arg, body, expr);
check_for_loop_reverse_range(cx, arg, expr);
check_for_loop_arg(cx, pat, arg, expr);
/// Check for looping over a range and then indexing a sequence with it.
/// The iteratee must be a range literal.
-fn check_for_loop_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, arg: &'tcx Expr, body: &'tcx Expr,
- expr: &'tcx Expr) {
+fn check_for_loop_range<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ pat: &'tcx Pat,
+ arg: &'tcx Expr,
+ body: &'tcx Expr,
+ expr: &'tcx Expr
+) {
if let Some(higher::Range { start: Some(start), ref end, limits }) = higher::range(arg) {
// the var must be a single name
if let PatKind::Binding(_, def_id, ref ident, _) = pat.node {
}
}
-fn check_for_loop_explicit_counter<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx Expr, body: &'tcx Expr,
- expr: &'tcx Expr) {
+fn check_for_loop_explicit_counter<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ arg: &'tcx Expr,
+ body: &'tcx Expr,
+ expr: &'tcx Expr
+) {
// Look for variables that are incremented once per loop iteration.
let mut visitor = IncrementVisitor {
cx: cx,
}
/// Check for the `FOR_KV_MAP` lint.
-fn check_for_loop_over_map_kv<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, arg: &'tcx Expr,
- body: &'tcx Expr, expr: &'tcx Expr) {
+fn check_for_loop_over_map_kv<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ pat: &'tcx Pat,
+ arg: &'tcx Expr,
+ body: &'tcx Expr,
+ expr: &'tcx Expr
+) {
let pat_span = pat.span;
if let PatKind::Tuple(ref pat, _) = pat.node {
}
}
-fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, ty: ty::Ty, els: Option<&Expr>) {
+fn check_single_match_opt_like(
+ cx: &LateContext,
+ ex: &Expr,
+ arms: &[Arm],
+ expr: &Expr,
+ ty: ty::Ty,
+ els: Option<&Expr>
+) {
// list of candidate Enums we know will never get any more members
let candidates = &[(&paths::COW, "Borrowed"),
(&paths::COW, "Cow::Borrowed"),
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir::Expr]) {
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
fn check_unwrap_or_default(
- cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr, or_has_args: bool,
+ cx: &LateContext,
+ name: &str,
+ fun: &hir::Expr,
+ self_expr: &hir::Expr,
+ arg: &hir::Expr,
+ or_has_args: bool,
span: Span
) -> bool {
if or_has_args {
/// Check for `*or(foo())`.
fn check_general_case(
- cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr, or_has_args: bool,
+ cx: &LateContext,
+ name: &str,
+ fun: &hir::Expr,
+ self_expr: &hir::Expr,
+ arg: &hir::Expr,
+ or_has_args: bool,
span: Span
) {
// don't lint for constant values
}
/// lint searching an Iterator followed by `is_some()`
-fn lint_search_is_some(cx: &LateContext, expr: &hir::Expr, search_method: &str, search_args: &[hir::Expr],
- is_some_args: &[hir::Expr]) {
+fn lint_search_is_some(
+ cx: &LateContext,
+ expr: &hir::Expr,
+ search_method: &str,
+ search_args: &[hir::Expr],
+ is_some_args: &[hir::Expr]
+) {
// lint if caller of search is an Iterator
if match_trait_method(cx, &is_some_args[0], &paths::ITERATOR) {
let msg = format!("called `is_some()` after searching an `Iterator` with {}. This is more succinctly \
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
- fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, k: FnKind<'tcx>, decl: &'tcx FnDecl, _: &'tcx Expr, _: Span,
- _: NodeId) {
+ fn check_fn(
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ k: FnKind<'tcx>,
+ decl: &'tcx FnDecl,
+ _: &'tcx Expr,
+ _: Span,
+ _: NodeId
+ ) {
if let FnKind::Closure(_) = k {
// Does not apply to closures
return;
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
fn check_fn(
- &mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl, _: &'tcx hir::Expr,
- span: Span, id: ast::NodeId
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ kind: FnKind<'tcx>,
+ decl: &'tcx hir::FnDecl,
+ _: &'tcx hir::Expr,
+ span: Span,
+ id: ast::NodeId
) {
if in_external_macro(cx, span) {
return;
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
- fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, _: FnKind<'tcx>, decl: &'tcx FnDecl, expr: &'tcx Expr,
- _: Span, _: NodeId) {
+ fn check_fn(
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ _: FnKind<'tcx>,
+ decl: &'tcx FnDecl,
+ expr: &'tcx Expr,
+ _: Span,
+ _: NodeId
+ ) {
if in_external_macro(cx, expr.span) {
return;
}
}
}
-fn check_pat<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, init: Option<&'tcx Expr>, span: Span,
- bindings: &mut Vec<(Name, Span)>) {
+fn check_pat<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ pat: &'tcx Pat,
+ init: Option<&'tcx Expr>,
+ span: Span,
+ bindings: &mut Vec<(Name, Span)>
+) {
// TODO: match more stuff / destructuring
match pat.node {
PatKind::Binding(_, _, ref ident, ref inner) => {
}
}
-fn lint_shadow<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, name: Name, span: Span, pattern_span: Span,
- init: Option<&'tcx Expr>, prev_span: Span) {
+fn lint_shadow<'a, 'tcx: 'a>(
+ cx: &LateContext<'a, 'tcx>,
+ name: Name,
+ span: Span,
+ pattern_span: Span,
+ init: Option<&'tcx Expr>,
+ prev_span: Span
+) {
if let Some(expr) = init {
if is_self_shadow(name, expr) {
span_lint_and_then(cx,
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
- fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, _: FnKind<'tcx>, decl: &'tcx FnDecl, _: &'tcx Expr, _: Span,
- _: NodeId) {
+ fn check_fn(
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ _: FnKind<'tcx>,
+ decl: &'tcx FnDecl,
+ _: &'tcx Expr,
+ _: Span,
+ _: NodeId
+ ) {
self.check_fndecl(cx, decl);
}
-fn detect_absurd_comparison<'a>(cx: &LateContext, op: BinOp_, lhs: &'a Expr, rhs: &'a Expr)
- -> Option<(ExtremeExpr<'a>, AbsurdComparisonResult)> {
+fn detect_absurd_comparison<'a>(
+ cx: &LateContext,
+ op: BinOp_,
+ lhs: &'a Expr,
+ rhs: &'a Expr
+) -> Option<(ExtremeExpr<'a>, AbsurdComparisonResult)> {
use types::ExtremeType::*;
use types::AbsurdComparisonResult::*;
use utils::comparisons::*;
}
fn upcast_comparison_bounds_err(
- cx: &LateContext, span: &Span, rel: comparisons::Rel, lhs_bounds: Option<(FullInt, FullInt)>, lhs: &Expr,
- rhs: &Expr, invert: bool
+ cx: &LateContext,
+ span: &Span,
+ rel: comparisons::Rel,
+ lhs_bounds: Option<(FullInt, FullInt)>,
+ lhs: &Expr,
+ rhs: &Expr,
+ invert: bool
) {
use utils::comparisons::*;
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
fn check_fn(
- &mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl, body: &'tcx hir::Expr,
- span: Span, fn_id: ast::NodeId
+ &mut self,
+ cx: &LateContext<'a, 'tcx>,
+ kind: FnKind<'tcx>,
+ decl: &'tcx hir::FnDecl,
+ body: &'tcx hir::Expr,
+ span: Span,
+ fn_id: ast::NodeId
) {
if in_macro(cx, span) {
return;
/// Check whether a type implements a trait.
/// See also `get_trait_def_id`.
-pub fn implements_trait<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, trait_id: DefId, ty_params: Vec<ty::Ty<'tcx>>)
- -> bool {
+pub fn implements_trait<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ ty: ty::Ty<'tcx>,
+ trait_id: DefId,
+ ty_params: Vec<ty::Ty<'tcx>>
+) -> bool {
cx.tcx.populate_implementations_for_trait_if_necessary(trait_id);
let ty = cx.tcx.erase_regions(&ty);
/// Like `snippet_block`, but add braces if the expr is not an `ExprBlock`.
/// Also takes an `Option<String>` which can be put inside the braces.
-pub fn expr_block<'a, 'b, T: LintContext<'b>>(cx: &T, expr: &Expr, option: Option<String>, default: &'a str)
- -> Cow<'a, str> {
+pub fn expr_block<'a, 'b, T: LintContext<'b>>(
+ cx: &T,
+ expr: &Expr,
+ option: Option<String>,
+ default: &'a str
+) -> Cow<'a, str> {
let code = snippet_block(cx, expr.span, default);
let string = option.unwrap_or_default();
if let ExprBlock(_) = expr.node {
}
}
-pub fn span_help_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str,
- help: &str) {
+pub fn span_help_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(
+ cx: &'a T,
+ lint: &'static Lint,
+ span: Span,
+ msg: &str,
+ help: &str
+) {
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
if cx.current_level(lint) != Level::Allow {
db.0.help(help);
}
}
-pub fn span_note_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str,
- note_span: Span, note: &str) {
+pub fn span_note_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(
+ cx: &'a T,
+ lint: &'static Lint,
+ span: Span,
+ msg: &str,
+ note_span: Span,
+ note: &str
+) {
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
if cx.current_level(lint) != Level::Allow {
if note_span == span {
}
}
-pub fn span_lint_and_then<'a, 'tcx: 'a, T: LintContext<'tcx>, F>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str,
- f: F)
- where F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>)
+pub fn span_lint_and_then<'a, 'tcx: 'a, T: LintContext<'tcx>, F>(
+ cx: &'a T,
+ lint: &'static Lint,
+ sp: Span,
+ msg: &str,
+ f: F
+) where F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>)
{
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, sp, msg));
if cx.current_level(lint) != Level::Allow {
/// Check if two types are the same.
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for <'b> Foo<'b>` but
// not for type parameters.
-pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: ty::Ty<'tcx>, b: ty::Ty<'tcx>, parameter_item: NodeId)
- -> bool {
+pub fn same_tys<'a, 'tcx>(
+ cx: &LateContext<'a, 'tcx>,
+ a: ty::Ty<'tcx>,
+ b: ty::Ty<'tcx>,
+ parameter_item: NodeId
+) -> bool {
let parameter_env = ty::ParameterEnvironment::for_item(cx.tcx, parameter_item);
cx.tcx.infer_ctxt(None, Some(parameter_env), Reveal::All).enter(|infcx| {
let new_a = a.subst(infcx.tcx, infcx.parameter_environment.free_substs);
max_width = 120
ideal_width = 100
-fn_args_density = "Compressed"
fn_call_width = 80
-fn_args_paren_newline = false
match_block_trailing_comma = true
fn_args_layout = "Block"
closure_block_indent_threshold = 0