Skip to content

Commit fc145e1

Browse files
committed
Auto merge of #71445 - Dylan-DPC:rollup-31givp1, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #71256 (Lint must_use on mem::replace) - #71350 (Error code explanation extra check) - #71369 (allow wasm32 compilation of librustc_data_structures/profiling.rs) - #71400 (proc_macro::is_available()) - #71440 (Implement `Copy` for `AllocErr`) Failed merges: r? @ghost
2 parents db9b05a + bb13aab commit fc145e1

File tree

41 files changed

+345
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+345
-129
lines changed

src/libcore/alloc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::ptr::{self, NonNull};
1818
/// something wrong when combining the given input arguments with this
1919
/// allocator.
2020
#[unstable(feature = "allocator_api", issue = "32838")]
21-
#[derive(Clone, PartialEq, Eq, Debug)]
21+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2222
pub struct AllocErr;
2323

2424
// (we need this for downstream impl of trait Error)

src/libcore/marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
709709
/// So this, for example, can only be done on types implementing `Unpin`:
710710
///
711711
/// ```rust
712+
/// # #![allow(unused_must_use)]
712713
/// use std::mem;
713714
/// use std::pin::Pin;
714715
///

src/libcore/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
808808
/// [`Clone`]: ../../std/clone/trait.Clone.html
809809
#[inline]
810810
#[stable(feature = "rust1", since = "1.0.0")]
811+
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
811812
pub fn replace<T>(dest: &mut T, mut src: T) -> T {
812813
swap(dest, &mut src);
813814
src

src/libproc_macro/bridge/client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ impl BridgeState<'_> {
290290
}
291291

292292
impl Bridge<'_> {
293+
pub(crate) fn is_available() -> bool {
294+
BridgeState::with(|state| match state {
295+
BridgeState::Connected(_) | BridgeState::InUse => true,
296+
BridgeState::NotConnected => false,
297+
})
298+
}
299+
293300
fn enter<R>(self, f: impl FnOnce() -> R) -> R {
294301
// Hide the default panic output within `proc_macro` expansions.
295302
// NB. the server can't do this because it may use a different libstd.

src/libproc_macro/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ use std::path::PathBuf;
4545
use std::str::FromStr;
4646
use std::{error, fmt, iter, mem};
4747

48+
/// Determines whether proc_macro has been made accessible to the currently
49+
/// running program.
50+
///
51+
/// The proc_macro crate is only intended for use inside the implementation of
52+
/// procedural macros. All the functions in this crate panic if invoked from
53+
/// outside of a procedural macro, such as from a build script or unit test or
54+
/// ordinary Rust binary.
55+
///
56+
/// With consideration for Rust libraries that are designed to support both
57+
/// macro and non-macro use cases, `proc_macro::is_available()` provides a
58+
/// non-panicking way to detect whether the infrastructure required to use the
59+
/// API of proc_macro is presently available. Returns true if invoked from
60+
/// inside of a procedural macro, false if invoked from any other binary.
61+
#[unstable(feature = "proc_macro_is_available", issue = "71436")]
62+
pub fn is_available() -> bool {
63+
bridge::Bridge::is_available()
64+
}
65+
4866
/// The main type provided by this crate, representing an abstract stream of
4967
/// tokens, or, more specifically, a sequence of token trees.
5068
/// The type provide interfaces for iterating over those token trees and, conversely,

src/librustc_data_structures/profiling.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ use std::time::{Duration, Instant};
9797
use measureme::{EventId, EventIdBuilder, SerializableString, StringId};
9898
use parking_lot::RwLock;
9999

100-
/// MmapSerializatioSink is faster on macOS and Linux
101-
/// but FileSerializationSink is faster on Windows
102-
#[cfg(not(windows))]
103-
type SerializationSink = measureme::MmapSerializationSink;
104-
#[cfg(windows)]
105-
type SerializationSink = measureme::FileSerializationSink;
100+
cfg_if! {
101+
if #[cfg(any(windows, target_os = "wasi"))] {
102+
/// FileSerializationSink is faster on Windows
103+
type SerializationSink = measureme::FileSerializationSink;
104+
} else if #[cfg(target_arch = "wasm32")] {
105+
type SerializationSink = measureme::ByteVecSink;
106+
} else {
107+
/// MmapSerializatioSink is faster on macOS and Linux
108+
type SerializationSink = measureme::MmapSerializationSink;
109+
}
110+
}
106111

107112
type Profiler = measureme::Profiler<SerializationSink>;
108113

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

604609
// Memory reporting
605-
#[cfg(unix)]
606-
fn get_resident() -> Option<usize> {
607-
let field = 1;
608-
let contents = fs::read("/proc/self/statm").ok()?;
609-
let contents = String::from_utf8(contents).ok()?;
610-
let s = contents.split_whitespace().nth(field)?;
611-
let npages = s.parse::<usize>().ok()?;
612-
Some(npages * 4096)
613-
}
614-
615-
#[cfg(windows)]
616-
fn get_resident() -> Option<usize> {
617-
use std::mem::{self, MaybeUninit};
618-
use winapi::shared::minwindef::DWORD;
619-
use winapi::um::processthreadsapi::GetCurrentProcess;
620-
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
621-
622-
let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
623-
match unsafe {
624-
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
625-
} {
626-
0 => None,
627-
_ => {
628-
let pmc = unsafe { pmc.assume_init() };
629-
Some(pmc.WorkingSetSize as usize)
610+
cfg_if! {
611+
if #[cfg(windows)] {
612+
fn get_resident() -> Option<usize> {
613+
use std::mem::{self, MaybeUninit};
614+
use winapi::shared::minwindef::DWORD;
615+
use winapi::um::processthreadsapi::GetCurrentProcess;
616+
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
617+
618+
let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
619+
match unsafe {
620+
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
621+
} {
622+
0 => None,
623+
_ => {
624+
let pmc = unsafe { pmc.assume_init() };
625+
Some(pmc.WorkingSetSize as usize)
626+
}
627+
}
628+
}
629+
} else if #[cfg(unix)] {
630+
fn get_resident() -> Option<usize> {
631+
let field = 1;
632+
let contents = fs::read("/proc/self/statm").ok()?;
633+
let contents = String::from_utf8(contents).ok()?;
634+
let s = contents.split_whitespace().nth(field)?;
635+
let npages = s.parse::<usize>().ok()?;
636+
Some(npages * 4096)
637+
}
638+
} else {
639+
fn get_resident() -> Option<usize> {
640+
None
630641
}
631642
}
632643
}

src/librustc_error_codes/error_codes/E0060.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ External C functions are allowed to be variadic. However, a variadic function
22
takes a minimum number of arguments. For example, consider C's variadic `printf`
33
function:
44

5-
```
5+
```compile_fail,E0060
66
use std::os::raw::{c_char, c_int};
77
88
extern "C" {
99
fn printf(_: *const c_char, ...) -> c_int;
1010
}
11+
12+
unsafe { printf(); } // error!
1113
```
1214

1315
Using this declaration, it must be called with at least one argument, so

src/librustc_error_codes/error_codes/E0130.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A pattern was declared as an argument in a foreign function declaration.
22

33
Erroneous code example:
44

5-
```compile_fail
5+
```compile_fail,E0130
66
extern {
77
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
88
// function declarations

src/librustc_error_codes/error_codes/E0198.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A negative implementation was marked as unsafe.
22

33
Erroneous code example:
44

5-
```compile_fail
5+
```compile_fail,E0198
66
struct Foo;
77
88
unsafe impl !Clone for Foo { } // error!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Inherent associated types were part of [RFC 195] but are not yet implemented.
22
See [the tracking issue][iss8995] for the status of this implementation.
33

4+
Erroneous code example:
5+
6+
```compile_fail,E0202
7+
struct Foo;
8+
9+
impl Foo {
10+
type Bar = isize; // error!
11+
}
12+
```
13+
414
[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
515
[iss8995]: https://github.com/rust-lang/rust/issues/8995

0 commit comments

Comments
 (0)