Skip to content

Commit b4b4076

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#86527 - JohnTitor:rollup-cbu78g4, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#85054 (Revert SGX inline asm syntax) - rust-lang#85182 (Move `available_concurrency` implementation to `sys`) - rust-lang#86037 (Add `io::Cursor::{remaining, remaining_slice, is_empty}`) - rust-lang#86114 (Reopen rust-lang#79692 (Format symbols under shared frames)) - rust-lang#86297 (Allow to pass arguments to rustdoc-gui tool) - rust-lang#86334 (Resolve type aliases to the type they point to in intra-doc links) - rust-lang#86367 (Fix comment about rustc_inherit_overflow_checks in abs().) - rust-lang#86381 (Add regression test for issue rust-lang#39161) - rust-lang#86387 (Remove `#[allow(unused_lifetimes)]` which is now unnecessary) - rust-lang#86398 (Add regression test for issue rust-lang#54685) - rust-lang#86493 (Say "this enum variant takes"/"this struct takes" instead of "this function takes") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2a92ef + e102a48 commit b4b4076

File tree

4 files changed

+95
-15
lines changed

4 files changed

+95
-15
lines changed

std/src/backtrace.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,11 @@ impl fmt::Display for Backtrace {
399399
let mut f = backtrace_rs::BacktraceFmt::new(fmt, style, &mut print_path);
400400
f.add_context()?;
401401
for frame in frames {
402-
let mut f = f.frame();
403402
if frame.symbols.is_empty() {
404-
f.print_raw(frame.frame.ip(), None, None, None)?;
403+
f.frame().print_raw(frame.frame.ip(), None, None, None)?;
405404
} else {
406405
for symbol in frame.symbols.iter() {
407-
f.print_raw_with_column(
406+
f.frame().print_raw_with_column(
408407
frame.frame.ip(),
409408
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
410409
symbol.filename.as_ref().map(|b| match b {

std/src/io/cursor.rs

+85-4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,88 @@ impl<T> Cursor<T> {
205205
}
206206
}
207207

208+
impl<T> Cursor<T>
209+
where
210+
T: AsRef<[u8]>,
211+
{
212+
/// Returns the remaining length.
213+
///
214+
/// # Examples
215+
///
216+
/// ```
217+
/// #![feature(cursor_remaining)]
218+
/// use std::io::Cursor;
219+
///
220+
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
221+
///
222+
/// assert_eq!(buff.remaining(), 5);
223+
///
224+
/// buff.set_position(2);
225+
/// assert_eq!(buff.remaining(), 3);
226+
///
227+
/// buff.set_position(4);
228+
/// assert_eq!(buff.remaining(), 1);
229+
///
230+
/// buff.set_position(6);
231+
/// assert_eq!(buff.remaining(), 0);
232+
/// ```
233+
#[unstable(feature = "cursor_remaining", issue = "86369")]
234+
pub fn remaining(&self) -> u64 {
235+
(self.inner.as_ref().len() as u64).checked_sub(self.pos).unwrap_or(0)
236+
}
237+
238+
/// Returns the remaining slice.
239+
///
240+
/// # Examples
241+
///
242+
/// ```
243+
/// #![feature(cursor_remaining)]
244+
/// use std::io::Cursor;
245+
///
246+
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
247+
///
248+
/// assert_eq!(buff.remaining_slice(), &[1, 2, 3, 4, 5]);
249+
///
250+
/// buff.set_position(2);
251+
/// assert_eq!(buff.remaining_slice(), &[3, 4, 5]);
252+
///
253+
/// buff.set_position(4);
254+
/// assert_eq!(buff.remaining_slice(), &[5]);
255+
///
256+
/// buff.set_position(6);
257+
/// assert_eq!(buff.remaining_slice(), &[]);
258+
/// ```
259+
#[unstable(feature = "cursor_remaining", issue = "86369")]
260+
pub fn remaining_slice(&self) -> &[u8] {
261+
let len = self.pos.min(self.inner.as_ref().len() as u64);
262+
&self.inner.as_ref()[(len as usize)..]
263+
}
264+
265+
/// Returns `true` if the remaining slice is empty.
266+
///
267+
/// # Examples
268+
///
269+
/// ```
270+
/// #![feature(cursor_remaining)]
271+
/// use std::io::Cursor;
272+
///
273+
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
274+
///
275+
/// buff.set_position(2);
276+
/// assert!(!buff.is_empty());
277+
///
278+
/// buff.set_position(5);
279+
/// assert!(buff.is_empty());
280+
///
281+
/// buff.set_position(10);
282+
/// assert!(buff.is_empty());
283+
/// ```
284+
#[unstable(feature = "cursor_remaining", issue = "86369")]
285+
pub fn is_empty(&self) -> bool {
286+
self.pos >= self.inner.as_ref().len() as u64
287+
}
288+
}
289+
208290
#[stable(feature = "rust1", since = "1.0.0")]
209291
impl<T> Clone for Cursor<T>
210292
where
@@ -268,7 +350,7 @@ where
268350
T: AsRef<[u8]>,
269351
{
270352
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
271-
let n = Read::read(&mut self.fill_buf()?, buf)?;
353+
let n = Read::read(&mut self.remaining_slice(), buf)?;
272354
self.pos += n as u64;
273355
Ok(n)
274356
}
@@ -291,7 +373,7 @@ where
291373

292374
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
293375
let n = buf.len();
294-
Read::read_exact(&mut self.fill_buf()?, buf)?;
376+
Read::read_exact(&mut self.remaining_slice(), buf)?;
295377
self.pos += n as u64;
296378
Ok(())
297379
}
@@ -308,8 +390,7 @@ where
308390
T: AsRef<[u8]>,
309391
{
310392
fn fill_buf(&mut self) -> io::Result<&[u8]> {
311-
let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64);
312-
Ok(&self.inner.as_ref()[(amt as usize)..])
393+
Ok(self.remaining_slice())
313394
}
314395
fn consume(&mut self, amt: usize) {
315396
self.pos += amt as u64;

std/src/os/fortanix_sgx/arch.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32>
3333

3434
asm!(
3535
// rbx is reserved by LLVM
36-
"xchg {0}, rbx",
36+
"xchg %rbx, {0}",
3737
"enclu",
38-
"mov rbx, {0}",
38+
"mov {0}, %rbx",
3939
inout(reg) request => _,
4040
inlateout("eax") ENCLU_EGETKEY => error,
4141
in("rcx") out.as_mut_ptr(),
42-
options(nostack),
42+
options(att_syntax, nostack),
4343
);
4444

4545
match error {
@@ -64,14 +64,14 @@ pub fn ereport(
6464

6565
asm!(
6666
// rbx is reserved by LLVM
67-
"xchg {0}, rbx",
67+
"xchg %rbx, {0}",
6868
"enclu",
69-
"mov rbx, {0}",
69+
"mov {0}, %rbx",
7070
inout(reg) targetinfo => _,
7171
in("eax") ENCLU_EREPORT,
7272
in("rcx") reportdata,
7373
in("rdx") report.as_mut_ptr(),
74-
options(preserves_flags, nostack),
74+
options(att_syntax, preserves_flags, nostack),
7575
);
7676

7777
report.assume_init()

std/src/sys/sgx/abi/mem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub fn image_base() -> u64 {
3636
let base: u64;
3737
unsafe {
3838
asm!(
39-
"lea {}, qword ptr [rip + IMAGE_BASE]",
39+
"lea IMAGE_BASE(%rip), {}",
4040
lateout(reg) base,
41-
options(nostack, preserves_flags, nomem, pure),
41+
options(att_syntax, nostack, preserves_flags, nomem, pure),
4242
)
4343
};
4444
base

0 commit comments

Comments
 (0)