mirror of
https://github.com/danbulant/oxc
synced 2026-05-22 05:38:54 +00:00
chore(clippy): enable undocumented_unsafe_blocks
This commit is contained in:
parent
db5417f9a9
commit
4886d408eb
11 changed files with 26 additions and 5 deletions
|
|
@ -45,9 +45,8 @@ rustflags = [
|
|||
"-Wclippy::rc_buffer",
|
||||
"-Wclippy::rc_mutex",
|
||||
"-Wclippy::rest_pat_in_fully_bound_structs",
|
||||
# "-Wclippy::same_name_method", # broke bitflags v2
|
||||
"-Wclippy::unnecessary_safety_comment",
|
||||
# TODO "-Wclippy::undocumented_unsafe_blocks",
|
||||
"-Wclippy::undocumented_unsafe_blocks",
|
||||
|
||||
# pedantic
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub struct Box<'alloc, T: ?Sized>(pub &'alloc mut T);
|
|||
|
||||
impl<'alloc, T> Box<'alloc, T> {
|
||||
pub fn unbox(self) -> T {
|
||||
// SAFETY:
|
||||
// This pointer read is safe because the reference `self.0` is
|
||||
// guaranteed to be unique--not just now, but we're guaranteed it's not
|
||||
// borrowed from some other reference. This in turn is because we never
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ impl<'a> AstBuilder<'a> {
|
|||
}
|
||||
|
||||
pub fn copy<T>(&self, src: &T) -> T {
|
||||
// SAFETY:
|
||||
// This should be safe as long as `src` is an reference from the allocator.
|
||||
// But honestly, I'm not really sure if this is safe.
|
||||
unsafe { std::mem::transmute_copy(src) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,9 +150,13 @@ pub enum AstKind<'a> {
|
|||
TSPropertySignature(&'a TSPropertySignature<'a>),
|
||||
}
|
||||
|
||||
// SAFETY: The AST is part of the bump allocator,
|
||||
// SAFETY:
|
||||
// The AST is part of the bump allocator,
|
||||
// it is our responsibility to never simultaneously mutate across threads.
|
||||
unsafe impl<'a> Send for AstKind<'a> {}
|
||||
// SAFETY:
|
||||
// The AST is part of the bump allocator,
|
||||
// it is our responsibility to never simultaneously mutate across threads.
|
||||
unsafe impl<'a> Sync for AstKind<'a> {}
|
||||
|
||||
impl<'a> AstKind<'a> {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ pub trait Visit<'a>: Sized {
|
|||
fn leave_scope(&mut self) {}
|
||||
|
||||
fn alloc<T>(&self, t: &T) -> &'a T {
|
||||
// SAFETY:
|
||||
// This should be safe as long as `src` is an reference from the allocator.
|
||||
// But honestly, I'm not really sure if this is safe.
|
||||
unsafe { std::mem::transmute(t) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -959,7 +959,10 @@ fn print_non_negative_float<const MINIFY: bool>(value: f64, _p: &Codegen<{ MINIF
|
|||
let chars = result.as_bytes();
|
||||
let len = chars.len();
|
||||
let dot = chars.iter().position(|&c| c == b'.');
|
||||
let u8_to_string = |num: &[u8]| unsafe { String::from_utf8_unchecked(num.to_vec()) };
|
||||
let u8_to_string = |num: &[u8]| {
|
||||
// SAFETY: criterias of `from_utf8_unchecked`.are met.
|
||||
unsafe { String::from_utf8_unchecked(num.to_vec()) }
|
||||
};
|
||||
|
||||
if dot == Some(1) && chars[0] == b'0' {
|
||||
// Strip off the leading zero when minifying
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
|
|||
}
|
||||
|
||||
pub fn into_code(self) -> String {
|
||||
// SAFETY: criterias of `from_utf8_unchecked`.are met.
|
||||
unsafe { String::from_utf8_unchecked(self.code) }
|
||||
}
|
||||
|
||||
|
|
@ -153,6 +154,7 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
|
|||
}
|
||||
|
||||
fn peek_nth(&self, n: usize) -> Option<char> {
|
||||
// SAFETY: criterias of `from_utf8_unchecked`.are met.
|
||||
unsafe { from_utf8_unchecked(self.code()) }.chars().nth_back(n)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ impl Formatter {
|
|||
|
||||
#[inline]
|
||||
pub fn into_code(self) -> String {
|
||||
// SAFETY: criterias of `from_utf8_unchecked`.are met.
|
||||
unsafe { String::from_utf8_unchecked(self.code) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,10 @@ use std::{sync::Arc, thread};
|
|||
/// Wrap the AST for unsafe `Send` and `Sync`
|
||||
struct BumpaloProgram<'a>(Program<'a>);
|
||||
|
||||
// SAFETY: It is now our responsibility to never simultaneously mutate the AST across threads.
|
||||
#[allow(clippy::non_send_fields_in_send_ty)]
|
||||
// SAFETY: It is now our responsibility to never simultaneously mutate the AST across threads.
|
||||
unsafe impl<'a> Send for BumpaloProgram<'a> {}
|
||||
// SAFETY: It is now our responsibility to never simultaneously mutate the AST across threads.
|
||||
unsafe impl<'a> Sync for BumpaloProgram<'a> {}
|
||||
|
||||
/// `ouroboros` is used to "bind" the allocator and AST together to remove the lifetime.
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ impl<'a> Parser<'a> {
|
|||
/// Get current source text
|
||||
pub(crate) fn cur_src(&self) -> &'a str {
|
||||
let range = self.cur_token().span();
|
||||
// SAFETY:
|
||||
// range comes from the parser, which are ensured to meeting the criteria of `get_unchecked`.
|
||||
unsafe { self.source_text.get_unchecked(range.start as usize..range.end as usize) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ fn strip_buf(state: &mut State, buf: &mut [u8], settings: CommentSettings) -> Re
|
|||
///
|
||||
/// ```
|
||||
pub fn strip_comments_in_place(s: &mut str) -> Result<()> {
|
||||
// SAFETY:
|
||||
// The content of the slice is valid UTF-8.
|
||||
strip_buf(&mut Top, unsafe { s.as_bytes_mut() }, CommentSettings::all())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue