Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 715c5a0

Browse files
committedNov 11, 2024
Auto merge of rust-lang#132919 - matthiaskrgr:rollup-ogghyvp, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#120077 (Add Set entry API ) - rust-lang#132144 (Arbitrary self types v2: (unused) Receiver trait) - rust-lang#132297 (Document some `check_expr` methods, and other misc `hir_typeck` tweaks) - rust-lang#132820 (Add a default implementation for CodegenBackend::link) - rust-lang#132881 (triagebot: Autolabel rustdoc book) - rust-lang#132912 (Simplify some places that deal with generic parameter defaults) - rust-lang#132916 (Unvacation fmease) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 81eef2d + 2d02652 commit 715c5a0

File tree

27 files changed

+670
-243
lines changed

27 files changed

+670
-243
lines changed
 

‎compiler/rustc_codegen_cranelift/src/archive.rs

-12
This file was deleted.

‎compiler/rustc_codegen_cranelift/src/lib.rs

-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use rustc_codegen_ssa::CodegenResults;
4343
use rustc_codegen_ssa::back::versioned_llvm_target;
4444
use rustc_codegen_ssa::traits::CodegenBackend;
4545
use rustc_data_structures::profiling::SelfProfilerRef;
46-
use rustc_errors::ErrorGuaranteed;
4746
use rustc_metadata::EncodedMetadata;
4847
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4948
use rustc_session::Session;
@@ -56,7 +55,6 @@ use crate::prelude::*;
5655
mod abi;
5756
mod allocator;
5857
mod analyze;
59-
mod archive;
6058
mod base;
6159
mod cast;
6260
mod codegen_i128;
@@ -249,17 +247,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
249247
self.config.borrow().as_ref().unwrap(),
250248
)
251249
}
252-
253-
fn link(
254-
&self,
255-
sess: &Session,
256-
codegen_results: CodegenResults,
257-
outputs: &OutputFilenames,
258-
) -> Result<(), ErrorGuaranteed> {
259-
use rustc_codegen_ssa::back::link::link_binary;
260-
261-
link_binary(sess, &crate::archive::ArArchiveBuilderBuilder, &codegen_results, outputs)
262-
}
263250
}
264251

265252
fn target_triple(sess: &Session) -> target_lexicon::Triple {

‎compiler/rustc_codegen_gcc/src/archive.rs

-25
This file was deleted.

‎compiler/rustc_codegen_gcc/src/lib.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ extern crate rustc_driver;
5858

5959
mod abi;
6060
mod allocator;
61-
mod archive;
6261
mod asm;
6362
mod attributes;
6463
mod back;
@@ -103,7 +102,7 @@ use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBacken
103102
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
104103
use rustc_data_structures::fx::FxIndexMap;
105104
use rustc_data_structures::sync::IntoDynSyncSend;
106-
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
105+
use rustc_errors::DiagCtxtHandle;
107106
use rustc_metadata::EncodedMetadata;
108107
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
109108
use rustc_middle::ty::TyCtxt;
@@ -261,17 +260,6 @@ impl CodegenBackend for GccCodegenBackend {
261260
.join(sess)
262261
}
263262

264-
fn link(
265-
&self,
266-
sess: &Session,
267-
codegen_results: CodegenResults,
268-
outputs: &OutputFilenames,
269-
) -> Result<(), ErrorGuaranteed> {
270-
use rustc_codegen_ssa::back::link::link_binary;
271-
272-
link_binary(sess, &crate::archive::ArArchiveBuilderBuilder, &codegen_results, outputs)
273-
}
274-
275263
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
276264
target_features(sess, allow_unstable, &self.target_info)
277265
}

‎compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl CodegenBackend for LlvmCodegenBackend {
382382

383383
// Run the linker on any artifacts that resulted from the LLVM run.
384384
// This should produce either a finished executable or library.
385-
link_binary(sess, &LlvmArchiveBuilderBuilder, &codegen_results, outputs)
385+
link_binary(sess, &LlvmArchiveBuilderBuilder, codegen_results, outputs)
386386
}
387387
}
388388

‎compiler/rustc_codegen_ssa/src/back/archive.rs

+8
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ pub trait ArchiveBuilder {
304304
fn build(self: Box<Self>, output: &Path) -> bool;
305305
}
306306

307+
pub struct ArArchiveBuilderBuilder;
308+
309+
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
310+
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
311+
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
312+
}
313+
}
314+
307315
#[must_use = "must call build() to finish building the archive"]
308316
pub struct ArArchiveBuilder<'a> {
309317
sess: &'a Session,

‎compiler/rustc_codegen_ssa/src/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6969
pub fn link_binary(
7070
sess: &Session,
7171
archive_builder_builder: &dyn ArchiveBuilderBuilder,
72-
codegen_results: &CodegenResults,
72+
codegen_results: CodegenResults,
7373
outputs: &OutputFilenames,
7474
) -> Result<(), ErrorGuaranteed> {
7575
let _timer = sess.timer("link_binary");
@@ -116,7 +116,7 @@ pub fn link_binary(
116116
link_rlib(
117117
sess,
118118
archive_builder_builder,
119-
codegen_results,
119+
&codegen_results,
120120
RlibFlavor::Normal,
121121
&path,
122122
)?
@@ -126,7 +126,7 @@ pub fn link_binary(
126126
link_staticlib(
127127
sess,
128128
archive_builder_builder,
129-
codegen_results,
129+
&codegen_results,
130130
&out_filename,
131131
&path,
132132
)?;
@@ -137,7 +137,7 @@ pub fn link_binary(
137137
archive_builder_builder,
138138
crate_type,
139139
&out_filename,
140-
codegen_results,
140+
&codegen_results,
141141
path.as_ref(),
142142
)?;
143143
}

‎compiler/rustc_codegen_ssa/src/traits/backend.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use rustc_span::symbol::Symbol;
1616

1717
use super::CodegenObject;
1818
use super::write::WriteBackendMethods;
19+
use crate::back::archive::ArArchiveBuilderBuilder;
20+
use crate::back::link::link_binary;
1921
use crate::back::write::TargetMachineFactoryFn;
2022
use crate::{CodegenResults, ModuleCodegen};
2123

@@ -87,7 +89,9 @@ pub trait CodegenBackend {
8789
sess: &Session,
8890
codegen_results: CodegenResults,
8991
outputs: &OutputFilenames,
90-
) -> Result<(), ErrorGuaranteed>;
92+
) -> Result<(), ErrorGuaranteed> {
93+
link_binary(sess, &ArArchiveBuilderBuilder, codegen_results, outputs)
94+
}
9195

9296
/// Returns `true` if this backend can be safely called from multiple threads.
9397
///

‎compiler/rustc_hir/src/lang_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ language_item_table! {
241241
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
242242
DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0);
243243
DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None;
244+
Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None;
245+
ReceiverTarget, sym::receiver_target, receiver_target, Target::AssocTy, GenericRequirement::None;
244246
LegacyReceiver, sym::legacy_receiver, legacy_receiver_trait, Target::Trait, GenericRequirement::None;
245247

246248
Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1);

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

+23-75
Original file line numberDiff line numberDiff line change
@@ -1427,57 +1427,28 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14271427
let predicates = tcx.predicates_of(def_id.to_def_id());
14281428
let generics = tcx.generics_of(def_id);
14291429

1430-
let is_our_default = |def: &ty::GenericParamDef| match def.kind {
1431-
GenericParamDefKind::Type { has_default, .. }
1432-
| GenericParamDefKind::Const { has_default, .. } => {
1433-
has_default && def.index >= generics.parent_count as u32
1434-
}
1435-
GenericParamDefKind::Lifetime => {
1436-
span_bug!(tcx.def_span(def.def_id), "lifetime params can have no default")
1437-
}
1438-
};
1439-
14401430
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
14411431
// For example, this forbids the declaration:
14421432
//
14431433
// struct Foo<T = Vec<[u32]>> { .. }
14441434
//
14451435
// Here, the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
14461436
for param in &generics.own_params {
1447-
match param.kind {
1448-
GenericParamDefKind::Type { .. } => {
1449-
if is_our_default(param) {
1450-
let ty = tcx.type_of(param.def_id).instantiate_identity();
1451-
// Ignore dependent defaults -- that is, where the default of one type
1452-
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
1453-
// be sure if it will error or not as user might always specify the other.
1454-
if !ty.has_param() {
1455-
wfcx.register_wf_obligation(
1456-
tcx.def_span(param.def_id),
1457-
Some(WellFormedLoc::Ty(param.def_id.expect_local())),
1458-
ty.into(),
1459-
);
1460-
}
1461-
}
1462-
}
1463-
GenericParamDefKind::Const { .. } => {
1464-
if is_our_default(param) {
1465-
// FIXME(const_generics_defaults): This
1466-
// is incorrect when dealing with unused args, for example
1467-
// for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>`
1468-
// we should eagerly error.
1469-
let default_ct = tcx.const_param_default(param.def_id).instantiate_identity();
1470-
if !default_ct.has_param() {
1471-
wfcx.register_wf_obligation(
1472-
tcx.def_span(param.def_id),
1473-
None,
1474-
default_ct.into(),
1475-
);
1476-
}
1477-
}
1437+
if let Some(default) = param.default_value(tcx).map(ty::EarlyBinder::instantiate_identity) {
1438+
// Ignore dependent defaults -- that is, where the default of one type
1439+
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
1440+
// be sure if it will error or not as user might always specify the other.
1441+
// FIXME(generic_const_exprs): This is incorrect when dealing with unused const params.
1442+
// E.g: `struct Foo<const N: usize, const M: usize = { 1 - 2 }>;`. Here, we should
1443+
// eagerly error but we don't as we have `ConstKind::Unevaluated(.., [N, M])`.
1444+
if !default.has_param() {
1445+
wfcx.register_wf_obligation(
1446+
tcx.def_span(param.def_id),
1447+
matches!(param.kind, GenericParamDefKind::Type { .. })
1448+
.then(|| WellFormedLoc::Ty(param.def_id.expect_local())),
1449+
default,
1450+
);
14781451
}
1479-
// Doesn't have defaults.
1480-
GenericParamDefKind::Lifetime => {}
14811452
}
14821453
}
14831454

@@ -1490,39 +1461,16 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14901461
//
14911462
// First we build the defaulted generic parameters.
14921463
let args = GenericArgs::for_item(tcx, def_id.to_def_id(), |param, _| {
1493-
match param.kind {
1494-
GenericParamDefKind::Lifetime => {
1495-
// All regions are identity.
1496-
tcx.mk_param_from_def(param)
1497-
}
1498-
1499-
GenericParamDefKind::Type { .. } => {
1500-
// If the param has a default, ...
1501-
if is_our_default(param) {
1502-
let default_ty = tcx.type_of(param.def_id).instantiate_identity();
1503-
// ... and it's not a dependent default, ...
1504-
if !default_ty.has_param() {
1505-
// ... then instantiate it with the default.
1506-
return default_ty.into();
1507-
}
1508-
}
1509-
1510-
tcx.mk_param_from_def(param)
1511-
}
1512-
GenericParamDefKind::Const { .. } => {
1513-
// If the param has a default, ...
1514-
if is_our_default(param) {
1515-
let default_ct = tcx.const_param_default(param.def_id).instantiate_identity();
1516-
// ... and it's not a dependent default, ...
1517-
if !default_ct.has_param() {
1518-
// ... then instantiate it with the default.
1519-
return default_ct.into();
1520-
}
1521-
}
1522-
1523-
tcx.mk_param_from_def(param)
1524-
}
1464+
if param.index >= generics.parent_count as u32
1465+
// If the param has a default, ...
1466+
&& let Some(default) = param.default_value(tcx).map(ty::EarlyBinder::instantiate_identity)
1467+
// ... and it's not a dependent default, ...
1468+
&& !default.has_param()
1469+
{
1470+
// ... then instantiate it with the default.
1471+
return default;
15251472
}
1473+
tcx.mk_param_from_def(param)
15261474
});
15271475

15281476
// Now we build the instantiated predicates.

‎compiler/rustc_hir_typeck/src/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{Diverges, Expectation, FnCtxt, Needs};
1515

1616
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1717
#[instrument(skip(self), level = "debug", ret)]
18-
pub(crate) fn check_match(
18+
pub(crate) fn check_expr_match(
1919
&self,
2020
expr: &'tcx hir::Expr<'tcx>,
2121
scrut: &'tcx hir::Expr<'tcx>,

‎compiler/rustc_hir_typeck/src/callee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enum CallStep<'tcx> {
6262
}
6363

6464
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
65-
pub(crate) fn check_call(
65+
pub(crate) fn check_expr_call(
6666
&self,
6767
call_expr: &'tcx hir::Expr<'tcx>,
6868
callee_expr: &'tcx hir::Expr<'tcx>,
@@ -74,8 +74,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7474
.check_expr_with_expectation_and_args(
7575
callee_expr,
7676
Expectation::NoExpectation,
77-
arg_exprs,
78-
Some(call_expr),
77+
Some((call_expr, arg_exprs)),
7978
),
8079
_ => self.check_expr(callee_expr),
8180
};

‎compiler/rustc_hir_typeck/src/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub(super) fn check_fn<'a, 'tcx>(
137137
}
138138

139139
fcx.is_whole_body.set(true);
140-
fcx.check_return_expr(body.value, false);
140+
fcx.check_return_or_body_tail(body.value, false);
141141

142142
// Finalize the return check by taking the LUB of the return types
143143
// we saw and assigning it to the expected return type. This isn't
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.