|
1 | 1 | use rustc::lint::*;
|
2 |
| -use rustc::ty::{self, Ty, walk::TypeWalker}; |
| 2 | +use rustc::ty::{self, Ty}; |
3 | 3 | use rustc::hir::*;
|
4 | 4 | use std::borrow::Cow;
|
5 |
| -use std::mem; |
6 | 5 | use syntax::ast;
|
7 | 6 | use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then};
|
8 | 7 | use utils::{opt_def_id, sugg};
|
@@ -364,7 +363,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
364 | 363 | }
|
365 | 364 | )
|
366 | 365 | } else {
|
367 |
| - if !differ_only_in_lifetime_params(from_ty, to_ty) { |
| 366 | + if cx.tcx.erase_regions(&from_ty) != cx.tcx.erase_regions(&to_ty) { |
368 | 367 | span_lint_and_then(
|
369 | 368 | cx,
|
370 | 369 | TRANSMUTE_PTR_TO_PTR,
|
@@ -448,48 +447,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
448 | 447 | }
|
449 | 448 | }
|
450 | 449 |
|
451 |
| -/// Returns true if `type1` and `type2` are the same type except for their lifetime parameters |
452 |
| -fn differ_only_in_lifetime_params(type1: Ty, type2: Ty) -> bool { |
453 |
| - use rustc::ty::TypeVariants::*; |
454 |
| - if TypeWalker::new(type1).count() != TypeWalker::new(type2).count() { |
455 |
| - return false; |
456 |
| - } |
457 |
| - TypeWalker::new(type1) |
458 |
| - .zip(TypeWalker::new(type2)) |
459 |
| - .all(|(t1, t2)| { |
460 |
| - match (&t1.sty, &t2.sty) { |
461 |
| - // types with generic parameters which can contain lifetimes |
462 |
| - (TyAdt(_, sub1), TyAdt(_, sub2)) |
463 |
| - | (TyFnDef(_, sub1), TyFnDef(_, sub2)) |
464 |
| - | (TyAnon(_, sub1), TyAnon(_, sub2)) |
465 |
| - => { |
466 |
| - // Iterate over generic parameters, which are either Lifetimes or Types. |
467 |
| - // Here we only need to check that they are the same type of thing, because |
468 |
| - // if they are both Lifetimes then we don't care about their equality, and if |
469 |
| - // they are both Types, we will check their equality later in the type walk. |
470 |
| - sub1.iter().count() == sub2.iter().count() |
471 |
| - && sub1.iter().zip(sub2.iter()).all(|(k1, k2)| { |
472 |
| - mem::discriminant(&k1.unpack()) == mem::discriminant(&k2.unpack()) |
473 |
| - }) |
474 |
| - } |
475 |
| - // types without subtypes: check that the types are equal |
476 |
| - (TyBool, TyBool) |
477 |
| - | (TyChar, TyChar) |
478 |
| - | (TyInt(_), TyInt(_)) |
479 |
| - | (TyUint(_), TyUint(_)) |
480 |
| - | (TyFloat(_), TyFloat(_)) |
481 |
| - | (TyForeign(_), TyForeign(_)) |
482 |
| - | (TyStr, TyStr) |
483 |
| - | (TyNever, TyNever) |
484 |
| - | (TyInfer(_), TyInfer(_)) |
485 |
| - => t1.sty == t2.sty, |
486 |
| - // types with subtypes: return true for now if they are the same sort of type. |
487 |
| - // we will check their subtypes later |
488 |
| - (sty1, sty2) => mem::discriminant(sty1) == mem::discriminant(sty2) |
489 |
| - } |
490 |
| - }) |
491 |
| -} |
492 |
| - |
493 | 450 | /// Get the snippet of `Bar` in `…::transmute<Foo, &Bar>`. If that snippet is
|
494 | 451 | /// not available , use
|
495 | 452 | /// the type's `ToString` implementation. In weird cases it could lead to types
|
|
0 commit comments