Skip to content

Commit 491208f

Browse files
committed
Auto merge of #154079 - Zalathar:rollup-ss1ohNa, r=<try>
Rollup of 20 pull requests try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: test-various try-job: armhf-gnu try-job: aarch64-apple try-job: aarch64-msvc-1
2 parents fd0c901 + 773e481 commit 491208f

File tree

114 files changed

+1773
-1021
lines changed

Some content is hidden

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

114 files changed

+1773
-1021
lines changed

bootstrap.example.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,10 @@
10131013
# its historical default, but when compiling the compiler itself, we skip it by
10141014
# default since we know it's safe to do so in that case.
10151015
#
1016-
# On Windows platforms, packed debuginfo is the only supported option,
1017-
# producing a `.pdb` file.
1018-
#split-debuginfo = if linux { off } else if windows { packed } else if apple { unpacked }
1016+
# On Windows MSVC platforms, packed debuginfo is the only supported option,
1017+
# producing a `.pdb` file. On Windows GNU rustc doesn't support splitting debuginfo,
1018+
# and enabling it causes issues.
1019+
#split-debuginfo = if linux || windows-gnu { off } else if windows-msvc { packed } else if apple { unpacked }
10191020

10201021
# Path to the `llvm-config` binary of the installation of a custom LLVM to link
10211022
# against. Note that if this is specified we don't compile LLVM at all for this

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
13101310
}
13111311
GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
13121312
}
1313-
ast::GenericArg::Const(ct) => GenericArg::Const(
1314-
self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
1315-
),
1313+
ast::GenericArg::Const(ct) => {
1314+
let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1315+
match ct.try_as_ambig_ct() {
1316+
Some(ct) => GenericArg::Const(ct),
1317+
None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
1318+
}
1319+
}
13161320
}
13171321
}
13181322

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_borrowck/src/type_check/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
374374
self.body
375375
}
376376

377-
fn unsized_feature_enabled(&self) -> bool {
378-
self.tcx().features().unsized_fn_params()
379-
}
380-
381377
/// Equate the inferred type and the annotated type for user type annotations
382378
#[instrument(skip(self), level = "debug")]
383379
fn check_user_type_annotations(&mut self) {
@@ -660,7 +656,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
660656
);
661657
}
662658

663-
if !self.unsized_feature_enabled() {
659+
if !self.tcx().features().unsized_fn_params() {
664660
let trait_ref = ty::TraitRef::new(
665661
tcx,
666662
tcx.require_lang_item(LangItem::Sized, self.last_span),
@@ -936,9 +932,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
936932
}
937933
}
938934

939-
// When `unsized_fn_params` is enabled, only function calls
940-
// and nullary ops are checked in `check_call_dest`.
941-
if !self.unsized_feature_enabled() {
935+
// When `unsized_fn_params` is enabled, this is checked in `check_call_dest`,
936+
// and `hir_typeck` still forces all non-argument locals to be sized (i.e., we don't
937+
// fully re-check what was already checked on HIR).
938+
if !self.tcx().features().unsized_fn_params() {
942939
match self.body.local_kind(local) {
943940
LocalKind::ReturnPointer | LocalKind::Arg => {
944941
// return values of normal functions are required to be
@@ -1953,8 +1950,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19531950
}
19541951

19551952
// When `unsized_fn_params` is not enabled,
1956-
// this check is done at `check_local`.
1957-
if self.unsized_feature_enabled() {
1953+
// this check is done at `visit_local_decl`.
1954+
if self.tcx().features().unsized_fn_params() {
19581955
let span = term.source_info.span;
19591956
self.ensure_place_sized(dest_ty, span);
19601957
}

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_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::attrs::DivergingBlockBehavior;
1111
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
1212
use rustc_hir::def_id::DefId;
1313
use rustc_hir::intravisit::Visitor;
14-
use rustc_hir::{Expr, ExprKind, HirId, LangItem, Node, QPath, is_range_literal};
14+
use rustc_hir::{Expr, ExprKind, FnRetTy, HirId, LangItem, Node, QPath, is_range_literal};
1515
use rustc_hir_analysis::check::potentially_plural_count;
1616
use rustc_hir_analysis::hir_ty_lowering::{HirTyLowerer, PermitVariants};
1717
use rustc_index::IndexVec;
@@ -1587,6 +1587,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15871587
}
15881588
}
15891589
err.span_note(spans, format!("{} defined here", self.tcx.def_descr(def_id)));
1590+
if let DefKind::Fn | DefKind::AssocFn = self.tcx.def_kind(def_id)
1591+
&& let ty::Param(_) =
1592+
self.tcx.fn_sig(def_id).instantiate_identity().skip_binder().output().kind()
1593+
&& let parent = self.tcx.hir_get_parent_item(call_expr.hir_id).def_id
1594+
&& let Some((output, body_id)) = match self.tcx.hir_node_by_def_id(parent) {
1595+
hir::Node::Item(hir::Item {
1596+
kind: hir::ItemKind::Fn { sig, body, .. },
1597+
..
1598+
})
1599+
| hir::Node::TraitItem(hir::TraitItem {
1600+
kind: hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body)),
1601+
..
1602+
})
1603+
| hir::Node::ImplItem(hir::ImplItem {
1604+
kind: hir::ImplItemKind::Fn(sig, body),
1605+
..
1606+
}) => Some((sig.decl.output, body)),
1607+
_ => None,
1608+
}
1609+
&& let expr = self.tcx.hir_body(*body_id).value
1610+
&& (expr.peel_blocks().span == call_expr.span
1611+
|| matches!(
1612+
self.tcx.parent_hir_node(call_expr.hir_id),
1613+
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. })
1614+
))
1615+
{
1616+
err.span_label(
1617+
output.span(),
1618+
match output {
1619+
FnRetTy::DefaultReturn(_) => format!(
1620+
"this implicit `()` return type influences the call expression's return type"
1621+
),
1622+
FnRetTy::Return(_) => {
1623+
"this return type influences the call expression's return type"
1624+
.to_string()
1625+
}
1626+
},
1627+
);
1628+
}
15901629
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir_get_if_local(def_id)
15911630
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
15921631
{

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
}

0 commit comments

Comments
 (0)