Skip to content

Commit 28847e5

Browse files
committed
Merge branch 'master' into fix-doc-links
2 parents 547219c + 66f7a5d commit 28847e5

File tree

110 files changed

+804
-819
lines changed

Some content is hidden

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

110 files changed

+804
-819
lines changed

src/libcore/alloc/mod.rs

+1-1
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

+1
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

+1
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

+7
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

+18
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_codegen_ssa/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
120120
};
121121
if is_consume {
122122
let base_ty =
123-
mir::Place::ty_from(place_ref.local, proj_base, *self.fx.mir, cx.tcx());
123+
mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx());
124124
let base_ty = self.fx.monomorphize(&base_ty);
125125

126126
// ZSTs don't require any actual memory access.

src/librustc_codegen_ssa/mir/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
152152
// a loop.
153153
fn maybe_sideeffect<Bx: BuilderMethods<'a, 'tcx>>(
154154
&self,
155-
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
155+
mir: &'tcx mir::Body<'tcx>,
156156
bx: &mut Bx,
157157
targets: &[mir::BasicBlock],
158158
) {
@@ -306,7 +306,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
306306
target: mir::BasicBlock,
307307
unwind: Option<mir::BasicBlock>,
308308
) {
309-
let ty = location.ty(*self.mir, bx.tcx()).ty;
309+
let ty = location.ty(self.mir, bx.tcx()).ty;
310310
let ty = self.monomorphize(&ty);
311311
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
312312

@@ -572,7 +572,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
572572
let extra_args = extra_args
573573
.iter()
574574
.map(|op_arg| {
575-
let op_ty = op_arg.ty(*self.mir, bx.tcx());
575+
let op_ty = op_arg.ty(self.mir, bx.tcx());
576576
self.monomorphize(&op_ty)
577577
})
578578
.collect::<Vec<_>>();

src/librustc_codegen_ssa/mir/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue};
2121
pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
2222
instance: Instance<'tcx>,
2323

24-
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
24+
mir: &'tcx mir::Body<'tcx>,
2525

2626
debug_context: Option<FunctionDebugContext<Bx::DIScope>>,
2727

@@ -169,7 +169,6 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
169169
.collect();
170170

171171
let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs);
172-
let mir_body: &mir::Body<'_> = *mir;
173172
let mut fx = FunctionCx {
174173
instance,
175174
mir,
@@ -197,7 +196,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
197196
let args = arg_local_refs(&mut bx, &mut fx, &memory_locals);
198197

199198
let mut allocate_local = |local| {
200-
let decl = &mir_body.local_decls[local];
199+
let decl = &mir.local_decls[local];
201200
let layout = bx.layout_of(fx.monomorphize(&decl.ty));
202201
assert!(!layout.ty.has_erasable_regions());
203202

@@ -223,7 +222,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
223222
let retptr = allocate_local(mir::RETURN_PLACE);
224223
iter::once(retptr)
225224
.chain(args.into_iter())
226-
.chain(mir_body.vars_and_temps_iter().map(allocate_local))
225+
.chain(mir.vars_and_temps_iter().map(allocate_local))
227226
.collect()
228227
};
229228

@@ -235,8 +234,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
235234
bx.br(fx.blocks[mir::START_BLOCK]);
236235
}
237236

238-
let rpo = traversal::reverse_postorder(&mir_body);
239-
let mut visited = BitSet::new_empty(mir_body.basic_blocks().len());
237+
let rpo = traversal::reverse_postorder(&mir);
238+
let mut visited = BitSet::new_empty(mir.basic_blocks().len());
240239

241240
// Codegen the body of each block using reverse postorder
242241
for (bb, _) in rpo {
@@ -246,7 +245,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
246245

247246
// Remove blocks that haven't been visited, or have no
248247
// predecessors.
249-
for bb in mir_body.basic_blocks().indices() {
248+
for bb in mir.basic_blocks().indices() {
250249
// Unreachable block
251250
if !visited.contains(bb.index()) {
252251
debug!("codegen_mir: block {:?} was not visited", bb);

src/librustc_codegen_ssa/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
497497

498498
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> {
499499
let tcx = self.cx.tcx();
500-
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx);
500+
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, self.mir, tcx);
501501
self.monomorphize(&place_ty.ty)
502502
}
503503
}

src/librustc_codegen_ssa/mir/rvalue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
473473
}
474474

475475
mir::Rvalue::Discriminant(ref place) => {
476-
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
476+
let discr_ty = rvalue.ty(self.mir, bx.tcx());
477477
let discr = self
478478
.codegen_place(&mut bx, place.as_ref())
479479
.codegen_get_discr(&mut bx, discr_ty);
@@ -529,7 +529,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
529529
mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => {
530530
// According to `rvalue_creates_operand`, only ZST
531531
// aggregate rvalues are allowed to be operands.
532-
let ty = rvalue.ty(*self.mir, self.cx.tcx());
532+
let ty = rvalue.ty(self.mir, self.cx.tcx());
533533
let operand =
534534
OperandRef::new_zst(&mut bx, self.cx.layout_of(self.monomorphize(&ty)));
535535
(bx, operand)
@@ -749,7 +749,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
749749
true,
750750
mir::Rvalue::Repeat(..) |
751751
mir::Rvalue::Aggregate(..) => {
752-
let ty = rvalue.ty(*self.mir, self.cx.tcx());
752+
let ty = rvalue.ty(self.mir, self.cx.tcx());
753753
let ty = self.monomorphize(&ty);
754754
self.cx.spanned_layout_of(ty, span).is_zst()
755755
}

src/librustc_data_structures/profiling.rs

+42-31
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

+3-1
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

+1-1
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

+1-1
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!
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

src/librustc_error_codes/error_codes/E0230.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0230
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error
10+
trait BadAnnotation<A> {}
1511
```
1612

1713
There will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0231.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0231
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error!
10+
trait BadAnnotation<A> {}
1511
```
1612

1713
there will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0232.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0232
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented(lorem="")] // error!
10+
trait BadAnnotation {}
1511
```
1612

1713
there will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0281.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You tried to supply a type which doesn't implement some trait in a location
44
which expected that trait. This error typically occurs when working with
55
`Fn`-based types. Erroneous code example:
66

7-
```compile-fail
7+
```compile_fail
88
fn foo<F: Fn(usize)>(x: F) { }
99
1010
fn main() {

0 commit comments

Comments
 (0)