Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6e78d9b

Browse files
committed
Auto merge of rust-lang#138516 - fmease:rollup-6afhd1u, r=fmease
Rollup of 8 pull requests Successful merges: - rust-lang#138056 (rustc_target: Add target features for LoongArch v1.1) - rust-lang#138349 (Emit function declarations for functions with `#[linkage="extern_weak"]`) - rust-lang#138451 (Build GCC on CI with GCC, not Clang) - rust-lang#138454 (Improve post-merge workflow) - rust-lang#138460 (Pass struct field HirId when check_expr_struct_fields) - rust-lang#138482 (Fix HIR printing of parameters) - rust-lang#138507 (Mirror NetBSD sources) - rust-lang#138511 (Make `Parser::parse_expr_cond` public) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ecade53 + 5472e59 commit 6e78d9b

File tree

31 files changed

+511
-188
lines changed

31 files changed

+511
-188
lines changed

.github/workflows/post-merge.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ jobs:
3535
3636
cd src/ci/citool
3737
38-
echo "Post-merge analysis result" > output.log
38+
printf "*This is an experimental post-merge analysis report. You can ignore it.*\n\n" > output.log
39+
printf "<details>\n<summary>Post-merge report</summary>\n\n" >> output.log
40+
3941
cargo run --release post-merge-report ${PARENT_COMMIT} ${{ github.sha }} >> output.log
42+
43+
printf "</details>\n" >> output.log
44+
4045
cat output.log
4146
4247
gh pr comment ${HEAD_PR} -F output.log

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15161516
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
15171517
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
15181518
PatKind::Ident(_, ident, _) => self.lower_ident(ident),
1519-
_ => Ident::new(kw::Empty, self.lower_span(param.pat.span)),
1519+
PatKind::Wild => Ident::new(kw::Underscore, self.lower_span(param.pat.span)),
1520+
_ => {
1521+
self.dcx().span_delayed_bug(
1522+
param.pat.span,
1523+
"non-ident/wild param pat must trigger an error",
1524+
);
1525+
Ident::new(kw::Empty, self.lower_span(param.pat.span))
1526+
}
15201527
}))
15211528
}
15221529

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ use rustc_abi::{
55
};
66
use rustc_codegen_ssa::common;
77
use rustc_codegen_ssa::traits::*;
8+
use rustc_hir::LangItem;
89
use rustc_hir::def::DefKind;
910
use rustc_hir::def_id::DefId;
1011
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1112
use rustc_middle::mir::interpret::{
1213
Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar,
1314
read_target_uint,
1415
};
15-
use rustc_middle::mir::mono::MonoItem;
16-
use rustc_middle::ty::Instance;
16+
use rustc_middle::mir::mono::{Linkage, MonoItem};
1717
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
18+
use rustc_middle::ty::{self, Instance};
1819
use rustc_middle::{bug, span_bug};
1920
use tracing::{debug, instrument, trace};
2021

@@ -171,8 +172,27 @@ fn check_and_apply_linkage<'ll, 'tcx>(
171172
if let Some(linkage) = attrs.import_linkage {
172173
debug!("get_static: sym={} linkage={:?}", sym, linkage);
173174

174-
// Declare a symbol `foo` with the desired linkage.
175-
let g1 = cx.declare_global(sym, cx.type_i8());
175+
// Declare a symbol `foo`. If `foo` is an extern_weak symbol, we declare
176+
// an extern_weak function, otherwise a global with the desired linkage.
177+
let g1 = if matches!(attrs.import_linkage, Some(Linkage::ExternalWeak)) {
178+
// An `extern_weak` function is represented as an `Option<unsafe extern ...>`,
179+
// we extract the function signature and declare it as an extern_weak function
180+
// instead of an extern_weak i8.
181+
let instance = Instance::mono(cx.tcx, def_id);
182+
if let ty::Adt(struct_def, args) = instance.ty(cx.tcx, cx.typing_env()).kind()
183+
&& cx.tcx.is_lang_item(struct_def.did(), LangItem::Option)
184+
&& let ty::FnPtr(sig, header) = args.type_at(0).kind()
185+
{
186+
let fn_sig = sig.with(*header);
187+
188+
let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
189+
cx.declare_fn(sym, &fn_abi, None)
190+
} else {
191+
cx.declare_global(sym, cx.type_i8())
192+
}
193+
} else {
194+
cx.declare_global(sym, cx.type_i8())
195+
};
176196
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));
177197

178198
// Declare an internal global `extern_with_linkage_foo` which

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,9 +2148,11 @@ impl<'a> State<'a> {
21482148
s.print_implicit_self(&decl.implicit_self);
21492149
} else {
21502150
if let Some(arg_name) = arg_names.get(i) {
2151-
s.word(arg_name.to_string());
2152-
s.word(":");
2153-
s.space();
2151+
if arg_name.name != kw::Empty {
2152+
s.word(arg_name.to_string());
2153+
s.word(":");
2154+
s.space();
2155+
}
21542156
} else if let Some(body_id) = body_id {
21552157
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
21562158
s.word(":");

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20602060
// struct-like enums (yet...), but it's definitely not
20612061
// a bug to have constructed one.
20622062
if adt_kind != AdtKind::Enum {
2063-
tcx.check_stability(v_field.did, Some(expr.hir_id), field.span, None);
2063+
tcx.check_stability(v_field.did, Some(field.hir_id), field.span, None);
20642064
}
20652065

20662066
self.field_ty(field.span, v_field, args)

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
1919
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
2020
use rustc_middle::{bug, span_bug};
2121
use rustc_session::Session;
22-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
22+
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};
2323
use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt};
2424
use rustc_trait_selection::infer::InferCtxtExt;
2525
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt, SelectionContext};
@@ -2679,7 +2679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26792679
params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?;
26802680
debug_assert_eq!(params.len(), fn_inputs.len());
26812681
Some((
2682-
fn_inputs.zip(params.iter().map(|param| FnParam::Name(param))).collect(),
2682+
fn_inputs.zip(params.iter().map(|&param| FnParam::Name(param))).collect(),
26832683
generics,
26842684
))
26852685
}
@@ -2710,32 +2710,38 @@ impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> {
27102710
#[derive(Clone, Copy)]
27112711
enum FnParam<'hir> {
27122712
Param(&'hir hir::Param<'hir>),
2713-
Name(&'hir Ident),
2713+
Name(Ident),
27142714
}
2715+
27152716
impl FnParam<'_> {
27162717
fn span(&self) -> Span {
27172718
match self {
2718-
Self::Param(x) => x.span,
2719-
Self::Name(x) => x.span,
2720-
}
2721-
}
2722-
2723-
fn name(&self) -> Option<Symbol> {
2724-
match self {
2725-
Self::Param(x) if let hir::PatKind::Binding(_, _, ident, _) = x.pat.kind => {
2726-
Some(ident.name)
2727-
}
2728-
Self::Name(x) if x.name != kw::Empty => Some(x.name),
2729-
_ => None,
2719+
Self::Param(param) => param.span,
2720+
Self::Name(ident) => ident.span,
27302721
}
27312722
}
27322723

27332724
fn display(&self, idx: usize) -> impl '_ + fmt::Display {
27342725
struct D<'a>(FnParam<'a>, usize);
27352726
impl fmt::Display for D<'_> {
27362727
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2737-
if let Some(name) = self.0.name() {
2738-
write!(f, "`{name}`")
2728+
// A "unique" param name is one that (a) exists, and (b) is guaranteed to be unique
2729+
// among the parameters, i.e. `_` does not count.
2730+
let unique_name = match self.0 {
2731+
FnParam::Param(param)
2732+
if let hir::PatKind::Binding(_, _, ident, _) = param.pat.kind =>
2733+
{
2734+
Some(ident.name)
2735+
}
2736+
FnParam::Name(ident)
2737+
if ident.name != kw::Empty && ident.name != kw::Underscore =>
2738+
{
2739+
Some(ident.name)
2740+
}
2741+
_ => None,
2742+
};
2743+
if let Some(unique_name) = unique_name {
2744+
write!(f, "`{unique_name}`")
27392745
} else {
27402746
write!(f, "parameter #{}", self.1 + 1)
27412747
}

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14221422

14231423
self.tcx.check_stability(
14241424
variant.fields[FieldIdx::from_usize(i)].did,
1425-
Some(pat.hir_id),
1425+
Some(subpat.hir_id),
14261426
subpat.span,
14271427
None,
14281428
);
@@ -1686,7 +1686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16861686
.get(&ident)
16871687
.map(|(i, f)| {
16881688
self.write_field_index(field.hir_id, *i);
1689-
self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
1689+
self.tcx.check_stability(f.did, Some(field.hir_id), span, None);
16901690
self.field_ty(span, f, args)
16911691
})
16921692
.unwrap_or_else(|| {

compiler/rustc_middle/src/hir/map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ impl<'tcx> TyCtxt<'tcx> {
281281
}
282282

283283
pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> {
284-
self.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
284+
self.hir_body(id).params.iter().map(|param| match param.pat.kind {
285285
PatKind::Binding(_, _, ident, _) => ident,
286+
PatKind::Wild => Ident::new(kw::Underscore, param.pat.span),
286287
_ => Ident::empty(),
287288
})
288289
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,8 @@ impl<'a> Parser<'a> {
25882588
}
25892589

25902590
/// Parses the condition of a `if` or `while` expression.
2591-
fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>> {
2591+
// Public because it is used in rustfmt forks such as https://github.com/tucant/rustfmt/blob/30c83df9e1db10007bdd16dafce8a86b404329b2/src/parse/macros/html.rs#L57 for custom if expressions.
2592+
pub fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>> {
25922593
let attrs = self.parse_outer_attributes()?;
25932594
let (mut cond, _) =
25942595
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, attrs)?;

compiler/rustc_target/src/target_features.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,18 @@ static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
603603
static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
604604
// tidy-alphabetical-start
605605
("d", Unstable(sym::loongarch_target_feature), &["f"]),
606+
("div32", Unstable(sym::loongarch_target_feature), &[]),
606607
("f", Unstable(sym::loongarch_target_feature), &[]),
607608
("frecipe", Unstable(sym::loongarch_target_feature), &[]),
609+
("lam-bh", Unstable(sym::loongarch_target_feature), &[]),
610+
("lamcas", Unstable(sym::loongarch_target_feature), &[]),
608611
("lasx", Unstable(sym::loongarch_target_feature), &["lsx"]),
609612
("lbt", Unstable(sym::loongarch_target_feature), &[]),
613+
("ld-seq-sa", Unstable(sym::loongarch_target_feature), &[]),
610614
("lsx", Unstable(sym::loongarch_target_feature), &["d"]),
611615
("lvz", Unstable(sym::loongarch_target_feature), &[]),
612616
("relax", Unstable(sym::loongarch_target_feature), &[]),
617+
("scq", Unstable(sym::loongarch_target_feature), &[]),
613618
("ual", Unstable(sym::loongarch_target_feature), &[]),
614619
// tidy-alphabetical-end
615620
];

0 commit comments

Comments
 (0)