Skip to content

Commit 4d48a6b

Browse files
committed
Auto merge of rust-lang#128673 - matthiaskrgr:rollup-gtvpkm7, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128026 (std::thread: available_parallelism implementation for vxWorks proposal.) - rust-lang#128471 (rustdoc: Fix handling of `Self` type in search index and refactor its representation) - rust-lang#128607 (Use `object` in `run-make/symbols-visibility`) - rust-lang#128609 (Remove unnecessary constants from flt2dec dragon) - rust-lang#128611 (run-make: Remove cygpath) - rust-lang#128619 (Correct the const stabilization of `<[T]>::last_chunk`) - rust-lang#128630 (docs(resolve): more explain about `target`) - rust-lang#128660 (tests: more crashes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 29e9248 + 5fa740f commit 4d48a6b

File tree

27 files changed

+489
-422
lines changed

27 files changed

+489
-422
lines changed

compiler/rustc_resolve/src/imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) enum ImportKind<'a> {
4848
/// `source` in `use prefix::source as target`.
4949
source: Ident,
5050
/// `target` in `use prefix::source as target`.
51+
/// It will directly use `source` when the format is `use prefix::source`.
5152
target: Ident,
5253
/// Bindings to which `source` refers to.
5354
source_bindings: PerNS<Cell<Result<NameBinding<'a>, Determinacy>>>,

library/core/src/num/flt2dec/strategy/dragon.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,51 @@ use crate::num::flt2dec::{round_up, Decoded, MAX_SIG_DIGITS};
1212

1313
static POW10: [Digit; 10] =
1414
[1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000];
15-
static TWOPOW10: [Digit; 10] =
16-
[2, 20, 200, 2000, 20000, 200000, 2000000, 20000000, 200000000, 2000000000];
17-
18-
// precalculated arrays of `Digit`s for 10^(2^n)
19-
static POW10TO16: [Digit; 2] = [0x6fc10000, 0x2386f2];
20-
static POW10TO32: [Digit; 4] = [0, 0x85acef81, 0x2d6d415b, 0x4ee];
21-
static POW10TO64: [Digit; 7] = [0, 0, 0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03];
22-
static POW10TO128: [Digit; 14] = [
23-
0, 0, 0, 0, 0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08, 0xbccdb0da,
24-
0xa6337f19, 0xe91f2603, 0x24e,
15+
// precalculated arrays of `Digit`s for 5^(2^n).
16+
static POW5TO16: [Digit; 2] = [0x86f26fc1, 0x23];
17+
static POW5TO32: [Digit; 3] = [0x85acef81, 0x2d6d415b, 0x4ee];
18+
static POW5TO64: [Digit; 5] = [0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03];
19+
static POW5TO128: [Digit; 10] = [
20+
0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08, 0xbccdb0da, 0xa6337f19,
21+
0xe91f2603, 0x24e,
2522
];
26-
static POW10TO256: [Digit; 27] = [
27-
0, 0, 0, 0, 0, 0, 0, 0, 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70,
28-
0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0, 0x65f9ef17,
29-
0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x553f7,
23+
static POW5TO256: [Digit; 19] = [
24+
0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70, 0xd595d80f, 0x26b2716e,
25+
0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0, 0x65f9ef17, 0x55bc28f2, 0x80dcc7f7,
26+
0xf46eeddc, 0x5fdcefce, 0x553f7,
3027
];
3128

3229
#[doc(hidden)]
3330
pub fn mul_pow10(x: &mut Big, n: usize) -> &mut Big {
3431
debug_assert!(n < 512);
32+
// Save ourself the left shift for the smallest cases.
33+
if n < 8 {
34+
return x.mul_small(POW10[n & 7]);
35+
}
36+
// Multiply by the powers of 5 and shift the 2s in at the end.
37+
// This keeps the intermediate products smaller and faster.
3538
if n & 7 != 0 {
36-
x.mul_small(POW10[n & 7]);
39+
x.mul_small(POW10[n & 7] >> (n & 7));
3740
}
3841
if n & 8 != 0 {
39-
x.mul_small(POW10[8]);
42+
x.mul_small(POW10[8] >> 8);
4043
}
4144
if n & 16 != 0 {
42-
x.mul_digits(&POW10TO16);
45+
x.mul_digits(&POW5TO16);
4346
}
4447
if n & 32 != 0 {
45-
x.mul_digits(&POW10TO32);
48+
x.mul_digits(&POW5TO32);
4649
}
4750
if n & 64 != 0 {
48-
x.mul_digits(&POW10TO64);
51+
x.mul_digits(&POW5TO64);
4952
}
5053
if n & 128 != 0 {
51-
x.mul_digits(&POW10TO128);
54+
x.mul_digits(&POW5TO128);
5255
}
5356
if n & 256 != 0 {
54-
x.mul_digits(&POW10TO256);
57+
x.mul_digits(&POW5TO256);
5558
}
56-
x
59+
x.mul_pow2(n)
5760
}
5861

5962
fn div_2pow10(x: &mut Big, mut n: usize) -> &mut Big {
@@ -62,7 +65,7 @@ fn div_2pow10(x: &mut Big, mut n: usize) -> &mut Big {
6265
x.div_rem_small(POW10[largest]);
6366
n -= largest;
6467
}
65-
x.div_rem_small(TWOPOW10[n]);
68+
x.div_rem_small(POW10[n] << 1);
6669
x
6770
}
6871

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<T> [T] {
522522
/// ```
523523
#[inline]
524524
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
525-
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "1.77.0")]
525+
#[rustc_const_stable(feature = "const_slice_last_chunk", since = "1.80.0")]
526526
pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]> {
527527
if self.len() < N {
528528
None

library/std/src/sys/pal/unix/thread.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,18 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
455455

456456
Ok(NonZero::new_unchecked(sinfo.cpu_count as usize))
457457
}
458+
} else if #[cfg(target_os = "vxworks")] {
459+
// Note: there is also `vxCpuConfiguredGet`, closer to _SC_NPROCESSORS_CONF
460+
// expectations than the actual cores availability.
461+
extern "C" {
462+
fn vxCpuEnabledGet() -> libc::cpuset_t;
463+
}
464+
465+
// always fetches a valid bitmask
466+
let set = unsafe { vxCpuEnabledGet() };
467+
Ok(NonZero::new_unchecked(set.count_ones() as usize))
458468
} else {
459-
// FIXME: implement on vxWorks, Redox, l4re
469+
// FIXME: implement on Redox, l4re
460470
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))
461471
}
462472
}

src/librustdoc/clean/inline.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType;
1212
use rustc_middle::ty::{self, TyCtxt};
1313
use rustc_span::def_id::LOCAL_CRATE;
1414
use rustc_span::hygiene::MacroKind;
15-
use rustc_span::symbol::{kw, sym, Symbol};
15+
use rustc_span::symbol::{sym, Symbol};
1616
use thin_vec::{thin_vec, ThinVec};
1717
use {rustc_ast as ast, rustc_hir as hir};
1818

@@ -792,11 +792,7 @@ fn build_macro(
792792
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean::Generics {
793793
for pred in &mut g.where_predicates {
794794
match *pred {
795-
clean::WherePredicate::BoundPredicate {
796-
ty: clean::Generic(ref s),
797-
ref mut bounds,
798-
..
799-
} if *s == kw::SelfUpper => {
795+
clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref mut bounds, .. } => {
800796
bounds.retain(|bound| match bound {
801797
clean::GenericBound::TraitBound(clean::PolyTrait { trait_, .. }, _) => {
802798
trait_.def_id() != trait_did
@@ -812,13 +808,13 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
812808
clean::WherePredicate::BoundPredicate {
813809
ty:
814810
clean::QPath(box clean::QPathData {
815-
self_type: clean::Generic(ref s),
811+
self_type: clean::Generic(_),
816812
trait_: Some(trait_),
817813
..
818814
}),
819815
bounds,
820816
..
821-
} => !(bounds.is_empty() || *s == kw::SelfUpper && trait_.def_id() == trait_did),
817+
} => !bounds.is_empty() && trait_.def_id() != trait_did,
822818
_ => true,
823819
});
824820
g
@@ -832,9 +828,7 @@ fn separate_supertrait_bounds(
832828
) -> (clean::Generics, Vec<clean::GenericBound>) {
833829
let mut ty_bounds = Vec::new();
834830
g.where_predicates.retain(|pred| match *pred {
835-
clean::WherePredicate::BoundPredicate { ty: clean::Generic(ref s), ref bounds, .. }
836-
if *s == kw::SelfUpper =>
837-
{
831+
clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref bounds, .. } => {
838832
ty_bounds.extend(bounds.iter().cloned());
839833
false
840834
}

src/librustdoc/clean/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,11 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13511351
let self_arg_ty =
13521352
tcx.fn_sig(assoc_item.def_id).instantiate_identity().input(0).skip_binder();
13531353
if self_arg_ty == self_ty {
1354-
item.decl.inputs.values[0].type_ = Generic(kw::SelfUpper);
1354+
item.decl.inputs.values[0].type_ = SelfTy;
13551355
} else if let ty::Ref(_, ty, _) = *self_arg_ty.kind() {
13561356
if ty == self_ty {
13571357
match item.decl.inputs.values[0].type_ {
1358-
BorrowedRef { ref mut type_, .. } => **type_ = Generic(kw::SelfUpper),
1358+
BorrowedRef { ref mut type_, .. } => **type_ = SelfTy,
13591359
_ => unreachable!(),
13601360
}
13611361
}
@@ -1439,9 +1439,8 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14391439
if trait_.def_id() != assoc_item.container_id(tcx) {
14401440
return true;
14411441
}
1442-
match *self_type {
1443-
Generic(ref s) if *s == kw::SelfUpper => {}
1444-
_ => return true,
1442+
if *self_type != SelfTy {
1443+
return true;
14451444
}
14461445
match &assoc.args {
14471446
GenericArgs::AngleBracketed { args, constraints } => {
@@ -2228,6 +2227,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
22282227
ty::Param(ref p) => {
22292228
if let Some(bounds) = cx.impl_trait_bounds.remove(&p.index.into()) {
22302229
ImplTrait(bounds)
2230+
} else if p.name == kw::SelfUpper {
2231+
SelfTy
22312232
} else {
22322233
Generic(p.name)
22332234
}

src/librustdoc/clean/simplify.rs

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ pub(crate) fn sized_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generi
145145
// should be handled when cleaning associated types.
146146
generics.where_predicates.retain(|pred| {
147147
if let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred
148-
&& *param != rustc_span::symbol::kw::SelfUpper
149148
&& bounds.iter().any(|b| b.is_sized_bound(cx))
150149
{
151150
sized_params.insert(*param);

src/librustdoc/clean/types.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ use thin_vec::ThinVec;
3434
use {rustc_ast as ast, rustc_hir as hir};
3535

3636
pub(crate) use self::ItemKind::*;
37-
pub(crate) use self::SelfTy::*;
3837
pub(crate) use self::Type::{
3938
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
40-
RawPointer, Slice, Tuple,
39+
RawPointer, SelfTy, Slice, Tuple,
4140
};
4241
use crate::clean::cfg::Cfg;
4342
use crate::clean::clean_middle_path;
@@ -1384,8 +1383,8 @@ pub(crate) struct FnDecl {
13841383
}
13851384

13861385
impl FnDecl {
1387-
pub(crate) fn self_type(&self) -> Option<SelfTy> {
1388-
self.inputs.values.get(0).and_then(|v| v.to_self())
1386+
pub(crate) fn receiver_type(&self) -> Option<&Type> {
1387+
self.inputs.values.get(0).and_then(|v| v.to_receiver())
13891388
}
13901389
}
13911390

@@ -1403,27 +1402,9 @@ pub(crate) struct Argument {
14031402
pub(crate) is_const: bool,
14041403
}
14051404

1406-
#[derive(Clone, PartialEq, Debug)]
1407-
pub(crate) enum SelfTy {
1408-
SelfValue,
1409-
SelfBorrowed(Option<Lifetime>, Mutability),
1410-
SelfExplicit(Type),
1411-
}
1412-
14131405
impl Argument {
1414-
pub(crate) fn to_self(&self) -> Option<SelfTy> {
1415-
if self.name != kw::SelfLower {
1416-
return None;
1417-
}
1418-
if self.type_.is_self_type() {
1419-
return Some(SelfValue);
1420-
}
1421-
match self.type_ {
1422-
BorrowedRef { ref lifetime, mutability, ref type_ } if type_.is_self_type() => {
1423-
Some(SelfBorrowed(lifetime.clone(), mutability))
1424-
}
1425-
_ => Some(SelfExplicit(self.type_.clone())),
1426-
}
1406+
pub(crate) fn to_receiver(&self) -> Option<&Type> {
1407+
if self.name == kw::SelfLower { Some(&self.type_) } else { None }
14271408
}
14281409
}
14291410

@@ -1477,6 +1458,8 @@ pub(crate) enum Type {
14771458
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
14781459
/// A type parameter.
14791460
Generic(Symbol),
1461+
/// The `Self` type.
1462+
SelfTy,
14801463
/// A primitive (aka, builtin) type.
14811464
Primitive(PrimitiveType),
14821465
/// A function pointer: `extern "ABI" fn(...) -> ...`
@@ -1571,6 +1554,8 @@ impl Type {
15711554
// If both sides are generic, this returns true.
15721555
(_, Type::Generic(_)) => true,
15731556
(Type::Generic(_), _) => false,
1557+
// `Self` only matches itself.
1558+
(Type::SelfTy, Type::SelfTy) => true,
15741559
// Paths account for both the path itself and its generics.
15751560
(Type::Path { path: a }, Type::Path { path: b }) => {
15761561
a.def_id() == b.def_id()
@@ -1642,7 +1627,7 @@ impl Type {
16421627

16431628
pub(crate) fn is_self_type(&self) -> bool {
16441629
match *self {
1645-
Generic(name) => name == kw::SelfUpper,
1630+
SelfTy => true,
16461631
_ => false,
16471632
}
16481633
}
@@ -1700,7 +1685,7 @@ impl Type {
17001685
Type::Pat(..) => PrimitiveType::Pat,
17011686
RawPointer(..) => PrimitiveType::RawPointer,
17021687
QPath(box QPathData { ref self_type, .. }) => return self_type.def_id(cache),
1703-
Generic(_) | Infer | ImplTrait(_) => return None,
1688+
Generic(_) | SelfTy | Infer | ImplTrait(_) => return None,
17041689
};
17051690
Primitive(t).def_id(cache)
17061691
}

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
468468
match path.res {
469469
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
470470
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } if path.segments.len() == 1 => {
471-
Generic(kw::SelfUpper)
471+
Type::SelfTy
472472
}
473473
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
474474
_ => {

src/librustdoc/html/format.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ fn fmt_type<'cx>(
10061006

10071007
match *t {
10081008
clean::Generic(name) => f.write_str(name.as_str()),
1009+
clean::SelfTy => f.write_str("Self"),
10091010
clean::Type::Path { ref path } => {
10101011
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
10111012
let did = path.def_id();
@@ -1452,29 +1453,22 @@ impl clean::FnDecl {
14521453

14531454
let last_input_index = self.inputs.values.len().checked_sub(1);
14541455
for (i, input) in self.inputs.values.iter().enumerate() {
1455-
if let Some(selfty) = input.to_self() {
1456+
if let Some(selfty) = input.to_receiver() {
14561457
match selfty {
1457-
clean::SelfValue => {
1458+
clean::SelfTy => {
14581459
write!(f, "self")?;
14591460
}
1460-
clean::SelfBorrowed(Some(ref lt), mutability) => {
1461-
write!(
1462-
f,
1463-
"{amp}{lifetime} {mutability}self",
1464-
lifetime = lt.print(),
1465-
mutability = mutability.print_with_space(),
1466-
)?;
1467-
}
1468-
clean::SelfBorrowed(None, mutability) => {
1469-
write!(
1470-
f,
1471-
"{amp}{mutability}self",
1472-
mutability = mutability.print_with_space(),
1473-
)?;
1461+
clean::BorrowedRef { lifetime, mutability, type_: box clean::SelfTy } => {
1462+
write!(f, "{amp}")?;
1463+
match lifetime {
1464+
Some(lt) => write!(f, "{lt} ", lt = lt.print())?,
1465+
None => {}
1466+
}
1467+
write!(f, "{mutability}self", mutability = mutability.print_with_space())?;
14741468
}
1475-
clean::SelfExplicit(ref typ) => {
1469+
_ => {
14761470
write!(f, "self: ")?;
1477-
typ.print(cx).fmt(f)?;
1471+
selfty.print(cx).fmt(f)?;
14781472
}
14791473
}
14801474
} else {

src/librustdoc/html/render/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use serde::{Serialize, Serializer};
5858

5959
pub(crate) use self::context::*;
6060
pub(crate) use self::span_map::{collect_spans_and_sources, LinkFromSrc};
61-
use crate::clean::{self, ItemId, RenderedLink, SelfTy};
61+
use crate::clean::{self, ItemId, RenderedLink};
6262
use crate::error::Error;
6363
use crate::formats::cache::Cache;
6464
use crate::formats::item_type::ItemType;
@@ -1372,21 +1372,20 @@ fn render_deref_methods(
13721372

13731373
fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) -> bool {
13741374
let self_type_opt = match *item.kind {
1375-
clean::MethodItem(ref method, _) => method.decl.self_type(),
1376-
clean::TyMethodItem(ref method) => method.decl.self_type(),
1375+
clean::MethodItem(ref method, _) => method.decl.receiver_type(),
1376+
clean::TyMethodItem(ref method) => method.decl.receiver_type(),
13771377
_ => None,
13781378
};
13791379

13801380
if let Some(self_ty) = self_type_opt {
1381-
let (by_mut_ref, by_box, by_value) = match self_ty {
1382-
SelfTy::SelfBorrowed(_, mutability)
1383-
| SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
1381+
let (by_mut_ref, by_box, by_value) = match *self_ty {
1382+
clean::Type::BorrowedRef { mutability, .. } => {
13841383
(mutability == Mutability::Mut, false, false)
13851384
}
1386-
SelfTy::SelfExplicit(clean::Type::Path { path }) => {
1385+
clean::Type::Path { ref path } => {
13871386
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
13881387
}
1389-
SelfTy::SelfValue => (false, false, true),
1388+
clean::Type::SelfTy => (false, false, true),
13901389
_ => (false, false, false),
13911390
};
13921391

0 commit comments

Comments
 (0)