Skip to content

Rollup of 7 pull requests #101882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fdf7ec8
Rustdoc-Json: Fix Type docs.
aDotInTheVoid Sep 12, 2022
3c184db
Fix raw-dylib with link_name
dpaoliello Sep 12, 2022
7794ea5
Prefer explict closure sig types over expected ones
oli-obk Sep 13, 2022
2506aa0
jsondoclint: New Tool
aDotInTheVoid Aug 23, 2022
404b60b
Constify impl Fn* &(mut) Fn*
onestacked Sep 13, 2022
478c471
Added Tracking Issue number.
onestacked Sep 14, 2022
a7a4fe9
jsondoclint: Tree Walk Validator
aDotInTheVoid Aug 24, 2022
bb1911d
jsondoclint: Add `Kind` abstraction
aDotInTheVoid Aug 24, 2022
5f1bc6f
jsondocck: Better errors
aDotInTheVoid Aug 24, 2022
41d35a9
jsondocck: Find path to Id's not in index
aDotInTheVoid Aug 24, 2022
c98c7cb
Primitives can appear in modules.
aDotInTheVoid Aug 30, 2022
5956b56
jsondoclint: Document validator
aDotInTheVoid Sep 14, 2022
393792d
Remove check_missing_items.py
aDotInTheVoid Sep 14, 2022
24c751b
Rustdoc-Json: Add test for extern_types
aDotInTheVoid Sep 14, 2022
6e21a28
jsondoclint: More precise `Path` checks
aDotInTheVoid Sep 14, 2022
f69a6c2
jsondoclint: Fix TODO's
aDotInTheVoid Sep 14, 2022
4cdf264
cache collect_trait_impl_trait_tys
compiler-errors Sep 9, 2022
7f1734c
rustdoc: remove no-op CSS `h1-4 { color: --main-color }`
notriddle Sep 15, 2022
b763cd5
Rollup merge of #101722 - aDotInTheVoid:rdy-ty-prim-docs, r=CraftSpider
Dylan-DPC Sep 16, 2022
61126d3
Rollup merge of #101738 - dpaoliello:linkname, r=petrochenkov
Dylan-DPC Sep 16, 2022
edf9e5e
Rollup merge of #101753 - oli-obk:tait_closure_args, r=compiler-errors
Dylan-DPC Sep 16, 2022
28b4c62
Rollup merge of #101787 - compiler-errors:cache-rpitit, r=petrochenkov
Dylan-DPC Sep 16, 2022
cfef659
Rollup merge of #101802 - chriss0612:const_fn_trait_ref_impls, r=fee1…
Dylan-DPC Sep 16, 2022
458555d
Rollup merge of #101809 - aDotInTheVoid:jsondoclint, r=GuillaumeGomez
Dylan-DPC Sep 16, 2022
18d3063
Rollup merge of #101864 - notriddle:notriddle/h1-h2-h3-h4, r=Guillaum…
Dylan-DPC Sep 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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