Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #86527

Merged
merged 28 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5bbf8cf
Revert SGX inline asm syntax
May 7, 2021
08d44c2
Implement `Cursor::{remaining, is_empty}`
soerenmeier Jun 5, 2021
5fb2986
format symbols under shared frames
KodrAus Dec 4, 2020
8423a19
make both panic display formats collapse frames
KodrAus Dec 16, 2020
95c1bf6
Allow to pass arguments to rustdoc-gui tool
GuillaumeGomez Jun 14, 2021
212e91a
Update tracking issue
soerenmeier Jun 16, 2021
503abc7
add regression test for issue #39161
yerke Jun 16, 2021
636170a
Remove `#[allow(unused_lifetimes)]` which is now unnecessary
JohnTitor Jun 16, 2021
664bde0
rename `remaining` to `remaining_slice` and add a new `remaining`
soerenmeier Jun 17, 2021
13bfbb4
Fix comment about rustc_inherit_overflow_checks in abs().
m-ou-se Jun 16, 2021
22029a2
add regression test for issue #54685
yerke Jun 18, 2021
4cd2fab
Specify if struct/enum in arg mismatch error
syvb Jun 20, 2021
9063eda
Move `available_concurrency` implementation to `sys`
CDirkx Apr 29, 2021
dd90900
Resolve type aliases to the type they point to in intra-doc links
LeSeulArtichaut Jun 15, 2021
05ec710
Remove tidy exception for `available_concurrency`
CDirkx May 11, 2021
888418a
Use `Unsupported` on platforms where `available_concurrency` is not i…
CDirkx Jun 21, 2021
b8a7bfb
Reference issue test originated from
syvb Jun 21, 2021
d6e344d
Rollup merge of #85054 - jethrogb:jb/sgx-inline-asm, r=Amanieu
JohnTitor Jun 21, 2021
7f1a4a2
Rollup merge of #85182 - CDirkx:available_concurrency, r=JohnTitor
JohnTitor Jun 21, 2021
4463b08
Rollup merge of #86037 - soerenmeier:cursor_remaining, r=yaahc
JohnTitor Jun 21, 2021
7ee6b8b
Rollup merge of #86114 - JDuchniewicz:feat/panic-frame-fmt, r=yaahc
JohnTitor Jun 21, 2021
7dca2e2
Rollup merge of #86297 - GuillaumeGomez:rustdoc-gui-args, r=Mark-Simu…
JohnTitor Jun 21, 2021
83d9b1b
Rollup merge of #86334 - LeSeulArtichaut:86120-links-type-aliases, r=…
JohnTitor Jun 21, 2021
8389cd3
Rollup merge of #86367 - m-ou-se:fix-abs-comment, r=scottmcm
JohnTitor Jun 21, 2021
4d73300
Rollup merge of #86381 - yerke:add-test-for-issue-39161, r=JohnTitor
JohnTitor Jun 21, 2021
d285235
Rollup merge of #86387 - JohnTitor:now-no-unused-lifetimes, r=Mark-Si…
JohnTitor Jun 21, 2021
fdb1daa
Rollup merge of #86398 - yerke:add-test-for-issue-54685, r=Mark-Simul…
JohnTitor Jun 21, 2021
4495ce7
Rollup merge of #86493 - Smittyvb:ctor-typeck-error, r=davidtwco
JohnTitor Jun 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_data_structures/src/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
/// Basically a workaround; see [this comment] for details.
///
/// [this comment]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
// FIXME(eddyb) false positive, the lifetime parameter is "phantom" but needed.
#[allow(unused_lifetimes)]
pub trait Captures<'a> {}

impl<'a, T: ?Sized> Captures<'a> for T {}
28 changes: 24 additions & 4 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::check::{
use rustc_ast as ast;
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{ExprKind, Node, QPath};
use rustc_middle::ty::adjustment::AllowTwoPhase;
Expand Down Expand Up @@ -120,8 +120,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error_code: &str,
c_variadic: bool,
sugg_unit: bool| {
let (span, start_span, args) = match &expr.kind {
hir::ExprKind::Call(hir::Expr { span, .. }, args) => (*span, *span, &args[..]),
let (span, start_span, args, ctor_of) = match &expr.kind {
hir::ExprKind::Call(
hir::Expr {
span,
kind:
hir::ExprKind::Path(hir::QPath::Resolved(
_,
hir::Path { res: Res::Def(DefKind::Ctor(of, _), _), .. },
)),
..
},
args,
) => (*span, *span, &args[..], Some(of)),
hir::ExprKind::Call(hir::Expr { span, .. }, args) => {
(*span, *span, &args[..], None)
}
hir::ExprKind::MethodCall(path_segment, span, args, _) => (
*span,
// `sp` doesn't point at the whole `foo.bar()`, only at `bar`.
Expand All @@ -137,6 +151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
.unwrap_or(*span),
&args[1..], // Skip the receiver.
None, // methods are never ctors
),
k => span_bug!(sp, "checking argument types on a non-call: `{:?}`", k),
};
Expand All @@ -157,7 +172,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut err = tcx.sess.struct_span_err_with_code(
span,
&format!(
"this function takes {}{} but {} {} supplied",
"this {} takes {}{} but {} {} supplied",
match ctor_of {
Some(CtorOf::Struct) => "struct",
Some(CtorOf::Variant) => "enum variant",
None => "function",
},
if c_variadic { "at least " } else { "" },
potentially_plural_count(expected_count, "argument"),
potentially_plural_count(arg_count, "argument"),
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,9 +1772,9 @@ macro_rules! int_impl {
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn abs(self) -> Self {
// Note that the #[inline] above means that the overflow
// semantics of the subtraction depend on the crate we're being
// inlined into.
// Note that the #[rustc_inherit_overflow_checks] and #[inline]
// above mean that the overflow semantics of the subtraction
// depend on the crate we're being called from.
if self.is_negative() {
-self
} else {
Expand Down
5 changes: 2 additions & 3 deletions library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,11 @@ impl fmt::Display for Backtrace {
let mut f = backtrace_rs::BacktraceFmt::new(fmt, style, &mut print_path);
f.add_context()?;
for frame in frames {
let mut f = f.frame();
if frame.symbols.is_empty() {
f.print_raw(frame.frame.ip(), None, None, None)?;
f.frame().print_raw(frame.frame.ip(), None, None, None)?;
} else {
for symbol in frame.symbols.iter() {
f.print_raw_with_column(
f.frame().print_raw_with_column(
frame.frame.ip(),
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
symbol.filename.as_ref().map(|b| match b {
Expand Down
89 changes: 85 additions & 4 deletions library/std/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,88 @@ impl<T> Cursor<T> {
}
}

impl<T> Cursor<T>
where
T: AsRef<[u8]>,
{
/// Returns the remaining length.
///
/// # Examples
///
/// ```
/// #![feature(cursor_remaining)]
/// use std::io::Cursor;
///
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
///
/// assert_eq!(buff.remaining(), 5);
///
/// buff.set_position(2);
/// assert_eq!(buff.remaining(), 3);
///
/// buff.set_position(4);
/// assert_eq!(buff.remaining(), 1);
///
/// buff.set_position(6);
/// assert_eq!(buff.remaining(), 0);
/// ```
#[unstable(feature = "cursor_remaining", issue = "86369")]
pub fn remaining(&self) -> u64 {
(self.inner.as_ref().len() as u64).checked_sub(self.pos).unwrap_or(0)
}

/// Returns the remaining slice.
///
/// # Examples
///
/// ```
/// #![feature(cursor_remaining)]
/// use std::io::Cursor;
///
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
///
/// assert_eq!(buff.remaining_slice(), &[1, 2, 3, 4, 5]);
///
/// buff.set_position(2);
/// assert_eq!(buff.remaining_slice(), &[3, 4, 5]);
///
/// buff.set_position(4);
/// assert_eq!(buff.remaining_slice(), &[5]);
///
/// buff.set_position(6);
/// assert_eq!(buff.remaining_slice(), &[]);
/// ```
#[unstable(feature = "cursor_remaining", issue = "86369")]
pub fn remaining_slice(&self) -> &[u8] {
let len = self.pos.min(self.inner.as_ref().len() as u64);
&self.inner.as_ref()[(len as usize)..]
}

/// Returns `true` if the remaining slice is empty.
///
/// # Examples
///
/// ```
/// #![feature(cursor_remaining)]
/// use std::io::Cursor;
///
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
///
/// buff.set_position(2);
/// assert!(!buff.is_empty());
///
/// buff.set_position(5);
/// assert!(buff.is_empty());
///
/// buff.set_position(10);
/// assert!(buff.is_empty());
/// ```
#[unstable(feature = "cursor_remaining", issue = "86369")]
pub fn is_empty(&self) -> bool {
self.pos >= self.inner.as_ref().len() as u64
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for Cursor<T>
where
Expand Down Expand Up @@ -268,7 +350,7 @@ where
T: AsRef<[u8]>,
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let n = Read::read(&mut self.fill_buf()?, buf)?;
let n = Read::read(&mut self.remaining_slice(), buf)?;
self.pos += n as u64;
Ok(n)
}
Expand All @@ -291,7 +373,7 @@ where

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
let n = buf.len();
Read::read_exact(&mut self.fill_buf()?, buf)?;
Read::read_exact(&mut self.remaining_slice(), buf)?;
self.pos += n as u64;
Ok(())
}
Expand All @@ -308,8 +390,7 @@ where
T: AsRef<[u8]>,
{
fn fill_buf(&mut self) -> io::Result<&[u8]> {
let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64);
Ok(&self.inner.as_ref()[(amt as usize)..])
Ok(self.remaining_slice())
}
fn consume(&mut self, amt: usize) {
self.pos += amt as u64;
Expand Down
12 changes: 6 additions & 6 deletions library/std/src/os/fortanix_sgx/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32>

asm!(
// rbx is reserved by LLVM
"xchg {0}, rbx",
"xchg %rbx, {0}",
"enclu",
"mov rbx, {0}",
"mov {0}, %rbx",
inout(reg) request => _,
inlateout("eax") ENCLU_EGETKEY => error,
in("rcx") out.as_mut_ptr(),
options(nostack),
options(att_syntax, nostack),
);

match error {
Expand All @@ -64,14 +64,14 @@ pub fn ereport(

asm!(
// rbx is reserved by LLVM
"xchg {0}, rbx",
"xchg %rbx, {0}",
"enclu",
"mov rbx, {0}",
"mov {0}, %rbx",
inout(reg) targetinfo => _,
in("eax") ENCLU_EREPORT,
in("rcx") reportdata,
in("rdx") report.as_mut_ptr(),
options(preserves_flags, nostack),
options(att_syntax, preserves_flags, nostack),
);

report.assume_init()
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/hermit/thread.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(dead_code)]

use super::unsupported;
use crate::ffi::CStr;
use crate::io;
use crate::mem;
use crate::num::NonZeroUsize;
use crate::sys::hermit::abi;
use crate::sys::hermit::thread_local_dtor::run_dtors;
use crate::time::Duration;
Expand Down Expand Up @@ -95,6 +97,10 @@ impl Thread {
}
}

pub fn available_concurrency() -> io::Result<NonZeroUsize> {
unsupported()
}

pub mod guard {
pub type Guard = !;
pub unsafe fn current() -> Option<Guard> {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/sgx/abi/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub fn image_base() -> u64 {
let base: u64;
unsafe {
asm!(
"lea {}, qword ptr [rip + IMAGE_BASE]",
"lea IMAGE_BASE(%rip), {}",
lateout(reg) base,
options(nostack, preserves_flags, nomem, pure),
options(att_syntax, nostack, preserves_flags, nomem, pure),
)
};
base
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/sgx/thread.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![cfg_attr(test, allow(dead_code))] // why is this necessary?
use super::unsupported;
use crate::ffi::CStr;
use crate::io;
use crate::num::NonZeroUsize;
use crate::time::Duration;

use super::abi::usercalls;
Expand Down Expand Up @@ -135,6 +137,10 @@ impl Thread {
}
}

pub fn available_concurrency() -> io::Result<NonZeroUsize> {
unsupported()
}

pub mod guard {
pub type Guard = !;
pub unsafe fn current() -> Option<Guard> {
Expand Down
83 changes: 83 additions & 0 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cmp;
use crate::ffi::CStr;
use crate::io;
use crate::mem;
use crate::num::NonZeroUsize;
use crate::ptr;
use crate::sys::{os, stack_overflow};
use crate::time::Duration;
Expand Down Expand Up @@ -198,6 +199,88 @@ impl Drop for Thread {
}
}

pub fn available_concurrency() -> io::Result<NonZeroUsize> {
cfg_if::cfg_if! {
if #[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "solaris",
target_os = "illumos",
))] {
match unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) } {
-1 => Err(io::Error::last_os_error()),
0 => Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform")),
cpus => Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }),
}
} else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] {
use crate::ptr;

let mut cpus: libc::c_uint = 0;
let mut cpus_size = crate::mem::size_of_val(&cpus);

unsafe {
cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
}

// Fallback approach in case of errors or no hardware threads.
if cpus < 1 {
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
let res = unsafe {
libc::sysctl(
mib.as_mut_ptr(),
2,
&mut cpus as *mut _ as *mut _,
&mut cpus_size as *mut _ as *mut _,
ptr::null_mut(),
0,
)
};

// Handle errors if any.
if res == -1 {
return Err(io::Error::last_os_error());
} else if cpus == 0 {
return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
}
}
Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
} else if #[cfg(target_os = "openbsd")] {
use crate::ptr;

let mut cpus: libc::c_uint = 0;
let mut cpus_size = crate::mem::size_of_val(&cpus);
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];

let res = unsafe {
libc::sysctl(
mib.as_mut_ptr(),
2,
&mut cpus as *mut _ as *mut _,
&mut cpus_size as *mut _ as *mut _,
ptr::null_mut(),
0,
)
};

// Handle errors if any.
if res == -1 {
return Err(io::Error::last_os_error());
} else if cpus == 0 {
return Err(io::Error::new_const(io::ErrorKind::NotFound, &"The number of hardware threads is not known for the target platform"));
}

Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) })
} else {
// FIXME: implement on vxWorks, Redox, Haiku, l4re
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Getting the number of hardware threads is not supported on the target platform"))
}
}
}

#[cfg(all(
not(target_os = "linux"),
not(target_os = "freebsd"),
Expand Down
Loading