Skip to content

Commit a784a80

Browse files
committed
Auto merge of #60672 - Centril:rollup-fhcx463, r=Centril
Rollup of 5 pull requests Successful merges: - #60601 (Add a `cast` method to raw pointers.) - #60638 (pin: make the to-module link more visible) - #60647 (cleanup: Remove `DefIndexAddressSpace`) - #60656 (Inline some Cursor calls for slices) - #60657 (Stabilize and re-export core::array in std) Failed merges: r? @ghost
2 parents ef01f29 + e40f9a6 commit a784a80

Some content is hidden

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

47 files changed

+275
-409
lines changed

src/libcore/array.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
//!
55
//! *[See also the array primitive type](../../std/primitive.array.html).*
66
7-
#![unstable(feature = "fixed_size_array",
8-
reason = "traits and impls are better expressed through generic \
9-
integer constants",
10-
issue = "27778")]
7+
#![stable(feature = "core_array", since = "1.36.0")]
118

129
use crate::borrow::{Borrow, BorrowMut};
1310
use crate::cmp::Ordering;
@@ -30,13 +27,17 @@ use crate::slice::{Iter, IterMut};
3027
/// Note that the traits AsRef and AsMut provide similar methods for types that
3128
/// may not be fixed-size arrays. Implementors should prefer those traits
3229
/// instead.
30+
#[unstable(feature = "fixed_size_array", issue = "27778")]
3331
pub unsafe trait FixedSizeArray<T> {
3432
/// Converts the array to immutable slice
33+
#[unstable(feature = "fixed_size_array", issue = "27778")]
3534
fn as_slice(&self) -> &[T];
3635
/// Converts the array to mutable slice
36+
#[unstable(feature = "fixed_size_array", issue = "27778")]
3737
fn as_mut_slice(&mut self) -> &mut [T];
3838
}
3939

40+
#[unstable(feature = "fixed_size_array", issue = "27778")]
4041
unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
4142
#[inline]
4243
fn as_slice(&self) -> &[T] {
@@ -53,6 +54,7 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
5354
#[derive(Debug, Copy, Clone)]
5455
pub struct TryFromSliceError(());
5556

57+
#[stable(feature = "core_array", since = "1.36.0")]
5658
impl fmt::Display for TryFromSliceError {
5759
#[inline]
5860
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/libcore/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ use crate::ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
274274
/// value in place, preventing the value referenced by that pointer from being moved
275275
/// unless it implements [`Unpin`].
276276
///
277-
/// See the [`pin` module] documentation for further explanation on pinning.
277+
/// *See the [`pin` module] documentation for an explanation of pinning.*
278278
///
279279
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
280280
/// [`pin` module]: ../../std/pin/index.html

src/libcore/ptr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,13 @@ impl<T: ?Sized> *const T {
974974
(self as *const u8) == null()
975975
}
976976

977+
/// Cast to a pointer to a different type
978+
#[unstable(feature = "ptr_cast", issue = "60602")]
979+
#[inline]
980+
pub const fn cast<U>(self) -> *const U {
981+
self as _
982+
}
983+
977984
/// Returns `None` if the pointer is null, or else returns a reference to
978985
/// the value wrapped in `Some`.
979986
///
@@ -1593,6 +1600,13 @@ impl<T: ?Sized> *mut T {
15931600
(self as *mut u8) == null_mut()
15941601
}
15951602

1603+
/// Cast to a pointer to a different type
1604+
#[unstable(feature = "ptr_cast", issue = "60602")]
1605+
#[inline]
1606+
pub const fn cast<U>(self) -> *mut U {
1607+
self as _
1608+
}
1609+
15961610
/// Returns `None` if the pointer is null, or else returns a reference to
15971611
/// the value wrapped in `Some`.
15981612
///

src/librustc/hir/def_id.rs

+11-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::{self, TyCtxt};
2-
use crate::hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
2+
use crate::hir::map::definitions::FIRST_FREE_DEF_INDEX;
33
use rustc_data_structures::indexed_vec::Idx;
44
use serialize;
55
use std::fmt;
@@ -99,17 +99,6 @@ impl serialize::UseSpecializedDecodable for CrateNum {}
9999
/// A DefIndex is an index into the hir-map for a crate, identifying a
100100
/// particular definition. It should really be considered an interned
101101
/// shorthand for a particular DefPath.
102-
///
103-
/// At the moment we are allocating the numerical values of DefIndexes from two
104-
/// address spaces: DefIndexAddressSpace::Low and DefIndexAddressSpace::High.
105-
/// This allows us to allocate the DefIndexes of all item-likes
106-
/// (Items, TraitItems, and ImplItems) into one of these spaces and
107-
/// consequently use a simple array for lookup tables keyed by DefIndex and
108-
/// known to be densely populated. This is especially important for the HIR map.
109-
///
110-
/// Since the DefIndex is mostly treated as an opaque ID, you probably
111-
/// don't have to care about these address spaces.
112-
113102
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
114103
pub struct DefIndex(u32);
115104

@@ -119,67 +108,49 @@ pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
119108

120109
impl fmt::Debug for DefIndex {
121110
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122-
write!(f,
123-
"DefIndex({}:{})",
124-
self.address_space().index(),
125-
self.as_array_index())
111+
write!(f, "DefIndex({})", self.as_array_index())
126112
}
127113
}
128114

129115
impl DefIndex {
130-
#[inline]
131-
pub fn address_space(&self) -> DefIndexAddressSpace {
132-
match self.0 & 1 {
133-
0 => DefIndexAddressSpace::Low,
134-
1 => DefIndexAddressSpace::High,
135-
_ => unreachable!()
136-
}
137-
}
138-
139116
/// Converts this DefIndex into a zero-based array index.
140-
/// This index is the offset within the given DefIndexAddressSpace.
141117
#[inline]
142118
pub fn as_array_index(&self) -> usize {
143-
(self.0 >> 1) as usize
119+
self.0 as usize
144120
}
145121

146122
#[inline]
147-
pub fn from_array_index(i: usize, address_space: DefIndexAddressSpace) -> DefIndex {
148-
DefIndex::from_raw_u32(((i << 1) | (address_space as usize)) as u32)
123+
pub fn from_array_index(i: usize) -> DefIndex {
124+
DefIndex(i as u32)
149125
}
150126

151127
// Proc macros from a proc-macro crate have a kind of virtual DefIndex. This
152128
// function maps the index of the macro within the crate (which is also the
153129
// index of the macro in the CrateMetadata::proc_macros array) to the
154130
// corresponding DefIndex.
155131
pub fn from_proc_macro_index(proc_macro_index: usize) -> DefIndex {
156-
// DefIndex for proc macros start from FIRST_FREE_HIGH_DEF_INDEX,
157-
// because the first FIRST_FREE_HIGH_DEF_INDEX indexes are reserved
132+
// DefIndex for proc macros start from FIRST_FREE_DEF_INDEX,
133+
// because the first FIRST_FREE_DEF_INDEX indexes are reserved
158134
// for internal use.
159135
let def_index = DefIndex::from_array_index(
160-
proc_macro_index.checked_add(FIRST_FREE_HIGH_DEF_INDEX)
161-
.expect("integer overflow adding `proc_macro_index`"),
162-
DefIndexAddressSpace::High);
136+
proc_macro_index.checked_add(FIRST_FREE_DEF_INDEX)
137+
.expect("integer overflow adding `proc_macro_index`"));
163138
assert!(def_index != CRATE_DEF_INDEX);
164139
def_index
165140
}
166141

167142
// This function is the reverse of from_proc_macro_index() above.
168143
pub fn to_proc_macro_index(self: DefIndex) -> usize {
169-
assert_eq!(self.address_space(), DefIndexAddressSpace::High);
170-
171-
self.as_array_index().checked_sub(FIRST_FREE_HIGH_DEF_INDEX)
144+
self.as_array_index().checked_sub(FIRST_FREE_DEF_INDEX)
172145
.unwrap_or_else(|| {
173146
bug!("using local index {:?} as proc-macro index", self)
174147
})
175148
}
176149

177-
// Don't use this if you don't know about the DefIndex encoding.
178150
pub fn from_raw_u32(x: u32) -> DefIndex {
179151
DefIndex(x)
180152
}
181153

182-
// Don't use this if you don't know about the DefIndex encoding.
183154
pub fn as_raw_u32(&self) -> u32 {
184155
self.0
185156
}
@@ -188,19 +159,6 @@ impl DefIndex {
188159
impl serialize::UseSpecializedEncodable for DefIndex {}
189160
impl serialize::UseSpecializedDecodable for DefIndex {}
190161

191-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
192-
pub enum DefIndexAddressSpace {
193-
Low = 0,
194-
High = 1,
195-
}
196-
197-
impl DefIndexAddressSpace {
198-
#[inline]
199-
pub fn index(&self) -> usize {
200-
*self as usize
201-
}
202-
}
203-
204162
/// A `DefId` identifies a particular *definition*, by combining a crate
205163
/// index and a def index.
206164
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
@@ -211,10 +169,7 @@ pub struct DefId {
211169

212170
impl fmt::Debug for DefId {
213171
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214-
write!(f, "DefId({}/{}:{}",
215-
self.krate,
216-
self.index.address_space().index(),
217-
self.index.as_array_index())?;
172+
write!(f, "DefId({}:{}", self.krate, self.index.as_array_index())?;
218173

219174
ty::tls::with_opt(|opt_tcx| {
220175
if let Some(tcx) = opt_tcx {

src/librustc/hir/lowering.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::dep_graph::DepGraph;
3636
use crate::hir::{self, ParamName};
3737
use crate::hir::HirVec;
3838
use crate::hir::map::{DefKey, DefPathData, Definitions};
39-
use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
39+
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
4040
use crate::hir::def::{Res, DefKind, PartialRes, PerNS};
4141
use crate::hir::{GenericArg, ConstArg};
4242
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
@@ -418,7 +418,6 @@ impl<'a> LoweringContext<'a> {
418418
owner,
419419
id,
420420
DefPathData::Misc,
421-
DefIndexAddressSpace::High,
422421
Mark::root(),
423422
tree.prefix.span,
424423
);
@@ -962,7 +961,6 @@ impl<'a> LoweringContext<'a> {
962961
parent_index,
963962
node_id,
964963
DefPathData::LifetimeNs(str_name),
965-
DefIndexAddressSpace::High,
966964
Mark::root(),
967965
span,
968966
);
@@ -1763,7 +1761,6 @@ impl<'a> LoweringContext<'a> {
17631761
self.parent,
17641762
def_node_id,
17651763
DefPathData::LifetimeNs(name.ident().as_interned_str()),
1766-
DefIndexAddressSpace::High,
17671764
Mark::root(),
17681765
lifetime.span,
17691766
);

src/librustc/hir/map/collector.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
145145
);
146146
}
147147

148-
let (lo, hi) = definitions.def_index_counts_lo_hi();
149-
150148
let mut collector = NodeCollector {
151149
krate,
152150
source_map: sess.source_map(),
153-
map: [
154-
repeat(None).take(lo).collect(),
155-
repeat(None).take(hi).collect(),
156-
],
151+
map: vec![None; definitions.def_index_count()],
157152
parent_node: hir::CRATE_HIR_ID,
158153
current_signature_dep_index: root_mod_sig_dep_index,
159154
current_full_dep_index: root_mod_full_dep_index,
@@ -231,7 +226,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
231226

232227
fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
233228
debug!("hir_map: {:?} => {:?}", id, entry);
234-
let local_map = &mut self.map[id.owner.address_space().index()][id.owner.as_array_index()];
229+
let local_map = &mut self.map[id.owner.as_array_index()];
235230
let i = id.local_id.as_u32() as usize;
236231
if local_map.is_none() {
237232
*local_map = Some(IndexVec::with_capacity(i + 1));

0 commit comments

Comments
 (0)