|
1 | 1 | use rustc::lint::*;
|
2 | 2 | use rustc::hir::def_id::DefId;
|
3 |
| -use rustc::ty::{self, MethodTraitItemId, ImplOrTraitItemId}; |
| 3 | +use rustc::ty::{self, ImplOrTraitItem}; |
4 | 4 | use rustc::hir::*;
|
5 | 5 | use syntax::ast::{Lit, LitKind, Name};
|
6 | 6 | use syntax::codemap::{Span, Spanned};
|
@@ -184,37 +184,33 @@ fn check_len_zero(cx: &LateContext, span: Span, name: &Name, args: &[P<Expr>], l
|
184 | 184 | /// Check if this type has an `is_empty` method.
|
185 | 185 | fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
|
186 | 186 | /// Get an `ImplOrTraitItem` and return true if it matches `is_empty(self)`.
|
187 |
| - fn is_is_empty(cx: &LateContext, id: &ImplOrTraitItemId) -> bool { |
188 |
| - if let MethodTraitItemId(def_id) = *id { |
189 |
| - if let ty::MethodTraitItem(ref method) = cx.tcx.impl_or_trait_item(def_id) { |
190 |
| - method.name.as_str() == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1 |
191 |
| - } else { |
192 |
| - false |
193 |
| - } |
| 187 | + fn is_is_empty(item: &ImplOrTraitItem) -> bool { |
| 188 | + if let ty::MethodTraitItem(ref method) = *item { |
| 189 | + method.name.as_str() == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1 |
194 | 190 | } else {
|
195 | 191 | false
|
196 | 192 | }
|
197 | 193 | }
|
198 | 194 |
|
199 | 195 | /// Check the inherent impl's items for an `is_empty(self)` method.
|
200 |
| - fn has_is_empty_impl(cx: &LateContext, id: &DefId) -> bool { |
201 |
| - let impl_items = cx.tcx.impl_items.borrow(); |
202 |
| - cx.tcx.inherent_impls.borrow().get(id).map_or(false, |ids| { |
203 |
| - ids.iter().any(|iid| impl_items.get(iid).map_or(false, |iids| iids.iter().any(|i| is_is_empty(cx, i)))) |
| 196 | + fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool { |
| 197 | + cx.tcx.inherent_impls.borrow()[&id].iter().any(|imp| { |
| 198 | + cx.tcx.impl_or_trait_items(*imp).iter().any(|item| { |
| 199 | + is_is_empty(&cx.tcx.impl_or_trait_item(*item)) |
| 200 | + }) |
204 | 201 | })
|
205 | 202 | }
|
206 | 203 |
|
207 | 204 | let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr));
|
208 | 205 | match ty.sty {
|
209 | 206 | ty::TyTrait(_) => {
|
210 | 207 | cx.tcx
|
211 |
| - .trait_item_def_ids |
212 |
| - .borrow() |
213 |
| - .get(&ty.ty_to_def_id().expect("trait impl not found")) |
214 |
| - .map_or(false, |ids| ids.iter().any(|i| is_is_empty(cx, i))) |
| 208 | + .impl_or_trait_items(ty.ty_to_def_id().expect("trait impl not found")) |
| 209 | + .iter() |
| 210 | + .any(|item| is_is_empty(&cx.tcx.impl_or_trait_item(*item))) |
215 | 211 | }
|
216 |
| - ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)), |
217 |
| - ty::TyAdt(id, _) => has_is_empty_impl(cx, &id.did), |
| 212 | + ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, id)), |
| 213 | + ty::TyAdt(id, _) => has_is_empty_impl(cx, id.did), |
218 | 214 | ty::TyArray(..) | ty::TyStr => true,
|
219 | 215 | _ => false,
|
220 | 216 | }
|
|
0 commit comments