|
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,34 +184,35 @@ 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(id: &ImplOrTraitItem) -> bool { |
| 188 | + println!("1: {:?}", id); |
| 189 | + if let ty::MethodTraitItem(ref method) = *id { |
| 190 | + method.name.as_str() == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1 |
194 | 191 | } else {
|
195 | 192 | false
|
196 | 193 | }
|
197 | 194 | }
|
198 | 195 |
|
199 | 196 | /// Check the inherent impl's items for an `is_empty(self)` method.
|
200 | 197 | fn has_is_empty_impl(cx: &LateContext, id: &DefId) -> bool {
|
201 |
| - let impl_items = cx.tcx.impl_items.borrow(); |
| 198 | + let impl_items = cx.tcx.impl_or_trait_items.borrow(); |
202 | 199 | 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)))) |
| 200 | + println!("2: {:?}", ids); |
| 201 | + ids.iter().any(|impl_id| { |
| 202 | + impl_items.get(impl_id).map_or(false, |i| is_is_empty(i)) |
| 203 | + }) |
204 | 204 | })
|
205 | 205 | }
|
206 | 206 |
|
207 | 207 | let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr));
|
| 208 | + println!("3: {:?}", ty); |
208 | 209 | match ty.sty {
|
209 | 210 | ty::TyTrait(_) => {
|
210 | 211 | cx.tcx
|
211 |
| - .trait_item_def_ids |
| 212 | + .impl_or_trait_items |
212 | 213 | .borrow()
|
213 | 214 | .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))) |
| 215 | + .map_or(false, |i| is_is_empty(i)) |
215 | 216 | }
|
216 | 217 | ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)),
|
217 | 218 | ty::TyAdt(id, _) => has_is_empty_impl(cx, &id.did),
|
|
0 commit comments