Skip to content

Commit 13fc33e

Browse files
committed
Auto merge of rust-lang#110585 - JohnTitor:rollup-gfffoiv, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#102341 (Implement `Neg` for signed non-zero integers.) - rust-lang#110424 (Spelling misc) - rust-lang#110448 (cmp doc examples improvements) - rust-lang#110516 (bootstrap: Update linux-raw-sys to 0.3.2) - rust-lang#110548 (Make `impl Debug for Span` not panic on not having session globals.) - rust-lang#110554 (`deny(unsafe_op_in_unsafe_fn)` in `rustc_data_structures`) - rust-lang#110575 (fix lint regression in `non_upper_case_globals`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 23a76a8 + a2826dc commit 13fc33e

File tree

14 files changed

+254
-178
lines changed

14 files changed

+254
-178
lines changed

.github/ISSUE_TEMPLATE/library_tracking_issue.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Tracking issues are for tracking a feature from implementation to stabilization.
1212
Make sure to include the relevant RFC for the feature if it has one.
1313
1414
If the new feature is small, it may be fine to skip the RFC process. In that
15-
case, you can use use `issue = "none"` in your initial implementation PR. The
15+
case, you can use `issue = "none"` in your initial implementation PR. The
1616
reviewer will ask you to open a tracking issue if they agree your feature can be
1717
added without an RFC.
1818
-->
@@ -65,7 +65,7 @@ the rfcbot will ask all the team members to verify they agree with
6565
stabilization. Once enough members agree and there are no concerns, the final
6666
comment period begins: this issue will be marked as such and will be listed
6767
in the next This Week in Rust newsletter. If no blocking concerns are raised in
68-
that period of 10 days, a stabilzation PR can be opened by anyone.
68+
that period of 10 days, a stabilization PR can be opened by anyone.
6969
-->
7070

7171
### Unresolved Questions

RELEASES.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ Compatibility Notes
963963
- [rustdoc: doctests are now run on unexported `macro_rules!` macros, matching other private items][96630]
964964
- [rustdoc: Remove .woff font files][96279]
965965
- [Enforce Copy bounds for repeat elements while considering lifetimes][95819]
966-
- [Windows: Fix potentinal unsoundness by aborting if `File` reads or writes cannot
966+
- [Windows: Fix potential unsoundness by aborting if `File` reads or writes cannot
967967
complete synchronously][95469].
968968

969969
Internal Changes
@@ -1794,10 +1794,10 @@ Libraries
17941794
- [impl Default, Copy, Clone for std::io::Sink and std::io::Empty][rust#86744]
17951795
- [`impl From<[(K, V); N]>` for all collections.][rust#84111]
17961796
- [Remove `P: Unpin` bound on impl Future for Pin.][rust#81363]
1797-
- [Treat invalid environment variable names as non-existent.][rust#86183]
1797+
- [Treat invalid environment variable names as nonexistent.][rust#86183]
17981798
Previously, the environment functions would panic if given a variable name
17991799
with an internal null character or equal sign (`=`). Now, these functions will
1800-
just treat such names as non-existent variables, since the OS cannot represent
1800+
just treat such names as nonexistent variables, since the OS cannot represent
18011801
the existence of a variable with such a name.
18021802

18031803
Stabilised APIs
@@ -1990,7 +1990,7 @@ Compatibility Notes
19901990
kinds of errors could be categorised [into newer more specific `ErrorKind`
19911991
variants][79965], and that they do not represent a user error.
19921992
- [Using environment variable names with `process::Command` on Windows now
1993-
behaves as expected.][85270] Previously using envionment variables with
1993+
behaves as expected.][85270] Previously using environment variables with
19941994
`Command` would cause them to be ASCII-uppercased.
19951995
- [Rustdoc will now warn on using rustdoc lints that aren't prefixed
19961996
with `rustdoc::`][86849]
@@ -6367,7 +6367,7 @@ eg. `static MINUTE: Duration = Duration::from_secs(60);`
63676367

63686368
Cargo
63696369
-----
6370-
- [`cargo new` no longer removes `rust` or `rs` prefixs/suffixs.][cargo/5013]
6370+
- [`cargo new` no longer removes `rust` or `rs` prefixes/suffixes.][cargo/5013]
63716371
- [`cargo new` now defaults to creating a binary crate, instead of a
63726372
library crate.][cargo/5029]
63736373

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#![allow(rustc::potential_query_instability)]
3636
#![deny(rustc::untranslatable_diagnostic)]
3737
#![deny(rustc::diagnostic_outside_of_impl)]
38+
#![deny(unsafe_op_in_unsafe_fn)]
3839

3940
#[macro_use]
4041
extern crate tracing;

compiler/rustc_data_structures/src/memmap.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub struct Mmap(Vec<u8>);
1313
impl Mmap {
1414
#[inline]
1515
pub unsafe fn map(file: File) -> io::Result<Self> {
16-
memmap2::Mmap::map(&file).map(Mmap)
16+
// Safety: this is in fact not safe.
17+
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
1718
}
1819
}
1920

compiler/rustc_data_structures/src/sip128.rs

+101-95
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,30 @@ macro_rules! compress {
9696
unsafe fn copy_nonoverlapping_small(src: *const u8, dst: *mut u8, count: usize) {
9797
debug_assert!(count <= 8);
9898

99-
if count == 8 {
100-
ptr::copy_nonoverlapping(src, dst, 8);
101-
return;
102-
}
99+
unsafe {
100+
if count == 8 {
101+
ptr::copy_nonoverlapping(src, dst, 8);
102+
return;
103+
}
103104

104-
let mut i = 0;
105-
if i + 3 < count {
106-
ptr::copy_nonoverlapping(src.add(i), dst.add(i), 4);
107-
i += 4;
108-
}
105+
let mut i = 0;
106+
if i + 3 < count {
107+
ptr::copy_nonoverlapping(src.add(i), dst.add(i), 4);
108+
i += 4;
109+
}
109110

110-
if i + 1 < count {
111-
ptr::copy_nonoverlapping(src.add(i), dst.add(i), 2);
112-
i += 2
113-
}
111+
if i + 1 < count {
112+
ptr::copy_nonoverlapping(src.add(i), dst.add(i), 2);
113+
i += 2
114+
}
114115

115-
if i < count {
116-
*dst.add(i) = *src.add(i);
117-
i += 1;
118-
}
116+
if i < count {
117+
*dst.add(i) = *src.add(i);
118+
i += 1;
119+
}
119120

120-
debug_assert_eq!(i, count);
121+
debug_assert_eq!(i, count);
122+
}
121123
}
122124

123125
// # Implementation
@@ -232,38 +234,40 @@ impl SipHasher128 {
232234
// overflow) if it wasn't already.
233235
#[inline(never)]
234236
unsafe fn short_write_process_buffer<const LEN: usize>(&mut self, bytes: [u8; LEN]) {
235-
let nbuf = self.nbuf;
236-
debug_assert!(LEN <= 8);
237-
debug_assert!(nbuf < BUFFER_SIZE);
238-
debug_assert!(nbuf + LEN >= BUFFER_SIZE);
239-
debug_assert!(nbuf + LEN < BUFFER_WITH_SPILL_SIZE);
237+
unsafe {
238+
let nbuf = self.nbuf;
239+
debug_assert!(LEN <= 8);
240+
debug_assert!(nbuf < BUFFER_SIZE);
241+
debug_assert!(nbuf + LEN >= BUFFER_SIZE);
242+
debug_assert!(nbuf + LEN < BUFFER_WITH_SPILL_SIZE);
243+
244+
// Copy first part of input into end of buffer, possibly into spill
245+
// element. The memcpy call is optimized away because the size is known.
246+
let dst = (self.buf.as_mut_ptr() as *mut u8).add(nbuf);
247+
ptr::copy_nonoverlapping(bytes.as_ptr(), dst, LEN);
248+
249+
// Process buffer.
250+
for i in 0..BUFFER_CAPACITY {
251+
let elem = self.buf.get_unchecked(i).assume_init().to_le();
252+
self.state.v3 ^= elem;
253+
Sip13Rounds::c_rounds(&mut self.state);
254+
self.state.v0 ^= elem;
255+
}
240256

241-
// Copy first part of input into end of buffer, possibly into spill
242-
// element. The memcpy call is optimized away because the size is known.
243-
let dst = (self.buf.as_mut_ptr() as *mut u8).add(nbuf);
244-
ptr::copy_nonoverlapping(bytes.as_ptr(), dst, LEN);
245-
246-
// Process buffer.
247-
for i in 0..BUFFER_CAPACITY {
248-
let elem = self.buf.get_unchecked(i).assume_init().to_le();
249-
self.state.v3 ^= elem;
250-
Sip13Rounds::c_rounds(&mut self.state);
251-
self.state.v0 ^= elem;
257+
// Copy remaining input into start of buffer by copying LEN - 1
258+
// elements from spill (at most LEN - 1 bytes could have overflowed
259+
// into the spill). The memcpy call is optimized away because the size
260+
// is known. And the whole copy is optimized away for LEN == 1.
261+
let dst = self.buf.as_mut_ptr() as *mut u8;
262+
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
263+
ptr::copy_nonoverlapping(src, dst, LEN - 1);
264+
265+
// This function should only be called when the write fills the buffer.
266+
// Therefore, when LEN == 1, the new `self.nbuf` must be zero.
267+
// LEN is statically known, so the branch is optimized away.
268+
self.nbuf = if LEN == 1 { 0 } else { nbuf + LEN - BUFFER_SIZE };
269+
self.processed += BUFFER_SIZE;
252270
}
253-
254-
// Copy remaining input into start of buffer by copying LEN - 1
255-
// elements from spill (at most LEN - 1 bytes could have overflowed
256-
// into the spill). The memcpy call is optimized away because the size
257-
// is known. And the whole copy is optimized away for LEN == 1.
258-
let dst = self.buf.as_mut_ptr() as *mut u8;
259-
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
260-
ptr::copy_nonoverlapping(src, dst, LEN - 1);
261-
262-
// This function should only be called when the write fills the buffer.
263-
// Therefore, when LEN == 1, the new `self.nbuf` must be zero.
264-
// LEN is statically known, so the branch is optimized away.
265-
self.nbuf = if LEN == 1 { 0 } else { nbuf + LEN - BUFFER_SIZE };
266-
self.processed += BUFFER_SIZE;
267271
}
268272

269273
// A write function for byte slices.
@@ -301,57 +305,59 @@ impl SipHasher128 {
301305
// containing the byte offset `self.nbuf`.
302306
#[inline(never)]
303307
unsafe fn slice_write_process_buffer(&mut self, msg: &[u8]) {
304-
let length = msg.len();
305-
let nbuf = self.nbuf;
306-
debug_assert!(nbuf < BUFFER_SIZE);
307-
debug_assert!(nbuf + length >= BUFFER_SIZE);
308-
309-
// Always copy first part of input into current element of buffer.
310-
// This function should only be called when the write fills the buffer,
311-
// so we know that there is enough input to fill the current element.
312-
let valid_in_elem = nbuf % ELEM_SIZE;
313-
let needed_in_elem = ELEM_SIZE - valid_in_elem;
314-
315-
let src = msg.as_ptr();
316-
let dst = (self.buf.as_mut_ptr() as *mut u8).add(nbuf);
317-
copy_nonoverlapping_small(src, dst, needed_in_elem);
318-
319-
// Process buffer.
308+
unsafe {
309+
let length = msg.len();
310+
let nbuf = self.nbuf;
311+
debug_assert!(nbuf < BUFFER_SIZE);
312+
debug_assert!(nbuf + length >= BUFFER_SIZE);
313+
314+
// Always copy first part of input into current element of buffer.
315+
// This function should only be called when the write fills the buffer,
316+
// so we know that there is enough input to fill the current element.
317+
let valid_in_elem = nbuf % ELEM_SIZE;
318+
let needed_in_elem = ELEM_SIZE - valid_in_elem;
319+
320+
let src = msg.as_ptr();
321+
let dst = (self.buf.as_mut_ptr() as *mut u8).add(nbuf);
322+
copy_nonoverlapping_small(src, dst, needed_in_elem);
323+
324+
// Process buffer.
325+
326+
// Using `nbuf / ELEM_SIZE + 1` rather than `(nbuf + needed_in_elem) /
327+
// ELEM_SIZE` to show the compiler that this loop's upper bound is > 0.
328+
// We know that is true, because last step ensured we have a full
329+
// element in the buffer.
330+
let last = nbuf / ELEM_SIZE + 1;
331+
332+
for i in 0..last {
333+
let elem = self.buf.get_unchecked(i).assume_init().to_le();
334+
self.state.v3 ^= elem;
335+
Sip13Rounds::c_rounds(&mut self.state);
336+
self.state.v0 ^= elem;
337+
}
320338

321-
// Using `nbuf / ELEM_SIZE + 1` rather than `(nbuf + needed_in_elem) /
322-
// ELEM_SIZE` to show the compiler that this loop's upper bound is > 0.
323-
// We know that is true, because last step ensured we have a full
324-
// element in the buffer.
325-
let last = nbuf / ELEM_SIZE + 1;
339+
// Process the remaining element-sized chunks of input.
340+
let mut processed = needed_in_elem;
341+
let input_left = length - processed;
342+
let elems_left = input_left / ELEM_SIZE;
343+
let extra_bytes_left = input_left % ELEM_SIZE;
344+
345+
for _ in 0..elems_left {
346+
let elem = (msg.as_ptr().add(processed) as *const u64).read_unaligned().to_le();
347+
self.state.v3 ^= elem;
348+
Sip13Rounds::c_rounds(&mut self.state);
349+
self.state.v0 ^= elem;
350+
processed += ELEM_SIZE;
351+
}
326352

327-
for i in 0..last {
328-
let elem = self.buf.get_unchecked(i).assume_init().to_le();
329-
self.state.v3 ^= elem;
330-
Sip13Rounds::c_rounds(&mut self.state);
331-
self.state.v0 ^= elem;
332-
}
353+
// Copy remaining input into start of buffer.
354+
let src = msg.as_ptr().add(processed);
355+
let dst = self.buf.as_mut_ptr() as *mut u8;
356+
copy_nonoverlapping_small(src, dst, extra_bytes_left);
333357

334-
// Process the remaining element-sized chunks of input.
335-
let mut processed = needed_in_elem;
336-
let input_left = length - processed;
337-
let elems_left = input_left / ELEM_SIZE;
338-
let extra_bytes_left = input_left % ELEM_SIZE;
339-
340-
for _ in 0..elems_left {
341-
let elem = (msg.as_ptr().add(processed) as *const u64).read_unaligned().to_le();
342-
self.state.v3 ^= elem;
343-
Sip13Rounds::c_rounds(&mut self.state);
344-
self.state.v0 ^= elem;
345-
processed += ELEM_SIZE;
358+
self.nbuf = extra_bytes_left;
359+
self.processed += nbuf + processed;
346360
}
347-
348-
// Copy remaining input into start of buffer.
349-
let src = msg.as_ptr().add(processed);
350-
let dst = self.buf.as_mut_ptr() as *mut u8;
351-
copy_nonoverlapping_small(src, dst, extra_bytes_left);
352-
353-
self.nbuf = extra_bytes_left;
354-
self.processed += nbuf + processed;
355361
}
356362

357363
#[inline]

compiler/rustc_data_structures/src/tagged_ptr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
153153
#[inline]
154154
unsafe fn from_ptr(ptr: NonNull<T>) -> Self {
155155
// Safety: `ptr` comes from `into_ptr` which calls `Box::into_raw`
156-
Box::from_raw(ptr.as_ptr())
156+
unsafe { Box::from_raw(ptr.as_ptr()) }
157157
}
158158
}
159159

@@ -169,7 +169,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Rc<T> {
169169
#[inline]
170170
unsafe fn from_ptr(ptr: NonNull<T>) -> Self {
171171
// Safety: `ptr` comes from `into_ptr` which calls `Rc::into_raw`
172-
Rc::from_raw(ptr.as_ptr())
172+
unsafe { Rc::from_raw(ptr.as_ptr()) }
173173
}
174174
}
175175

@@ -185,7 +185,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Arc<T> {
185185
#[inline]
186186
unsafe fn from_ptr(ptr: NonNull<T>) -> Self {
187187
// Safety: `ptr` comes from `into_ptr` which calls `Arc::into_raw`
188-
Arc::from_raw(ptr.as_ptr())
188+
unsafe { Arc::from_raw(ptr.as_ptr()) }
189189
}
190190
}
191191

@@ -201,7 +201,7 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a T {
201201
unsafe fn from_ptr(ptr: NonNull<T>) -> Self {
202202
// Safety:
203203
// `ptr` comes from `into_ptr` which gets the pointer from a reference
204-
ptr.as_ref()
204+
unsafe { ptr.as_ref() }
205205
}
206206
}
207207

@@ -217,7 +217,7 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a mut T {
217217
unsafe fn from_ptr(mut ptr: NonNull<T>) -> Self {
218218
// Safety:
219219
// `ptr` comes from `into_ptr` which gets the pointer from a reference
220-
ptr.as_mut()
220+
unsafe { ptr.as_mut() }
221221
}
222222
}
223223

compiler/rustc_lint/src/nonstandard_style.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext
3333
}
3434
}
3535

36+
fn assoc_item_in_trait_impl(cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) -> bool {
37+
let item = cx.tcx.associated_item(ii.owner_id);
38+
item.trait_item_def_id.is_some()
39+
}
40+
3641
declare_lint! {
3742
/// The `non_camel_case_types` lint detects types, variants, traits and
3843
/// type parameters that don't have camel case names.
@@ -177,6 +182,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
177182
// trait impls where we should have warned for the trait definition already.
178183
ast::ItemKind::Impl(box ast::Impl { of_trait: None, items, .. }) => {
179184
for it in items {
185+
// FIXME: this doesn't respect `#[allow(..)]` on the item itself.
180186
if let ast::AssocItemKind::Type(..) = it.kind {
181187
self.check_case(cx, "associated type", &it.ident);
182188
}
@@ -494,15 +500,6 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
494500
hir::ItemKind::Const(..) => {
495501
NonUpperCaseGlobals::check_upper_case(cx, "constant", &it.ident);
496502
}
497-
// we only want to check inherent associated consts, trait consts
498-
// are linted at def-site.
499-
hir::ItemKind::Impl(hir::Impl { of_trait: None, items, .. }) => {
500-
for it in *items {
501-
if let hir::AssocItemKind::Const = it.kind {
502-
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &it.ident);
503-
}
504-
}
505-
}
506503
_ => {}
507504
}
508505
}
@@ -513,6 +510,12 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
513510
}
514511
}
515512

513+
fn check_impl_item(&mut self, cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) {
514+
if let hir::ImplItemKind::Const(..) = ii.kind && !assoc_item_in_trait_impl(cx, ii) {
515+
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
516+
}
517+
}
518+
516519
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
517520
// Lint for constants that look like binding identifiers (#7526)
518521
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {

0 commit comments

Comments
 (0)