Skip to content

Commit 706141b

Browse files
committed
Auto merge of #133940 - GuillaumeGomez:rollup-nm1cz5j, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #132155 (Always display first line of impl blocks even when collapsed) - #133256 (CI: use free runners for i686-gnu jobs) - #133607 (implement checks for tail calls) - #133821 (Replace black with ruff in `tidy`) - #133827 (CI: rfl: move job forward to Linux v6.13-rc1) - #133910 (Normalize target-cpus.rs stdout test for LLVM changes) - #133921 (Adapt codegen tests for NUW inference) - #133936 (Avoid fetching the anon const hir node that is already available) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c94848c + 5dc05a8 commit 706141b

File tree

82 files changed

+2774
-1158
lines changed

Some content is hidden

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

82 files changed

+2774
-1158
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ use rustc_errors::codes::*;
2929
use rustc_errors::{
3030
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, struct_span_code_err,
3131
};
32-
use rustc_hir as hir;
3332
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
3433
use rustc_hir::def_id::{DefId, LocalDefId};
35-
use rustc_hir::{GenericArg, GenericArgs, HirId};
34+
use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId};
3635
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
3736
use rustc_infer::traits::ObligationCause;
3837
use rustc_middle::middle::stability::AllowUnstable;
@@ -2089,7 +2088,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20892088
qpath.span(),
20902089
format!("Const::lower_const_arg: invalid qpath {qpath:?}"),
20912090
),
2092-
hir::ConstArgKind::Anon(anon) => self.lower_anon_const(anon.def_id),
2091+
hir::ConstArgKind::Anon(anon) => self.lower_anon_const(anon),
20932092
hir::ConstArgKind::Infer(span) => self.ct_infer(None, span),
20942093
}
20952094
}
@@ -2180,27 +2179,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21802179
/// Literals and const generic parameters are eagerly converted to a constant, everything else
21812180
/// becomes `Unevaluated`.
21822181
#[instrument(skip(self), level = "debug")]
2183-
fn lower_anon_const(&self, def: LocalDefId) -> Const<'tcx> {
2182+
fn lower_anon_const(&self, anon: &AnonConst) -> Const<'tcx> {
21842183
let tcx = self.tcx();
21852184

2186-
let body_id = match tcx.hir_node_by_def_id(def) {
2187-
hir::Node::AnonConst(ac) => ac.body,
2188-
node => span_bug!(
2189-
tcx.def_span(def.to_def_id()),
2190-
"from_anon_const can only process anonymous constants, not {node:?}"
2191-
),
2192-
};
2193-
2194-
let expr = &tcx.hir().body(body_id).value;
2185+
let expr = &tcx.hir().body(anon.body).value;
21952186
debug!(?expr);
21962187

2197-
let ty = tcx.type_of(def).no_bound_vars().expect("const parameter types cannot be generic");
2188+
let ty = tcx
2189+
.type_of(anon.def_id)
2190+
.no_bound_vars()
2191+
.expect("const parameter types cannot be generic");
21982192

21992193
match self.try_lower_anon_const_lit(ty, expr) {
22002194
Some(v) => v,
22012195
None => ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst {
2202-
def: def.to_def_id(),
2203-
args: ty::GenericArgs::identity_for_item(tcx, def.to_def_id()),
2196+
def: anon.def_id.to_def_id(),
2197+
args: ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()),
22042198
}),
22052199
}
22062200
}

compiler/rustc_middle/src/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ rustc_queries! {
916916
cache_on_disk_if { true }
917917
}
918918

919+
/// Checks well-formedness of tail calls (`become f()`).
920+
query check_tail_calls(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
921+
desc { |tcx| "tail-call-checking `{}`", tcx.def_path_str(key) }
922+
cache_on_disk_if { true }
923+
}
924+
919925
/// Returns the types assumed to be well formed while "inside" of the given item.
920926
///
921927
/// Note that we've liberated the late bound regions of function signatures, so

compiler/rustc_mir_build/src/build/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub(crate) fn mir_build<'tcx>(tcx: TyCtxtAt<'tcx>, def: LocalDefId) -> Body<'tcx
5050
return construct_error(tcx, def, e);
5151
}
5252

53+
if let Err(err) = tcx.check_tail_calls(def) {
54+
return construct_error(tcx, def, err);
55+
}
56+
5357
let body = match tcx.thir_body(def) {
5458
Err(error_reported) => construct_error(tcx, def, error_reported),
5559
Ok((thir, expr)) => {

0 commit comments

Comments
 (0)