Skip to content

Commit 2828650

Browse files
committed
Auto merge of #138523 - fmease:rollup-j2j5h59, r=fmease
Rollup of 9 pull requests Successful merges: - #138056 (rustc_target: Add target features for LoongArch v1.1) - #138451 (Build GCC on CI with GCC, not Clang) - #138454 (Improve post-merge workflow) - #138460 (Pass struct field HirId when check_expr_struct_fields) - #138474 (Refactor is_snake_case.) - #138482 (Fix HIR printing of parameters) - #138507 (Mirror NetBSD sources) - #138511 (Make `Parser::parse_expr_cond` public) - #138518 (Fix typo in hir lowering lint diag) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d9e5539 + 9838591 commit 2828650

38 files changed

+486
-210
lines changed

.github/workflows/post-merge.yml

+6-1
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

+8-1
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_hir_analysis/src/hir_ty_lowering/lint.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
411411
Applicability::MachineApplicable,
412412
);
413413
if !is_dyn_compatible {
414-
diag.note(format!("`{trait_name}` it is dyn-incompatible, so it can't be `dyn`"));
414+
diag.note(format!(
415+
"`{trait_name}` is dyn-incompatible, otherwise a trait object could be used"
416+
));
415417
} else {
416418
// No ampersand in suggestion if it's borrowed already
417419
let (dyn_str, paren_dyn_str) =
418420
if borrowed { ("dyn ", "(dyn ") } else { ("&dyn ", "&(dyn ") };
419421

420422
let sugg = if let hir::TyKind::TraitObject([_, _, ..], _) = self_ty.kind {
421-
// There are more than one trait bound, we need surrounding parentheses.
423+
// There is more than one trait bound, we need surrounding parentheses.
422424
vec![
423425
(self_ty.span.shrink_to_lo(), paren_dyn_str.to_string()),
424426
(self_ty.span.shrink_to_hi(), ")".to_string()),

compiler/rustc_hir_pretty/src/lib.rs

+5-3
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

+1-1
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

+23-17
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

+2-2
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_lint/src/nonstandard_style.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,13 @@ impl NonSnakeCase {
274274
let ident = ident.trim_start_matches('\'');
275275
let ident = ident.trim_matches('_');
276276

277-
let mut allow_underscore = true;
278-
ident.chars().all(|c| {
279-
allow_underscore = match c {
280-
'_' if !allow_underscore => return false,
281-
'_' => false,
282-
// It would be more obvious to use `c.is_lowercase()`,
283-
// but some characters do not have a lowercase form
284-
c if !c.is_uppercase() => true,
285-
_ => return false,
286-
};
287-
true
288-
})
277+
if ident.contains("__") {
278+
return false;
279+
}
280+
281+
// This correctly handles letters in languages with and without
282+
// cases, as well as numbers and underscores.
283+
!ident.chars().any(char::is_uppercase)
289284
}
290285

291286
let name = ident.name.as_str();

compiler/rustc_middle/src/hir/map.rs

+2-1
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

+2-1
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

+5
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
];

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19981998
.iter()
19991999
.enumerate()
20002000
.map(|(i, ident)| {
2001-
if ident.name.is_empty() || ident.name == kw::SelfLower {
2001+
if ident.name.is_empty()
2002+
|| ident.name == kw::Underscore
2003+
|| ident.name == kw::SelfLower
2004+
{
20022005
format!("arg{i}")
20032006
} else {
20042007
format!("{ident}")

src/bootstrap/src/core/build_steps/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,7 @@ impl Step for Gcc {
24812481
fn run(self, builder: &Builder<'_>) -> Self::Output {
24822482
let tarball = Tarball::new(builder, "gcc", &self.target.triple);
24832483
let output = builder.ensure(super::gcc::Gcc { target: self.target });
2484-
tarball.add_file(output.libgccjit, ".", 0o644);
2484+
tarball.add_file(output.libgccjit, "lib", 0o644);
24852485
tarball.generate()
24862486
}
24872487
}

src/bootstrap/src/core/build_steps/gcc.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,23 @@ impl Step for Gcc {
6363
}
6464

6565
build_gcc(&metadata, builder, target);
66-
67-
let lib_alias = metadata.install_dir.join("lib/libgccjit.so.0");
68-
if !lib_alias.exists() {
69-
t!(builder.symlink_file(&libgccjit_path, lib_alias));
70-
}
66+
create_lib_alias(builder, &libgccjit_path);
7167

7268
t!(metadata.stamp.write());
7369

7470
GccOutput { libgccjit: libgccjit_path }
7571
}
7672
}
7773

74+
/// Creates a libgccjit.so.0 alias next to libgccjit.so if it does not
75+
/// already exist
76+
fn create_lib_alias(builder: &Builder<'_>, libgccjit: &PathBuf) {
77+
let lib_alias = libgccjit.parent().unwrap().join("libgccjit.so.0");
78+
if !lib_alias.exists() {
79+
t!(builder.symlink_file(libgccjit, lib_alias));
80+
}
81+
}
82+
7883
pub struct Meta {
7984
stamp: BuildStamp,
8085
out_dir: PathBuf,
@@ -109,8 +114,10 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
109114
builder.config.download_ci_gcc(&sha, &root);
110115
t!(gcc_stamp.write());
111116
}
112-
// FIXME: put libgccjit.so into a lib directory in dist::Gcc
113-
Some(root.join("libgccjit.so"))
117+
118+
let libgccjit = root.join("lib").join("libgccjit.so");
119+
create_lib_alias(builder, &libgccjit);
120+
Some(libgccjit)
114121
}
115122

116123
#[cfg(test)]
@@ -177,6 +184,14 @@ fn libgccjit_built_path(install_dir: &Path) -> PathBuf {
177184
}
178185

179186
fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
187+
if builder.build.cc_tool(target).is_like_clang()
188+
|| builder.build.cxx_tool(target).is_like_clang()
189+
{
190+
panic!(
191+
"Attempting to build GCC using Clang, which is known to misbehave. Please use GCC as the host C/C++ compiler. "
192+
);
193+
}
194+
180195
let Meta { stamp: _, out_dir, install_dir, root } = metadata;
181196

182197
t!(fs::create_dir_all(out_dir));
@@ -203,18 +218,13 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
203218
let mut configure_cmd = command(src_dir.join("configure"));
204219
configure_cmd
205220
.current_dir(out_dir)
206-
// On CI, we compile GCC with Clang.
207-
// The -Wno-everything flag is needed to make GCC compile with Clang 19.
208-
// `-g -O2` are the default flags that are otherwise used by Make.
209-
// FIXME(kobzol): change the flags once we have [gcc] configuration in config.toml.
210-
.env("CXXFLAGS", "-Wno-everything -g -O2")
211-
.env("CFLAGS", "-Wno-everything -g -O2")
212221
.arg("--enable-host-shared")
213-
.arg("--enable-languages=jit")
222+
.arg("--enable-languages=c,jit,lto")
214223
.arg("--enable-checking=release")
215224
.arg("--disable-bootstrap")
216225
.arg("--disable-multilib")
217226
.arg(format!("--prefix={}", install_dir.display()));
227+
218228
let cc = builder.build.cc(target).display().to_string();
219229
let cc = builder
220230
.build

src/bootstrap/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::{env, fs, io, str};
2727

2828
use build_helper::ci::gha;
2929
use build_helper::exit;
30+
use cc::Tool;
3031
use termcolor::{ColorChoice, StandardStream, WriteColor};
3132
use utils::build_stamp::BuildStamp;
3233
use utils::channel::GitInfo;
@@ -1218,6 +1219,16 @@ Executed at: {executed_at}"#,
12181219
self.cc.borrow()[&target].path().into()
12191220
}
12201221

1222+
/// Returns the internal `cc::Tool` for the C compiler.
1223+
fn cc_tool(&self, target: TargetSelection) -> Tool {
1224+
self.cc.borrow()[&target].clone()
1225+
}
1226+
1227+
/// Returns the internal `cc::Tool` for the C++ compiler.
1228+
fn cxx_tool(&self, target: TargetSelection) -> Tool {
1229+
self.cxx.borrow()[&target].clone()
1230+
}
1231+
12211232
/// Returns C flags that `cc-rs` thinks should be enabled for the
12221233
/// specified target by default.
12231234
fn cc_handled_clags(&self, target: TargetSelection, c: CLang) -> Vec<String> {

0 commit comments

Comments
 (0)