Skip to content

Commit 2c04f0b

Browse files
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 4573a4a + 4495ce7 commit 2c04f0b

File tree

30 files changed

+535
-204
lines changed

30 files changed

+535
-204
lines changed

compiler/rustc_data_structures/src/captures.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
/// Basically a workaround; see [this comment] for details.
44
///
55
/// [this comment]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
6-
// FIXME(eddyb) false positive, the lifetime parameter is "phantom" but needed.
7-
#[allow(unused_lifetimes)]
86
pub trait Captures<'a> {}
97

108
impl<'a, T: ?Sized> Captures<'a> for T {}

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::check::{
1111
use rustc_ast as ast;
1212
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
1313
use rustc_hir as hir;
14-
use rustc_hir::def::{DefKind, Res};
14+
use rustc_hir::def::{CtorOf, DefKind, Res};
1515
use rustc_hir::def_id::DefId;
1616
use rustc_hir::{ExprKind, Node, QPath};
1717
use rustc_middle::ty::adjustment::AllowTwoPhase;
@@ -120,8 +120,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
120120
error_code: &str,
121121
c_variadic: bool,
122122
sugg_unit: bool| {
123-
let (span, start_span, args) = match &expr.kind {
124-
hir::ExprKind::Call(hir::Expr { span, .. }, args) => (*span, *span, &args[..]),
123+
let (span, start_span, args, ctor_of) = match &expr.kind {
124+
hir::ExprKind::Call(
125+
hir::Expr {
126+
span,
127+
kind:
128+
hir::ExprKind::Path(hir::QPath::Resolved(
129+
_,
130+
hir::Path { res: Res::Def(DefKind::Ctor(of, _), _), .. },
131+
)),
132+
..
133+
},
134+
args,
135+
) => (*span, *span, &args[..], Some(of)),
136+
hir::ExprKind::Call(hir::Expr { span, .. }, args) => {
137+
(*span, *span, &args[..], None)
138+
}
125139
hir::ExprKind::MethodCall(path_segment, span, args, _) => (
126140
*span,
127141
// `sp` doesn't point at the whole `foo.bar()`, only at `bar`.
@@ -137,6 +151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137151
})
138152
.unwrap_or(*span),
139153
&args[1..], // Skip the receiver.
154+
None, // methods are never ctors
140155
),
141156
k => span_bug!(sp, "checking argument types on a non-call: `{:?}`", k),
142157
};
@@ -157,7 +172,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
157172
let mut err = tcx.sess.struct_span_err_with_code(
158173
span,
159174
&format!(
160-
"this function takes {}{} but {} {} supplied",
175+
"this {} takes {}{} but {} {} supplied",
176+
match ctor_of {
177+
Some(CtorOf::Struct) => "struct",
178+
Some(CtorOf::Variant) => "enum variant",
179+
None => "function",
180+
},
161181
if c_variadic { "at least " } else { "" },
162182
potentially_plural_count(expected_count, "argument"),
163183
potentially_plural_count(arg_count, "argument"),

library/core/src/num/int_macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1772,9 +1772,9 @@ macro_rules! int_impl {
17721772
#[inline]
17731773
#[rustc_inherit_overflow_checks]
17741774
pub const fn abs(self) -> Self {
1775-
// Note that the #[inline] above means that the overflow
1776-
// semantics of the subtraction depend on the crate we're being
1777-
// inlined into.
1775+
// Note that the #[rustc_inherit_overflow_checks] and #[inline]
1776+
// above mean that the overflow semantics of the subtraction
1777+
// depend on the crate we're being called from.
17781778
if self.is_negative() {
17791779
-self
17801780
} else {

library/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 {

library/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;

library/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()

library/std/src/sys/hermit/thread.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#![allow(dead_code)]
22

3+
use super::unsupported;
34
use crate::ffi::CStr;
45
use crate::io;
56
use crate::mem;
7+
use crate::num::NonZeroUsize;
68
use crate::sys::hermit::abi;
79
use crate::sys::hermit::thread_local_dtor::run_dtors;
810
use crate::time::Duration;
@@ -95,6 +97,10 @@ impl Thread {
9597
}
9698
}
9799

100+
pub fn available_concurrency() -> io::Result<NonZeroUsize> {
101+
unsupported()
102+
}
103+
98104
pub mod guard {
99105
pub type Guard = !;
100106
pub unsafe fn current() -> Option<Guard> {

library/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

library/std/src/sys/sgx/thread.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![cfg_attr(test, allow(dead_code))] // why is this necessary?
2+
use super::unsupported;
23
use crate::ffi::CStr;
34
use crate::io;
5+
use crate::num::NonZeroUsize;
46
use crate::time::Duration;
57

68
use super::abi::usercalls;
@@ -135,6 +137,10 @@ impl Thread {
135137
}
136138
}
137139

140+
pub fn available_concurrency() -> io::Result<NonZeroUsize> {
141+
unsupported()
142+
}
143+
138144
pub mod guard {
139145
pub type Guard = !;
140146
pub unsafe fn current() -> Option<Guard> {

library/std/src/sys/unix/thread.rs

+83
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::cmp;
22
use crate::ffi::CStr;
33
use crate::io;
44
use crate::mem;
5+
use crate::num::NonZeroUsize;
56
use crate::ptr;
67
use crate::sys::{os, stack_overflow};
78
use crate::time::Duration;
@@ -198,6 +199,88 @@ impl Drop for Thread {
198199
}
199200
}
200201

202+
pub fn available_concurrency() -> io::Result<NonZeroUsize> {
203+
cfg_if::cfg_if! {
204+
if #[cfg(any(
205+
target_os = "android",
206+
target_os = "emscripten",
207+
target_os = "fuchsia",
208+
target_os = "ios",
209+
target_os = "linux",
210+
target_os = "macos",
211+
target_os = "solaris",
212+
target_os = "illumos",
213+
))] {
214+
match unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) } {
215+
-1 => Err(io::Error::last_os_error()),
216+
0 => Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")),
217+
cpus => Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }),
218+
}
219+
} else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] {
220+
use crate::ptr;
221+
222+
let mut cpus: libc::c_uint = 0;
223+
let mut cpus_size = crate::mem::size_of_val(&cpus);
224+
225+
unsafe {
226+
cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
227+
}
228+
229+
// Fallback approach in case of errors or no hardware threads.
230+
if cpus < 1 {
231+
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
232+
let res = unsafe {
233+
libc::sysctl(
234+
mib.as_mut_ptr(),
235+
2,
236+
&mut cpus as *mut _ as *mut _,
237+
&mut cpus_size as *mut _ as *mut _,
238+
ptr::null_mut(),
239+
0,
240+
)
241+
};
242+
243+
// Handle errors if any.
244+
if res == -1 {
245+
return Err(io::Error::last_os_error());
246+
} else if cpus == 0 {
247+
return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
248+
}
249+
}
250+
Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
251+
} else if #[cfg(target_os = "openbsd")] {
252+
use crate::ptr;
253+
254+
let mut cpus: libc::c_uint = 0;
255+
let mut cpus_size = crate::mem::size_of_val(&cpus);
256+
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
257+
258+
let res = unsafe {
259+
libc::sysctl(
260+
mib.as_mut_ptr(),
261+
2,
262+
&mut cpus as *mut _ as *mut _,
263+
&mut cpus_size as *mut _ as *mut _,
264+
ptr::null_mut(),
265+
0,
266+
)
267+
};
268+
269+
// Handle errors if any.
270+
if res == -1 {
271+
return Err(io::Error::last_os_error());
272+
} else if cpus == 0 {
273+
return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
274+
}
275+
276+
Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
277+
} else {
278+
// FIXME: implement on vxWorks, Redox, Haiku, l4re
279+
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Getting the number of hardware threads is not supported on the target platform"))
280+
}
281+
}
282+
}
283+
201284
#[cfg(all(
202285
not(target_os = "linux"),
203286
not(target_os = "freebsd"),

0 commit comments

Comments
 (0)