Skip to content

Commit e649e90

Browse files
committed
Auto merge of #62873 - Centril:rollup-ncnuelj, r=Centril
Rollup of 14 pull requests Successful merges: - #62709 (Test that maplike FromIter satisfies uniqueness) - #62713 (Stabilize <*mut _>::cast and <*const _>::cast) - #62746 ( do not use assume_init in std::io) - #62787 (Fix typo in src/libstd/net/udp.rs doc comment) - #62788 (normalize use of backticks in compiler messages for libcore/ptr) - #62799 (use const array repeat expressions for uninit_array) - #62810 (normalize use of backticks in compiler messages for librustc_lint) - #62812 (normalize use of backticks in compiler messages for librustc_metadata) - #62832 (normalize use of backticks in compiler messages for librustc_incremental) - #62845 (read: fix doc comment) - #62853 (normalize use of backticks in compiler messages for librustc/hir) - #62854 (Fix typo in Unicode character name) - #62858 (Change wrong variable name.) - #62870 (fix lexing of comments with many \r) Failed merges: r? @ghost
2 parents 4bc1ce7 + 376382a commit e649e90

Some content is hidden

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

62 files changed

+212
-154
lines changed

src/liballoc/collections/btree/map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ use Entry::*;
7575
///
7676
/// // look up the values associated with some keys.
7777
/// let to_find = ["Up!", "Office Space"];
78-
/// for book in &to_find {
79-
/// match movie_reviews.get(book) {
80-
/// Some(review) => println!("{}: {}", book, review),
81-
/// None => println!("{} is unreviewed.", book)
78+
/// for movie in &to_find {
79+
/// match movie_reviews.get(movie) {
80+
/// Some(review) => println!("{}: {}", movie, review),
81+
/// None => println!("{} is unreviewed.", movie)
8282
/// }
8383
/// }
8484
///

src/liballoc/collections/btree/node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ impl<K, V> LeafNode<K, V> {
106106
LeafNode {
107107
// As a general policy, we leave fields uninitialized if they can be, as this should
108108
// be both slightly faster and easier to track in Valgrind.
109-
keys: uninitialized_array![_; CAPACITY],
110-
vals: uninitialized_array![_; CAPACITY],
109+
keys: uninit_array![_; CAPACITY],
110+
vals: uninit_array![_; CAPACITY],
111111
parent: ptr::null(),
112112
parent_idx: MaybeUninit::uninit(),
113113
len: 0
@@ -159,7 +159,7 @@ impl<K, V> InternalNode<K, V> {
159159
unsafe fn new() -> Self {
160160
InternalNode {
161161
data: LeafNode::new(),
162-
edges: uninitialized_array![_; 2*B],
162+
edges: uninit_array![_; 2*B],
163163
}
164164
}
165165
}

src/liballoc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@
7777
#![feature(box_syntax)]
7878
#![feature(cfg_target_has_atomic)]
7979
#![feature(coerce_unsized)]
80+
#![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
8081
#![feature(dispatch_from_dyn)]
8182
#![feature(core_intrinsics)]
8283
#![feature(dropck_eyepatch)]
8384
#![feature(exact_size_is_empty)]
8485
#![feature(fmt_internals)]
8586
#![feature(fn_traits)]
8687
#![feature(fundamental)]
88+
#![feature(internal_uninit_const)]
8789
#![feature(lang_items)]
8890
#![feature(libc)]
8991
#![feature(nll)]

src/libcore/fmt/float.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
1212
unsafe {
1313
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
1414
let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit();
15-
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
16-
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
15+
// FIXME(#53491): This is calling `get_mut` on an uninitialized
16+
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
1717
// we decided whether that is valid or not.
18-
// Using `freeze` is *not enough*; `flt2dec::Part` is an enum!
18+
// We can do this only because we are libstd and coupled to the compiler.
19+
// (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
1920
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2021
*num, sign, precision,
2122
false, buf.get_mut(), parts.get_mut());

src/libcore/fmt/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait GenericRadix {
5151
// characters for a base 2 number.
5252
let zero = T::zero();
5353
let is_nonnegative = x >= zero;
54-
let mut buf = uninitialized_array![u8; 128];
54+
let mut buf = [MaybeUninit::<u8>::uninit(); 128];
5555
let mut curr = buf.len();
5656
let base = T::from_u8(Self::BASE);
5757
if is_nonnegative {
@@ -189,7 +189,7 @@ static DEC_DIGITS_LUT: &[u8; 200] =
189189
macro_rules! impl_Display {
190190
($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => {
191191
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192-
let mut buf = uninitialized_array![u8; 39];
192+
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
193193
let mut curr = buf.len() as isize;
194194
let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf);
195195
let lut_ptr = DEC_DIGITS_LUT.as_ptr();

src/libcore/macros.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -626,20 +626,37 @@ macro_rules! todo {
626626
/// Creates an array of [`MaybeUninit`].
627627
///
628628
/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`.
629+
/// It exists solely because bootstrap does not yet support const array-init expressions.
629630
///
630631
/// [`MaybeUninit`]: mem/union.MaybeUninit.html
632+
// FIXME: Remove both versions of this macro once bootstrap is 1.38.
631633
#[macro_export]
632634
#[unstable(feature = "maybe_uninit_array", issue = "53491")]
633-
macro_rules! uninitialized_array {
635+
#[cfg(bootstrap)]
636+
macro_rules! uninit_array {
634637
// This `assume_init` is safe because an array of `MaybeUninit` does not
635638
// require initialization.
636-
// FIXME(#49147): Could be replaced by an array initializer, once those can
637-
// be any const expression.
638639
($t:ty; $size:expr) => (unsafe {
639640
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninit().assume_init()
640641
});
641642
}
642643

644+
/// Creates an array of [`MaybeUninit`].
645+
///
646+
/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`.
647+
/// It exists solely because bootstrap does not yet support const array-init expressions.
648+
///
649+
/// [`MaybeUninit`]: mem/union.MaybeUninit.html
650+
// FIXME: Just inline this version of the macro once bootstrap is 1.38.
651+
#[macro_export]
652+
#[unstable(feature = "maybe_uninit_array", issue = "53491")]
653+
#[cfg(not(bootstrap))]
654+
macro_rules! uninit_array {
655+
($t:ty; $size:expr) => (
656+
[MaybeUninit::<$t>::UNINIT; $size]
657+
);
658+
}
659+
643660
/// Built-in macros to the compiler itself.
644661
///
645662
/// These macros do not have any corresponding definition with a `macro_rules!`

src/libcore/mem/maybe_uninit.rs

+5
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ impl<T> MaybeUninit<T> {
252252
MaybeUninit { uninit: () }
253253
}
254254

255+
/// A promotable constant, equivalent to `uninit()`.
256+
#[unstable(feature = "internal_uninit_const", issue = "0",
257+
reason = "hack to work around promotability")]
258+
pub const UNINIT: Self = Self::uninit();
259+
255260
/// Creates a new `MaybeUninit<T>` in an uninitialized state, with the memory being
256261
/// filled with `0` bytes. It depends on `T` whether that already makes for
257262
/// proper initialization. For example, `MaybeUninit<usize>::zeroed()` is initialized,

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ impl<T: ?Sized> *const T {
10431043
}
10441044

10451045
/// Cast to a pointer to a different type
1046-
#[unstable(feature = "ptr_cast", issue = "60602")]
1046+
#[stable(feature = "ptr_cast", since = "1.38.0")]
10471047
#[inline]
10481048
pub const fn cast<U>(self) -> *const U {
10491049
self as _
@@ -1678,7 +1678,7 @@ impl<T: ?Sized> *mut T {
16781678
}
16791679

16801680
/// Cast to a pointer to a different type
1681-
#[unstable(feature = "ptr_cast", issue = "60602")]
1681+
#[stable(feature = "ptr_cast", since = "1.38.0")]
16821682
#[inline]
16831683
pub const fn cast<U>(self) -> *mut U {
16841684
self as _

src/libcore/ptr/unique.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use crate::ptr::NonNull;
2626
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
2727
/// for any type which upholds Unique's aliasing requirements.
2828
#[unstable(feature = "ptr_internals", issue = "0",
29-
reason = "use NonNull instead and consider PhantomData<T> \
30-
(if you also use #[may_dangle]), Send, and/or Sync")]
29+
reason = "use `NonNull` instead and consider `PhantomData<T>` \
30+
(if you also use `#[may_dangle]`), `Send`, and/or `Sync`")]
3131
#[doc(hidden)]
3232
#[repr(transparent)]
3333
#[rustc_layout_scalar_valid_range_start(1)]

src/libcore/slice/sort.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
216216
let mut block_l = BLOCK;
217217
let mut start_l = ptr::null_mut();
218218
let mut end_l = ptr::null_mut();
219-
let mut offsets_l: [MaybeUninit<u8>; BLOCK] = uninitialized_array![u8; BLOCK];
219+
let mut offsets_l = [MaybeUninit::<u8>::uninit(); BLOCK];
220220

221221
// The current block on the right side (from `r.sub(block_r)` to `r`).
222222
let mut r = unsafe { l.add(v.len()) };
223223
let mut block_r = BLOCK;
224224
let mut start_r = ptr::null_mut();
225225
let mut end_r = ptr::null_mut();
226-
let mut offsets_r: [MaybeUninit<u8>; BLOCK] = uninitialized_array![u8; BLOCK];
226+
let mut offsets_r = [MaybeUninit::<u8>::uninit(); BLOCK];
227227

228228
// FIXME: When we get VLAs, try creating one array of length `min(v.len(), 2 * BLOCK)` rather
229229
// than two fixed-size arrays of length `BLOCK`. VLAs might be more cache-efficient.

src/librustc/hir/def_id.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ impl CrateNum {
6969
pub fn as_usize(self) -> usize {
7070
match self {
7171
CrateNum::Index(id) => id.as_usize(),
72-
_ => bug!("tried to get index of nonstandard crate {:?}", self),
72+
_ => bug!("tried to get index of non-standard crate {:?}", self),
7373
}
7474
}
7575

7676
pub fn as_u32(self) -> u32 {
7777
match self {
7878
CrateNum::Index(id) => id.as_u32(),
79-
_ => bug!("tried to get index of nonstandard crate {:?}", self),
79+
_ => bug!("tried to get index of non-standard crate {:?}", self),
8080
}
8181
}
8282

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,8 @@ impl<'a> LoweringContext<'a> {
16931693
if pos == ImplTraitPosition::Binding &&
16941694
nightly_options::is_nightly_build() {
16951695
help!(err,
1696-
"add #![feature(impl_trait_in_bindings)] to the crate attributes \
1697-
to enable");
1696+
"add `#![feature(impl_trait_in_bindings)]` to the crate \
1697+
attributes to enable");
16981698
}
16991699
err.emit();
17001700
hir::TyKind::Err

src/librustc_incremental/assert_dep_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
190190
for &(target_span, _, _, _) in then_this_would_need {
191191
tcx.sess.span_err(
192192
target_span,
193-
"no #[rustc_if_this_changed] annotation detected");
193+
"no `#[rustc_if_this_changed]` annotation detected");
194194

195195
}
196196
return;

src/librustc_incremental/persist/dirty_clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ impl FindAllAttrs<'tcx> {
610610
for attr in &self.found_attrs {
611611
if !checked_attrs.contains(&attr.id) {
612612
self.tcx.sess.span_err(attr.span, &format!("found unchecked \
613-
#[rustc_dirty]/#[rustc_clean] attribute"));
613+
`#[rustc_dirty]` / `#[rustc_clean]` attribute"));
614614
}
615615
}
616616
}

src/librustc_incremental/persist/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ fn find_source_directory_in_iter<I>(iter: I,
538538
if source_directories_already_tried.contains(&session_dir) ||
539539
!is_session_directory(&directory_name) ||
540540
!is_finalized(&directory_name) {
541-
debug!("find_source_directory_in_iter - ignoring.");
541+
debug!("find_source_directory_in_iter - ignoring");
542542
continue
543543
}
544544

@@ -693,7 +693,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
693693
let timestamp = match extract_timestamp_from_session_dir(lock_file_name) {
694694
Ok(timestamp) => timestamp,
695695
Err(()) => {
696-
debug!("Found lock-file with malformed timestamp: {}",
696+
debug!("found lock-file with malformed timestamp: {}",
697697
crate_directory.join(&lock_file_name).display());
698698
// Ignore it
699699
continue
@@ -746,7 +746,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
746746
let timestamp = match extract_timestamp_from_session_dir(directory_name) {
747747
Ok(timestamp) => timestamp,
748748
Err(()) => {
749-
debug!("Found session-dir with malformed timestamp: {}",
749+
debug!("found session-dir with malformed timestamp: {}",
750750
crate_directory.join(directory_name).display());
751751
// Ignore it
752752
continue

src/librustc_lint/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
591591
if !self.impling_types.as_ref().unwrap().contains(&item.hir_id) {
592592
cx.span_lint(MISSING_DEBUG_IMPLEMENTATIONS,
593593
item.span,
594-
"type does not implement `fmt::Debug`; consider adding #[derive(Debug)] \
594+
"type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` \
595595
or a manual implementation")
596596
}
597597
}
@@ -867,7 +867,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
867867
if attr::contains_name(&it.attrs, sym::no_mangle) {
868868
// Const items do not refer to a particular location in memory, and therefore
869869
// don't have anything to attach a symbol to
870-
let msg = "const items should never be #[no_mangle]";
870+
let msg = "const items should never be `#[no_mangle]`";
871871
let mut err = cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, msg);
872872

873873
// account for "pub const" (#45562)
@@ -1358,7 +1358,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
13581358
declare_lint! {
13591359
UNNAMEABLE_TEST_ITEMS,
13601360
Warn,
1361-
"detects an item that cannot be named being marked as #[test_case]",
1361+
"detects an item that cannot be named being marked as `#[test_case]`",
13621362
report_in_external_macro: true
13631363
}
13641364

src/librustc_lint/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
481481
store.register_removed("resolve_trait_on_defaulted_unit",
482482
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
483483
store.register_removed("private_no_mangle_fns",
484-
"no longer a warning, #[no_mangle] functions always exported");
484+
"no longer a warning, `#[no_mangle]` functions always exported");
485485
store.register_removed("private_no_mangle_statics",
486-
"no longer a warning, #[no_mangle] statics always exported");
486+
"no longer a warning, `#[no_mangle]` statics always exported");
487487
store.register_removed("bad_repr",
488488
"replaced with a generic attribute input check");
489489
store.register_removed("duplicate_matcher_binding_name",

src/librustc_lint/unused.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use log::debug;
2424
declare_lint! {
2525
pub UNUSED_MUST_USE,
2626
Warn,
27-
"unused result of a type flagged as #[must_use]",
27+
"unused result of a type flagged as `#[must_use]`",
2828
report_in_external_macro: true
2929
}
3030

@@ -316,7 +316,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
316316

317317
let name = attr.name_or_empty();
318318
if !attr::is_used(attr) {
319-
debug!("Emitting warning for: {:?}", attr);
319+
debug!("emitting warning for: {:?}", attr);
320320
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
321321
// Is it a builtin attribute that must be used at the crate level?
322322
let known_crate = attr_info.map(|&&(_, ty, ..)| {
@@ -332,7 +332,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
332332
let msg = match attr.style {
333333
ast::AttrStyle::Outer => {
334334
"crate-level attribute should be an inner attribute: add an exclamation \
335-
mark: #![foo]"
335+
mark: `#![foo]`"
336336
}
337337
ast::AttrStyle::Inner => "crate-level attribute should be in the root module",
338338
};
@@ -570,9 +570,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation {
570570
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
571571
let msg = match m {
572572
adjustment::AutoBorrowMutability::Immutable =>
573-
"unnecessary allocation, use & instead",
573+
"unnecessary allocation, use `&` instead",
574574
adjustment::AutoBorrowMutability::Mutable { .. }=>
575-
"unnecessary allocation, use &mut instead"
575+
"unnecessary allocation, use `&mut` instead"
576576
};
577577
cx.span_lint(UNUSED_ALLOCATION, e.span, msg);
578578
}

src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,14 @@ impl<'a> CrateLoader<'a> {
938938
}
939939
match global_allocator {
940940
Some(Some(other_crate)) => {
941-
self.sess.err(&format!("the #[global_allocator] in {} \
941+
self.sess.err(&format!("the `#[global_allocator]` in {} \
942942
conflicts with this global \
943943
allocator in: {}",
944944
other_crate,
945945
data.root.name));
946946
}
947947
Some(None) => {
948-
self.sess.err(&format!("the #[global_allocator] in this \
948+
self.sess.err(&format!("the `#[global_allocator]` in this \
949949
crate conflicts with global \
950950
allocator in: {}", data.root.name));
951951
}
@@ -971,7 +971,7 @@ impl<'a> CrateLoader<'a> {
971971
if !has_default {
972972
self.sess.err("no global memory allocator found but one is \
973973
required; link to std or \
974-
add #[global_allocator] to a static item \
974+
add `#[global_allocator]` to a static item \
975975
that implements the GlobalAlloc trait.");
976976
}
977977
self.sess.allocator_kind.set(Some(AllocatorKind::DefaultLib));

src/librustc_metadata/error_codes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ E0454: r##"
77
A link name was given with an empty name. Erroneous code example:
88
99
```ignore (cannot-test-this-because-rustdoc-stops-compile-fail-before-codegen)
10-
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
10+
#[link(name = "")] extern {}
11+
// error: `#[link(name = "")]` given with empty name
1112
```
1213
1314
The rust compiler cannot link to an external library if you don't give it its
@@ -61,7 +62,7 @@ A link was used without a name parameter. Erroneous code example:
6162
6263
```ignore (cannot-test-this-because-rustdoc-stops-compile-fail-before-codegen)
6364
#[link(kind = "dylib")] extern {}
64-
// error: #[link(...)] specified without `name = "foo"`
65+
// error: `#[link(...)]` specified without `name = "foo"`
6566
```
6667
6768
Please add the name parameter to allow the rust compiler to find the library

0 commit comments

Comments
 (0)