11use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_sugg} ;
22use clippy_utils:: source:: { snippet, snippet_with_macro_callsite} ;
33use 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 } ;
55use clippy_utils:: { get_parent_expr, match_def_path, match_trait_method, paths} ;
66use if_chain:: if_chain;
77use rustc_errors:: Applicability ;
88use rustc_hir:: { Expr , ExprKind , HirId , MatchSource } ;
99use rustc_lint:: { LateContext , LateLintPass } ;
10- use rustc_middle:: ty:: { self , TyS } ;
10+ use rustc_middle:: ty;
1111use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
1212use rustc_span:: sym;
1313
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
6767 if match_trait_method ( cx, e, & paths:: INTO ) && & * name. ident . as_str ( ) == "into" {
6868 let a = cx. typeck_results ( ) . expr_ty ( e) ;
6969 let b = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
70- if TyS :: same_type ( a, b) {
70+ if same_type_and_consts ( a, b) {
7171 let sugg = snippet_with_macro_callsite ( cx, args[ 0 ] . span , "<expr>" ) . to_string ( ) ;
7272 span_lint_and_sugg (
7373 cx,
@@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
9090 }
9191 let a = cx. typeck_results ( ) . expr_ty ( e) ;
9292 let b = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
93- if TyS :: same_type ( a, b) {
93+ if same_type_and_consts ( a, b) {
9494 let sugg = snippet ( cx, args[ 0 ] . span , "<expr>" ) . into_owned ( ) ;
9595 span_lint_and_sugg (
9696 cx,
@@ -110,7 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
110110 if is_type_diagnostic_item( cx, a, sym:: result_type) ;
111111 if let ty:: Adt ( _, substs) = a. kind( ) ;
112112 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+
114115 then {
115116 span_lint_and_help(
116117 cx,
@@ -137,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
137138 if is_type_diagnostic_item( cx, a, sym:: result_type) ;
138139 if let ty:: Adt ( _, substs) = a. kind( ) ;
139140 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) ;
141142
142143 then {
143144 let hint = format!( "consider removing `{}()`" , snippet( cx, path. span, "TryFrom::try_from" ) ) ;
@@ -154,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
154155
155156 if_chain! {
156157 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) ;
158159
159160 then {
160161 let sugg = Sugg :: hir_with_macro_callsite( cx, & args[ 0 ] , "<expr>" ) . maybe_par( ) ;
0 commit comments