1
Fork 0

Fix cast_possible_truncation warnings

This commit is contained in:
Devon Hollowood 2018-10-08 21:40:21 -07:00
parent 995a974182
commit eef2e8948b
5 changed files with 43 additions and 11 deletions

View file

@ -18,6 +18,7 @@ use crate::syntax::ast::{LitKind, NodeId, StrStyle};
use crate::syntax::source_map::{BytePos, Span};
use crate::utils::{is_expn_of, match_def_path, match_type, opt_def_id, paths, span_help_and_lint, span_lint};
use crate::consts::{constant, Constant};
use std::convert::TryInto;
/// **What it does:** Checks [regex](https://crates.io/crates/regex) creation
/// (with `Regex::new`,`RegexBuilder::new` or `RegexSet::new`) for correct
@ -143,8 +144,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span {
let offset = u32::from(offset);
let end = base.lo() + BytePos(c.end.offset as u32 + offset);
let start = base.lo() + BytePos(c.start.offset as u32 + offset);
let end = base.lo() + BytePos(
c.end
.offset
.try_into()
.ok()
.and_then(|o: u32| o.checked_add(offset))
.expect("offset too large"),
);
let start = base.lo() + BytePos(
c.start
.offset
.try_into()
.ok()
.and_then(|o: u32| o.checked_add(offset))
.expect("offset too large"),
);
assert!(start <= end);
Span::new(start, end, base.ctxt())
}