Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca05e93

Browse files
committedMay 17, 2016
Rustup to *1.10.0-nightly (cd6a400 2016-05-16)*
1 parent 4c4b1af commit ca05e93

File tree

4 files changed

+94
-103
lines changed

4 files changed

+94
-103
lines changed
 

‎src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItem]) {
126126
}
127127

128128
fn is_self_sig(sig: &MethodSig) -> bool {
129-
if let SelfStatic = sig.explicit_self.node {
130-
false
131-
} else {
129+
if sig.decl.has_self() {
132130
sig.decl.inputs.len() == 1
131+
} else {
132+
false
133133
}
134134
}
135135

‎src/lifetimes.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ impl LintPass for LifetimePass {
4646
impl LateLintPass for LifetimePass {
4747
fn check_item(&mut self, cx: &LateContext, item: &Item) {
4848
if let ItemFn(ref decl, _, _, _, ref generics, _) = item.node {
49-
check_fn_inner(cx, decl, None, generics, item.span);
49+
check_fn_inner(cx, decl, generics, item.span);
5050
}
5151
}
5252

5353
fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
5454
if let ImplItemKind::Method(ref sig, _) = item.node {
55-
check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self), &sig.generics, item.span);
55+
check_fn_inner(cx, &sig.decl, &sig.generics, item.span);
5656
}
5757
}
5858

5959
fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
6060
if let MethodTraitItem(ref sig, _) = item.node {
61-
check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self), &sig.generics, item.span);
61+
check_fn_inner(cx, &sig.decl, &sig.generics, item.span);
6262
}
6363
}
6464
}
@@ -87,7 +87,7 @@ fn bound_lifetimes(bound: &TyParamBound) -> Option<HirVec<&Lifetime>> {
8787
}
8888
}
8989

90-
fn check_fn_inner(cx: &LateContext, decl: &FnDecl, slf: Option<&ExplicitSelf>, generics: &Generics, span: Span) {
90+
fn check_fn_inner(cx: &LateContext, decl: &FnDecl, generics: &Generics, span: Span) {
9191
if in_external_macro(cx, span) || has_where_lifetimes(cx, &generics.where_clause) {
9292
return;
9393
}
@@ -96,16 +96,16 @@ fn check_fn_inner(cx: &LateContext, decl: &FnDecl, slf: Option<&ExplicitSelf>, g
9696
.iter()
9797
.flat_map(|ref typ| typ.bounds.iter().filter_map(bound_lifetimes).flat_map(|lts| lts));
9898

99-
if could_use_elision(cx, decl, slf, &generics.lifetimes, bounds_lts) {
99+
if could_use_elision(cx, decl, &generics.lifetimes, bounds_lts) {
100100
span_lint(cx,
101101
NEEDLESS_LIFETIMES,
102102
span,
103103
"explicit lifetimes given in parameter types where they could be elided");
104104
}
105-
report_extra_lifetimes(cx, decl, generics, slf);
105+
report_extra_lifetimes(cx, decl, generics);
106106
}
107107

108-
fn could_use_elision<'a, T: Iterator<Item = &'a Lifetime>>(cx: &LateContext, func: &FnDecl, slf: Option<&ExplicitSelf>,
108+
fn could_use_elision<'a, T: Iterator<Item = &'a Lifetime>>(cx: &LateContext, func: &FnDecl,
109109
named_lts: &[LifetimeDef], bounds_lts: T)
110110
-> bool {
111111
// There are two scenarios where elision works:
@@ -121,15 +121,6 @@ fn could_use_elision<'a, T: Iterator<Item = &'a Lifetime>>(cx: &LateContext, fun
121121
let mut input_visitor = RefVisitor::new(cx);
122122
let mut output_visitor = RefVisitor::new(cx);
123123

124-
// extract lifetime in "self" argument for methods (there is a "self" argument
125-
// in func.inputs, but its type is TyInfer)
126-
if let Some(slf) = slf {
127-
match slf.node {
128-
SelfRegion(ref opt_lt, _, _) => input_visitor.record(opt_lt),
129-
SelfExplicit(ref ty, _) => walk_ty(&mut input_visitor, ty),
130-
_ => (),
131-
}
132-
}
133124
// extract lifetimes in input argument types
134125
for arg in &func.inputs {
135126
input_visitor.visit_ty(&arg.ty);
@@ -340,7 +331,7 @@ impl<'v> Visitor<'v> for LifetimeChecker {
340331
}
341332
}
342333

343-
fn report_extra_lifetimes(cx: &LateContext, func: &FnDecl, generics: &Generics, slf: Option<&ExplicitSelf>) {
334+
fn report_extra_lifetimes(cx: &LateContext, func: &FnDecl, generics: &Generics) {
344335
let hs = generics.lifetimes
345336
.iter()
346337
.map(|lt| (lt.lifetime.name, lt.lifetime.span))
@@ -350,14 +341,6 @@ fn report_extra_lifetimes(cx: &LateContext, func: &FnDecl, generics: &Generics,
350341
walk_generics(&mut checker, generics);
351342
walk_fn_decl(&mut checker, func);
352343

353-
if let Some(slf) = slf {
354-
match slf.node {
355-
SelfRegion(Some(ref lt), _, _) => checker.visit_lifetime(lt),
356-
SelfExplicit(ref t, _) => walk_ty(&mut checker, t),
357-
_ => (),
358-
}
359-
}
360-
361344
for &v in checker.0.values() {
362345
span_lint(cx, UNUSED_LIFETIMES, v, "this lifetime isn't used in the function definition");
363346
}

‎src/methods.rs

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc::hir::*;
1+
use rustc::hir;
22
use rustc::lint::*;
33
use rustc::middle::const_val::ConstVal;
44
use rustc::middle::const_qualif::ConstQualif;
@@ -335,13 +335,13 @@ impl LintPass for MethodsPass {
335335
}
336336

337337
impl LateLintPass for MethodsPass {
338-
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
338+
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
339339
if in_macro(cx, expr.span) {
340340
return;
341341
}
342342

343343
match expr.node {
344-
ExprMethodCall(name, _, ref args) => {
344+
hir::ExprMethodCall(name, _, ref args) => {
345345
// Chain calls
346346
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
347347
lint_unwrap(cx, expr, arglists[0]);
@@ -384,90 +384,92 @@ impl LateLintPass for MethodsPass {
384384
_ => (),
385385
}
386386
}
387-
ExprBinary(op, ref lhs, ref rhs) if op.node == BiEq || op.node == BiNe => {
388-
if !lint_chars_next(cx, expr, lhs, rhs, op.node == BiEq) {
389-
lint_chars_next(cx, expr, rhs, lhs, op.node == BiEq);
387+
hir::ExprBinary(op, ref lhs, ref rhs) if op.node == hir::BiEq || op.node == hir::BiNe => {
388+
if !lint_chars_next(cx, expr, lhs, rhs, op.node == hir::BiEq) {
389+
lint_chars_next(cx, expr, rhs, lhs, op.node == hir::BiEq);
390390
}
391391
}
392392
_ => (),
393393
}
394394
}
395395

396-
fn check_item(&mut self, cx: &LateContext, item: &Item) {
396+
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
397397
if in_external_macro(cx, item.span) {
398398
return;
399399
}
400400

401-
if let ItemImpl(_, _, _, None, _, ref items) = item.node {
401+
if let hir::ItemImpl(_, _, _, None, _, ref items) = item.node {
402402
for implitem in items {
403403
let name = implitem.name;
404-
if let ImplItemKind::Method(ref sig, _) = implitem.node {
404+
if_let_chain! {[
405+
let hir::ImplItemKind::Method(ref sig, _) = implitem.node,
406+
let Some(explicit_self) = sig.decl.inputs.get(0).and_then(hir::Arg::to_self),
407+
], {
405408
// check missing trait implementations
406409
for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS {
407-
if_let_chain! {
408-
[
409-
name.as_str() == method_name,
410-
sig.decl.inputs.len() == n_args,
411-
out_type.matches(&sig.decl.output),
412-
self_kind.matches(&sig.explicit_self.node, false)
413-
], {
414-
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!(
415-
"defining a method called `{}` on this type; consider implementing \
416-
the `{}` trait or choosing a less ambiguous name", name, trait_name));
417-
}
410+
if name.as_str() == method_name &&
411+
sig.decl.inputs.len() == n_args &&
412+
out_type.matches(&sig.decl.output) &&
413+
self_kind.matches(&explicit_self, false) {
414+
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!(
415+
"defining a method called `{}` on this type; consider implementing \
416+
the `{}` trait or choosing a less ambiguous name", name, trait_name));
418417
}
419418
}
420419

421420
// check conventions w.r.t. conversion method names and predicates
422421
let ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(item.id)).ty;
423422
let is_copy = is_copy(cx, ty, item);
424423
for &(ref conv, self_kinds) in &CONVENTIONS {
425-
if conv.check(&name.as_str()) &&
426-
!self_kinds.iter().any(|k| k.matches(&sig.explicit_self.node, is_copy)) {
427-
let lint = if item.vis == Visibility::Public {
424+
if_let_chain! {[
425+
conv.check(&name.as_str()),
426+
let Some(explicit_self) = sig.decl.inputs.get(0).and_then(hir::Arg::to_self),
427+
!self_kinds.iter().any(|k| k.matches(&explicit_self, is_copy)),
428+
], {
429+
let lint = if item.vis == hir::Visibility::Public {
428430
WRONG_PUB_SELF_CONVENTION
429431
} else {
430432
WRONG_SELF_CONVENTION
431433
};
432434
span_lint(cx,
433435
lint,
434-
sig.explicit_self.span,
436+
explicit_self.span,
435437
&format!("methods called `{}` usually take {}; consider choosing a less \
436438
ambiguous name",
437439
conv,
438440
&self_kinds.iter()
439441
.map(|k| k.description())
440442
.collect::<Vec<_>>()
441443
.join(" or ")));
442-
}
444+
}}
443445
}
444446

445447
let ret_ty = return_ty(cx, implitem.id);
446448
if &name.as_str() == &"new" &&
447449
!ret_ty.map_or(false, |ret_ty| ret_ty.walk().any(|t| same_tys(cx, t, ty, implitem.id))) {
448450
span_lint(cx,
449451
NEW_RET_NO_SELF,
450-
sig.explicit_self.span,
452+
explicit_self.span,
451453
"methods called `new` usually return `Self`");
452454
}
453455
}
454-
}
456+
}}
455457
}
456458
}
457459
}
458460

459461
/// Checks for the `OR_FUN_CALL` lint.
460-
fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>]) {
462+
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hir::Expr>]) {
461463
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
462-
fn check_unwrap_or_default(cx: &LateContext, name: &str, fun: &Expr, self_expr: &Expr, arg: &Expr,
464+
fn check_unwrap_or_default(cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr,
463465
or_has_args: bool, span: Span)
464466
-> bool {
465467
if or_has_args {
466468
return false;
467469
}
468470

469471
if name == "unwrap_or" {
470-
if let ExprPath(_, ref path) = fun.node {
472+
if let hir::ExprPath(_, ref path) = fun.node {
471473
let path: &str = &path.segments
472474
.last()
473475
.expect("A path must have at least one segment")
@@ -501,7 +503,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
501503
}
502504

503505
/// Check for `*or(foo())`.
504-
fn check_general_case(cx: &LateContext, name: &str, fun: &Expr, self_expr: &Expr, arg: &Expr, or_has_args: bool,
506+
fn check_general_case(cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr, or_has_args: bool,
505507
span: Span) {
506508
// don't lint for constant values
507509
// FIXME: can we `expect` here instead of match?
@@ -545,7 +547,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
545547
}
546548

547549
if args.len() == 2 {
548-
if let ExprCall(ref fun, ref or_args) = args[1].node {
550+
if let hir::ExprCall(ref fun, ref or_args) = args[1].node {
549551
let or_has_args = !or_args.is_empty();
550552
if !check_unwrap_or_default(cx, name, fun, &args[0], &args[1], or_has_args, expr.span) {
551553
check_general_case(cx, name, fun, &args[0], &args[1], or_has_args, expr.span);
@@ -555,7 +557,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
555557
}
556558

557559
/// Checks for the `CLONE_ON_COPY` lint.
558-
fn lint_clone_on_copy(cx: &LateContext, expr: &Expr) {
560+
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr) {
559561
let ty = cx.tcx.expr_ty(expr);
560562
let parent = cx.tcx.map.get_parent(expr.id);
561563
let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, parent);
@@ -566,7 +568,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &Expr) {
566568
}
567569

568570
/// Checks for the `CLONE_DOUBLE_REF` lint.
569-
fn lint_clone_double_ref(cx: &LateContext, expr: &Expr, arg: &Expr, ty: ty::Ty) {
571+
fn lint_clone_double_ref(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, ty: ty::Ty) {
570572
if let ty::TyRef(_, ty::TypeAndMut { ty: ref inner, .. }) = ty.sty {
571573
if let ty::TyRef(..) = inner.sty {
572574
let mut db = span_lint(cx,
@@ -582,7 +584,7 @@ fn lint_clone_double_ref(cx: &LateContext, expr: &Expr, arg: &Expr, ty: ty::Ty)
582584
}
583585
}
584586

585-
fn lint_extend(cx: &LateContext, expr: &Expr, args: &MethodArgs) {
587+
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
586588
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.expr_ty(&args[0]));
587589
if !match_type(cx, obj_ty, &paths::VEC) {
588590
return;
@@ -599,11 +601,11 @@ fn lint_extend(cx: &LateContext, expr: &Expr, args: &MethodArgs) {
599601
}
600602
}
601603

602-
fn lint_cstring_as_ptr(cx: &LateContext, expr: &Expr, new: &Expr, unwrap: &Expr) {
604+
fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwrap: &hir::Expr) {
603605
if_let_chain!{[
604-
let ExprCall(ref fun, ref args) = new.node,
606+
let hir::ExprCall(ref fun, ref args) = new.node,
605607
args.len() == 1,
606-
let ExprPath(None, ref path) = fun.node,
608+
let hir::ExprPath(None, ref path) = fun.node,
607609
match_path(path, &paths::CSTRING_NEW),
608610
], {
609611
span_lint_and_then(cx, TEMPORARY_CSTRING_AS_PTR, expr.span,
@@ -615,7 +617,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &Expr, new: &Expr, unwrap: &Expr)
615617
}}
616618
}
617619

618-
fn derefs_to_slice(cx: &LateContext, expr: &Expr, ty: &ty::Ty) -> Option<(Span, &'static str)> {
620+
fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: &ty::Ty) -> Option<(Span, &'static str)> {
619621
fn may_slice(cx: &LateContext, ty: &ty::Ty) -> bool {
620622
match ty.sty {
621623
ty::TySlice(_) => true,
@@ -626,7 +628,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &Expr, ty: &ty::Ty) -> Option<(Span,
626628
_ => false,
627629
}
628630
}
629-
if let ExprMethodCall(name, _, ref args) = expr.node {
631+
if let hir::ExprMethodCall(name, _, ref args) = expr.node {
630632
if &name.node.as_str() == &"iter" && may_slice(cx, &cx.tcx.expr_ty(&args[0])) {
631633
Some((args[0].span, "&"))
632634
} else {
@@ -651,7 +653,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &Expr, ty: &ty::Ty) -> Option<(Span,
651653
#[allow(ptr_arg)]
652654
// Type of MethodArgs is potentially a Vec
653655
/// lint use of `unwrap()` for `Option`s and `Result`s
654-
fn lint_unwrap(cx: &LateContext, expr: &Expr, unwrap_args: &MethodArgs) {
656+
fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &MethodArgs) {
655657
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.expr_ty(&unwrap_args[0]));
656658

657659
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
@@ -677,7 +679,7 @@ fn lint_unwrap(cx: &LateContext, expr: &Expr, unwrap_args: &MethodArgs) {
677679
#[allow(ptr_arg)]
678680
// Type of MethodArgs is potentially a Vec
679681
/// lint use of `ok().expect()` for `Result`s
680-
fn lint_ok_expect(cx: &LateContext, expr: &Expr, ok_args: &MethodArgs) {
682+
fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &MethodArgs) {
681683
// lint if the caller of `ok()` is a `Result`
682684
if match_type(cx, cx.tcx.expr_ty(&ok_args[0]), &paths::RESULT) {
683685
let result_type = cx.tcx.expr_ty(&ok_args[0]);
@@ -695,7 +697,7 @@ fn lint_ok_expect(cx: &LateContext, expr: &Expr, ok_args: &MethodArgs) {
695697
#[allow(ptr_arg)]
696698
// Type of MethodArgs is potentially a Vec
697699
/// lint use of `map().unwrap_or()` for `Option`s
698-
fn lint_map_unwrap_or(cx: &LateContext, expr: &Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
700+
fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
699701
// lint if the caller of `map()` is an `Option`
700702
if match_type(cx, cx.tcx.expr_ty(&map_args[0]), &paths::OPTION) {
701703
// lint message
@@ -726,7 +728,7 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &Expr, map_args: &MethodArgs, unwr
726728
#[allow(ptr_arg)]
727729
// Type of MethodArgs is potentially a Vec
728730
/// lint use of `map().unwrap_or_else()` for `Option`s
729-
fn lint_map_unwrap_or_else(cx: &LateContext, expr: &Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
731+
fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
730732
// lint if the caller of `map()` is an `Option`
731733
if match_type(cx, cx.tcx.expr_ty(&map_args[0]), &paths::OPTION) {
732734
// lint message
@@ -757,7 +759,7 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &Expr, map_args: &MethodArgs,
757759
#[allow(ptr_arg)]
758760
// Type of MethodArgs is potentially a Vec
759761
/// lint use of `filter().next() for Iterators`
760-
fn lint_filter_next(cx: &LateContext, expr: &Expr, filter_args: &MethodArgs) {
762+
fn lint_filter_next(cx: &LateContext, expr: &hir::Expr, filter_args: &MethodArgs) {
761763
// lint if caller of `.filter().next()` is an Iterator
762764
if match_trait_method(cx, expr, &paths::ITERATOR) {
763765
let msg = "called `filter(p).next()` on an Iterator. This is more succinctly expressed by calling `.find(p)` \
@@ -780,7 +782,7 @@ fn lint_filter_next(cx: &LateContext, expr: &Expr, filter_args: &MethodArgs) {
780782
#[allow(ptr_arg)]
781783
// Type of MethodArgs is potentially a Vec
782784
/// lint searching an Iterator followed by `is_some()`
783-
fn lint_search_is_some(cx: &LateContext, expr: &Expr, search_method: &str, search_args: &MethodArgs,
785+
fn lint_search_is_some(cx: &LateContext, expr: &hir::Expr, search_method: &str, search_args: &MethodArgs,
784786
is_some_args: &MethodArgs) {
785787
// lint if caller of search is an Iterator
786788
if match_trait_method(cx, &*is_some_args[0], &paths::ITERATOR) {
@@ -803,12 +805,12 @@ fn lint_search_is_some(cx: &LateContext, expr: &Expr, search_method: &str, searc
803805
}
804806

805807
/// Checks for the `CHARS_NEXT_CMP` lint.
806-
fn lint_chars_next(cx: &LateContext, expr: &Expr, chain: &Expr, other: &Expr, eq: bool) -> bool {
808+
fn lint_chars_next(cx: &LateContext, expr: &hir::Expr, chain: &hir::Expr, other: &hir::Expr, eq: bool) -> bool {
807809
if_let_chain! {[
808810
let Some(args) = method_chain_args(chain, &["chars", "next"]),
809-
let ExprCall(ref fun, ref arg_char) = other.node,
811+
let hir::ExprCall(ref fun, ref arg_char) = other.node,
810812
arg_char.len() == 1,
811-
let ExprPath(None, ref path) = fun.node,
813+
let hir::ExprPath(None, ref path) = fun.node,
812814
path.segments.len() == 1 && path.segments[0].identifier.name.as_str() == "Some"
813815
], {
814816
let self_ty = walk_ptrs_ty(cx.tcx.expr_ty_adjusted(&args[0][0]));
@@ -838,7 +840,7 @@ fn lint_chars_next(cx: &LateContext, expr: &Expr, chain: &Expr, other: &Expr, eq
838840
}
839841

840842
/// lint for length-1 `str`s for methods in `PATTERN_METHODS`
841-
fn lint_single_char_pattern(cx: &LateContext, expr: &Expr, arg: &Expr) {
843+
fn lint_single_char_pattern(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr) {
842844
if let Ok(ConstVal::Str(r)) = eval_const_expr_partial(cx.tcx, arg, ExprTypeChecked, None) {
843845
if r.len() == 1 {
844846
let hint = snippet(cx, expr.span, "..").replace(&format!("\"{}\"", r), &format!("'{}'", r));
@@ -954,26 +956,26 @@ enum SelfKind {
954956
}
955957

956958
impl SelfKind {
957-
fn matches(&self, slf: &ExplicitSelf_, allow_value_for_ref: bool) -> bool {
958-
match (self, slf) {
959-
(&SelfKind::Value, &SelfValue(_)) |
960-
(&SelfKind::Ref, &SelfRegion(_, Mutability::MutImmutable, _)) |
961-
(&SelfKind::RefMut, &SelfRegion(_, Mutability::MutMutable, _)) |
962-
(&SelfKind::No, &SelfStatic) => true,
963-
(&SelfKind::Ref, &SelfValue(_)) |
964-
(&SelfKind::RefMut, &SelfValue(_)) => allow_value_for_ref,
965-
(_, &SelfExplicit(ref ty, _)) => self.matches_explicit_type(ty, allow_value_for_ref),
959+
fn matches(self, slf: &hir::ExplicitSelf, allow_value_for_ref: bool) -> bool {
960+
match (self, &slf.node) {
961+
(SelfKind::Value, &hir::SelfKind::Value(_)) |
962+
(SelfKind::Ref, &hir::SelfKind::Region(_, hir::Mutability::MutImmutable)) |
963+
(SelfKind::RefMut, &hir::SelfKind::Region(_, hir::Mutability::MutMutable)) => true,
964+
(SelfKind::Ref, &hir::SelfKind::Value(_)) |
965+
(SelfKind::RefMut, &hir::SelfKind::Value(_)) => allow_value_for_ref,
966+
(_, &hir::SelfKind::Explicit(ref ty, _)) => self.matches_explicit_type(ty, allow_value_for_ref),
967+
966968
_ => false,
967969
}
968970
}
969971

970-
fn matches_explicit_type(&self, ty: &Ty, allow_value_for_ref: bool) -> bool {
972+
fn matches_explicit_type(self, ty: &hir::Ty, allow_value_for_ref: bool) -> bool {
971973
match (self, &ty.node) {
972-
(&SelfKind::Value, &TyPath(..)) |
973-
(&SelfKind::Ref, &TyRptr(_, MutTy { mutbl: Mutability::MutImmutable, .. })) |
974-
(&SelfKind::RefMut, &TyRptr(_, MutTy { mutbl: Mutability::MutMutable, .. })) => true,
975-
(&SelfKind::Ref, &TyPath(..)) |
976-
(&SelfKind::RefMut, &TyPath(..)) => allow_value_for_ref,
974+
(SelfKind::Value, &hir::TyPath(..)) |
975+
(SelfKind::Ref, &hir::TyRptr(_, hir::MutTy { mutbl: hir::Mutability::MutImmutable, .. })) |
976+
(SelfKind::RefMut, &hir::TyRptr(_, hir::MutTy { mutbl: hir::Mutability::MutMutable, .. })) => true,
977+
(SelfKind::Ref, &hir::TyPath(..)) |
978+
(SelfKind::RefMut, &hir::TyPath(..)) => allow_value_for_ref,
977979
_ => false,
978980
}
979981
}
@@ -1015,14 +1017,14 @@ enum OutType {
10151017
}
10161018

10171019
impl OutType {
1018-
fn matches(&self, ty: &FunctionRetTy) -> bool {
1020+
fn matches(&self, ty: &hir::FunctionRetTy) -> bool {
10191021
match (self, ty) {
1020-
(&OutType::Unit, &DefaultReturn(_)) => true,
1021-
(&OutType::Unit, &Return(ref ty)) if ty.node == TyTup(vec![].into()) => true,
1022-
(&OutType::Bool, &Return(ref ty)) if is_bool(ty) => true,
1023-
(&OutType::Any, &Return(ref ty)) if ty.node != TyTup(vec![].into()) => true,
1024-
(&OutType::Ref, &Return(ref ty)) => {
1025-
if let TyRptr(_, _) = ty.node {
1022+
(&OutType::Unit, &hir::DefaultReturn(_)) => true,
1023+
(&OutType::Unit, &hir::Return(ref ty)) if ty.node == hir::TyTup(vec![].into()) => true,
1024+
(&OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
1025+
(&OutType::Any, &hir::Return(ref ty)) if ty.node != hir::TyTup(vec![].into()) => true,
1026+
(&OutType::Ref, &hir::Return(ref ty)) => {
1027+
if let hir::TyRptr(_, _) = ty.node {
10261028
true
10271029
} else {
10281030
false
@@ -1033,16 +1035,16 @@ impl OutType {
10331035
}
10341036
}
10351037

1036-
fn is_bool(ty: &Ty) -> bool {
1037-
if let TyPath(None, ref p) = ty.node {
1038+
fn is_bool(ty: &hir::Ty) -> bool {
1039+
if let hir::TyPath(None, ref p) = ty.node {
10381040
if match_path(p, &["bool"]) {
10391041
return true;
10401042
}
10411043
}
10421044
false
10431045
}
10441046

1045-
fn is_copy<'a, 'ctx>(cx: &LateContext<'a, 'ctx>, ty: ty::Ty<'ctx>, item: &Item) -> bool {
1047+
fn is_copy<'a, 'ctx>(cx: &LateContext<'a, 'ctx>, ty: ty::Ty<'ctx>, item: &hir::Item) -> bool {
10461048
let env = ty::ParameterEnvironment::for_item(cx.tcx, item.id);
10471049
!ty.subst(cx.tcx, env.free_substs).moves_by_default(cx.tcx.global_tcx(), &env, item.span)
10481050
}

‎tests/compile-fail/unused_lt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ impl<'a> Foo<'a> for u8 {
4444
}
4545
}
4646

47+
struct Bar;
48+
49+
impl Bar {
50+
fn x<'a>(&self) {} //~ ERROR this lifetime
51+
}
52+
4753
// test for #489 (used lifetimes in bounds)
4854
pub fn parse<'a, I: Iterator<Item=&'a str>>(_it: &mut I) {
4955
unimplemented!()

0 commit comments

Comments
 (0)
Please sign in to comment.