mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Fix ICE in undocumented_unsafe_blocks
This commit is contained in:
parent
131ff87a1e
commit
c82dd0f36e
3 changed files with 20 additions and 3 deletions
|
@ -156,8 +156,9 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
|
|||
.array_windows::<2>()
|
||||
.rev()
|
||||
.map_while(|[start, end]| {
|
||||
src.get(start.to_usize() - offset..end.to_usize() - offset)
|
||||
.map(|text| (start.to_usize(), text.trim_start()))
|
||||
let start = start.to_usize() - offset;
|
||||
let end = end.to_usize() - offset;
|
||||
src.get(start..end).map(|text| (start, text.trim_start()))
|
||||
})
|
||||
.filter(|(_, text)| !text.is_empty());
|
||||
|
||||
|
@ -182,7 +183,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
|
|||
let (mut line_start, mut line) = (line_start, line);
|
||||
loop {
|
||||
if line.starts_with("/*") {
|
||||
let src = src[line_start..line_starts.last().unwrap().to_usize()].trim_start();
|
||||
let src = src[line_start..line_starts.last().unwrap().to_usize() - offset].trim_start();
|
||||
let mut tokens = tokenize(src);
|
||||
return src[..tokens.next().unwrap().len]
|
||||
.to_ascii_uppercase()
|
||||
|
|
6
tests/ui/crashes/auxiliary/ice-8681-aux.rs
Normal file
6
tests/ui/crashes/auxiliary/ice-8681-aux.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
pub fn foo(x: &u32) -> u32 {
|
||||
/* Safety:
|
||||
* This is totally ok.
|
||||
*/
|
||||
unsafe { *(x as *const u32) }
|
||||
}
|
10
tests/ui/crashes/ice-8681.rs
Normal file
10
tests/ui/crashes/ice-8681.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// aux-build: ice-8681-aux.rs
|
||||
|
||||
#![warn(clippy::undocumented_unsafe_blocks)]
|
||||
|
||||
#[path = "auxiliary/ice-8681-aux.rs"]
|
||||
mod ice_8681_aux;
|
||||
|
||||
fn main() {
|
||||
let _ = ice_8681_aux::foo(&0u32);
|
||||
}
|
Loading…
Reference in a new issue