Skip to content

Commit 22ee395

Browse files
committed
Auto merge of #97211 - GuillaumeGomez:rollup-jul7x7e, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #96565 (rustdoc: show implementations on `#[fundamental]` wrappers) - #97179 (Add new lint to enforce whitespace after keywords) - #97185 (interpret/validity: separately control checking numbers for being init and non-ptr) - #97188 (Remove unneeded null pointer asserts in ptr2int casts) - #97189 (Update .mailmap) - #97192 (Say "last" instead of "rightmost" in the documentation for `std::str:rfind`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 512a328 + 9b25cc0 commit 22ee395

27 files changed

+116
-70
lines changed

.mailmap

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ Chris Vittal <christopher.vittal@gmail.com> Christopher Vittal <christopher.vitt
105105
Christiaan Dirkx <christiaan@dirkx.email> <christiaan@dirkx.com>
106106
Christiaan Dirkx <christiaan@dirkx.email> CDirkx <christiaan@dirkx.com>
107107
Christiaan Dirkx <christiaan@dirkx.email> CDirkx <christiaan@dirkx.email>
108-
Christian Poveda <git@christianpoveda.xyz> <christianpoveda@protonmail.com>
109-
Christian Poveda <git@christianpoveda.xyz> <cn.poveda.ruiz@gmail.com>
110-
Christian Poveda <git@christianpoveda.xyz> <z1mvader@protonmail.com>
111-
Christian Poveda <git@christianpoveda.xyz> <cpovedar@fnal.gov>
108+
Christian Poveda <git@pvdrz.com> <christianpoveda@protonmail.com>
109+
Christian Poveda <git@pvdrz.com> <cn.poveda.ruiz@gmail.com>
110+
Christian Poveda <git@pvdrz.com> <z1mvader@protonmail.com>
111+
Christian Poveda <git@pvdrz.com> <cpovedar@fnal.gov>
112+
Christian Poveda <git@pvdrz.com> <git@christianpoveda.xyz>
113+
Christian Poveda <git@pvdrz.com> <31802960+christianpoveda@users.noreply.github.com>
114+
Christian Poveda <git@pvdrz.com> <christianpoveda@uhura.edef.eu>
112115
Christian Vallentin <vallentinsource@gmail.com>
113116
Christoffer Buchholz <chris@chrisbuchholz.me>
114117
Christopher Durham <cad97@cad97.com>

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
225225
let addr = u64::try_from(size.truncate(v)).unwrap();
226226

227227
let ptr = M::ptr_from_addr_cast(&self, addr);
228-
if addr == 0 {
229-
assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId");
230-
}
231228
Scalar::from_maybe_pointer(ptr, self)
232229
}
233230

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
133133
/// Whether to enforce the validity invariant
134134
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
135135

136-
/// Whether to enforce validity (e.g., initialization and not having ptr provenance)
137-
/// of integers and floats.
138-
fn enforce_number_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
136+
/// Whether to enforce integers and floats being initialized.
137+
fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
138+
139+
/// Whether to enforce integers and floats not having provenance.
140+
fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
139141

140142
/// Whether function calls should be [ABI](Abi)-checked.
141143
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
@@ -453,7 +455,12 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
453455
}
454456

455457
#[inline(always)]
456-
fn enforce_number_validity(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
458+
fn enforce_number_init(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
459+
true
460+
}
461+
462+
#[inline(always)]
463+
fn enforce_number_no_provenance(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
457464
true
458465
}
459466

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,15 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
924924
self.read_scalar(alloc_range(offset, self.tcx.data_layout().pointer_size))
925925
}
926926

927-
pub fn check_bytes(&self, range: AllocRange, allow_uninit_and_ptr: bool) -> InterpResult<'tcx> {
927+
pub fn check_bytes(
928+
&self,
929+
range: AllocRange,
930+
allow_uninit: bool,
931+
allow_ptr: bool,
932+
) -> InterpResult<'tcx> {
928933
Ok(self
929934
.alloc
930-
.check_bytes(&self.tcx, self.range.subrange(range), allow_uninit_and_ptr)
935+
.check_bytes(&self.tcx, self.range.subrange(range), allow_uninit, allow_ptr)
931936
.map_err(|e| e.to_interp_error(self.alloc_id))?)
932937
}
933938
}
@@ -1144,11 +1149,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11441149
Err(ptr) => ptr.into(),
11451150
Ok(bits) => {
11461151
let addr = u64::try_from(bits).unwrap();
1147-
let ptr = M::ptr_from_addr_transmute(&self, addr);
1148-
if addr == 0 {
1149-
assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId");
1150-
}
1151-
ptr
1152+
M::ptr_from_addr_transmute(&self, addr)
11521153
}
11531154
},
11541155
)

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,21 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
536536
let value = self.read_scalar(value)?;
537537
// NOTE: Keep this in sync with the array optimization for int/float
538538
// types below!
539-
if M::enforce_number_validity(self.ecx) {
540-
// Integers/floats with number validity: Must be scalar bits, pointers are dangerous.
539+
if M::enforce_number_init(self.ecx) {
540+
try_validation!(
541+
value.check_init(),
542+
self.path,
543+
err_ub!(InvalidUninitBytes(..)) =>
544+
{ "{:x}", value } expected { "initialized bytes" }
545+
);
546+
}
547+
if M::enforce_number_no_provenance(self.ecx) {
541548
// As a special exception we *do* match on a `Scalar` here, since we truly want
542549
// to know its underlying representation (and *not* cast it to an integer).
543-
let is_bits =
544-
value.check_init().map_or(false, |v| matches!(v, Scalar::Int(..)));
545-
if !is_bits {
550+
let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..)));
551+
if is_ptr {
546552
throw_validation_failure!(self.path,
547-
{ "{:x}", value } expected { "initialized plain (non-pointer) bytes" }
553+
{ "{:x}", value } expected { "plain (non-pointer) bytes" }
548554
)
549555
}
550556
}
@@ -651,7 +657,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
651657
let size = scalar_layout.size(self.ecx);
652658
let is_full_range = match scalar_layout {
653659
ScalarAbi::Initialized { .. } => {
654-
if M::enforce_number_validity(self.ecx) {
660+
if M::enforce_number_init(self.ecx) {
655661
false // not "full" since uninit is not accepted
656662
} else {
657663
scalar_layout.is_always_valid(self.ecx)
@@ -910,10 +916,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
910916
return Ok(());
911917
};
912918

913-
let allow_uninit_and_ptr = !M::enforce_number_validity(self.ecx);
914919
match alloc.check_bytes(
915920
alloc_range(Size::ZERO, size),
916-
allow_uninit_and_ptr,
921+
/*allow_uninit*/ !M::enforce_number_init(self.ecx),
922+
/*allow_ptr*/ !M::enforce_number_no_provenance(self.ecx),
917923
) {
918924
// In the happy case, we needn't check anything else.
919925
Ok(()) => {}

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,22 @@ impl<Tag: Provenance, Extra> Allocation<Tag, Extra> {
350350
/// Reading and writing.
351351
impl<Tag: Provenance, Extra> Allocation<Tag, Extra> {
352352
/// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
353-
/// relocation. If `allow_uninit_and_ptr` is `false`, also enforces that the memory in the
354-
/// given range contains neither relocations nor uninitialized bytes.
353+
/// relocation. If `allow_uninit`/`allow_ptr` is `false`, also enforces that the memory in the
354+
/// given range contains no uninitialized bytes/relocations.
355355
pub fn check_bytes(
356356
&self,
357357
cx: &impl HasDataLayout,
358358
range: AllocRange,
359-
allow_uninit_and_ptr: bool,
359+
allow_uninit: bool,
360+
allow_ptr: bool,
360361
) -> AllocResult {
361362
// Check bounds and relocations on the edges.
362363
self.get_bytes_with_uninit_and_ptr(cx, range)?;
363364
// Check uninit and ptr.
364-
if !allow_uninit_and_ptr {
365+
if !allow_uninit {
365366
self.check_init(range)?;
367+
}
368+
if !allow_ptr {
366369
self.check_relocations(cx, range)?;
367370
}
368371
Ok(())

library/core/src/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ impl str {
11581158
pat.into_searcher(self).next_match().map(|(i, _)| i)
11591159
}
11601160

1161-
/// Returns the byte index for the first character of the rightmost match of the pattern in
1161+
/// Returns the byte index for the first character of the last match of the pattern in
11621162
/// this string slice.
11631163
///
11641164
/// Returns [`None`] if the pattern doesn't match.

src/librustdoc/formats/cache.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::mem;
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_hir::def_id::{CrateNum, DefId};
55
use rustc_middle::middle::privacy::AccessLevels;
6-
use rustc_middle::ty::TyCtxt;
6+
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_span::{sym, Symbol};
88

99
use crate::clean::{self, types::ExternalLocation, ExternalCrate, ItemId, PrimitiveType};
@@ -452,6 +452,15 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
452452
clean::Type::Path { ref path }
453453
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
454454
dids.insert(path.def_id());
455+
if let Some(generics) = path.generics() &&
456+
let ty::Adt(adt, _) = self.tcx.type_of(path.def_id()).kind() &&
457+
adt.is_fundamental() {
458+
for ty in generics {
459+
if let Some(did) = ty.def_id(&self.cache) {
460+
dids.insert(did);
461+
}
462+
}
463+
}
455464
}
456465
clean::DynTrait(ref bounds, _)
457466
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {

src/librustdoc/html/static/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ module.exports = {
3434
"1tbs",
3535
{ "allowSingleLine": false }
3636
],
37+
"keyword-spacing": [
38+
"error",
39+
{ "before": true, "after": true }
40+
],
3741
}
3842
};

src/librustdoc/html/static/js/storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ function onEachLazy(lazyArray, func, reversed) {
103103
function updateLocalStorage(name, value) {
104104
try {
105105
window.localStorage.setItem("rustdoc-" + name, value);
106-
} catch(e) {
106+
} catch (e) {
107107
// localStorage is not accessible, do nothing
108108
}
109109
}
110110

111111
function getCurrentValue(name) {
112112
try {
113113
return window.localStorage.getItem("rustdoc-" + name);
114-
} catch(e) {
114+
} catch (e) {
115115
return null;
116116
}
117117
}

0 commit comments

Comments
 (0)