@@ -12,7 +12,7 @@ use rustc_hir::{
12
12
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
13
13
use rustc_session:: declare_lint_pass;
14
14
use rustc_span:: edition:: Edition ;
15
- use rustc_span:: { BytePos , Span , sym} ;
15
+ use rustc_span:: { BytePos , Pos as _ , Span , sym} ;
16
16
17
17
declare_clippy_lint ! {
18
18
/// ### What it does
@@ -97,16 +97,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnit {
97
97
}
98
98
99
99
fn check_poly_trait_ref ( & mut self , cx : & LateContext < ' tcx > , poly : & ' tcx PolyTraitRef < ' tcx > ) {
100
- let segments = & poly. trait_ref . path . segments ;
101
-
102
- if segments. len ( ) == 1
103
- && matches ! ( segments[ 0 ] . ident. name, sym:: Fn | sym:: FnMut | sym:: FnOnce )
104
- && let Some ( args) = segments[ 0 ] . args
100
+ if let [ segment] = & poly. trait_ref . path . segments
101
+ && matches ! ( segment. ident. name, sym:: Fn | sym:: FnMut | sym:: FnOnce )
102
+ && let Some ( args) = segment. args
105
103
&& args. parenthesized == GenericArgsParentheses :: ParenSugar
106
- && let constraints = & args. constraints
107
- && constraints. len ( ) == 1
108
- && constraints[ 0 ] . ident . name == sym:: Output
109
- && let AssocItemConstraintKind :: Equality { term : Term :: Ty ( hir_ty) } = constraints[ 0 ] . kind
104
+ && let [ constraint] = & args. constraints
105
+ && constraint. ident . name == sym:: Output
106
+ && let AssocItemConstraintKind :: Equality { term : Term :: Ty ( hir_ty) } = constraint. kind
110
107
&& args. span_ext . hi ( ) != poly. span . hi ( )
111
108
&& !hir_ty. span . from_expansion ( )
112
109
&& args. span_ext . hi ( ) != hir_ty. span . hi ( )
@@ -160,17 +157,15 @@ fn get_def(span: Span) -> Option<Span> {
160
157
161
158
fn lint_unneeded_unit_return ( cx : & LateContext < ' _ > , ty_span : Span , span : Span ) {
162
159
let ( ret_span, appl) =
163
- span. with_hi ( ty_span. hi ( ) )
164
- . get_source_text ( cx)
165
- . map_or ( ( ty_span, Applicability :: MaybeIncorrect ) , |src| {
166
- position_before_rarrow ( & src) . map_or ( ( ty_span, Applicability :: MaybeIncorrect ) , |rpos| {
167
- (
168
- #[ expect( clippy:: cast_possible_truncation) ]
169
- ty_span. with_lo ( BytePos ( span. lo ( ) . 0 + rpos as u32 ) ) ,
170
- Applicability :: MachineApplicable ,
171
- )
172
- } )
173
- } ) ;
160
+ if let Some ( Some ( rpos) ) = span. with_hi ( ty_span. hi ( ) ) . with_source_text ( cx, position_before_rarrow) {
161
+ (
162
+ ty_span. with_lo ( span. lo ( ) + BytePos :: from_usize ( rpos) ) ,
163
+ Applicability :: MachineApplicable ,
164
+ )
165
+ } else {
166
+ ( ty_span, Applicability :: MaybeIncorrect )
167
+ } ;
168
+
174
169
span_lint_and_sugg (
175
170
cx,
176
171
UNUSED_UNIT ,
0 commit comments