Skip to content

Commit 809e180

Browse files
committed
Auto merge of #66794 - tmandry:rollup-99qrpr0, r=tmandry
Rollup of 14 pull requests Successful merges: - #66128 (alloc: Add new_zeroed() versions like new_uninit().) - #66661 (Add riscv64gc-unknown-linux-gnu target) - #66663 (Miri: print leak report even without tracing) - #66711 (Add hardware floating point features to aarch64-pc-windows-msvc) - #66713 (introduce a target to build the kernel of the unikernel HermitCore) - #66717 (tidy: Accommodate rustfmt's preferred layout of stability attributes) - #66719 (Store pointer width as u32 on Config) - #66720 (Move ErrorReported to rustc_errors) - #66737 (Error codes cleanup) - #66754 (Various tweaks to diagnostic output) - #66763 (Minor edit for documentation-tests.md that increases clarity) - #66779 (follow the same function order in the trait) - #66786 (Add wildcard test for const_if_match) - #66788 (Allow `Unreachable` terminators through `min_const_fn` checks) Failed merges: r? @ghost
2 parents a7d791b + 8547ea3 commit 809e180

File tree

63 files changed

+441
-402
lines changed

Some content is hidden

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

63 files changed

+441
-402
lines changed

src/doc/rustdoc/src/documentation-tests.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Documentation tests
22

33
`rustdoc` supports executing your documentation examples as tests. This makes sure
4-
that your tests are up to date and working.
4+
that examples within your documentation are up to date and working.
55

66
The basic idea is this:
77

src/liballoc/boxed.rs

+27
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ impl<T> Box<T> {
152152
Box(ptr.cast().into())
153153
}
154154

155+
/// Constructs a new `Box` with uninitialized contents, with the memory
156+
/// being filled with `0` bytes.
157+
///
158+
/// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
159+
/// of this method.
160+
///
161+
/// # Examples
162+
///
163+
/// ```
164+
/// #![feature(new_uninit)]
165+
///
166+
/// let zero = Box::<u32>::new_zeroed();
167+
/// let zero = unsafe { zero.assume_init() };
168+
///
169+
/// assert_eq!(*zero, 0)
170+
/// ```
171+
///
172+
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
173+
#[unstable(feature = "new_uninit", issue = "63291")]
174+
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
175+
unsafe {
176+
let mut uninit = Self::new_uninit();
177+
ptr::write_bytes::<T>(uninit.as_mut_ptr(), 0, 1);
178+
uninit
179+
}
180+
}
181+
155182
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
156183
/// `x` will be pinned in memory and unable to be moved.
157184
#[stable(feature = "pin", since = "1.33.0")]

src/liballoc/rc.rs

+29
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,35 @@ impl<T> Rc<T> {
361361
}
362362
}
363363

364+
/// Constructs a new `Rc` with uninitialized contents, with the memory
365+
/// being filled with `0` bytes.
366+
///
367+
/// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and
368+
/// incorrect usage of this method.
369+
///
370+
/// # Examples
371+
///
372+
/// ```
373+
/// #![feature(new_uninit)]
374+
///
375+
/// use std::rc::Rc;
376+
///
377+
/// let zero = Rc::<u32>::new_zeroed();
378+
/// let zero = unsafe { zero.assume_init() };
379+
///
380+
/// assert_eq!(*zero, 0)
381+
/// ```
382+
///
383+
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
384+
#[unstable(feature = "new_uninit", issue = "63291")]
385+
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
386+
unsafe {
387+
let mut uninit = Self::new_uninit();
388+
ptr::write_bytes::<T>(Rc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1);
389+
uninit
390+
}
391+
}
392+
364393
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
365394
/// `value` will be pinned in memory and unable to be moved.
366395
#[stable(feature = "pin", since = "1.33.0")]

src/liballoc/sync.rs

+29
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,35 @@ impl<T> Arc<T> {
341341
}
342342
}
343343

344+
/// Constructs a new `Arc` with uninitialized contents, with the memory
345+
/// being filled with `0` bytes.
346+
///
347+
/// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
348+
/// of this method.
349+
///
350+
/// # Examples
351+
///
352+
/// ```
353+
/// #![feature(new_uninit)]
354+
///
355+
/// use std::sync::Arc;
356+
///
357+
/// let zero = Arc::<u32>::new_zeroed();
358+
/// let zero = unsafe { zero.assume_init() };
359+
///
360+
/// assert_eq!(*zero, 0)
361+
/// ```
362+
///
363+
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
364+
#[unstable(feature = "new_uninit", issue = "63291")]
365+
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
366+
unsafe {
367+
let mut uninit = Self::new_uninit();
368+
ptr::write_bytes::<T>(Arc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1);
369+
uninit
370+
}
371+
}
372+
344373
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
345374
/// `data` will be pinned in memory and unable to be moved.
346375
#[stable(feature = "pin", since = "1.33.0")]

src/libcore/cmp.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ impl<T: PartialOrd> PartialOrd for Reverse<T> {
464464
#[inline]
465465
fn le(&self, other: &Self) -> bool { other.0 <= self.0 }
466466
#[inline]
467-
fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
468-
#[inline]
469467
fn gt(&self, other: &Self) -> bool { other.0 > self.0 }
468+
#[inline]
469+
fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
470470
}
471471

472472
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
@@ -1176,9 +1176,9 @@ mod impls {
11761176
#[inline]
11771177
fn le(&self, other: & &B) -> bool { PartialOrd::le(*self, *other) }
11781178
#[inline]
1179-
fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) }
1180-
#[inline]
11811179
fn gt(&self, other: & &B) -> bool { PartialOrd::gt(*self, *other) }
1180+
#[inline]
1181+
fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) }
11821182
}
11831183
#[stable(feature = "rust1", since = "1.0.0")]
11841184
impl<A: ?Sized> Ord for &A where A: Ord {
@@ -1208,9 +1208,9 @@ mod impls {
12081208
#[inline]
12091209
fn le(&self, other: &&mut B) -> bool { PartialOrd::le(*self, *other) }
12101210
#[inline]
1211-
fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) }
1212-
#[inline]
12131211
fn gt(&self, other: &&mut B) -> bool { PartialOrd::gt(*self, *other) }
1212+
#[inline]
1213+
fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) }
12141214
}
12151215
#[stable(feature = "rust1", since = "1.0.0")]
12161216
impl<A: ?Sized> Ord for &mut A where A: Ord {

src/librustc/infer/error_reporting/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
463463
&self,
464464
err: &mut DiagnosticBuilder<'_>,
465465
terr: &TypeError<'tcx>,
466-
sp: Span,
467466
) {
468467
use hir::def_id::CrateNum;
469468
use hir::map::DisambiguatedDefPathData;
@@ -577,14 +576,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
577576
};
578577
if same_path().unwrap_or(false) {
579578
let crate_name = self.tcx.crate_name(did1.krate);
580-
err.span_note(
581-
sp,
582-
&format!(
583-
"Perhaps two different versions \
584-
of crate `{}` are being used?",
585-
crate_name
586-
),
587-
);
579+
err.note(&format!(
580+
"perhaps two different versions of crate `{}` are being used?",
581+
crate_name
582+
));
588583
}
589584
}
590585
};
@@ -1434,7 +1429,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14341429
.unwrap_or_else(|| {
14351430
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
14361431
});
1437-
self.check_and_note_conflicting_crates(diag, terr, span);
1432+
self.check_and_note_conflicting_crates(diag, terr);
14381433
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);
14391434

14401435
// It reads better to have the error origin as the final

src/librustc/session/config.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel
1212
use rustc_target::spec::{Target, TargetTriple};
1313

1414
use syntax;
15-
use syntax::ast::{self, IntTy, UintTy};
15+
use syntax::ast;
1616
use syntax::source_map::{FileName, FilePathMapping};
1717
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
1818
use syntax::symbol::{sym, Symbol};
@@ -36,8 +36,7 @@ use std::path::{Path, PathBuf};
3636

3737
pub struct Config {
3838
pub target: Target,
39-
pub isize_ty: IntTy,
40-
pub usize_ty: UintTy,
39+
pub ptr_width: u32,
4140
}
4241

4342
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
@@ -1621,10 +1620,10 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
16211620
FatalError.raise();
16221621
});
16231622

1624-
let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
1625-
"16" => (ast::IntTy::I16, ast::UintTy::U16),
1626-
"32" => (ast::IntTy::I32, ast::UintTy::U32),
1627-
"64" => (ast::IntTy::I64, ast::UintTy::U64),
1623+
let ptr_width = match &target.target_pointer_width[..] {
1624+
"16" => 16,
1625+
"32" => 32,
1626+
"64" => 64,
16281627
w => sp.fatal(&format!(
16291628
"target specification was invalid: \
16301629
unrecognized target-pointer-width {}",
@@ -1634,8 +1633,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
16341633

16351634
Config {
16361635
target,
1637-
isize_ty,
1638-
usize_ty,
1636+
ptr_width,
16391637
}
16401638
}
16411639

src/librustc/util/common.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::fmt::Debug;
77
use std::time::{Duration, Instant};
88

99
use syntax::symbol::{Symbol, sym};
10-
use rustc_macros::HashStable;
1110
use crate::session::Session;
1211

1312
#[cfg(test)]
@@ -16,10 +15,7 @@ mod tests;
1615
// The name of the associated type for `Fn` return types.
1716
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
1817

19-
// Useful type to use with `Result<>` indicate that an error has already
20-
// been reported to the user, so no need to continue checking.
21-
#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, HashStable)]
22-
pub struct ErrorReported;
18+
pub use errors::ErrorReported;
2319

2420
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
2521

src/librustc_codegen_llvm/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
325325
use rustc::ty::{Int, Uint};
326326

327327
let new_kind = match ty.kind {
328-
Int(Isize) => Int(self.tcx.sess.target.isize_ty),
329-
Uint(Usize) => Uint(self.tcx.sess.target.usize_ty),
328+
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
329+
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
330330
ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
331331
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
332332
};

src/librustc_codegen_llvm/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1926,15 +1926,15 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
19261926
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
19271927
match ty.kind {
19281928
ty::Int(t) => Some((match t {
1929-
ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64,
1929+
ast::IntTy::Isize => cx.tcx.sess.target.ptr_width as u64,
19301930
ast::IntTy::I8 => 8,
19311931
ast::IntTy::I16 => 16,
19321932
ast::IntTy::I32 => 32,
19331933
ast::IntTy::I64 => 64,
19341934
ast::IntTy::I128 => 128,
19351935
}, true)),
19361936
ty::Uint(t) => Some((match t {
1937-
ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64,
1937+
ast::UintTy::Usize => cx.tcx.sess.target.ptr_width as u64,
19381938
ast::UintTy::U8 => 8,
19391939
ast::UintTy::U16 => 16,
19401940
ast::UintTy::U32 => 32,

src/librustc_error_codes/error_codes/E0062.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
This error indicates that during an attempt to build a struct or struct-like
2-
enum variant, one of the fields was specified more than once. Erroneous code
3-
example:
1+
A struct's or struct-like enum variant's field was specified more than once.
2+
3+
Erroneous code example:
44

55
```compile_fail,E0062
66
struct Foo {
@@ -15,7 +15,9 @@ fn main() {
1515
}
1616
```
1717

18-
Each field should be specified exactly one time. Example:
18+
This error indicates that during an attempt to build a struct or struct-like
19+
enum variant, one of the fields was specified more than once. Each field should
20+
be specified exactly one time. Example:
1921

2022
```
2123
struct Foo {

src/librustc_error_codes/error_codes/E0063.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
This error indicates that during an attempt to build a struct or struct-like
2-
enum variant, one of the fields was not provided. Erroneous code example:
1+
A struct's or struct-like enum variant's field was not provided.
2+
3+
Erroneous code example:
34

45
```compile_fail,E0063
56
struct Foo {
+7-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1-
The left-hand side of a compound assignment expression must be a place
2-
expression. A place expression represents a memory location and includes
3-
item paths (ie, namespaced variables), dereferences, indexing expressions,
4-
and field references.
1+
An invalid left-hand side expression was used on an assignment operation.
52

6-
Let's start with some erroneous code examples:
3+
Erroneous code example:
74

85
```compile_fail,E0067
9-
use std::collections::LinkedList;
10-
11-
// Bad: assignment to non-place expression
12-
LinkedList::new() += 1;
13-
14-
// ...
15-
16-
fn some_func(i: &mut i32) {
17-
i += 12; // Error : '+=' operation cannot be applied on a reference !
18-
}
6+
12 += 1; // error!
197
```
208

21-
And now some working examples:
9+
You need to have a place expression to be able to assign it something. For
10+
example:
2211

2312
```
24-
let mut i : i32 = 0;
25-
26-
i += 12; // Good !
27-
28-
// ...
29-
30-
fn some_func(i: &mut i32) {
31-
*i += 12; // Good !
32-
}
13+
let mut x: i8 = 12;
14+
x += 1; // ok!
3315
```

src/librustc_error_codes/error_codes/E0069.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
The compiler found a function whose body contains a `return;` statement but
2-
whose return type is not `()`. An example of this is:
2+
whose return type is not `()`.
3+
4+
Erroneous code example:
35

46
```compile_fail,E0069
57
// error

0 commit comments

Comments
 (0)