Skip to content

Commit

Permalink
Auto merge of rust-lang#101882 - Dylan-DPC:rollup-9lxwuwj, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#101722 (Rustdoc-Json: Fix Type docs.)
 - rust-lang#101738 (Fix `#[link kind="raw-dylib"]` to respect `#[link_name]`)
 - rust-lang#101753 (Prefer explict closure sig types over expected ones)
 - rust-lang#101787 (cache `collect_trait_impl_trait_tys`)
 - rust-lang#101802 (Constify impl Fn* &(mut) Fn*)
 - rust-lang#101809 (Replace `check_missing_items.py` with `jsondoclint`)
 - rust-lang#101864 (rustdoc: remove no-op CSS `h1-4 { color: --main-color }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 16, 2022
2 parents 0ee5a1a + 18d3063 commit 22f6aec
Show file tree
Hide file tree
Showing 41 changed files with 1,069 additions and 263 deletions.
22 changes: 16 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ dependencies = [

[[package]]
name = "anyhow"
version = "1.0.60"
version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142"
checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"

[[package]]
name = "array_tool"
Expand Down Expand Up @@ -1362,9 +1362,9 @@ dependencies = [

[[package]]
name = "fs-err"
version = "2.5.0"
version = "2.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcd1163ae48bda72a20ae26d66a04d3094135cadab911cff418ae5e33f253431"
checksum = "64db3e262960f0662f43a6366788d5f10f7f244b8f7d7d987f560baf5ded5c50"

[[package]]
name = "fs_extra"
Expand Down Expand Up @@ -1891,6 +1891,16 @@ dependencies = [
"shlex",
]

[[package]]
name = "jsondoclint"
version = "0.1.0"
dependencies = [
"anyhow",
"fs-err",
"rustdoc-json-types",
"serde_json",
]

[[package]]
name = "jsonpath_lib"
version = "0.2.6"
Expand Down Expand Up @@ -4445,9 +4455,9 @@ dependencies = [

[[package]]
name = "serde_json"
version = "1.0.83"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
dependencies = [
"indexmap",
"itoa",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"src/tools/unicode-table-generator",
"src/tools/expand-yaml-anchors",
"src/tools/jsondocck",
"src/tools/jsondoclint",
"src/tools/html-checker",
"src/tools/bump-stage0",
"src/tools/replace-version-placeholder",
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,13 @@ impl<'tcx> Collector<'tcx> {
}
};

let import_name_type = self
.tcx
.codegen_fn_attrs(item.id.def_id)
let codegen_fn_attrs = self.tcx.codegen_fn_attrs(item.id.def_id);
let import_name_type = codegen_fn_attrs
.link_ordinal
.map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord)));

DllImport {
name: item.ident.name,
name: codegen_fn_attrs.link_name.unwrap_or(item.ident.name),
import_name_type,
calling_convention,
span: item.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ macro_rules! arena_types {

[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,

[] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
[decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
]);
)
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ rustc_queries! {
query collect_trait_impl_trait_tys(key: DefId)
-> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
{
desc { "better description please" }
desc { "compare an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
cache_on_disk_if { key.is_local() }
separate_provide_extern
}

Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_query_impl/src/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashSet<LocalDefId>
}
}

impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashMap<DefId, Ty<'tcx>> {
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
RefDecodable::decode(d)
}
}

impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
for &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>>
{
Expand Down
60 changes: 39 additions & 21 deletions compiler/rustc_typeck/src/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ struct ExpectedSig<'tcx> {
}

struct ClosureSignatures<'tcx> {
/// The signature users of the closure see.
bound_sig: ty::PolyFnSig<'tcx>,
/// The signature within the function body.
/// This mostly differs in the sense that lifetimes are now early bound and any
/// opaque types from the signature expectation are overriden in case there are
/// explicit hidden types written by the user in the closure signature.
liberated_sig: ty::FnSig<'tcx>,
}

Expand Down Expand Up @@ -444,18 +449,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Along the way, it also writes out entries for types that the user
// wrote into our typeck results, which are then later used by the privacy
// check.
match self.check_supplied_sig_against_expectation(
match self.merge_supplied_sig_with_expectation(
hir_id,
expr_def_id,
decl,
body,
&closure_sigs,
closure_sigs,
) {
Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
Err(_) => return self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body),
Err(_) => self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body),
}

closure_sigs
}

fn sig_of_closure_with_mismatched_number_of_arguments(
Expand Down Expand Up @@ -497,21 +500,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Enforce the user's types against the expectation. See
/// `sig_of_closure_with_expectation` for details on the overall
/// strategy.
fn check_supplied_sig_against_expectation(
#[instrument(level = "debug", skip(self, hir_id, expr_def_id, decl, body, expected_sigs))]
fn merge_supplied_sig_with_expectation(
&self,
hir_id: hir::HirId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
expected_sigs: &ClosureSignatures<'tcx>,
) -> InferResult<'tcx, ()> {
mut expected_sigs: ClosureSignatures<'tcx>,
) -> InferResult<'tcx, ClosureSignatures<'tcx>> {
// Get the signature S that the user gave.
//
// (See comment on `sig_of_closure_with_expectation` for the
// meaning of these letters.)
let supplied_sig = self.supplied_sig_of_closure(hir_id, expr_def_id, decl, body);

debug!("check_supplied_sig_against_expectation: supplied_sig={:?}", supplied_sig);
debug!(?supplied_sig);

// FIXME(#45727): As discussed in [this comment][c1], naively
// forcing equality here actually results in suboptimal error
Expand All @@ -529,23 +533,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// [c2]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341096796
self.commit_if_ok(|_| {
let mut all_obligations = vec![];
let inputs: Vec<_> = iter::zip(
decl.inputs,
supplied_sig.inputs().skip_binder(), // binder moved to (*) below
)
.map(|(hir_ty, &supplied_ty)| {
// Instantiate (this part of..) S to S', i.e., with fresh variables.
self.replace_bound_vars_with_fresh_vars(
hir_ty.span,
LateBoundRegionConversionTime::FnCall,
// (*) binder moved to here
supplied_sig.inputs().rebind(supplied_ty),
)
})
.collect();

// The liberated version of this signature should be a subtype
// of the liberated form of the expectation.
for ((hir_ty, &supplied_ty), expected_ty) in iter::zip(
iter::zip(
decl.inputs,
supplied_sig.inputs().skip_binder(), // binder moved to (*) below
),
iter::zip(decl.inputs, &inputs),
expected_sigs.liberated_sig.inputs(), // `liberated_sig` is E'.
) {
// Instantiate (this part of..) S to S', i.e., with fresh variables.
let supplied_ty = self.replace_bound_vars_with_fresh_vars(
hir_ty.span,
LateBoundRegionConversionTime::FnCall,
supplied_sig.inputs().rebind(supplied_ty),
); // recreated from (*) above

// Check that E' = S'.
let cause = self.misc(hir_ty.span);
let InferOk { value: (), obligations } =
Expand All @@ -564,7 +572,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
all_obligations.extend(obligations);

Ok(InferOk { value: (), obligations: all_obligations })
let inputs = inputs.into_iter().map(|ty| self.resolve_vars_if_possible(ty));

expected_sigs.liberated_sig = self.tcx.mk_fn_sig(
inputs,
supplied_output_ty,
expected_sigs.liberated_sig.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
);

Ok(InferOk { value: expected_sigs, obligations: all_obligations })
})
}

Expand Down
25 changes: 15 additions & 10 deletions library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,32 @@ pub trait FnOnce<Args> {

mod impls {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> Fn<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A, F: ?Sized> const Fn<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
extern "rust-call" fn call(&self, args: A) -> F::Output {
(**self).call(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnMut<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A, F: ?Sized> const FnMut<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(**self).call(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnOnce<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A, F: ?Sized> const FnOnce<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
type Output = F::Output;

Expand All @@ -282,19 +285,21 @@ mod impls {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnMut<A> for &mut F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A, F: ?Sized> const FnMut<A> for &mut F
where
F: FnMut<A>,
F: ~const FnMut<A>,
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(*self).call_mut(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnOnce<A> for &mut F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A, F: ?Sized> const FnOnce<A> for &mut F
where
F: FnMut<A>,
F: ~const FnMut<A>,
{
type Output = F::Output;
extern "rust-call" fn call_once(self, args: A) -> F::Output {
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
let json_compiler = compiler.with_stage(0);
cmd.arg("--jsondocck-path")
.arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
cmd.arg("--jsondoclint-path")
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
}

if mode == "run-make" {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ bootstrap_tool!(
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
LintDocs, "src/tools/lint-docs", "lint-docs";
JsonDocCk, "src/tools/jsondocck", "jsondocck";
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
HtmlChecker, "src/tools/html-checker", "html-checker";
BumpStage0, "src/tools/bump-stage0", "bump-stage0";
ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";
Expand Down
Loading

0 comments on commit 22f6aec

Please sign in to comment.