1
1
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_sugg} ;
2
2
use clippy_utils:: source:: { snippet, snippet_with_macro_callsite} ;
3
3
use clippy_utils:: sugg:: Sugg ;
4
- use clippy_utils:: ty:: is_type_diagnostic_item;
4
+ use clippy_utils:: ty:: { is_type_diagnostic_item, same_type_and_consts } ;
5
5
use clippy_utils:: { get_parent_expr, match_def_path, match_trait_method, paths} ;
6
6
use if_chain:: if_chain;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: { Expr , ExprKind , HirId , MatchSource } ;
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
- use rustc_middle:: ty:: { self , TyS } ;
10
+ use rustc_middle:: ty;
11
11
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
12
12
use rustc_span:: sym;
13
13
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
67
67
if match_trait_method ( cx, e, & paths:: INTO ) && & * name. ident . as_str ( ) == "into" {
68
68
let a = cx. typeck_results ( ) . expr_ty ( e) ;
69
69
let b = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
70
- if TyS :: same_type ( a, b) {
70
+ if same_type_and_consts ( a, b) {
71
71
let sugg = snippet_with_macro_callsite ( cx, args[ 0 ] . span , "<expr>" ) . to_string ( ) ;
72
72
span_lint_and_sugg (
73
73
cx,
@@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
90
90
}
91
91
let a = cx. typeck_results ( ) . expr_ty ( e) ;
92
92
let b = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
93
- if TyS :: same_type ( a, b) {
93
+ if same_type_and_consts ( a, b) {
94
94
let sugg = snippet ( cx, args[ 0 ] . span , "<expr>" ) . into_owned ( ) ;
95
95
span_lint_and_sugg (
96
96
cx,
@@ -110,7 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
110
110
if is_type_diagnostic_item( cx, a, sym:: result_type) ;
111
111
if let ty:: Adt ( _, substs) = a. kind( ) ;
112
112
if let Some ( a_type) = substs. types( ) . next( ) ;
113
- if TyS :: same_type( a_type, b) ;
113
+ if same_type_and_consts( a_type, b) ;
114
+
114
115
then {
115
116
span_lint_and_help(
116
117
cx,
@@ -137,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
137
138
if is_type_diagnostic_item( cx, a, sym:: result_type) ;
138
139
if let ty:: Adt ( _, substs) = a. kind( ) ;
139
140
if let Some ( a_type) = substs. types( ) . next( ) ;
140
- if TyS :: same_type ( a_type, b) ;
141
+ if same_type_and_consts ( a_type, b) ;
141
142
142
143
then {
143
144
let hint = format!( "consider removing `{}()`" , snippet( cx, path. span, "TryFrom::try_from" ) ) ;
@@ -154,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
154
155
155
156
if_chain! {
156
157
if match_def_path( cx, def_id, & paths:: FROM_FROM ) ;
157
- if TyS :: same_type ( a, b) ;
158
+ if same_type_and_consts ( a, b) ;
158
159
159
160
then {
160
161
let sugg = Sugg :: hir_with_macro_callsite( cx, & args[ 0 ] , "<expr>" ) . maybe_par( ) ;
0 commit comments