@@ -18,7 +18,7 @@ use crate::syntax::ast::{LitKind, NodeId, StrStyle};
18
18
use crate :: syntax:: source_map:: { BytePos , Span } ;
19
19
use crate :: utils:: { is_expn_of, match_def_path, match_type, opt_def_id, paths, span_help_and_lint, span_lint} ;
20
20
use crate :: consts:: { constant, Constant } ;
21
- use std:: convert:: TryInto ;
21
+ use std:: convert:: TryFrom ;
22
22
23
23
/// **What it does:** Checks [regex](https://crates.io/crates/regex) creation
24
24
/// (with `Regex::new`,`RegexBuilder::new` or `RegexSet::new`) for correct
@@ -142,24 +142,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
142
142
}
143
143
}
144
144
145
+ #[ allow( clippy:: cast_possible_truncation) ] // truncation very unlikely here
145
146
fn str_span ( base : Span , c : regex_syntax:: ast:: Span , offset : u16 ) -> Span {
146
147
let offset = u32:: from ( offset) ;
147
- let end = base. lo ( ) + BytePos (
148
- c. end
149
- . offset
150
- . try_into ( )
151
- . ok ( )
152
- . and_then ( |o : u32 | o. checked_add ( offset) )
153
- . expect ( "offset too large" ) ,
154
- ) ;
155
- let start = base. lo ( ) + BytePos (
156
- c. start
157
- . offset
158
- . try_into ( )
159
- . ok ( )
160
- . and_then ( |o : u32 | o. checked_add ( offset) )
161
- . expect ( "offset too large" ) ,
162
- ) ;
148
+ let end = base. lo ( ) + BytePos ( u32:: try_from ( c. end . offset ) . expect ( "offset too large" ) + offset) ;
149
+ let start = base. lo ( ) + BytePos ( u32:: try_from ( c. start . offset ) . expect ( "offset too large" ) + offset) ;
163
150
assert ! ( start <= end) ;
164
151
Span :: new ( start, end, base. ctxt ( ) )
165
152
}
0 commit comments