Skip to content

Commit 22f6aec

Browse files
committed
Auto merge of rust-lang#101882 - Dylan-DPC:rollup-9lxwuwj, r=Dylan-DPC
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
2 parents 0ee5a1a + 18d3063 commit 22f6aec

File tree

41 files changed

+1069
-263
lines changed

Some content is hidden

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

41 files changed

+1069
-263
lines changed

Cargo.lock

+16-6
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ dependencies = [
103103

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

110110
[[package]]
111111
name = "array_tool"
@@ -1362,9 +1362,9 @@ dependencies = [
13621362

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

13691369
[[package]]
13701370
name = "fs_extra"
@@ -1891,6 +1891,16 @@ dependencies = [
18911891
"shlex",
18921892
]
18931893

1894+
[[package]]
1895+
name = "jsondoclint"
1896+
version = "0.1.0"
1897+
dependencies = [
1898+
"anyhow",
1899+
"fs-err",
1900+
"rustdoc-json-types",
1901+
"serde_json",
1902+
]
1903+
18941904
[[package]]
18951905
name = "jsonpath_lib"
18961906
version = "0.2.6"
@@ -4445,9 +4455,9 @@ dependencies = [
44454455

44464456
[[package]]
44474457
name = "serde_json"
4448-
version = "1.0.83"
4458+
version = "1.0.85"
44494459
source = "registry+https://github.com/rust-lang/crates.io-index"
4450-
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
4460+
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
44514461
dependencies = [
44524462
"indexmap",
44534463
"itoa",

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ members = [
3333
"src/tools/unicode-table-generator",
3434
"src/tools/expand-yaml-anchors",
3535
"src/tools/jsondocck",
36+
"src/tools/jsondoclint",
3637
"src/tools/html-checker",
3738
"src/tools/bump-stage0",
3839
"src/tools/replace-version-placeholder",

compiler/rustc_metadata/src/native_libs.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,13 @@ impl<'tcx> Collector<'tcx> {
560560
}
561561
};
562562

563-
let import_name_type = self
564-
.tcx
565-
.codegen_fn_attrs(item.id.def_id)
563+
let codegen_fn_attrs = self.tcx.codegen_fn_attrs(item.id.def_id);
564+
let import_name_type = codegen_fn_attrs
566565
.link_ordinal
567566
.map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord)));
568567

569568
DllImport {
570-
name: item.ident.name,
569+
name: codegen_fn_attrs.link_name.unwrap_or(item.ident.name),
571570
import_name_type,
572571
calling_convention,
573572
span: item.span,

compiler/rustc_middle/src/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ macro_rules! arena_types {
102102

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

105-
[] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
105+
[decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
106106
]);
107107
)
108108
}

compiler/rustc_middle/src/query/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ rustc_queries! {
164164
query collect_trait_impl_trait_tys(key: DefId)
165165
-> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
166166
{
167-
desc { "better description please" }
167+
desc { "compare an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
168+
cache_on_disk_if { key.is_local() }
168169
separate_provide_extern
169170
}
170171

compiler/rustc_query_impl/src/on_disk_cache.rs

+6
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashSet<LocalDefId>
798798
}
799799
}
800800

801+
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashMap<DefId, Ty<'tcx>> {
802+
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
803+
RefDecodable::decode(d)
804+
}
805+
}
806+
801807
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
802808
for &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>>
803809
{

compiler/rustc_typeck/src/check/closure.rs

+39-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ struct ExpectedSig<'tcx> {
3030
}
3131

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

@@ -444,18 +449,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
444449
// Along the way, it also writes out entries for types that the user
445450
// wrote into our typeck results, which are then later used by the privacy
446451
// check.
447-
match self.check_supplied_sig_against_expectation(
452+
match self.merge_supplied_sig_with_expectation(
448453
hir_id,
449454
expr_def_id,
450455
decl,
451456
body,
452-
&closure_sigs,
457+
closure_sigs,
453458
) {
454459
Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
455-
Err(_) => return self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body),
460+
Err(_) => self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body),
456461
}
457-
458-
closure_sigs
459462
}
460463

461464
fn sig_of_closure_with_mismatched_number_of_arguments(
@@ -497,21 +500,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
497500
/// Enforce the user's types against the expectation. See
498501
/// `sig_of_closure_with_expectation` for details on the overall
499502
/// strategy.
500-
fn check_supplied_sig_against_expectation(
503+
#[instrument(level = "debug", skip(self, hir_id, expr_def_id, decl, body, expected_sigs))]
504+
fn merge_supplied_sig_with_expectation(
501505
&self,
502506
hir_id: hir::HirId,
503507
expr_def_id: DefId,
504508
decl: &hir::FnDecl<'_>,
505509
body: &hir::Body<'_>,
506-
expected_sigs: &ClosureSignatures<'tcx>,
507-
) -> InferResult<'tcx, ()> {
510+
mut expected_sigs: ClosureSignatures<'tcx>,
511+
) -> InferResult<'tcx, ClosureSignatures<'tcx>> {
508512
// Get the signature S that the user gave.
509513
//
510514
// (See comment on `sig_of_closure_with_expectation` for the
511515
// meaning of these letters.)
512516
let supplied_sig = self.supplied_sig_of_closure(hir_id, expr_def_id, decl, body);
513517

514-
debug!("check_supplied_sig_against_expectation: supplied_sig={:?}", supplied_sig);
518+
debug!(?supplied_sig);
515519

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

533551
// The liberated version of this signature should be a subtype
534552
// of the liberated form of the expectation.
535553
for ((hir_ty, &supplied_ty), expected_ty) in iter::zip(
536-
iter::zip(
537-
decl.inputs,
538-
supplied_sig.inputs().skip_binder(), // binder moved to (*) below
539-
),
554+
iter::zip(decl.inputs, &inputs),
540555
expected_sigs.liberated_sig.inputs(), // `liberated_sig` is E'.
541556
) {
542-
// Instantiate (this part of..) S to S', i.e., with fresh variables.
543-
let supplied_ty = self.replace_bound_vars_with_fresh_vars(
544-
hir_ty.span,
545-
LateBoundRegionConversionTime::FnCall,
546-
supplied_sig.inputs().rebind(supplied_ty),
547-
); // recreated from (*) above
548-
549557
// Check that E' = S'.
550558
let cause = self.misc(hir_ty.span);
551559
let InferOk { value: (), obligations } =
@@ -564,7 +572,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
564572
.eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
565573
all_obligations.extend(obligations);
566574

567-
Ok(InferOk { value: (), obligations: all_obligations })
575+
let inputs = inputs.into_iter().map(|ty| self.resolve_vars_if_possible(ty));
576+
577+
expected_sigs.liberated_sig = self.tcx.mk_fn_sig(
578+
inputs,
579+
supplied_output_ty,
580+
expected_sigs.liberated_sig.c_variadic,
581+
hir::Unsafety::Normal,
582+
Abi::RustCall,
583+
);
584+
585+
Ok(InferOk { value: expected_sigs, obligations: all_obligations })
568586
})
569587
}
570588

library/core/src/ops/function.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,32 @@ pub trait FnOnce<Args> {
250250

251251
mod impls {
252252
#[stable(feature = "rust1", since = "1.0.0")]
253-
impl<A, F: ?Sized> Fn<A> for &F
253+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
254+
impl<A, F: ?Sized> const Fn<A> for &F
254255
where
255-
F: Fn<A>,
256+
F: ~const Fn<A>,
256257
{
257258
extern "rust-call" fn call(&self, args: A) -> F::Output {
258259
(**self).call(args)
259260
}
260261
}
261262

262263
#[stable(feature = "rust1", since = "1.0.0")]
263-
impl<A, F: ?Sized> FnMut<A> for &F
264+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
265+
impl<A, F: ?Sized> const FnMut<A> for &F
264266
where
265-
F: Fn<A>,
267+
F: ~const Fn<A>,
266268
{
267269
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
268270
(**self).call(args)
269271
}
270272
}
271273

272274
#[stable(feature = "rust1", since = "1.0.0")]
273-
impl<A, F: ?Sized> FnOnce<A> for &F
275+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
276+
impl<A, F: ?Sized> const FnOnce<A> for &F
274277
where
275-
F: Fn<A>,
278+
F: ~const Fn<A>,
276279
{
277280
type Output = F::Output;
278281

@@ -282,19 +285,21 @@ mod impls {
282285
}
283286

284287
#[stable(feature = "rust1", since = "1.0.0")]
285-
impl<A, F: ?Sized> FnMut<A> for &mut F
288+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
289+
impl<A, F: ?Sized> const FnMut<A> for &mut F
286290
where
287-
F: FnMut<A>,
291+
F: ~const FnMut<A>,
288292
{
289293
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
290294
(*self).call_mut(args)
291295
}
292296
}
293297

294298
#[stable(feature = "rust1", since = "1.0.0")]
295-
impl<A, F: ?Sized> FnOnce<A> for &mut F
299+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
300+
impl<A, F: ?Sized> const FnOnce<A> for &mut F
296301
where
297-
F: FnMut<A>,
302+
F: ~const FnMut<A>,
298303
{
299304
type Output = F::Output;
300305
extern "rust-call" fn call_once(self, args: A) -> F::Output {

src/bootstrap/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13411341
let json_compiler = compiler.with_stage(0);
13421342
cmd.arg("--jsondocck-path")
13431343
.arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1344+
cmd.arg("--jsondoclint-path")
1345+
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
13441346
}
13451347

13461348
if mode == "run-make" {

src/bootstrap/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ bootstrap_tool!(
376376
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
377377
LintDocs, "src/tools/lint-docs", "lint-docs";
378378
JsonDocCk, "src/tools/jsondocck", "jsondocck";
379+
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
379380
HtmlChecker, "src/tools/html-checker", "html-checker";
380381
BumpStage0, "src/tools/bump-stage0", "bump-stage0";
381382
ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";

0 commit comments

Comments
 (0)