Skip to content

Commit fba9f33

Browse files
committed
Auto merge of rust-lang#107463 - Dylan-DPC:rollup-6mq1li8, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#101569 (Don't re-export private/unstable ArgumentV1 from `alloc`.) - rust-lang#106106 (Pass `branch.{branch}.remote=origin` to `git submodule update`) - rust-lang#107146 (Make `unsizing_params_for_adt` into a query) - rust-lang#107264 (Add option to include private items in library docs) - rust-lang#107452 (Fix typo in `{Rc, Arc}::get_mut_unchecked` docs) - rust-lang#107459 (end entry paragraph with a period (.)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3f25e56 + da56c44 commit fba9f33

File tree

14 files changed

+115
-58
lines changed

14 files changed

+115
-58
lines changed

compiler/rustc_middle/src/query/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ rustc_queries! {
183183
separate_provide_extern
184184
}
185185

186+
query unsizing_params_for_adt(key: DefId) -> rustc_index::bit_set::BitSet<u32>
187+
{
188+
arena_cache
189+
desc { |tcx|
190+
"determining what parameters of `{}` can participate in unsizing",
191+
tcx.def_path_str(key),
192+
}
193+
}
194+
186195
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
187196
eval_always
188197
desc { "running analysis passes on this crate" }

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+10-44
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
//! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation
99
use rustc_data_structures::stack::ensure_sufficient_stack;
1010
use rustc_hir::lang_items::LangItem;
11-
use rustc_index::bit_set::GrowableBitSet;
1211
use rustc_infer::infer::InferOk;
1312
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
1413
use rustc_middle::ty::{
15-
self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
16-
ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeVisitable,
14+
self, Binder, GenericParamDefKind, InternalSubsts, SubstsRef, ToPolyTraitRef, ToPredicate,
15+
TraitRef, Ty, TyCtxt, TypeVisitable,
1716
};
1817
use rustc_session::config::TraitSolver;
1918
use rustc_span::def_id::DefId;
@@ -1064,51 +1063,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10641063

10651064
// `Struct<T>` -> `Struct<U>`
10661065
(&ty::Adt(def, substs_a), &ty::Adt(_, substs_b)) => {
1067-
let maybe_unsizing_param_idx = |arg: GenericArg<'tcx>| match arg.unpack() {
1068-
GenericArgKind::Type(ty) => match ty.kind() {
1069-
ty::Param(p) => Some(p.index),
1070-
_ => None,
1071-
},
1072-
1073-
// Lifetimes aren't allowed to change during unsizing.
1074-
GenericArgKind::Lifetime(_) => None,
1075-
1076-
GenericArgKind::Const(ct) => match ct.kind() {
1077-
ty::ConstKind::Param(p) => Some(p.index),
1078-
_ => None,
1079-
},
1080-
};
1081-
1082-
// FIXME(eddyb) cache this (including computing `unsizing_params`)
1083-
// by putting it in a query; it would only need the `DefId` as it
1084-
// looks at declared field types, not anything substituted.
1085-
1086-
// The last field of the structure has to exist and contain type/const parameters.
1087-
let (tail_field, prefix_fields) =
1088-
def.non_enum_variant().fields.split_last().ok_or(Unimplemented)?;
1089-
let tail_field_ty = tcx.bound_type_of(tail_field.did);
1090-
1091-
let mut unsizing_params = GrowableBitSet::new_empty();
1092-
for arg in tail_field_ty.0.walk() {
1093-
if let Some(i) = maybe_unsizing_param_idx(arg) {
1094-
unsizing_params.insert(i);
1095-
}
1096-
}
1097-
1098-
// Ensure none of the other fields mention the parameters used
1099-
// in unsizing.
1100-
for field in prefix_fields {
1101-
for arg in tcx.type_of(field.did).walk() {
1102-
if let Some(i) = maybe_unsizing_param_idx(arg) {
1103-
unsizing_params.remove(i);
1104-
}
1105-
}
1106-
}
1107-
1066+
let unsizing_params = tcx.unsizing_params_for_adt(def.did());
11081067
if unsizing_params.is_empty() {
11091068
return Err(Unimplemented);
11101069
}
11111070

1071+
let tail_field = def
1072+
.non_enum_variant()
1073+
.fields
1074+
.last()
1075+
.expect("expected unsized ADT to have a tail field");
1076+
let tail_field_ty = tcx.bound_type_of(tail_field.did);
1077+
11121078
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`,
11131079
// normalizing in the process, since `type_of` returns something directly from
11141080
// astconv (which means it's un-normalized).

compiler/rustc_ty_utils/src/ty.rs

+52
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
3+
use rustc_index::bit_set::BitSet;
34
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
45
use rustc_session::config::TraitSolver;
56
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
@@ -406,6 +407,56 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
406407
node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness)
407408
}
408409

410+
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
411+
let def = tcx.adt_def(def_id);
412+
let num_params = tcx.generics_of(def_id).count();
413+
414+
let maybe_unsizing_param_idx = |arg: ty::GenericArg<'tcx>| match arg.unpack() {
415+
ty::GenericArgKind::Type(ty) => match ty.kind() {
416+
ty::Param(p) => Some(p.index),
417+
_ => None,
418+
},
419+
420+
// We can't unsize a lifetime
421+
ty::GenericArgKind::Lifetime(_) => None,
422+
423+
ty::GenericArgKind::Const(ct) => match ct.kind() {
424+
ty::ConstKind::Param(p) => Some(p.index),
425+
_ => None,
426+
},
427+
};
428+
429+
// FIXME(eddyb) cache this (including computing `unsizing_params`)
430+
// by putting it in a query; it would only need the `DefId` as it
431+
// looks at declared field types, not anything substituted.
432+
433+
// The last field of the structure has to exist and contain type/const parameters.
434+
let Some((tail_field, prefix_fields)) =
435+
def.non_enum_variant().fields.split_last() else
436+
{
437+
return BitSet::new_empty(num_params);
438+
};
439+
440+
let mut unsizing_params = BitSet::new_empty(num_params);
441+
for arg in tcx.bound_type_of(tail_field.did).subst_identity().walk() {
442+
if let Some(i) = maybe_unsizing_param_idx(arg) {
443+
unsizing_params.insert(i);
444+
}
445+
}
446+
447+
// Ensure none of the other fields mention the parameters used
448+
// in unsizing.
449+
for field in prefix_fields {
450+
for arg in tcx.bound_type_of(field.did).subst_identity().walk() {
451+
if let Some(i) = maybe_unsizing_param_idx(arg) {
452+
unsizing_params.remove(i);
453+
}
454+
}
455+
}
456+
457+
unsizing_params
458+
}
459+
409460
pub fn provide(providers: &mut ty::query::Providers) {
410461
*providers = ty::query::Providers {
411462
asyncness,
@@ -415,6 +466,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
415466
instance_def_size_estimate,
416467
issue33140_self_ty,
417468
impl_defaultness,
469+
unsizing_params_for_adt,
418470
..*providers
419471
};
420472
}

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ changelog-seen = 2
233233
# and generated in already-minified form from the beginning.
234234
#docs-minification = true
235235

236+
# Flag to specify whether private items should be included in the library docs.
237+
#library-docs-private-items = false
238+
236239
# Indicate whether the compiler should be documented in addition to the standard
237240
# library and facade crates.
238241
#compiler-docs = false

library/alloc/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ pub use core::fmt::Alignment;
558558
#[stable(feature = "rust1", since = "1.0.0")]
559559
pub use core::fmt::Error;
560560
#[stable(feature = "rust1", since = "1.0.0")]
561-
pub use core::fmt::{write, ArgumentV1, Arguments};
561+
pub use core::fmt::{write, Arguments};
562562
#[stable(feature = "rust1", since = "1.0.0")]
563563
pub use core::fmt::{Binary, Octal};
564564
#[stable(feature = "rust1", since = "1.0.0")]

library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ impl<T: ?Sized> Rc<T> {
10921092
/// # Safety
10931093
///
10941094
/// If any other `Rc` or [`Weak`] pointers to the same allocation exist, then
1095-
/// they must be must not be dereferenced or have active borrows for the duration
1095+
/// they must not be dereferenced or have active borrows for the duration
10961096
/// of the returned borrow, and their inner type must be exactly the same as the
10971097
/// inner type of this Rc (including lifetimes). This is trivially the case if no
10981098
/// such pointers exist, for example immediately after `Rc::new`.

library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ impl<T: ?Sized> Arc<T> {
17331733
/// # Safety
17341734
///
17351735
/// If any other `Arc` or [`Weak`] pointers to the same allocation exist, then
1736-
/// they must be must not be dereferenced or have active borrows for the duration
1736+
/// they must not be dereferenced or have active borrows for the duration
17371737
/// of the returned borrow, and their inner type must be exactly the same as the
17381738
/// inner type of this Rc (including lifetimes). This is trivially the case if no
17391739
/// such pointers exist, for example immediately after `Arc::new`.

library/core/src/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ macro_rules! int_impl {
55
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr,
66
$bound_condition:expr) => {
77
/// The smallest value that can be represented by this integer type
8-
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ")")]
8+
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ").")]
99
///
1010
/// # Examples
1111
///
@@ -18,7 +18,7 @@ macro_rules! int_impl {
1818
pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
1919

2020
/// The largest value that can be represented by this integer type
21-
#[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1", $bound_condition, ")")]
21+
#[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1", $bound_condition, ").")]
2222
///
2323
/// # Examples
2424
///

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct Config {
6565
pub verbose: usize,
6666
pub submodules: Option<bool>,
6767
pub compiler_docs: bool,
68+
pub library_docs_private_items: bool,
6869
pub docs_minification: bool,
6970
pub docs: bool,
7071
pub locked_deps: bool,
@@ -606,6 +607,7 @@ define_config! {
606607
rustfmt: Option<PathBuf> = "rustfmt",
607608
docs: Option<bool> = "docs",
608609
compiler_docs: Option<bool> = "compiler-docs",
610+
library_docs_private_items: Option<bool> = "library-docs-private-items",
609611
docs_minification: Option<bool> = "docs-minification",
610612
submodules: Option<bool> = "submodules",
611613
gdb: Option<String> = "gdb",
@@ -1018,6 +1020,7 @@ impl Config {
10181020
config.submodules = build.submodules;
10191021
set(&mut config.low_priority, build.low_priority);
10201022
set(&mut config.compiler_docs, build.compiler_docs);
1023+
set(&mut config.library_docs_private_items, build.library_docs_private_items);
10211024
set(&mut config.docs_minification, build.docs_minification);
10221025
set(&mut config.docs, build.docs);
10231026
set(&mut config.locked_deps, build.locked_deps);

src/bootstrap/doc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ fn doc_std(
597597
.arg("--resource-suffix")
598598
.arg(&builder.version)
599599
.args(extra_args);
600+
if builder.config.library_docs_private_items {
601+
cargo.arg("--document-private-items").arg("--document-hidden-items");
602+
}
600603
builder.run(&mut cargo.into());
601604
};
602605

src/bootstrap/lib.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use std::fs::{self, File};
110110
use std::io;
111111
use std::io::ErrorKind;
112112
use std::path::{Path, PathBuf};
113-
use std::process::Command;
113+
use std::process::{Command, Stdio};
114114
use std::str;
115115

116116
use build_helper::ci::CiEnv;
@@ -662,12 +662,32 @@ impl Build {
662662

663663
// Try passing `--progress` to start, then run git again without if that fails.
664664
let update = |progress: bool| {
665-
let mut git = Command::new("git");
665+
// Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
666+
// even though that has no relation to the upstream for the submodule.
667+
let current_branch = {
668+
let output = self
669+
.config
670+
.git()
671+
.args(["symbolic-ref", "--short", "HEAD"])
672+
.stderr(Stdio::inherit())
673+
.output();
674+
let output = t!(output);
675+
if output.status.success() {
676+
Some(String::from_utf8(output.stdout).unwrap().trim().to_owned())
677+
} else {
678+
None
679+
}
680+
};
681+
682+
let mut git = self.config.git();
683+
if let Some(branch) = current_branch {
684+
git.arg("-c").arg(format!("branch.{branch}.remote=origin"));
685+
}
666686
git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]);
667687
if progress {
668688
git.arg("--progress");
669689
}
670-
git.arg(relative_path).current_dir(&self.config.src);
690+
git.arg(relative_path);
671691
git
672692
};
673693
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.

tests/pretty/issue-4264.pp

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
((::alloc::fmt::format as
3535
for<'a> fn(Arguments<'a>) -> String {format})(((<#[lang = "format_arguments"]>::new_v1
3636
as
37-
fn(&[&'static str], &[ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
37+
fn(&[&'static str], &[core::fmt::ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
3838
as &str)] as [&str; 1]) as &[&str; 1]),
39-
(&([] as [ArgumentV1<'_>; 0]) as &[ArgumentV1<'_>; 0])) as
40-
Arguments<'_>)) as String);
39+
(&([] as [core::fmt::ArgumentV1<'_>; 0]) as
40+
&[core::fmt::ArgumentV1<'_>; 0])) as Arguments<'_>)) as
41+
String);
4142
(res as String)
4243
} as String);
4344
} as ())

tests/ui/fmt/ifmt-unimpl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | format!("{:X}", "3");
1515
NonZeroIsize
1616
and 21 others
1717
= note: required for `&str` to implement `UpperHex`
18-
note: required by a bound in `ArgumentV1::<'a>::new_upper_hex`
18+
note: required by a bound in `core::fmt::ArgumentV1::<'a>::new_upper_hex`
1919
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
2020
= note: this error originates in the macro `$crate::__export::format_args` which comes from the expansion of the macro `arg_new` (in Nightly builds, run with -Z macro-backtrace for more info)
2121

tests/ui/fmt/send-sync.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | send(format_args!("{:?}", c));
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: within `[ArgumentV1<'_>]`, the trait `Sync` is not implemented for `core::fmt::Opaque`
9+
= help: within `[core::fmt::ArgumentV1<'_>]`, the trait `Sync` is not implemented for `core::fmt::Opaque`
1010
= note: required because it appears within the type `&core::fmt::Opaque`
1111
= note: required because it appears within the type `ArgumentV1<'_>`
1212
= note: required because it appears within the type `[ArgumentV1<'_>]`
13-
= note: required for `&[ArgumentV1<'_>]` to implement `Send`
13+
= note: required for `&[core::fmt::ArgumentV1<'_>]` to implement `Send`
1414
= note: required because it appears within the type `Arguments<'_>`
1515
note: required by a bound in `send`
1616
--> $DIR/send-sync.rs:1:12

0 commit comments

Comments
 (0)