Skip to content

Commit 2828650

Browse files
committed
Auto merge of rust-lang#138523 - fmease:rollup-j2j5h59, r=fmease
Rollup of 9 pull requests Successful merges: - rust-lang#138056 (rustc_target: Add target features for LoongArch v1.1) - 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#138474 (Refactor is_snake_case.) - rust-lang#138482 (Fix HIR printing of parameters) - rust-lang#138507 (Mirror NetBSD sources) - rust-lang#138511 (Make `Parser::parse_expr_cond` public) - rust-lang#138518 (Fix typo in hir lowering lint diag) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d9e5539 + 9838591 commit 2828650

File tree

38 files changed

+486
-210
lines changed

38 files changed

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

Lines changed: 4 additions & 2 deletions
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

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

Lines changed: 7 additions & 12 deletions
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

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)?;

0 commit comments

Comments
 (0)