Skip to content

Rollup of 5 pull requests #71445

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

Merged
merged 19 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 1 addition & 1 deletion src/libcore/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::ptr::{self, NonNull};
/// something wrong when combining the given input arguments with this
/// allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct AllocErr;

// (we need this for downstream impl of trait Error)
Expand Down
1 change: 1 addition & 0 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
/// So this, for example, can only be done on types implementing `Unpin`:
///
/// ```rust
/// # #![allow(unused_must_use)]
/// use std::mem;
/// use std::pin::Pin;
///
Expand Down
1 change: 1 addition & 0 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
/// [`Clone`]: ../../std/clone/trait.Clone.html
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
pub fn replace<T>(dest: &mut T, mut src: T) -> T {
swap(dest, &mut src);
src
Expand Down
7 changes: 7 additions & 0 deletions src/libproc_macro/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ impl BridgeState<'_> {
}

impl Bridge<'_> {
pub(crate) fn is_available() -> bool {
BridgeState::with(|state| match state {
BridgeState::Connected(_) | BridgeState::InUse => true,
BridgeState::NotConnected => false,
})
}

fn enter<R>(self, f: impl FnOnce() -> R) -> R {
// Hide the default panic output within `proc_macro` expansions.
// NB. the server can't do this because it may use a different libstd.
Expand Down
18 changes: 18 additions & 0 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::{error, fmt, iter, mem};

/// Determines whether proc_macro has been made accessible to the currently
/// running program.
///
/// The proc_macro crate is only intended for use inside the implementation of
/// procedural macros. All the functions in this crate panic if invoked from
/// outside of a procedural macro, such as from a build script or unit test or
/// ordinary Rust binary.
///
/// With consideration for Rust libraries that are designed to support both
/// macro and non-macro use cases, `proc_macro::is_available()` provides a
/// non-panicking way to detect whether the infrastructure required to use the
/// API of proc_macro is presently available. Returns true if invoked from
/// inside of a procedural macro, false if invoked from any other binary.
#[unstable(feature = "proc_macro_is_available", issue = "71436")]
pub fn is_available() -> bool {
bridge::Bridge::is_available()
}

/// The main type provided by this crate, representing an abstract stream of
/// tokens, or, more specifically, a sequence of token trees.
/// The type provide interfaces for iterating over those token trees and, conversely,
Expand Down
73 changes: 42 additions & 31 deletions src/librustc_data_structures/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ use std::time::{Duration, Instant};
use measureme::{EventId, EventIdBuilder, SerializableString, StringId};
use parking_lot::RwLock;

/// MmapSerializatioSink is faster on macOS and Linux
/// but FileSerializationSink is faster on Windows
#[cfg(not(windows))]
type SerializationSink = measureme::MmapSerializationSink;
#[cfg(windows)]
type SerializationSink = measureme::FileSerializationSink;
cfg_if! {
if #[cfg(any(windows, target_os = "wasi"))] {
/// FileSerializationSink is faster on Windows
type SerializationSink = measureme::FileSerializationSink;
} else if #[cfg(target_arch = "wasm32")] {
type SerializationSink = measureme::ByteVecSink;
} else {
/// MmapSerializatioSink is faster on macOS and Linux
type SerializationSink = measureme::MmapSerializationSink;
}
}

type Profiler = measureme::Profiler<SerializationSink>;

Expand Down Expand Up @@ -602,31 +607,37 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
}

// Memory reporting
#[cfg(unix)]
fn get_resident() -> Option<usize> {
let field = 1;
let contents = fs::read("/proc/self/statm").ok()?;
let contents = String::from_utf8(contents).ok()?;
let s = contents.split_whitespace().nth(field)?;
let npages = s.parse::<usize>().ok()?;
Some(npages * 4096)
}

#[cfg(windows)]
fn get_resident() -> Option<usize> {
use std::mem::{self, MaybeUninit};
use winapi::shared::minwindef::DWORD;
use winapi::um::processthreadsapi::GetCurrentProcess;
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};

let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
match unsafe {
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
} {
0 => None,
_ => {
let pmc = unsafe { pmc.assume_init() };
Some(pmc.WorkingSetSize as usize)
cfg_if! {
if #[cfg(windows)] {
fn get_resident() -> Option<usize> {
use std::mem::{self, MaybeUninit};
use winapi::shared::minwindef::DWORD;
use winapi::um::processthreadsapi::GetCurrentProcess;
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};

let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
match unsafe {
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
} {
0 => None,
_ => {
let pmc = unsafe { pmc.assume_init() };
Some(pmc.WorkingSetSize as usize)
}
}
}
} else if #[cfg(unix)] {
fn get_resident() -> Option<usize> {
let field = 1;
let contents = fs::read("/proc/self/statm").ok()?;
let contents = String::from_utf8(contents).ok()?;
let s = contents.split_whitespace().nth(field)?;
let npages = s.parse::<usize>().ok()?;
Some(npages * 4096)
}
} else {
fn get_resident() -> Option<usize> {
None
}
}
}
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0060.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ External C functions are allowed to be variadic. However, a variadic function
takes a minimum number of arguments. For example, consider C's variadic `printf`
function:

```
```compile_fail,E0060
use std::os::raw::{c_char, c_int};

extern "C" {
fn printf(_: *const c_char, ...) -> c_int;
}

unsafe { printf(); } // error!
```

Using this declaration, it must be called with at least one argument, so
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0130.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ A pattern was declared as an argument in a foreign function declaration.

Erroneous code example:

```compile_fail
```compile_fail,E0130
extern {
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
// function declarations
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0198.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ A negative implementation was marked as unsafe.

Erroneous code example:

```compile_fail
```compile_fail,E0198
struct Foo;

unsafe impl !Clone for Foo { } // error!
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_error_codes/error_codes/E0202.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Inherent associated types were part of [RFC 195] but are not yet implemented.
See [the tracking issue][iss8995] for the status of this implementation.

Erroneous code example:

```compile_fail,E0202
struct Foo;

impl Foo {
type Bar = isize; // error!
}
```

[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
[iss8995]: https://github.com/rust-lang/rust/issues/8995
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0230.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0230
#![feature(rustc_attrs)]

fn foo<T: Index<u8>>(x: T){}

#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }

foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error
trait BadAnnotation<A> {}
```

There will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0231.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0231
#![feature(rustc_attrs)]

fn foo<T: Index<u8>>(x: T){}

#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }

foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error!
trait BadAnnotation<A> {}
```

there will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0232.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0232
#![feature(rustc_attrs)]

fn foo<T: Index<u8>>(x: T){}

#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }

foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented(lorem="")] // error!
trait BadAnnotation {}
```

there will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0281.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You tried to supply a type which doesn't implement some trait in a location
which expected that trait. This error typically occurs when working with
`Fn`-based types. Erroneous code example:

```compile-fail
```compile_fail
fn foo<F: Fn(usize)>(x: F) { }

fn main() {
Expand Down
26 changes: 13 additions & 13 deletions src/librustc_error_codes/error_codes/E0364.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ attempted to `pub use` a type or value that was not itself public.

Erroneous code example:

```compile_fail
mod foo {
const X: u32 = 1;
}

pub use foo::X;
```compile_fail,E0364
mod a {
fn foo() {}

fn main() {}
mod a {
pub use super::foo; // error!
}
}
```

The solution to this problem is to ensure that the items that you are
re-exporting are themselves marked with `pub`:

```
mod foo {
pub const X: u32 = 1;
}

pub use foo::X;
mod a {
pub fn foo() {} // ok!

fn main() {}
mod a {
pub use super::foo;
}
}
```

See the [Use Declarations][use-declarations] section of the reference for
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0378.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ or a newtype wrapper around a pointer.

Erroneous code example:

```compile-fail,E0378
```compile_fail,E0378
#![feature(dispatch_from_dyn)]
use std::ops::DispatchFromDyn;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0590.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Example of erroneous code:

```compile_fail
```compile_fail,E0590
while break {}
```

Expand Down
12 changes: 12 additions & 0 deletions src/librustc_error_codes/error_codes/E0639.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,17 @@ instantiated from outside of the defining crate as it has been marked
as `non_exhaustive` and as such more fields/variants may be added in
future that could cause adverse side effects for this code.

Erroneous code example:

```ignore (it only works cross-crate)
#[non_exhaustive]
pub struct NormalStruct {
pub first_field: u16,
pub second_field: u16,
}

let ns = NormalStruct { first_field: 640, second_field: 480 }; // error!
```

It is recommended that you look for a `new` function or equivalent in the
crate's documentation.
10 changes: 5 additions & 5 deletions src/librustc_error_codes/error_codes/E0644.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ A closure or generator was constructed that references its own type.

Erroneous example:

```compile-fail,E0644
```compile_fail,E0644
fn fix<F>(f: &F)
where F: Fn(&F)
{
f(&f);
f(&f);
}

fn main() {
fix(&|y| {
// Here, when `x` is called, the parameter `y` is equal to `x`.
});
fix(&|y| {
// Here, when `x` is called, the parameter `y` is equal to `x`.
});
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0658.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ An unstable feature was used.

Erroneous code example:

```compile_fail,E658
```compile_fail,E0658
#[repr(u128)] // error: use of unstable library feature 'repr128'
enum Foo {
Bar(u64),
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_error_codes/error_codes/E0669.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Cannot convert inline assembly operand to a single LLVM value.

Erroneous code example:

```compile_fail,E0669
#![feature(llvm_asm)]

fn main() {
unsafe {
llvm_asm!("" :: "r"("")); // error!
}
}
```

This error usually happens when trying to pass in a value to an input inline
assembly operand that is actually a pair of values. In particular, this can
happen when trying to pass in a slice, for instance a `&str`. In Rust, these
Expand Down
Loading