mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Auto merge of #80449 - m-ou-se:rollup-kp2e5n8, r=m-ou-se
Rollup of 11 pull requests Successful merges: - #80383 (clarify wrapping ptr arithmetic docs) - #80390 (BTreeMap: rename the area access methods) - #80393 (Add links to the source for the rustc and rustdoc books.) - #80398 (Use raw version of align_of in rc data_offset) - #80402 (Document `InferTy` & co.) - #80403 (fix: small typo error in chalk/mod.rs) - #80410 (rustdoc book: fix example) - #80419 (Add regression test for #80375) - #80430 (Add "length" as doc alias to len methods) - #80431 (Add "chr" as doc alias to char::from_u32) - #80448 (Fix stabilization version of deque_range feature.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
d75f48e04d
@ -1424,28 +1424,33 @@ pub struct EarlyBoundRegion {
|
||||
pub name: Symbol,
|
||||
}
|
||||
|
||||
/// A **ty**pe **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct TyVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// A **`const`** **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct ConstVid<'tcx> {
|
||||
pub index: u32,
|
||||
pub phantom: PhantomData<&'tcx ()>,
|
||||
}
|
||||
|
||||
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct IntVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct FloatVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// A **region** (lifetime) **v**ariable **ID**.
|
||||
pub struct RegionVid {
|
||||
DEBUG_FORMAT = custom,
|
||||
}
|
||||
@ -1457,18 +1462,40 @@ impl Atom for RegionVid {
|
||||
}
|
||||
}
|
||||
|
||||
/// A placeholder for a type that hasn't been inferred yet.
|
||||
///
|
||||
/// E.g., if we have an empty array (`[]`), then we create a fresh
|
||||
/// type variable for the element type since we won't know until it's
|
||||
/// used what the element type is supposed to be.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable)]
|
||||
pub enum InferTy {
|
||||
/// A type variable.
|
||||
TyVar(TyVid),
|
||||
/// An integral type variable (`{integer}`).
|
||||
///
|
||||
/// These are created when the compiler sees an integer literal like
|
||||
/// `1` that could be several different types (`u8`, `i32`, `u32`, etc.).
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
IntVar(IntVid),
|
||||
/// A floating-point type variable (`{float}`).
|
||||
///
|
||||
/// These are created when the compiler sees an float literal like
|
||||
/// `1.0` that could be either an `f32` or an `f64`.
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
FloatVar(FloatVid),
|
||||
|
||||
/// A `FreshTy` is one that is generated as a replacement for an
|
||||
/// unbound type variable. This is convenient for caching etc. See
|
||||
/// `infer::freshen` for more details.
|
||||
/// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement
|
||||
/// for an unbound type variable. This is convenient for caching etc. See
|
||||
/// `rustc_infer::infer::freshen` for more details.
|
||||
///
|
||||
/// Compare with [`TyVar`][Self::TyVar].
|
||||
FreshTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar].
|
||||
FreshIntTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar].
|
||||
FreshFloatTy(u32),
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ crate fn evaluate_goal<'tcx>(
|
||||
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
|
||||
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
|
||||
let solution = solver.solve(&db, &lowered_goal);
|
||||
debug!(?obligation, ?solution, "evaluatate goal");
|
||||
debug!(?obligation, ?solution, "evaluate goal");
|
||||
|
||||
// Ideally, the code to convert *back* to rustc types would live close to
|
||||
// the code to convert *from* rustc types. Right now though, we don't
|
||||
|
@ -915,6 +915,7 @@ impl<T> BinaryHeap<T> {
|
||||
///
|
||||
/// assert_eq!(heap.len(), 2);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
|
@ -2132,6 +2132,7 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// a.insert(1, "a");
|
||||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
|
||||
pub const fn len(&self) -> usize {
|
||||
|
@ -489,7 +489,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
|
||||
///
|
||||
/// # Safety
|
||||
/// `index` is in bounds of 0..CAPACITY
|
||||
unsafe fn key_area_mut_at<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
unsafe fn key_area_mut<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
where
|
||||
I: SliceIndex<[MaybeUninit<K>], Output = Output>,
|
||||
{
|
||||
@ -503,7 +503,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
|
||||
///
|
||||
/// # Safety
|
||||
/// `index` is in bounds of 0..CAPACITY
|
||||
unsafe fn val_area_mut_at<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
unsafe fn val_area_mut<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
where
|
||||
I: SliceIndex<[MaybeUninit<V>], Output = Output>,
|
||||
{
|
||||
@ -519,7 +519,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||
///
|
||||
/// # Safety
|
||||
/// `index` is in bounds of 0..CAPACITY + 1
|
||||
unsafe fn edge_area_mut_at<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
unsafe fn edge_area_mut<I, Output: ?Sized>(&mut self, index: I) -> &mut Output
|
||||
where
|
||||
I: SliceIndex<[MaybeUninit<BoxedNode<K, V>>], Output = Output>,
|
||||
{
|
||||
@ -583,8 +583,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
|
||||
assert!(idx < CAPACITY);
|
||||
*len += 1;
|
||||
unsafe {
|
||||
self.key_area_mut_at(idx).write(key);
|
||||
self.val_area_mut_at(idx).write(val);
|
||||
self.key_area_mut(idx).write(key);
|
||||
self.val_area_mut(idx).write(val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,8 +593,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
|
||||
let new_len = self.len() + 1;
|
||||
assert!(new_len <= CAPACITY);
|
||||
unsafe {
|
||||
slice_insert(self.key_area_mut_at(..new_len), 0, key);
|
||||
slice_insert(self.val_area_mut_at(..new_len), 0, val);
|
||||
slice_insert(self.key_area_mut(..new_len), 0, key);
|
||||
slice_insert(self.val_area_mut(..new_len), 0, val);
|
||||
*self.len_mut() = new_len as u16;
|
||||
}
|
||||
}
|
||||
@ -627,9 +627,9 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||
assert!(idx < CAPACITY);
|
||||
*len += 1;
|
||||
unsafe {
|
||||
self.key_area_mut_at(idx).write(key);
|
||||
self.val_area_mut_at(idx).write(val);
|
||||
self.edge_area_mut_at(idx + 1).write(edge.node);
|
||||
self.key_area_mut(idx).write(key);
|
||||
self.val_area_mut(idx).write(val);
|
||||
self.edge_area_mut(idx + 1).write(edge.node);
|
||||
Handle::new_edge(self.reborrow_mut(), idx + 1).correct_parent_link();
|
||||
}
|
||||
}
|
||||
@ -642,9 +642,9 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||
assert!(new_len <= CAPACITY);
|
||||
|
||||
unsafe {
|
||||
slice_insert(self.key_area_mut_at(..new_len), 0, key);
|
||||
slice_insert(self.val_area_mut_at(..new_len), 0, val);
|
||||
slice_insert(self.edge_area_mut_at(..new_len + 1), 0, edge.node);
|
||||
slice_insert(self.key_area_mut(..new_len), 0, key);
|
||||
slice_insert(self.val_area_mut(..new_len), 0, val);
|
||||
slice_insert(self.edge_area_mut(..new_len + 1), 0, edge.node);
|
||||
*self.len_mut() = new_len as u16;
|
||||
}
|
||||
|
||||
@ -662,12 +662,12 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
|
||||
let idx = self.len() - 1;
|
||||
|
||||
unsafe {
|
||||
let key = self.key_area_mut_at(idx).assume_init_read();
|
||||
let val = self.val_area_mut_at(idx).assume_init_read();
|
||||
let key = self.key_area_mut(idx).assume_init_read();
|
||||
let val = self.val_area_mut(idx).assume_init_read();
|
||||
let edge = match self.reborrow_mut().force() {
|
||||
ForceResult::Leaf(_) => None,
|
||||
ForceResult::Internal(mut internal) => {
|
||||
let node = internal.edge_area_mut_at(idx + 1).assume_init_read();
|
||||
let node = internal.edge_area_mut(idx + 1).assume_init_read();
|
||||
let mut edge = Root { node, height: internal.height - 1, _marker: PhantomData };
|
||||
// Currently, clearing the parent link is superfluous, because we will
|
||||
// insert the node elsewhere and set its parent link again.
|
||||
@ -690,12 +690,12 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
|
||||
let old_len = self.len();
|
||||
|
||||
unsafe {
|
||||
let key = slice_remove(self.key_area_mut_at(..old_len), 0);
|
||||
let val = slice_remove(self.val_area_mut_at(..old_len), 0);
|
||||
let key = slice_remove(self.key_area_mut(..old_len), 0);
|
||||
let val = slice_remove(self.val_area_mut(..old_len), 0);
|
||||
let edge = match self.reborrow_mut().force() {
|
||||
ForceResult::Leaf(_) => None,
|
||||
ForceResult::Internal(mut internal) => {
|
||||
let node = slice_remove(internal.edge_area_mut_at(..old_len + 1), 0);
|
||||
let node = slice_remove(internal.edge_area_mut(..old_len + 1), 0);
|
||||
let mut edge = Root { node, height: internal.height - 1, _marker: PhantomData };
|
||||
// Currently, clearing the parent link is superfluous, because we will
|
||||
// insert the node elsewhere and set its parent link again.
|
||||
@ -919,11 +919,11 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
|
||||
let new_len = self.node.len() + 1;
|
||||
|
||||
unsafe {
|
||||
slice_insert(self.node.key_area_mut_at(..new_len), self.idx, key);
|
||||
slice_insert(self.node.val_area_mut_at(..new_len), self.idx, val);
|
||||
slice_insert(self.node.key_area_mut(..new_len), self.idx, key);
|
||||
slice_insert(self.node.val_area_mut(..new_len), self.idx, val);
|
||||
*self.node.len_mut() = new_len as u16;
|
||||
|
||||
self.node.val_area_mut_at(self.idx).assume_init_mut()
|
||||
self.node.val_area_mut(self.idx).assume_init_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -978,9 +978,9 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
|
||||
let new_len = self.node.len() + 1;
|
||||
|
||||
unsafe {
|
||||
slice_insert(self.node.key_area_mut_at(..new_len), self.idx, key);
|
||||
slice_insert(self.node.val_area_mut_at(..new_len), self.idx, val);
|
||||
slice_insert(self.node.edge_area_mut_at(..new_len + 1), self.idx + 1, edge.node);
|
||||
slice_insert(self.node.key_area_mut(..new_len), self.idx, key);
|
||||
slice_insert(self.node.val_area_mut(..new_len), self.idx, val);
|
||||
slice_insert(self.node.edge_area_mut(..new_len + 1), self.idx + 1, edge.node);
|
||||
*self.node.len_mut() = new_len as u16;
|
||||
|
||||
self.node.correct_childrens_parent_links(self.idx + 1..new_len + 1);
|
||||
@ -1085,7 +1085,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Immut<'a>, K, V, NodeTyp
|
||||
|
||||
impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::KV> {
|
||||
pub fn key_mut(&mut self) -> &mut K {
|
||||
unsafe { self.node.key_area_mut_at(self.idx).assume_init_mut() }
|
||||
unsafe { self.node.key_area_mut(self.idx).assume_init_mut() }
|
||||
}
|
||||
|
||||
pub fn into_val_mut(self) -> &'a mut V {
|
||||
@ -1127,16 +1127,16 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>
|
||||
let new_len = self.node.len() - self.idx - 1;
|
||||
new_node.len = new_len as u16;
|
||||
unsafe {
|
||||
let k = self.node.key_area_mut_at(self.idx).assume_init_read();
|
||||
let v = self.node.val_area_mut_at(self.idx).assume_init_read();
|
||||
let k = self.node.key_area_mut(self.idx).assume_init_read();
|
||||
let v = self.node.val_area_mut(self.idx).assume_init_read();
|
||||
|
||||
ptr::copy_nonoverlapping(
|
||||
self.node.key_area_mut_at(self.idx + 1..).as_ptr(),
|
||||
self.node.key_area_mut(self.idx + 1..).as_ptr(),
|
||||
new_node.keys.as_mut_ptr(),
|
||||
new_len,
|
||||
);
|
||||
ptr::copy_nonoverlapping(
|
||||
self.node.val_area_mut_at(self.idx + 1..).as_ptr(),
|
||||
self.node.val_area_mut(self.idx + 1..).as_ptr(),
|
||||
new_node.vals.as_mut_ptr(),
|
||||
new_len,
|
||||
);
|
||||
@ -1173,8 +1173,8 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
|
||||
) -> ((K, V), Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>) {
|
||||
let old_len = self.node.len();
|
||||
unsafe {
|
||||
let k = slice_remove(self.node.key_area_mut_at(..old_len), self.idx);
|
||||
let v = slice_remove(self.node.val_area_mut_at(..old_len), self.idx);
|
||||
let k = slice_remove(self.node.key_area_mut(..old_len), self.idx);
|
||||
let v = slice_remove(self.node.val_area_mut(..old_len), self.idx);
|
||||
*self.node.len_mut() = (old_len - 1) as u16;
|
||||
((k, v), self.left_edge())
|
||||
}
|
||||
@ -1195,7 +1195,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
|
||||
let kv = self.split_leaf_data(&mut new_node.data);
|
||||
let new_len = usize::from(new_node.data.len);
|
||||
ptr::copy_nonoverlapping(
|
||||
self.node.edge_area_mut_at(self.idx + 1..).as_ptr(),
|
||||
self.node.edge_area_mut(self.idx + 1..).as_ptr(),
|
||||
new_node.edges.as_mut_ptr(),
|
||||
new_len + 1,
|
||||
);
|
||||
@ -1321,25 +1321,23 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
|
||||
unsafe {
|
||||
*left_node.len_mut() = new_left_len as u16;
|
||||
|
||||
let parent_key =
|
||||
slice_remove(parent_node.key_area_mut_at(..old_parent_len), parent_idx);
|
||||
left_node.key_area_mut_at(old_left_len).write(parent_key);
|
||||
let parent_key = slice_remove(parent_node.key_area_mut(..old_parent_len), parent_idx);
|
||||
left_node.key_area_mut(old_left_len).write(parent_key);
|
||||
ptr::copy_nonoverlapping(
|
||||
right_node.key_area_mut_at(..).as_ptr(),
|
||||
left_node.key_area_mut_at(old_left_len + 1..).as_mut_ptr(),
|
||||
right_node.key_area_mut(..).as_ptr(),
|
||||
left_node.key_area_mut(old_left_len + 1..).as_mut_ptr(),
|
||||
right_len,
|
||||
);
|
||||
|
||||
let parent_val =
|
||||
slice_remove(parent_node.val_area_mut_at(..old_parent_len), parent_idx);
|
||||
left_node.val_area_mut_at(old_left_len).write(parent_val);
|
||||
let parent_val = slice_remove(parent_node.val_area_mut(..old_parent_len), parent_idx);
|
||||
left_node.val_area_mut(old_left_len).write(parent_val);
|
||||
ptr::copy_nonoverlapping(
|
||||
right_node.val_area_mut_at(..).as_ptr(),
|
||||
left_node.val_area_mut_at(old_left_len + 1..).as_mut_ptr(),
|
||||
right_node.val_area_mut(..).as_ptr(),
|
||||
left_node.val_area_mut(old_left_len + 1..).as_mut_ptr(),
|
||||
right_len,
|
||||
);
|
||||
|
||||
slice_remove(&mut parent_node.edge_area_mut_at(..old_parent_len + 1), parent_idx + 1);
|
||||
slice_remove(&mut parent_node.edge_area_mut(..old_parent_len + 1), parent_idx + 1);
|
||||
parent_node.correct_childrens_parent_links(parent_idx + 1..old_parent_len);
|
||||
*parent_node.len_mut() -= 1;
|
||||
|
||||
@ -1349,8 +1347,8 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
|
||||
let mut left_node = left_node.reborrow_mut().cast_to_internal_unchecked();
|
||||
let mut right_node = right_node.cast_to_internal_unchecked();
|
||||
ptr::copy_nonoverlapping(
|
||||
right_node.edge_area_mut_at(..).as_ptr(),
|
||||
left_node.edge_area_mut_at(old_left_len + 1..).as_mut_ptr(),
|
||||
right_node.edge_area_mut(..).as_ptr(),
|
||||
left_node.edge_area_mut(old_left_len + 1..).as_mut_ptr(),
|
||||
right_len + 1,
|
||||
);
|
||||
|
||||
@ -1458,7 +1456,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
|
||||
match (left_node.reborrow_mut().force(), right_node.reborrow_mut().force()) {
|
||||
(ForceResult::Internal(left), ForceResult::Internal(mut right)) => {
|
||||
// Make room for stolen edges.
|
||||
let right_edges = right.edge_area_mut_at(..).as_mut_ptr();
|
||||
let right_edges = right.edge_area_mut(..).as_mut_ptr();
|
||||
ptr::copy(right_edges, right_edges.add(count), old_right_len + 1);
|
||||
right.correct_childrens_parent_links(count..new_right_len + 1);
|
||||
|
||||
@ -1518,7 +1516,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
|
||||
move_edges(right.reborrow_mut(), 0, left, old_left_len + 1, count);
|
||||
|
||||
// Fill gap where stolen edges used to be.
|
||||
let right_edges = right.edge_area_mut_at(..).as_mut_ptr();
|
||||
let right_edges = right.edge_area_mut(..).as_mut_ptr();
|
||||
ptr::copy(right_edges.add(count), right_edges, new_right_len + 1);
|
||||
right.correct_childrens_parent_links(0..=new_right_len);
|
||||
}
|
||||
@ -1551,8 +1549,8 @@ unsafe fn move_edges<'a, K: 'a, V: 'a>(
|
||||
count: usize,
|
||||
) {
|
||||
unsafe {
|
||||
let source_ptr = source.edge_area_mut_at(..).as_ptr();
|
||||
let dest_ptr = dest.edge_area_mut_at(dest_offset..).as_mut_ptr();
|
||||
let source_ptr = source.edge_area_mut(..).as_ptr();
|
||||
let dest_ptr = dest.edge_area_mut(dest_offset..).as_mut_ptr();
|
||||
ptr::copy_nonoverlapping(source_ptr.add(source_offset), dest_ptr, count);
|
||||
dest.correct_childrens_parent_links(dest_offset..dest_offset + count);
|
||||
}
|
||||
|
@ -975,6 +975,7 @@ impl<T> BTreeSet<T> {
|
||||
/// v.insert(1);
|
||||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
|
||||
pub const fn len(&self) -> usize {
|
||||
|
@ -593,6 +593,7 @@ impl<T> LinkedList<T> {
|
||||
/// dl.push_back(3);
|
||||
/// assert_eq!(dl.len(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
|
@ -1038,6 +1038,7 @@ impl<T> VecDeque<T> {
|
||||
/// v.push_back(1);
|
||||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
count(self.tail, self.head, self.cap())
|
||||
@ -1091,7 +1092,7 @@ impl<T> VecDeque<T> {
|
||||
/// assert_eq!(all.len(), 3);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "deque_range", since = "1.50.0")]
|
||||
#[stable(feature = "deque_range", since = "1.51.0")]
|
||||
pub fn range<R>(&self, range: R) -> Iter<'_, T>
|
||||
where
|
||||
R: RangeBounds<usize>,
|
||||
@ -1130,7 +1131,7 @@ impl<T> VecDeque<T> {
|
||||
/// assert_eq!(v, vec![2, 4, 12]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "deque_range", since = "1.50.0")]
|
||||
#[stable(feature = "deque_range", since = "1.51.0")]
|
||||
pub fn range_mut<R>(&mut self, range: R) -> IterMut<'_, T>
|
||||
where
|
||||
R: RangeBounds<usize>,
|
||||
|
@ -1388,6 +1388,7 @@ impl String {
|
||||
/// assert_eq!(fancy_f.len(), 4);
|
||||
/// assert_eq!(fancy_f.chars().count(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
|
@ -14,7 +14,7 @@ use core::hint;
|
||||
use core::intrinsics::abort;
|
||||
use core::iter;
|
||||
use core::marker::{PhantomData, Unpin, Unsize};
|
||||
use core::mem::{self, align_of_val, size_of_val};
|
||||
use core::mem::{self, align_of_val_raw, size_of_val};
|
||||
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
|
||||
use core::pin::Pin;
|
||||
use core::ptr::{self, NonNull};
|
||||
@ -2366,7 +2366,7 @@ unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize {
|
||||
// Because it is `?Sized`, it will always be the last field in memory.
|
||||
// Note: This is a detail of the current implementation of the compiler,
|
||||
// and is not a guaranteed language detail. Do not rely on it outside of std.
|
||||
unsafe { data_offset_align(align_of_val(&*ptr)) }
|
||||
unsafe { data_offset_align(align_of_val_raw(ptr)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1559,6 +1559,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
/// let a = vec![1, 2, 3];
|
||||
/// assert_eq!(a.len(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
|
@ -47,6 +47,7 @@ use super::MAX;
|
||||
///
|
||||
/// assert_eq!(None, c);
|
||||
/// ```
|
||||
#[doc(alias = "chr")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn from_u32(i: u32) -> Option<char> {
|
||||
|
@ -91,6 +91,7 @@ pub trait ExactSizeIterator: Iterator {
|
||||
///
|
||||
/// assert_eq!(5, five.len());
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn len(&self) -> usize {
|
||||
|
@ -232,23 +232,27 @@ impl<T: ?Sized> *const T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// In other words, `x.wrapping_offset((y as usize).wrapping_sub(x as usize) / size_of::<T>())`
|
||||
/// is *not* the same as `y`, and dereferencing it is undefined behavior
|
||||
/// unless `x` and `y` point into the same allocated object.
|
||||
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`offset`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`offset`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_offset` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`offset`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// Compared to [`offset`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`offset`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_offset` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`offset`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
|
||||
/// words, leaving the allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
@ -571,19 +575,27 @@ impl<T: ?Sized> *const T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// Compared to [`add`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`add`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_add` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`add`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`add`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`add`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_add` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`add`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
|
||||
/// allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
@ -628,19 +640,27 @@ impl<T: ?Sized> *const T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// Compared to [`sub`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`sub`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_sub` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`sub`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`sub`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`sub`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_sub` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`sub`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
|
||||
/// allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
|
@ -238,23 +238,27 @@ impl<T: ?Sized> *mut T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// In other words, `x.wrapping_offset((y as usize).wrapping_sub(x as usize) / size_of::<T>())`
|
||||
/// is *not* the same as `y`, and dereferencing it is undefined behavior
|
||||
/// unless `x` and `y` point into the same allocated object.
|
||||
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`offset`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`offset`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_offset` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`offset`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// Compared to [`offset`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`offset`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_offset` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`offset`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
|
||||
/// words, leaving the allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
@ -678,19 +682,27 @@ impl<T: ?Sized> *mut T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// Compared to [`add`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`add`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_add` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`add`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`add`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`add`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_add` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`add`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
|
||||
/// allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
@ -735,19 +747,27 @@ impl<T: ?Sized> *mut T {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The resulting pointer does not need to be in bounds, but it is
|
||||
/// potentially hazardous to dereference (which requires `unsafe`).
|
||||
/// This operation itself is always safe, but using the resulting pointer is not.
|
||||
///
|
||||
/// In particular, the resulting pointer remains attached to the same allocated
|
||||
/// object that `self` points to. It may *not* be used to access a
|
||||
/// different allocated object. Note that in Rust,
|
||||
/// every (stack-allocated) variable is considered a separate allocated object.
|
||||
/// The resulting pointer remains attached to the same allocated object that `self` points to.
|
||||
/// It may *not* be used to access a different allocated object. Note that in Rust, every
|
||||
/// (stack-allocated) variable is considered a separate allocated object.
|
||||
///
|
||||
/// Compared to [`sub`], this method basically delays the requirement of staying
|
||||
/// within the same allocated object: [`sub`] is immediate Undefined Behavior when
|
||||
/// crossing object boundaries; `wrapping_sub` produces a pointer but still leads
|
||||
/// to Undefined Behavior if that pointer is dereferenced. [`sub`] can be optimized
|
||||
/// better and is thus preferable in performance-sensitive code.
|
||||
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
|
||||
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
|
||||
/// attached to the object `x` is attached to, and dereferencing it is Undefined Behavior unless
|
||||
/// `x` and `y` point into the same allocated object.
|
||||
///
|
||||
/// Compared to [`sub`], this method basically delays the requirement of staying within the
|
||||
/// same allocated object: [`sub`] is immediate Undefined Behavior when crossing object
|
||||
/// boundaries; `wrapping_sub` produces a pointer but still leads to Undefined Behavior if a
|
||||
/// pointer is dereferenced when it is out-of-bounds of the object it is attached to. [`sub`]
|
||||
/// can be optimized better and is thus preferable in performance-sensitive code.
|
||||
///
|
||||
/// The delayed check only considers the value of the pointer that was dereferenced, not the
|
||||
/// intermediate values used during the computation of the final result. For example,
|
||||
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
|
||||
/// allocated object and then re-entering it later is permitted.
|
||||
///
|
||||
/// If you need to cross object boundaries, cast the pointer to an integer and
|
||||
/// do the arithmetic there.
|
||||
|
@ -84,6 +84,7 @@ impl<T> [T] {
|
||||
/// let a = [1, 2, 3];
|
||||
/// assert_eq!(a.len(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")]
|
||||
#[inline]
|
||||
|
@ -138,6 +138,7 @@ impl str {
|
||||
/// assert_eq!("ƒoo".len(), 4); // fancy f!
|
||||
/// assert_eq!("ƒoo".chars().count(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_str_len", since = "1.32.0")]
|
||||
#[inline]
|
||||
|
@ -448,6 +448,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
||||
/// a.insert(1, "a");
|
||||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
self.base.len()
|
||||
|
@ -199,6 +199,7 @@ impl<T, S> HashSet<T, S> {
|
||||
/// v.insert(1);
|
||||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
|
@ -653,6 +653,7 @@ impl OsStr {
|
||||
/// let os_str = OsStr::new("foo");
|
||||
/// assert_eq!(os_str.len(), 3);
|
||||
/// ```
|
||||
#[doc(alias = "length")]
|
||||
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
|
||||
pub fn len(&self) -> usize {
|
||||
self.inner.inner.len()
|
||||
|
@ -3,3 +3,6 @@ authors = ["The Rust Project Developers"]
|
||||
multilingual = false
|
||||
src = "src"
|
||||
title = "The rustc book"
|
||||
|
||||
[output.html]
|
||||
git-repository-url = "https://github.com/rust-lang/rust/tree/master/src/doc/rustc"
|
||||
|
@ -2,3 +2,6 @@
|
||||
authors = ["The Rust Project Developers"]
|
||||
src = "src"
|
||||
title = "The rustdoc book"
|
||||
|
||||
[output.html]
|
||||
git-repository-url = "https://github.com/rust-lang/rust/tree/master/src/doc/rustdoc"
|
||||
|
@ -10,7 +10,7 @@ CSS, and JavaScript.
|
||||
Let's give it a try! Create a new project with Cargo:
|
||||
|
||||
```bash
|
||||
$ cargo new docs
|
||||
$ cargo new docs --lib
|
||||
$ cd docs
|
||||
```
|
||||
|
||||
|
4
src/test/ui/const-generics/issues/issue-80375.rs
Normal file
4
src/test/ui/const-generics/issues/issue-80375.rs
Normal file
@ -0,0 +1,4 @@
|
||||
struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
|
||||
//~^ ERROR generic parameters may not be used in const operations
|
||||
|
||||
fn main() {}
|
11
src/test/ui/const-generics/issues/issue-80375.stderr
Normal file
11
src/test/ui/const-generics/issues/issue-80375.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/issue-80375.rs:1:41
|
||||
|
|
||||
LL | struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
|
||||
| ^^^^^ cannot perform const operation using `COUNT`
|
||||
|
|
||||
= help: const parameters may only be used as standalone arguments, i.e. `COUNT`
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user