Skip to content

Commit 4c56aa5

Browse files
committed
Auto merge of #126950 - compiler-errors:rollup-tj8xx0r, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #126893 (Eliminate the distinction between PREC_POSTFIX and PREC_PAREN precedence level) - #126907 (Fixes for 32-bit SPARC on Linux) - #126932 (Tweak `FlatPat::new` to avoid a temporarily-invalid state) - #126934 (fix broken build cache caused by rustdoc builds) - #126943 (De-duplicate all consecutive native libs regardless of their options) - #126946 (Add missing slash in `const_eval_select` doc comment) - #126947 (Delegation: ast lowering refactor) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d929a42 + 6d0bb34 commit 4c56aa5

File tree

22 files changed

+161
-150
lines changed

22 files changed

+161
-150
lines changed

compiler/rustc_ast/src/util/parser.rs

+21-24
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ pub const PREC_JUMP: i8 = -30;
233233
pub const PREC_RANGE: i8 = -10;
234234
// The range 2..=14 is reserved for AssocOp binary operator precedences.
235235
pub const PREC_PREFIX: i8 = 50;
236-
pub const PREC_POSTFIX: i8 = 60;
237-
pub const PREC_PAREN: i8 = 99;
236+
pub const PREC_UNAMBIGUOUS: i8 = 60;
238237
pub const PREC_FORCE_PAREN: i8 = 100;
239238

240239
#[derive(Debug, Clone, Copy)]
@@ -325,37 +324,35 @@ impl ExprPrecedence {
325324
| ExprPrecedence::Let
326325
| ExprPrecedence::Unary => PREC_PREFIX,
327326

328-
// Unary, postfix
329-
ExprPrecedence::Await
327+
// Never need parens
328+
ExprPrecedence::Array
329+
| ExprPrecedence::Await
330+
| ExprPrecedence::Block
330331
| ExprPrecedence::Call
331-
| ExprPrecedence::MethodCall
332+
| ExprPrecedence::ConstBlock
332333
| ExprPrecedence::Field
334+
| ExprPrecedence::ForLoop
335+
| ExprPrecedence::FormatArgs
336+
| ExprPrecedence::Gen
337+
| ExprPrecedence::If
333338
| ExprPrecedence::Index
334-
| ExprPrecedence::Try
335339
| ExprPrecedence::InlineAsm
340+
| ExprPrecedence::Lit
341+
| ExprPrecedence::Loop
336342
| ExprPrecedence::Mac
337-
| ExprPrecedence::FormatArgs
343+
| ExprPrecedence::Match
344+
| ExprPrecedence::MethodCall
338345
| ExprPrecedence::OffsetOf
339-
| ExprPrecedence::PostfixMatch => PREC_POSTFIX,
340-
341-
// Never need parens
342-
ExprPrecedence::Array
346+
| ExprPrecedence::Paren
347+
| ExprPrecedence::Path
348+
| ExprPrecedence::PostfixMatch
343349
| ExprPrecedence::Repeat
350+
| ExprPrecedence::Struct
351+
| ExprPrecedence::Try
352+
| ExprPrecedence::TryBlock
344353
| ExprPrecedence::Tup
345-
| ExprPrecedence::Lit
346-
| ExprPrecedence::Path
347-
| ExprPrecedence::Paren
348-
| ExprPrecedence::If
349354
| ExprPrecedence::While
350-
| ExprPrecedence::ForLoop
351-
| ExprPrecedence::Loop
352-
| ExprPrecedence::Match
353-
| ExprPrecedence::ConstBlock
354-
| ExprPrecedence::Block
355-
| ExprPrecedence::TryBlock
356-
| ExprPrecedence::Gen
357-
| ExprPrecedence::Struct
358-
| ExprPrecedence::Err => PREC_PAREN,
355+
| ExprPrecedence::Err => PREC_UNAMBIGUOUS,
359356
}
360357
}
361358
}

compiler/rustc_ast_lowering/src/delegation.rs

+49-58
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
6666
let Ok(sig_id) = sig_id else {
6767
return false;
6868
};
69-
if let Some(local_sig_id) = sig_id.as_local() {
69+
self.has_self(sig_id, span)
70+
}
71+
72+
fn has_self(&self, def_id: DefId, span: Span) -> bool {
73+
if let Some(local_sig_id) = def_id.as_local() {
7074
// The value may be missing due to recursive delegation.
7175
// Error will be emmited later during HIR ty lowering.
7276
self.resolver.delegation_fn_sigs.get(&local_sig_id).map_or(false, |sig| sig.has_self)
7377
} else {
74-
match self.tcx.def_kind(sig_id) {
78+
match self.tcx.def_kind(def_id) {
7579
DefKind::Fn => false,
76-
DefKind::AssocFn => self.tcx.associated_item(sig_id).fn_has_self_parameter,
80+
DefKind::AssocFn => self.tcx.associated_item(def_id).fn_has_self_parameter,
7781
_ => span_bug!(span, "unexpected DefKind for delegation item"),
7882
}
7983
}
@@ -107,12 +111,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
107111
span: Span,
108112
) -> Result<DefId, ErrorGuaranteed> {
109113
let sig_id = if self.is_in_trait_impl { item_id } else { path_id };
110-
let sig_id =
111-
self.resolver.get_partial_res(sig_id).and_then(|r| r.expect_full_res().opt_def_id());
112-
sig_id.ok_or_else(|| {
113-
self.tcx
114-
.dcx()
115-
.span_delayed_bug(span, "LoweringContext: couldn't resolve delegation item")
114+
self.get_resolution_id(sig_id, span)
115+
}
116+
117+
fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
118+
let def_id =
119+
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
120+
def_id.ok_or_else(|| {
121+
self.tcx.dcx().span_delayed_bug(
122+
span,
123+
format!("LoweringContext: couldn't resolve node {:?} in delegation item", node_id),
124+
)
116125
})
117126
}
118127

@@ -122,7 +131,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
122131
predicates: &[],
123132
has_where_clause_predicates: false,
124133
where_clause_span: span,
125-
span: span,
134+
span,
126135
})
127136
}
128137

@@ -222,12 +231,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222231
}));
223232

224233
let path = self.arena.alloc(hir::Path { span, res: Res::Local(param_id), segments });
225-
226-
hir::Expr {
227-
hir_id: self.next_id(),
228-
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
229-
span,
230-
}
234+
self.mk_expr(hir::ExprKind::Path(hir::QPath::Resolved(None, path)), span)
231235
}
232236

233237
fn lower_delegation_body(
@@ -236,19 +240,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
236240
param_count: usize,
237241
span: Span,
238242
) -> BodyId {
239-
let path = self.lower_qpath(
240-
delegation.id,
241-
&delegation.qself,
242-
&delegation.path,
243-
ParamMode::Optional,
244-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
245-
None,
246-
);
247243
let block = delegation.body.as_deref();
248244

249245
self.lower_body(|this| {
250-
let mut parameters: Vec<hir::Param<'_>> = Vec::new();
251-
let mut args: Vec<hir::Expr<'hir>> = Vec::new();
246+
let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
247+
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
252248

253249
for idx in 0..param_count {
254250
let (param, pat_node_id) = this.generate_param(span);
@@ -264,55 +260,49 @@ impl<'hir> LoweringContext<'_, 'hir> {
264260
};
265261
self_resolver.visit_block(block);
266262
let block = this.lower_block(block, false);
267-
hir::Expr {
268-
hir_id: this.next_id(),
269-
kind: hir::ExprKind::Block(block, None),
270-
span: block.span,
271-
}
263+
this.mk_expr(hir::ExprKind::Block(block, None), block.span)
272264
} else {
273265
let pat_hir_id = this.lower_node_id(pat_node_id);
274266
this.generate_arg(pat_hir_id, span)
275267
};
276268
args.push(arg);
277269
}
278270

279-
let args = self.arena.alloc_from_iter(args);
280-
let final_expr = this.generate_call(path, args);
271+
let final_expr = this.finalize_body_lowering(delegation, args, span);
281272
(this.arena.alloc_from_iter(parameters), final_expr)
282273
})
283274
}
284275

285-
fn generate_call(
276+
// Generates fully qualified call for the resulting body.
277+
fn finalize_body_lowering(
286278
&mut self,
287-
path: hir::QPath<'hir>,
288-
args: &'hir [hir::Expr<'hir>],
279+
delegation: &Delegation,
280+
args: Vec<hir::Expr<'hir>>,
281+
span: Span,
289282
) -> hir::Expr<'hir> {
290-
let callee = self.arena.alloc(hir::Expr {
291-
hir_id: self.next_id(),
292-
kind: hir::ExprKind::Path(path),
293-
span: path.span(),
294-
});
283+
let path = self.lower_qpath(
284+
delegation.id,
285+
&delegation.qself,
286+
&delegation.path,
287+
ParamMode::Optional,
288+
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
289+
None,
290+
);
295291

296-
let expr = self.arena.alloc(hir::Expr {
297-
hir_id: self.next_id(),
298-
kind: hir::ExprKind::Call(callee, args),
299-
span: path.span(),
300-
});
292+
let args = self.arena.alloc_from_iter(args);
293+
let path_expr = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));
294+
let call = self.arena.alloc(self.mk_expr(hir::ExprKind::Call(path_expr, args), span));
301295

302296
let block = self.arena.alloc(hir::Block {
303297
stmts: &[],
304-
expr: Some(expr),
298+
expr: Some(call),
305299
hir_id: self.next_id(),
306300
rules: hir::BlockCheckMode::DefaultBlock,
307-
span: path.span(),
301+
span,
308302
targeted_by_break: false,
309303
});
310304

311-
hir::Expr {
312-
hir_id: self.next_id(),
313-
kind: hir::ExprKind::Block(block, None),
314-
span: path.span(),
315-
}
305+
self.mk_expr(hir::ExprKind::Block(block, None), span)
316306
}
317307

318308
fn generate_delegation_error(
@@ -333,11 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
333323
let header = self.generate_header_error();
334324
let sig = hir::FnSig { decl, header, span };
335325

336-
let body_id = self.lower_body(|this| {
337-
let expr =
338-
hir::Expr { hir_id: this.next_id(), kind: hir::ExprKind::Err(err), span: span };
339-
(&[], expr)
340-
});
326+
let body_id = self.lower_body(|this| (&[], this.mk_expr(hir::ExprKind::Err(err), span)));
341327
DelegationResults { generics, body_id, sig }
342328
}
343329

@@ -349,6 +335,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
349335
abi: abi::Abi::Rust,
350336
}
351337
}
338+
339+
#[inline]
340+
fn mk_expr(&mut self, kind: hir::ExprKind<'hir>, span: Span) -> hir::Expr<'hir> {
341+
hir::Expr { hir_id: self.next_id(), kind, span }
342+
}
352343
}
353344

354345
struct SelfResolver<'a> {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a> State<'a> {
217217
fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) {
218218
let prec = match func.kind {
219219
ast::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
220-
_ => parser::PREC_POSTFIX,
220+
_ => parser::PREC_UNAMBIGUOUS,
221221
};
222222

223223
// Independent of parenthesization related to precedence, we must
@@ -257,7 +257,7 @@ impl<'a> State<'a> {
257257
// boundaries, `$receiver.method()` can be parsed back as a statement
258258
// containing an expression if and only if `$receiver` can be parsed as
259259
// a statement containing an expression.
260-
self.print_expr_maybe_paren(receiver, parser::PREC_POSTFIX, fixup);
260+
self.print_expr_maybe_paren(receiver, parser::PREC_UNAMBIGUOUS, fixup);
261261

262262
self.word(".");
263263
self.print_ident(segment.ident);
@@ -489,7 +489,7 @@ impl<'a> State<'a> {
489489
self.space();
490490
}
491491
MatchKind::Postfix => {
492-
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
492+
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
493493
self.word_nbsp(".match");
494494
}
495495
}
@@ -549,7 +549,7 @@ impl<'a> State<'a> {
549549
self.print_block_with_attrs(blk, attrs);
550550
}
551551
ast::ExprKind::Await(expr, _) => {
552-
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
552+
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
553553
self.word(".await");
554554
}
555555
ast::ExprKind::Assign(lhs, rhs, _) => {
@@ -568,14 +568,14 @@ impl<'a> State<'a> {
568568
self.print_expr_maybe_paren(rhs, prec, fixup.subsequent_subexpression());
569569
}
570570
ast::ExprKind::Field(expr, ident) => {
571-
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
571+
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
572572
self.word(".");
573573
self.print_ident(*ident);
574574
}
575575
ast::ExprKind::Index(expr, index, _) => {
576576
self.print_expr_maybe_paren(
577577
expr,
578-
parser::PREC_POSTFIX,
578+
parser::PREC_UNAMBIGUOUS,
579579
fixup.leftmost_subexpression(),
580580
);
581581
self.word("[");
@@ -713,7 +713,7 @@ impl<'a> State<'a> {
713713
}
714714
}
715715
ast::ExprKind::Try(e) => {
716-
self.print_expr_maybe_paren(e, parser::PREC_POSTFIX, fixup);
716+
self.print_expr_maybe_paren(e, parser::PREC_UNAMBIGUOUS, fixup);
717717
self.word("?")
718718
}
719719
ast::ExprKind::TryBlock(blk) => {

compiler/rustc_codegen_ssa/src/back/link.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1490,11 +1490,6 @@ fn print_native_static_libs(
14901490
let mut lib_args: Vec<_> = all_native_libs
14911491
.iter()
14921492
.filter(|l| relevant_lib(sess, l))
1493-
// Deduplication of successive repeated libraries, see rust-lang/rust#113209
1494-
//
1495-
// note: we don't use PartialEq/Eq because NativeLib transitively depends on local
1496-
// elements like spans, which we don't care about and would make the deduplication impossible
1497-
.dedup_by(|l1, l2| l1.name == l2.name && l1.kind == l2.kind && l1.verbatim == l2.verbatim)
14981493
.filter_map(|lib| {
14991494
let name = lib.name;
15001495
match lib.kind {
@@ -1521,6 +1516,8 @@ fn print_native_static_libs(
15211516
| NativeLibKind::RawDylib => None,
15221517
}
15231518
})
1519+
// deduplication of consecutive repeated libraries, see rust-lang/rust#113209
1520+
.dedup()
15241521
.collect();
15251522
for path in all_rust_dylibs {
15261523
// FIXME deduplicate with add_dynamic_crate

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ libc = "0.2"
5050
memmap2 = "0.2.1"
5151
# tidy-alphabetical-end
5252

53-
[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
53+
[target.'cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))'.dependencies]
5454
portable-atomic = "1.5.1"
5555

5656
[features]

compiler/rustc_data_structures/src/marker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ cfg_match! {
147147
[crate::owned_slice::OwnedSlice]
148148
);
149149

150-
// PowerPC and MIPS platforms with 32-bit pointers do not
150+
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
151151
// have AtomicU64 type.
152-
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
152+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc", target_arch = "sparc")))]
153153
already_sync!(
154154
[std::sync::atomic::AtomicU64]
155155
);
156156

157-
#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
157+
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
158158
already_sync!(
159159
[portable_atomic::AtomicU64]
160160
);

compiler/rustc_data_structures/src/sync.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ cfg_match! {
270270

271271
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};
272272

273-
// PowerPC and MIPS platforms with 32-bit pointers do not
273+
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
274274
// have AtomicU64 type.
275-
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
275+
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc")))]
276276
pub use std::sync::atomic::AtomicU64;
277277

278-
#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
278+
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
279279
pub use portable_atomic::AtomicU64;
280280

281281
pub use std::sync::Arc as Lrc;

0 commit comments

Comments
 (0)