jiebi/CodeConvo huggingface dataset:
} pub fn stat(path: &Path) -> io::Result<FileAttr> { <del> let mut opts = OpenOptions::new(); // No read or write permissions are necessary opts.access_mode(0); // This flag is so we can open directories too opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); let file = File::open(path, &opts)?; file.file_attr() </del> <ins> metadata(path, ReparsePoint::Follow) </ins> } pub fn lstat(path: &Path) -> io::Result<FileAttr> { <ins> metadata(path, ReparsePoint::Open) } #[repr(u32)] #[derive(Clone, Copy, PartialEq, Eq)] enum ReparsePoint { Follow = 0, Open = c::FILE_FLAG_OPEN_REPARSE_POINT, } impl ReparsePoint { fn as_flag(self) -> u32 { self as u32 } } fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> { </ins> let mut opts = OpenOptions::new(); // No read or write permissions are necessary opts.access_mode(0); <del> opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT); let file = File::open(path, &opts)?; file.file_attr() </del> <ins> opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | reparse.as_flag()); // Attempt to open the file normally. // If that fails with `ERROR_SHARING_VIOLATION` then retry using `FindFirstFileW`. // If the fallback fails for any reason we return the original error. match File::open(path, &opts) { Ok(file) => file.file_attr(), Err(e) if e.raw_os_error() == Some(c::ERROR_SHARING_VIOLATION as _) => { // `ERROR_SHARING_VIOLATION` will almost never be returned. // Usually if a file is locked you can still read some metadata. // However, there are special system files, such as // `C:hiberfil.sys`, that are locked in a way that denies even that. unsafe { let path = maybe_verbatim(path)?; // `FindFirstFileW` accepts wildcard file names. // Fortunately wildcards are not valid file names and // `ERROR_SHARING_VIOLATION` means the file exists (but is locked) // therefore it's safe to assume the file name given does not // include wildcards. let mut wfd = mem::zeroed(); let handle = c::FindFirstFileW(path.as_ptr(), &mut wfd); if handle == c::INVALID_HANDLE_VALUE { // This can fail if the user does not have read access to the // directory. Err(e) } else { // We no longer need the find handle. c::FindClose(handle); // `FindFirstFileW` reads the cached file information from the // directory. The downside is that this metadata may be outdated. let attrs = FileAttr::from(wfd); if reparse == ReparsePoint::Follow && attrs.file_type().is_symlink() { Err(e) } else { Ok(attrs) } } } } Err(e) => Err(e), } </ins> } pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
ty = ty.print(cx), ); if let Some(default) = default { <ins> write!(w, " = "); </ins> // FIXME: `.value()` uses `clean::utils::format_integer_with_underscore_sep` under the //        hood which adds noisy underscores and a type suffix to number literals. //        This hurts readability in this context especially when more complex expressions //        are involved and it doesn't add much of value. //        Find a way to print constants here without all that jazz. <del> write!(w, " = {}", default.value(cx.tcx()).unwrap_or_else(|| default.expr(cx.tcx()))); </del> <ins> write!(w, "{}", Escape(&default.value(cx.tcx()).unwrap_or_else(|| default.expr(cx.tcx())))); </ins> } }
typ = c.type_.print(cx), ); <ins> // FIXME: The code below now prints //            ` = _; // 100i32` //        if the expression is //            `50 + 50` //        which looks just wrong. //        Should we print //            ` = 100i32;` //        instead? </ins> let value = c.value(cx.tcx()); let is_literal = c.is_literal(cx.tcx()); let expr = c.expr(cx.tcx());
// @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAR"]'  //      'const BAR: usize' pub const BAR: usize = 3; <ins> // @has - '//*[@id="associatedconstant.BAR_ESCAPED"]'  //      "const BAR_ESCAPED: &'static str = "<em>markup</em>"" pub const BAR_ESCAPED: &'static str = "<em>markup</em>"; </ins> } pub struct Baz<'a, U: 'a, T>(T, &'a [U]);
#![crate_name = "foo"] // @has 'foo/constant.HOUR_IN_SECONDS.html' <del> // @has - '//*[@class="docblock item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = 60 * 60; // 3_600u64' </del> <ins> // @has - '//*[@class="docblock item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = _; // 3_600u64' </ins> pub const HOUR_IN_SECONDS: u64 = 60 * 60; // @has 'foo/constant.NEGATIVE.html' <del> // @has - '//*[@class="docblock item-decl"]//code' 'pub const NEGATIVE: i64 = -60 * 60; // -3_600i64' </del> <ins> // @has - '//*[@class="docblock item-decl"]//code' 'pub const NEGATIVE: i64 = _; // -3_600i64' </ins> pub const NEGATIVE: i64 = -60 * 60;
<ins> // Test that certain unevaluated constant expression arguments that are // deemed too verbose or complex and that may leak private or // `doc(hidden)` struct fields are not displayed in the documentation. // // Read the documentation of `rustdoc::clean::utils::print_const_expr` // for further details. #![feature(const_trait_impl, generic_const_exprs)] #![allow(incomplete_features)] // @has hide_complex_unevaluated_const_arguments/trait.Stage.html pub trait Stage { // A helper constant that prevents const expressions containing it // from getting fully evaluated since it doesn't have a body and // thus is non-reducible. This allows us to specifically test the // pretty-printing of *unevaluated* consts. const ABSTRACT: usize; // Currently considered "overly complex" by the `generic_const_exprs` // feature. If / once this expression kind gets supported, this // unevaluated const expression could leak the private struct field. // // FIXME: Once the line below compiles, make this a test that //        ensures that the private field is not printed. // //const ARRAY0: [u8; Struct { private: () } + Self::ABSTRACT]; // This assoc. const could leak the private assoc. function `Struct::new`. // Ensure that this does not happen. // // @has - '//*[@id="associatedconstant.ARRAY1"]'  //        'const ARRAY1: [u8; { _ }]' const ARRAY1: [u8; Struct::new(/* ... */) + Self::ABSTRACT * 1_000]; // @has - '//*[@id="associatedconstant.VERBOSE"]'  //        'const VERBOSE: [u16; { _ }]' const VERBOSE: [u16; compute("thing", 9 + 9) * Self::ABSTRACT]; // Check that we do not leak the private struct field contained within // the path. The output could definitely be improved upon // (e.g. printing sth. akin to `<Self as Helper<{ _ }>>::OUT`) but // right now “safe is safe”. // // @has - '//*[@id="associatedconstant.PATH"]'  //        'const PATH: usize = _' const PATH: usize = <Self as Helper<{ Struct { private: () } }>>::OUT; } const fn compute(input: &str, extra: usize) -> usize { input.len() + extra } pub trait Helper<const S: Struct> { const OUT: usize; } impl<const S: Struct, St: Stage + ?Sized> Helper<S> for St { const OUT: usize = St::ABSTRACT; } // Currently in rustdoc, const arguments are not evaluated in this position // and therefore they fall under the realm of `print_const_expr`. // If rustdoc gets patched to evaluate const arguments, it is fine to replace // this test as long as one can ensure that private fields are not leaked! // // @has hide_complex_unevaluated_const_arguments/trait.Sub.html  //      '//*[@class="rust trait"]'  //      'pub trait Sub: Sup<{ _ }, { _ }> { }' pub trait Sub: Sup<{ 90 * 20 * 4 }, { Struct { private: () } }> {} pub trait Sup<const N: usize, const S: Struct> {} pub struct Struct { private: () } impl Struct { const fn new() -> Self { Self { private: () } } } impl const std::ops::Add<usize> for Struct { type Output = usize; fn add(self, _: usize) -> usize { 0 } } </ins>
<ins> // Regression test for issue #97933. // // Test that certain unevaluated constant expressions that are // deemed too verbose or complex and that may leak private or // `doc(hidden)` struct fields are not displayed in the documentation. // // Read the documentation of `rustdoc::clean::utils::print_const_expr` // for further details. // @has hide_complex_unevaluated_consts/trait.Container.html pub trait Container { // A helper constant that prevents const expressions containing it // from getting fully evaluated since it doesn't have a body and // thus is non-reducible. This allows us to specifically test the // pretty-printing of *unevaluated* consts. const ABSTRACT: i32; // Ensure that the private field does not get leaked: // // @has - '//*[@id="associatedconstant.STRUCT0"]'  //        'const STRUCT0: Struct = _' const STRUCT0: Struct = Struct { private: () }; // @has - '//*[@id="associatedconstant.STRUCT1"]'  //        'const STRUCT1: (Struct,) = _' const STRUCT1: (Struct,) = (Struct{private: /**/()},); // Although the struct field is public here, check that it is not // displayed. In a future version of rustdoc, we definitely want to // show it. However for the time being, the printing logic is a bit // conservative. // // @has - '//*[@id="associatedconstant.STRUCT2"]'  //        'const STRUCT2: Record = _' const STRUCT2: Record = Record { public: 5 }; // Test that we do not show the incredibly verbose match expr: // // @has - '//*[@id="associatedconstant.MATCH0"]'  //        'const MATCH0: i32 = _' const MATCH0: i32 = match 234 { 0 => 1, _ => Self::ABSTRACT, }; // @has - '//*[@id="associatedconstant.MATCH1"]'  //        'const MATCH1: bool = _' const MATCH1: bool = match Self::ABSTRACT { _ => true, }; // Check that we hide complex (arithmetic) operations. // In this case, it is a bit unfortunate since the expression // is not *that* verbose and it might be quite useful to the reader. // // However in general, the expression might be quite large and // contain match expressions and structs with private fields. // We would need to recurse over the whole expression and even more // importantly respect operator precedence when pretty-printing // the potentially partially censored expression. // For now, the implementation is quite simple and the choices // rather conservative. // // @has - '//*[@id="associatedconstant.ARITH_OPS"]'  //        'const ARITH_OPS: i32 = _' const ARITH_OPS: i32 = Self::ABSTRACT * 2 + 1; } pub struct Struct { private: () } pub struct Record { pub public: i32 } </ins>
// @!has show_const_contents/constant.CONST_EQ_TO_VALUE_I32.html '// 42i32' pub const CONST_EQ_TO_VALUE_I32: i32 = 42i32; <del> // @has show_const_contents/constant.CONST_CALC_I32.html '= 42 + 1; // 43i32' </del> <ins> // @has show_const_contents/constant.CONST_CALC_I32.html '= _; // 43i32' </ins> pub const CONST_CALC_I32: i32 = 42 + 1; // @!has show_const_contents/constant.CONST_REF_I32.html '= &42;'
/// /// This trait can be used with `#[derive]`. When `derive`d on structs, two /// instances are equal if all fields are equal, and not equal if any fields <del> /// are not equal. When `derive`d on enums, each variant is equal to itself /// and not equal to the other variants. </del> <ins> /// are not equal. When `derive`d on enums, two instances are equal if they /// are the same variant and all fields are equal. </ins> /// /// ## How can I implement `PartialEq`? ///
})); let their_thread = my_thread.clone(); <del> let my_packet: Arc<Packet<'scope, T>> = Arc::new(Packet { scope: scope_data, result: UnsafeCell::new(None) }); </del> <ins> let my_packet: Arc<Packet<'scope, T>> = Arc::new(Packet { scope: scope_data, result: UnsafeCell::new(None), _marker: PhantomData, }); </ins> let their_packet = my_packet.clone(); let output_capture = crate::io::set_output_capture(None);
// An Arc to the packet is stored into a `JoinInner` which in turns is placed // in `JoinHandle`. struct Packet<'scope, T> { <del> scope: Option<&'scope scoped::ScopeData>, </del> <ins> scope: Option<Arc<scoped::ScopeData>>, </ins> result: UnsafeCell<Option<Result<T>>>, <ins> _marker: PhantomData<Option<&'scope scoped::ScopeData>>, </ins> } // Due to the usage of `UnsafeCell` we need to manually implement Sync.
rtabort!("thread result panicked on drop"); } // Book-keeping so the scope knows when it's done. <del> if let Some(scope) = self.scope { </del> <ins> if let Some(scope) = &self.scope { </ins> // Now that there will be no more user code running on this thread // that can use 'scope, mark the thread as 'finished'. // It's important we only do this after the `result` has been dropped,
/// See [`scope`] for details. #[stable(feature = "scoped_threads", since = "1.63.0")] pub struct Scope<'scope, 'env: 'scope> { <del> data: ScopeData, </del> <ins> data: Arc<ScopeData>, </ins> /// Invariance over 'scope, to make sure 'scope cannot shrink, /// which is necessary for soundness. ///
where F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T, { <ins> // We put the `ScopeData` into an `Arc` so that other threads can finish their // `decrement_num_running_threads` even after this function returns. </ins> let scope = Scope { <del> data: ScopeData { </del> <ins> data: Arc::new(ScopeData { </ins> num_running_threads: AtomicUsize::new(0), main_thread: current(), a_thread_panicked: AtomicBool::new(false), <del> }, </del> <ins> }), </ins> env: PhantomData, scope: PhantomData, };
F: FnOnce() -> T + Send + 'scope, T: Send + 'scope, { <del> Ok(ScopedJoinHandle(unsafe { self.spawn_unchecked_(f, Some(&scope.data)) }?)) </del> <ins> Ok(ScopedJoinHandle(unsafe { self.spawn_unchecked_(f, Some(scope.data.clone())) }?)) </ins> } }
initializer_span: Span, else_block: &Block, visibility_scope: Option<SourceScope>, <ins> remainder_scope: region::Scope, </ins> remainder_span: Span, pattern: &Pat<'tcx>, ) -> BlockAnd<()> { <del> let scrutinee = unpack!(block = self.lower_scrutinee(block, init, initializer_span)); let pat = Pat { ty: init.ty, span: else_block.span, kind: Box::new(PatKind::Wild) }; let mut wildcard = Candidate::new(scrutinee.clone(), &pat, false); self.declare_bindings( visibility_scope, remainder_span, pattern, ArmHasGuard(false), Some((None, initializer_span)), ); let mut candidate = Candidate::new(scrutinee.clone(), pattern, false); let fake_borrow_temps = self.lower_match_tree( block, initializer_span, pattern.span, false, &mut [&mut candidate, &mut wildcard], ); // This block is for the matching case let matching = self.bind_pattern( self.source_info(pattern.span), candidate, None, &fake_borrow_temps, initializer_span, None, None, None, ); // This block is for the failure case let failure = self.bind_pattern( self.source_info(else_block.span), wildcard, None, &fake_borrow_temps, initializer_span, None, None, None, ); </del> <ins> let (matching, failure) = self.in_if_then_scope(remainder_scope, |this| { let scrutinee = unpack!(block = this.lower_scrutinee(block, init, initializer_span)); let pat = Pat { ty: init.ty, span: else_block.span, kind: Box::new(PatKind::Wild) }; let mut wildcard = Candidate::new(scrutinee.clone(), &pat, false); this.declare_bindings( visibility_scope, remainder_span, pattern, ArmHasGuard(false), Some((None, initializer_span)), ); let mut candidate = Candidate::new(scrutinee.clone(), pattern, false); let fake_borrow_temps = this.lower_match_tree( block, initializer_span, pattern.span, false, &mut [&mut candidate, &mut wildcard], ); // This block is for the matching case let matching = this.bind_pattern( this.source_info(pattern.span), candidate, None, &fake_borrow_temps, initializer_span, None, None, None, ); // This block is for the failure case let failure = this.bind_pattern( this.source_info(else_block.span), wildcard, None, &fake_borrow_temps, initializer_span, None, None, None, ); this.break_for_else(failure, remainder_scope, this.source_info(initializer_span)); matching.unit() }); </ins> // This place is not really used because this destination place // should never be used to take values at the end of the failure // block.
} drops.add_entry(block, drop_idx); <del> // `build_drop_tree` doesn't have access to our source_info, so we </del> <ins> // `build_drop_trees` doesn't have access to our source_info, so we </ins> // create a dummy terminator now. `TerminatorKind::Resume` is used // because MIR type checking will panic if it hasn't been overwritten. self.cfg.terminate(block, source_info, TerminatorKind::Resume);
<ins> // run-pass // // from issue #93951, where borrowck complained the temporary that `foo(&x)` was stored in was to // be dropped sometime after `x` was. It then suggested adding a semicolon that was already there. #![feature(let_else)] use std::fmt::Debug; fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> { Ok(x) } fn let_else() { let x = String::from("Hey"); let Ok(_) = foo(&x) else { return }; } fn if_let() { let x = String::from("Hey"); let _ = if let Ok(s) = foo(&x) { s } else { return }; } fn main() { let_else(); if_let(); } </ins>
} } <ins> fn foo<'a>(x: &'a str) -> Result<impl Display + 'a, ()> { Ok(x) } </ins> fn main() { assert_eq!(TRACKER.load(Ordering::Acquire), 0); let 0 = Droppy::default().inner else { return }; assert_eq!(TRACKER.load(Ordering::Acquire), 1); println!("Should have dropped 👆"); <ins> { // cf. https://github.com/rust-lang/rust/pull/99518#issuecomment-1191520030 struct Foo<'a>(&'a mut u32); impl<'a> Drop for Foo<'a> { fn drop(&mut self) { *self.0 = 0; } } let mut foo = 0; let Foo(0) = Foo(&mut foo) else { *&mut foo = 1; todo!() }; } { let x = String::from("Hey"); let Ok(s) = foo(&x) else { panic!() }; assert_eq!(s.to_string(), x); } { // test let-else drops temps after statement let rc = Rc::new(0); let 0 = *rc.clone() else { unreachable!() }; Rc::try_unwrap(rc).unwrap(); } { let mut rc = Rc::new(0); let mut i = 0; loop { if i > 3 { break; } let 1 = *rc.clone() else { if let Ok(v) = Rc::try_unwrap(rc) { rc = Rc::new(v); } else { panic!() } i += 1; continue }; } } { // test let-else drops temps before else block // NOTE: this test has to be the last block in the `main` // body. let rc = Rc::new(0); let 1 = *rc.clone() else { Rc::try_unwrap(rc).unwrap(); return; }; unreachable!(); } </ins> }
LazyLock::new(|| { let hook = panic::take_hook(); panic::set_hook(Box::new(|info| { <ins> // If the error was caused by a broken pipe then this is not a bug. // Write the error and return immediately. See #98700. #[cfg(windows)] if let Some(msg) = info.payload().downcast_ref::<String>() { if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") { early_error_no_abort(ErrorOutputType::default(), &msg); return; } }; </ins> // Invoke the default handler, which prints the actual panic message and optionally a backtrace (*DEFAULT_HOOK)(info);
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. use intrinsics::{ <del> unchecked_shl, unchecked_shr, unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub, </del> <ins> cttz_nonzero, exact_div, unchecked_rem, unchecked_shl, unchecked_shr, unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub, </ins> }; <del> let addr = p.addr(); </del> /// Calculate multiplicative modular inverse of `x` modulo `m`. /// /// This implementation is tailored for `align_offset` and has following preconditions:
// ` p' + s'o = 0 mod a' ` // ` o = (a' - (p' mod a')) * (s'^-1 mod a') ` // <del> // The first term is "the relative alignment of `p` to `a`" (divided by the `g`), the second // term is "how does incrementing `p` by `s` bytes change the relative alignment of `p`" (again // divided by `g`). // Division by `g` is necessary to make the inverse well formed if `a` and `s` are not // co-prime. </del> <ins> // The first term is "the relative alignment of `p` to `a`" (divided by the `g`), the // second term is "how does incrementing `p` by `s` bytes change the relative alignment of // `p`" (again divided by `g`). Division by `g` is necessary to make the inverse well // formed if `a` and `s` are not co-prime. </ins> // // Furthermore, the result produced by this solution is not "minimal", so it is necessary <del> // to take the result `o mod lcm(s, a)`. We can replace `lcm(s, a)` with just a `a'`. </del> <ins> // to take the result `o mod lcm(s, a)`. This `lcm(s, a)` is the same as `a'`. </ins> // SAFETY: `gcdpow` has an upper-bound not greater than the number of trailing 0-bits in // `a`.
let a2minus1 = unsafe { unchecked_sub(a2, 1) }; // SAFETY: `gcdpow` has an upper-bound not greater than the number of trailing 0-bits in // `a`. <del> let s2 = unsafe { unchecked_shr(smoda, gcdpow) }; </del> <ins> let s2 = unsafe { unchecked_shr(stride & a_minus_one, gcdpow) }; </ins> // SAFETY: `gcdpow` has an upper-bound not greater than the number of trailing 0-bits in // `a`. Furthermore, the subtraction cannot overflow, because `a2 = a >> gcdpow` will // always be strictly greater than `(p % a) >> gcdpow`. <del> let minusp2 = unsafe { unchecked_sub(a2, unchecked_shr(pmoda, gcdpow)) }; </del> <ins> let minusp2 = unsafe { unchecked_sub(a2, unchecked_shr(addr & a_minus_one, gcdpow)) }; </ins> // SAFETY: `a2` is a power-of-two, as proven above. `s2` is strictly less than `a2` // because `(s % a) >> gcdpow` is strictly less than `a >> gcdpow`. return wrapping_mul(minusp2, unsafe { mod_inv(s2, a2) }) & a2minus1;
} #[test] <del> fn align_offset_weird_strides() { #[repr(packed)] struct A3(u16, u8); struct A4(u32); #[repr(packed)] struct A5(u32, u8); #[repr(packed)] struct A6(u32, u16); #[repr(packed)] struct A7(u32, u16, u8); #[repr(packed)] struct A8(u32, u32); #[repr(packed)] struct A9(u32, u32, u8); #[repr(packed)] struct A10(u32, u32, u16); unsafe fn test_weird_stride<T>(ptr: *const T, align: usize) -> bool { </del> <ins> fn align_offset_various_strides() { unsafe fn test_stride<T>(ptr: *const T, align: usize) -> bool { </ins> let numptr = ptr as usize; let mut expected = usize::MAX; // Naive but definitely correct way to find the *first* aligned element of stride::<T>.
while align < limit { for ptr in 1usize..4 * align { unsafe { <del> x |= test_weird_stride::<A3>(ptr::invalid::<A3>(ptr), align); x |= test_weird_stride::<A4>(ptr::invalid::<A4>(ptr), align); x |= test_weird_stride::<A5>(ptr::invalid::<A5>(ptr), align); x |= test_weird_stride::<A6>(ptr::invalid::<A6>(ptr), align); x |= test_weird_stride::<A7>(ptr::invalid::<A7>(ptr), align); x |= test_weird_stride::<A8>(ptr::invalid::<A8>(ptr), align); x |= test_weird_stride::<A9>(ptr::invalid::<A9>(ptr), align); x |= test_weird_stride::<A10>(ptr::invalid::<A10>(ptr), align); </del> <ins> #[repr(packed)] struct A3(u16, u8); x |= test_stride::<A3>(ptr::invalid::<A3>(ptr), align); struct A4(u32); x |= test_stride::<A4>(ptr::invalid::<A4>(ptr), align); #[repr(packed)] struct A5(u32, u8); x |= test_stride::<A5>(ptr::invalid::<A5>(ptr), align); #[repr(packed)] struct A6(u32, u16); x |= test_stride::<A6>(ptr::invalid::<A6>(ptr), align); #[repr(packed)] struct A7(u32, u16, u8); x |= test_stride::<A7>(ptr::invalid::<A7>(ptr), align); #[repr(packed)] struct A8(u32, u32); x |= test_stride::<A8>(ptr::invalid::<A8>(ptr), align); #[repr(packed)] struct A9(u32, u32, u8); x |= test_stride::<A9>(ptr::invalid::<A9>(ptr), align); #[repr(packed)] struct A10(u32, u32, u16); x |= test_stride::<A10>(ptr::invalid::<A10>(ptr), align); x |= test_stride::<u32>(ptr::invalid::<u32>(ptr), align); x |= test_stride::<u128>(ptr::invalid::<u128>(ptr), align); </ins> } } align = (align + 1).next_power_of_two();
<ins> // assembly-output: emit-asm // compile-flags: -Copt-level=1 // only-x86_64 // min-llvm-version: 14.0 #![crate_type="rlib"] // CHECK-LABEL: align_offset_byte_ptr // CHECK: leaq 31 // CHECK: andq $-32 // CHECK: subq #[no_mangle] pub fn align_offset_byte_ptr(ptr: *const u8) -> usize { ptr.align_offset(32) } // CHECK-LABEL: align_offset_byte_slice // CHECK: leaq 31 // CHECK: andq $-32 // CHECK: subq #[no_mangle] pub fn align_offset_byte_slice(slice: &[u8]) -> usize { slice.as_ptr().align_offset(32) } // CHECK-LABEL: align_offset_word_ptr // CHECK: leaq 31 // CHECK: andq $-32 // CHECK: subq // CHECK: shrq // This `ptr` is not known to be aligned, so it is required to check if it is at all possible to // align. LLVM applies a simple mask. // CHECK: orq #[no_mangle] pub fn align_offset_word_ptr(ptr: *const u32) -> usize { ptr.align_offset(32) } // CHECK-LABEL: align_offset_word_slice // CHECK: leaq 31 // CHECK: andq $-32 // CHECK: subq // CHECK: shrq // `slice` is known to be aligned, so `!0` is not possible as a return // CHECK-NOT: orq #[no_mangle] pub fn align_offset_word_slice(slice: &[u32]) -> usize { slice.as_ptr().align_offset(32) } </ins>