function definition style simplification
This commit is contained in:
parent
ed9d71f2c9
commit
47eead5ada
@ -107,8 +107,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
|
||||
}
|
||||
|
||||
/// 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,
|
||||
|
@ -248,7 +248,11 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
|
||||
|
||||
/// 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),
|
||||
|
@ -86,8 +86,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
|
||||
}
|
||||
|
||||
/// 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()
|
||||
|
@ -78,8 +78,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -114,7 +114,14 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
@ -62,7 +62,12 @@ impl LintPass for Pass {
|
||||
|
||||
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);
|
||||
@ -146,8 +151,15 @@ impl<'a, 'tcx: 'a + 'gcx, 'gcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx,
|
||||
}
|
||||
|
||||
}
|
||||
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 {
|
||||
|
@ -70,8 +70,13 @@ impl LintPass for Functions {
|
||||
|
||||
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::*;
|
||||
|
||||
@ -127,7 +132,11 @@ impl<'a, 'tcx> Functions {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -149,8 +149,11 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
|
@ -116,8 +116,12 @@ fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, gene
|
||||
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
|
||||
|
@ -402,8 +402,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -413,8 +418,13 @@ fn check_for_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, arg: &'t
|
||||
|
||||
/// 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 {
|
||||
@ -641,8 +651,12 @@ fn check_arg_type(cx: &LateContext, pat: &Pat, arg: &Expr) {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@ -687,8 +701,13 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
|
@ -196,7 +196,14 @@ fn check_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm],
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
|
@ -696,7 +696,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
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 {
|
||||
@ -737,7 +742,12 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
|
||||
|
||||
/// 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
|
||||
@ -1157,8 +1167,13 @@ fn lint_filter_map_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &[
|
||||
}
|
||||
|
||||
/// 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 \
|
||||
|
@ -170,8 +170,15 @@ impl LintPass for Pass {
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -91,8 +91,13 @@ impl LintPass for NewWithoutDefault {
|
||||
|
||||
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;
|
||||
|
@ -80,8 +80,15 @@ impl LintPass for Pass {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -143,8 +150,13 @@ fn is_binding(cx: &LateContext, pat_id: NodeId) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
@ -222,8 +234,14 @@ fn check_pat<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, init: Option<
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -528,8 +528,15 @@ impl LintPass for TypeComplexityPass {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -740,8 +747,12 @@ enum AbsurdComparisonResult {
|
||||
|
||||
|
||||
|
||||
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::*;
|
||||
@ -1008,8 +1019,13 @@ fn err_upcast_comparison(cx: &LateContext, span: &Span, expr: &Expr, always: boo
|
||||
}
|
||||
|
||||
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::*;
|
||||
|
||||
|
@ -42,8 +42,13 @@ impl LintPass for UnusedLabel {
|
||||
|
||||
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;
|
||||
|
@ -317,8 +317,12 @@ pub fn get_trait_def_id(cx: &LateContext, path: &[&str]) -> Option<DefId> {
|
||||
|
||||
/// 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);
|
||||
@ -401,8 +405,12 @@ pub fn snippet_block<'a, 'b, T: LintContext<'b>>(cx: &T, span: Span, default: &'
|
||||
|
||||
/// 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 {
|
||||
@ -515,8 +523,13 @@ pub fn span_lint<'a, T: LintContext<'a>>(cx: &T, lint: &'static Lint, sp: Span,
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -524,8 +537,14 @@ pub fn span_help_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(cx: &'a T, lint: &
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -537,9 +556,13 @@ pub fn span_note_and_lint<'a, 'tcx: 'a, T: LintContext<'tcx>>(cx: &'a T, lint: &
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -756,8 +779,12 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> ty::T
|
||||
/// 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);
|
||||
|
@ -1,8 +1,6 @@
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user