Auto merge of #107463 - Dylan-DPC:rollup-6mq1li8, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #101569 (Don't re-export private/unstable ArgumentV1 from `alloc`.)
 - #106106 (Pass `branch.{branch}.remote=origin` to `git submodule update`)
 - #107146 (Make `unsizing_params_for_adt` into a query)
 - #107264 (Add option to include private items in library docs)
 - #107452 (Fix typo in `{Rc, Arc}::get_mut_unchecked` docs)
 - #107459 (end entry paragraph with a period (.))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-01-30 11:14:21 +00:00
commit fba9f33c7c
14 changed files with 115 additions and 58 deletions

View File

@ -183,6 +183,15 @@ rustc_queries! {
separate_provide_extern
}
query unsizing_params_for_adt(key: DefId) -> rustc_index::bit_set::BitSet<u32>
{
arena_cache
desc { |tcx|
"determining what parameters of `{}` can participate in unsizing",
tcx.def_path_str(key),
}
}
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
eval_always
desc { "running analysis passes on this crate" }

View File

@ -8,12 +8,11 @@
//! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::GrowableBitSet;
use rustc_infer::infer::InferOk;
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
use rustc_middle::ty::{
self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeVisitable,
self, Binder, GenericParamDefKind, InternalSubsts, SubstsRef, ToPolyTraitRef, ToPredicate,
TraitRef, Ty, TyCtxt, TypeVisitable,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::DefId;
@ -1064,51 +1063,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// `Struct<T>` -> `Struct<U>`
(&ty::Adt(def, substs_a), &ty::Adt(_, substs_b)) => {
let maybe_unsizing_param_idx = |arg: GenericArg<'tcx>| match arg.unpack() {
GenericArgKind::Type(ty) => match ty.kind() {
ty::Param(p) => Some(p.index),
_ => None,
},
// Lifetimes aren't allowed to change during unsizing.
GenericArgKind::Lifetime(_) => None,
GenericArgKind::Const(ct) => match ct.kind() {
ty::ConstKind::Param(p) => Some(p.index),
_ => None,
},
};
// FIXME(eddyb) cache this (including computing `unsizing_params`)
// by putting it in a query; it would only need the `DefId` as it
// looks at declared field types, not anything substituted.
// The last field of the structure has to exist and contain type/const parameters.
let (tail_field, prefix_fields) =
def.non_enum_variant().fields.split_last().ok_or(Unimplemented)?;
let tail_field_ty = tcx.bound_type_of(tail_field.did);
let mut unsizing_params = GrowableBitSet::new_empty();
for arg in tail_field_ty.0.walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i);
}
}
// Ensure none of the other fields mention the parameters used
// in unsizing.
for field in prefix_fields {
for arg in tcx.type_of(field.did).walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.remove(i);
}
}
}
let unsizing_params = tcx.unsizing_params_for_adt(def.did());
if unsizing_params.is_empty() {
return Err(Unimplemented);
}
let tail_field = def
.non_enum_variant()
.fields
.last()
.expect("expected unsized ADT to have a tail field");
let tail_field_ty = tcx.bound_type_of(tail_field.did);
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`,
// normalizing in the process, since `type_of` returns something directly from
// astconv (which means it's un-normalized).

View File

@ -1,5 +1,6 @@
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
use rustc_index::bit_set::BitSet;
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
@ -406,6 +407,56 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness)
}
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
let def = tcx.adt_def(def_id);
let num_params = tcx.generics_of(def_id).count();
let maybe_unsizing_param_idx = |arg: ty::GenericArg<'tcx>| match arg.unpack() {
ty::GenericArgKind::Type(ty) => match ty.kind() {
ty::Param(p) => Some(p.index),
_ => None,
},
// We can't unsize a lifetime
ty::GenericArgKind::Lifetime(_) => None,
ty::GenericArgKind::Const(ct) => match ct.kind() {
ty::ConstKind::Param(p) => Some(p.index),
_ => None,
},
};
// FIXME(eddyb) cache this (including computing `unsizing_params`)
// by putting it in a query; it would only need the `DefId` as it
// looks at declared field types, not anything substituted.
// The last field of the structure has to exist and contain type/const parameters.
let Some((tail_field, prefix_fields)) =
def.non_enum_variant().fields.split_last() else
{
return BitSet::new_empty(num_params);
};
let mut unsizing_params = BitSet::new_empty(num_params);
for arg in tcx.bound_type_of(tail_field.did).subst_identity().walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.insert(i);
}
}
// Ensure none of the other fields mention the parameters used
// in unsizing.
for field in prefix_fields {
for arg in tcx.bound_type_of(field.did).subst_identity().walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.remove(i);
}
}
}
unsizing_params
}
pub fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers {
asyncness,
@ -415,6 +466,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
instance_def_size_estimate,
issue33140_self_ty,
impl_defaultness,
unsizing_params_for_adt,
..*providers
};
}

View File

@ -233,6 +233,9 @@ changelog-seen = 2
# and generated in already-minified form from the beginning.
#docs-minification = true
# Flag to specify whether private items should be included in the library docs.
#library-docs-private-items = false
# Indicate whether the compiler should be documented in addition to the standard
# library and facade crates.
#compiler-docs = false

View File

@ -558,7 +558,7 @@ pub use core::fmt::Alignment;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::Error;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{write, ArgumentV1, Arguments};
pub use core::fmt::{write, Arguments};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Binary, Octal};
#[stable(feature = "rust1", since = "1.0.0")]

View File

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

View File

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

View File

@ -5,7 +5,7 @@ macro_rules! int_impl {
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr,
$bound_condition:expr) => {
/// The smallest value that can be represented by this integer type
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ")")]
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ").")]
///
/// # Examples
///
@ -18,7 +18,7 @@ macro_rules! int_impl {
pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
/// The largest value that can be represented by this integer type
#[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1", $bound_condition, ")")]
#[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1", $bound_condition, ").")]
///
/// # Examples
///

View File

@ -65,6 +65,7 @@ pub struct Config {
pub verbose: usize,
pub submodules: Option<bool>,
pub compiler_docs: bool,
pub library_docs_private_items: bool,
pub docs_minification: bool,
pub docs: bool,
pub locked_deps: bool,
@ -606,6 +607,7 @@ define_config! {
rustfmt: Option<PathBuf> = "rustfmt",
docs: Option<bool> = "docs",
compiler_docs: Option<bool> = "compiler-docs",
library_docs_private_items: Option<bool> = "library-docs-private-items",
docs_minification: Option<bool> = "docs-minification",
submodules: Option<bool> = "submodules",
gdb: Option<String> = "gdb",
@ -1018,6 +1020,7 @@ impl Config {
config.submodules = build.submodules;
set(&mut config.low_priority, build.low_priority);
set(&mut config.compiler_docs, build.compiler_docs);
set(&mut config.library_docs_private_items, build.library_docs_private_items);
set(&mut config.docs_minification, build.docs_minification);
set(&mut config.docs, build.docs);
set(&mut config.locked_deps, build.locked_deps);

View File

@ -597,6 +597,9 @@ fn doc_std(
.arg("--resource-suffix")
.arg(&builder.version)
.args(extra_args);
if builder.config.library_docs_private_items {
cargo.arg("--document-private-items").arg("--document-hidden-items");
}
builder.run(&mut cargo.into());
};

View File

@ -110,7 +110,7 @@ use std::fs::{self, File};
use std::io;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::process::{Command, Stdio};
use std::str;
use build_helper::ci::CiEnv;
@ -662,12 +662,32 @@ impl Build {
// Try passing `--progress` to start, then run git again without if that fails.
let update = |progress: bool| {
let mut git = Command::new("git");
// Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
// even though that has no relation to the upstream for the submodule.
let current_branch = {
let output = self
.config
.git()
.args(["symbolic-ref", "--short", "HEAD"])
.stderr(Stdio::inherit())
.output();
let output = t!(output);
if output.status.success() {
Some(String::from_utf8(output.stdout).unwrap().trim().to_owned())
} else {
None
}
};
let mut git = self.config.git();
if let Some(branch) = current_branch {
git.arg("-c").arg(format!("branch.{branch}.remote=origin"));
}
git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]);
if progress {
git.arg("--progress");
}
git.arg(relative_path).current_dir(&self.config.src);
git.arg(relative_path);
git
};
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.

View File

@ -34,10 +34,11 @@ fn bar() ({
((::alloc::fmt::format as
for<'a> fn(Arguments<'a>) -> String {format})(((<#[lang = "format_arguments"]>::new_v1
as
fn(&[&'static str], &[ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
fn(&[&'static str], &[core::fmt::ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
as &str)] as [&str; 1]) as &[&str; 1]),
(&([] as [ArgumentV1<'_>; 0]) as &[ArgumentV1<'_>; 0])) as
Arguments<'_>)) as String);
(&([] as [core::fmt::ArgumentV1<'_>; 0]) as
&[core::fmt::ArgumentV1<'_>; 0])) as Arguments<'_>)) as
String);
(res as String)
} as String);
} as ())

View File

@ -15,7 +15,7 @@ LL | format!("{:X}", "3");
NonZeroIsize
and 21 others
= note: required for `&str` to implement `UpperHex`
note: required by a bound in `ArgumentV1::<'a>::new_upper_hex`
note: required by a bound in `core::fmt::ArgumentV1::<'a>::new_upper_hex`
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
= 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)

View File

@ -6,11 +6,11 @@ LL | send(format_args!("{:?}", c));
| |
| required by a bound introduced by this call
|
= help: within `[ArgumentV1<'_>]`, the trait `Sync` is not implemented for `core::fmt::Opaque`
= help: within `[core::fmt::ArgumentV1<'_>]`, the trait `Sync` is not implemented for `core::fmt::Opaque`
= note: required because it appears within the type `&core::fmt::Opaque`
= note: required because it appears within the type `ArgumentV1<'_>`
= note: required because it appears within the type `[ArgumentV1<'_>]`
= note: required for `&[ArgumentV1<'_>]` to implement `Send`
= note: required for `&[core::fmt::ArgumentV1<'_>]` to implement `Send`
= note: required because it appears within the type `Arguments<'_>`
note: required by a bound in `send`
--> $DIR/send-sync.rs:1:12