Skip to content

Commit 93543a3

Browse files
committed
Auto merge of #154047 - JonathanBrouwer:rollup-BXQD7Mr, r=<try>
Rollup of 5 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents 53d60bb + 7bb7eb6 commit 93543a3

32 files changed

+450
-46
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12691269
}
12701270
GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
12711271
}
1272-
ast::GenericArg::Const(ct) => GenericArg::Const(
1273-
self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
1274-
),
1272+
ast::GenericArg::Const(ct) => {
1273+
let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1274+
match ct.try_as_ambig_ct() {
1275+
Some(ct) => GenericArg::Const(ct),
1276+
None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
1277+
}
1278+
}
12751279
}
12761280
}
12771281

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,23 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
737737
TokenTree::Token(token, spacing) => {
738738
let token_str = self.token_to_string_ext(token, convert_dollar_crate);
739739
self.word(token_str);
740+
// Emit hygiene annotations for identity-bearing tokens,
741+
// matching how print_ident() and print_lifetime() call ann_post().
742+
match token.kind {
743+
token::Ident(name, _) => {
744+
self.ann_post(Ident::new(name, token.span));
745+
}
746+
token::NtIdent(ident, _) => {
747+
self.ann_post(ident);
748+
}
749+
token::Lifetime(name, _) => {
750+
self.ann_post(Ident::new(name, token.span));
751+
}
752+
token::NtLifetime(ident, _) => {
753+
self.ann_post(ident);
754+
}
755+
_ => {}
756+
}
740757
if let token::DocComment(..) = token.kind {
741758
self.hardbreak()
742759
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
28742874
span: Span,
28752875
) -> Const<'tcx> {
28762876
let tcx = self.tcx();
2877+
2878+
let ty = if !ty.has_infer() { Some(ty) } else { None };
2879+
28772880
if let LitKind::Err(guar) = *kind {
28782881
return ty::Const::new_error(tcx, guar);
28792882
}
@@ -2905,16 +2908,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
29052908
};
29062909

29072910
let lit_input = match expr.kind {
2908-
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: lit.node, ty, neg: false }),
2911+
hir::ExprKind::Lit(lit) => {
2912+
Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: false })
2913+
}
29092914
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
2910-
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: lit.node, ty, neg: true }),
2915+
hir::ExprKind::Lit(lit) => {
2916+
Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: true })
2917+
}
29112918
_ => None,
29122919
},
29132920
_ => None,
29142921
};
29152922

29162923
lit_input.and_then(|l| {
2917-
if const_lit_matches_ty(tcx, &l.lit, l.ty, l.neg) {
2924+
if const_lit_matches_ty(tcx, &l.lit, ty, l.neg) {
29182925
tcx.at(expr.span)
29192926
.lit_to_const(l)
29202927
.map(|value| ty::Const::new_value(tcx, value.valtree, value.ty))

compiler/rustc_lint/src/for_loops_over_fallibles.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
4949
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5050
let Some((pat, arg)) = extract_for_loop(expr) else { return };
5151

52+
// Do not put suggestions for external macros.
53+
if pat.span.from_expansion() {
54+
return;
55+
}
56+
5257
let arg_span = arg.span.source_callsite();
5358

5459
let ty = cx.typeck_results().expr_ty(arg);
@@ -77,6 +82,8 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
7782
};
7883

7984
let sub = if let Some(recv) = extract_iterator_next_call(cx, arg)
85+
&& recv.span.can_be_used_for_suggestions()
86+
&& recv.span.between(arg_span.shrink_to_hi()).can_be_used_for_suggestions()
8087
&& let Ok(recv_snip) = cx.sess().source_map().span_to_snippet(recv.span)
8188
{
8289
ForLoopsOverFalliblesLoopSub::RemoveNext {

compiler/rustc_middle/src/ty/consts/lit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ pub struct LitToConstInput<'tcx> {
1010
/// The absolute value of the resultant constant.
1111
pub lit: LitKind,
1212
/// The type of the constant.
13-
pub ty: Ty<'tcx>,
13+
///
14+
/// `None` is used by const generics when the type of the constant is unknown, e.g.
15+
/// if there are inference variables
16+
pub ty: Option<Ty<'tcx>>,
1417
/// If the constant is negative.
1518
pub neg: bool,
1619
}

compiler/rustc_mir_build/src/builder/expr/as_constant.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub(crate) fn as_constant_inner<'tcx>(
5050

5151
match *kind {
5252
ExprKind::Literal { lit, neg } => {
53-
let const_ = lit_to_mir_constant(tcx, LitToConstInput { lit: lit.node, ty, neg });
53+
let const_ =
54+
lit_to_mir_constant(tcx, LitToConstInput { lit: lit.node, ty: Some(ty), neg });
5455

5556
ConstOperand { span, user_ty: None, const_ }
5657
}
@@ -109,6 +110,8 @@ pub(crate) fn as_constant_inner<'tcx>(
109110
fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>) -> Const<'tcx> {
110111
let LitToConstInput { lit, ty, neg } = lit_input;
111112

113+
let ty = ty.expect("type of literal must be known at this point");
114+
112115
if let Err(guar) = ty.error_reported() {
113116
return Const::Ty(Ty::new_error(tcx, guar), ty::Const::new_error(tcx, guar));
114117
}

compiler/rustc_mir_build/src/thir/constant.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,27 @@ pub(crate) fn lit_to_const<'tcx>(
3131
.unwrap_or_else(|| bug!("expected to create ScalarInt from uint {:?}", result))
3232
};
3333

34-
let (valtree, valtree_ty) = match (lit, expected_ty.kind()) {
34+
let (valtree, valtree_ty) = match (lit, expected_ty.map(|ty| ty.kind())) {
3535
(ast::LitKind::Str(s, _), _) => {
3636
let str_bytes = s.as_str().as_bytes();
3737
let valtree_ty = Ty::new_imm_ref(tcx, tcx.lifetimes.re_static, tcx.types.str_);
3838
(ty::ValTree::from_raw_bytes(tcx, str_bytes), valtree_ty)
3939
}
40-
(ast::LitKind::ByteStr(byte_sym, _), ty::Ref(_, inner_ty, _))
40+
(ast::LitKind::ByteStr(byte_sym, _), Some(ty::Ref(_, inner_ty, _)))
4141
if let ty::Slice(ty) | ty::Array(ty, _) = inner_ty.kind()
4242
&& let ty::Uint(UintTy::U8) = ty.kind() =>
4343
{
44-
(ty::ValTree::from_raw_bytes(tcx, byte_sym.as_byte_str()), expected_ty)
44+
(ty::ValTree::from_raw_bytes(tcx, byte_sym.as_byte_str()), expected_ty.unwrap())
4545
}
46-
(ast::LitKind::ByteStr(byte_sym, _), ty::Slice(inner_ty) | ty::Array(inner_ty, _))
47-
if tcx.features().deref_patterns()
48-
&& let ty::Uint(UintTy::U8) = inner_ty.kind() =>
46+
(
47+
ast::LitKind::ByteStr(byte_sym, _),
48+
Some(ty::Slice(inner_ty) | ty::Array(inner_ty, _)),
49+
) if tcx.features().deref_patterns()
50+
&& let ty::Uint(UintTy::U8) = inner_ty.kind() =>
4951
{
5052
// Byte string literal patterns may have type `[u8]` or `[u8; N]` if `deref_patterns` is
5153
// enabled, in order to allow, e.g., `deref!(b"..."): Vec<u8>`.
52-
(ty::ValTree::from_raw_bytes(tcx, byte_sym.as_byte_str()), expected_ty)
54+
(ty::ValTree::from_raw_bytes(tcx, byte_sym.as_byte_str()), expected_ty.unwrap())
5355
}
5456
(ast::LitKind::ByteStr(byte_sym, _), _) => {
5557
let valtree = ty::ValTree::from_raw_bytes(tcx, byte_sym.as_byte_str());
@@ -79,11 +81,11 @@ pub(crate) fn lit_to_const<'tcx>(
7981
trunc(if neg { u128::wrapping_neg(n.get()) } else { n.get() }, i.to_unsigned());
8082
(ty::ValTree::from_scalar_int(tcx, scalar_int), Ty::new_int(tcx, i))
8183
}
82-
(ast::LitKind::Int(n, ast::LitIntType::Unsuffixed), ty::Uint(ui)) if !neg => {
84+
(ast::LitKind::Int(n, ast::LitIntType::Unsuffixed), Some(ty::Uint(ui))) if !neg => {
8385
let scalar_int = trunc(n.get(), *ui);
8486
(ty::ValTree::from_scalar_int(tcx, scalar_int), Ty::new_uint(tcx, *ui))
8587
}
86-
(ast::LitKind::Int(n, ast::LitIntType::Unsuffixed), ty::Int(i)) => {
88+
(ast::LitKind::Int(n, ast::LitIntType::Unsuffixed), Some(ty::Int(i))) => {
8789
// Unsigned "negation" has the same bitwise effect as signed negation,
8890
// which gets the result we want without additional casts.
8991
let scalar_int =
@@ -101,7 +103,7 @@ pub(crate) fn lit_to_const<'tcx>(
101103
let bits = parse_float_into_scalar(n, fty, neg)?;
102104
(ty::ValTree::from_scalar_int(tcx, bits), Ty::new_float(tcx, fty))
103105
}
104-
(ast::LitKind::Float(n, ast::LitFloatType::Unsuffixed), ty::Float(fty)) => {
106+
(ast::LitKind::Float(n, ast::LitFloatType::Unsuffixed), Some(ty::Float(fty))) => {
105107
let bits = parse_float_into_scalar(n, *fty, neg)?;
106108
(ty::ValTree::from_scalar_int(tcx, bits), Ty::new_float(tcx, *fty))
107109
}

compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl<'tcx> PatCtxt<'tcx> {
696696
// patterns to `str`, and byte-string literal patterns to `[u8; N]` or `[u8]`.
697697

698698
let pat_ty = self.typeck_results.node_type(pat.hir_id);
699-
let lit_input = LitToConstInput { lit: lit.node, ty: pat_ty, neg: *negated };
699+
let lit_input = LitToConstInput { lit: lit.node, ty: Some(pat_ty), neg: *negated };
700700
let constant = const_lit_matches_ty(self.tcx, &lit.node, pat_ty, *negated)
701701
.then(|| self.tcx.at(expr.span).lit_to_const(lit_input))
702702
.flatten()

compiler/rustc_ty_utils/src/consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ fn recurse_build<'tcx>(
5858
}
5959
&ExprKind::Literal { lit, neg } => {
6060
let sp = node.span;
61-
match tcx.at(sp).lit_to_const(LitToConstInput { lit: lit.node, ty: node.ty, neg }) {
61+
match tcx.at(sp).lit_to_const(LitToConstInput { lit: lit.node, ty: Some(node.ty), neg })
62+
{
6263
Some(value) => ty::Const::new_value(tcx, value.valtree, value.ty),
6364
None => ty::Const::new_misc_error(tcx),
6465
}

src/bootstrap/src/utils/exec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! relevant to command execution in the bootstrap process. This includes settings such as
88
//! dry-run mode, verbosity level, and failure behavior.
99
10+
use std::backtrace::{Backtrace, BacktraceStatus};
1011
use std::collections::HashMap;
1112
use std::ffi::{OsStr, OsString};
1213
use std::fmt::{Debug, Formatter};
@@ -930,6 +931,16 @@ Executed at: {executed_at}"#,
930931
if stderr.captures() {
931932
writeln!(error_message, "\n--- STDERR vvv\n{}", output.stderr().trim()).unwrap();
932933
}
934+
let backtrace = if exec_ctx.verbosity > 1 {
935+
Backtrace::force_capture()
936+
} else if matches!(command.failure_behavior, BehaviorOnFailure::Ignore) {
937+
Backtrace::disabled()
938+
} else {
939+
Backtrace::capture()
940+
};
941+
if matches!(backtrace.status(), BacktraceStatus::Captured) {
942+
writeln!(error_message, "\n--- BACKTRACE vvv\n{backtrace}").unwrap();
943+
}
933944

934945
match command.failure_behavior {
935946
BehaviorOnFailure::DelayFail => {

0 commit comments

Comments
 (0)