Skip to content

Commit 2b0ceb8

Browse files
committed
Auto merge of #134839 - dtolnay:rollup-1jm11rl, r=dtolnay
Rollup of 4 pull requests Successful merges: - #134823 (Fix typos) - #134827 (Some random region tweaks) - #134833 (Skip parenthesis if `.` makes statement boundary unambiguous) - #134834 (Skip parenthesis around tuple struct field calls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ecc1899 + 0a09252 commit 2b0ceb8

File tree

14 files changed

+61
-25
lines changed

14 files changed

+61
-25
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ impl<'a> State<'a> {
213213

214214
fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) {
215215
let needs_paren = match func.kind {
216-
ast::ExprKind::Field(..) => true,
216+
// In order to call a named field, needs parens: `(self.fun)()`
217+
// But not for an unnamed field: `self.0()`
218+
ast::ExprKind::Field(_, name) => !name.is_numeric(),
217219
_ => func.precedence() < ExprPrecedence::Unambiguous,
218220
};
219221

@@ -245,19 +247,21 @@ impl<'a> State<'a> {
245247
base_args: &[P<ast::Expr>],
246248
fixup: FixupContext,
247249
) {
248-
// Unlike in `print_expr_call`, no change to fixup here because
250+
// The fixup here is different than in `print_expr_call` because
249251
// statement boundaries never occur in front of a `.` (or `?`) token.
250252
//
251-
// match () { _ => f }.method();
253+
// Needs parens:
254+
//
255+
// (loop { break x; })();
256+
//
257+
// Does not need parens:
258+
//
259+
// loop { break x; }.method();
252260
//
253-
// Parenthesizing only for precedence and not with regard to statement
254-
// boundaries, `$receiver.method()` can be parsed back as a statement
255-
// containing an expression if and only if `$receiver` can be parsed as
256-
// a statement containing an expression.
257261
self.print_expr_cond_paren(
258262
receiver,
259263
receiver.precedence() < ExprPrecedence::Unambiguous,
260-
fixup,
264+
fixup.leftmost_subexpression_with_dot(),
261265
);
262266

263267
self.word(".");
@@ -503,7 +507,7 @@ impl<'a> State<'a> {
503507
self.print_expr_cond_paren(
504508
expr,
505509
expr.precedence() < ExprPrecedence::Unambiguous,
506-
fixup,
510+
fixup.leftmost_subexpression_with_dot(),
507511
);
508512
self.word_nbsp(".match");
509513
}
@@ -567,7 +571,7 @@ impl<'a> State<'a> {
567571
self.print_expr_cond_paren(
568572
expr,
569573
expr.precedence() < ExprPrecedence::Unambiguous,
570-
fixup,
574+
fixup.leftmost_subexpression_with_dot(),
571575
);
572576
self.word(".await");
573577
}
@@ -606,7 +610,7 @@ impl<'a> State<'a> {
606610
self.print_expr_cond_paren(
607611
expr,
608612
expr.precedence() < ExprPrecedence::Unambiguous,
609-
fixup,
613+
fixup.leftmost_subexpression_with_dot(),
610614
);
611615
self.word(".");
612616
self.print_ident(*ident);
@@ -763,7 +767,11 @@ impl<'a> State<'a> {
763767
}
764768
}
765769
ast::ExprKind::Try(e) => {
766-
self.print_expr_cond_paren(e, e.precedence() < ExprPrecedence::Unambiguous, fixup);
770+
self.print_expr_cond_paren(
771+
e,
772+
e.precedence() < ExprPrecedence::Unambiguous,
773+
fixup.leftmost_subexpression_with_dot(),
774+
);
767775
self.word("?")
768776
}
769777
ast::ExprKind::TryBlock(blk) => {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ impl FixupContext {
138138
}
139139
}
140140

141+
/// Transform this fixup into the one that should apply when printing a
142+
/// leftmost subexpression followed by a `.` or `?` token, which confer
143+
/// different statement boundary rules compared to other leftmost
144+
/// subexpressions.
145+
pub(crate) fn leftmost_subexpression_with_dot(self) -> Self {
146+
FixupContext {
147+
stmt: self.stmt || self.leftmost_subexpression_in_stmt,
148+
leftmost_subexpression_in_stmt: false,
149+
match_arm: self.match_arm || self.leftmost_subexpression_in_match_arm,
150+
leftmost_subexpression_in_match_arm: false,
151+
..self
152+
}
153+
}
154+
141155
/// Transform this fixup into the one that should apply when printing any
142156
/// subexpression that is neither a leftmost subexpression nor surrounded in
143157
/// delimiters.

compiler/rustc_borrowck/src/diagnostics/opaque_suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
3131
diag: &mut Diag<'_>,
3232
) {
3333
// We look at all the locals. Why locals? Because it's the best thing
34-
// I could think of that's correlated with the *instantiated* higer-ranked
34+
// I could think of that's correlated with the *instantiated* higher-ranked
3535
// binder for calls, since we don't really store those anywhere else.
3636
for ty in self.body.local_decls.iter().map(|local| local.ty) {
3737
if !ty.has_opaque_types() {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ pub(crate) fn type_check<'a, 'tcx>(
140140
&mut constraints,
141141
);
142142

143+
let pre_obligations = infcx.take_registered_region_obligations();
144+
assert!(
145+
pre_obligations.is_empty(),
146+
"there should be no incoming region obligations = {pre_obligations:#?}",
147+
);
148+
143149
debug!(?normalized_inputs_and_output);
144150

145151
let mut typeck = TypeChecker {

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
299299
self.storage.var_infos.len()
300300
}
301301

302-
pub fn region_constraint_data(&self) -> &RegionConstraintData<'tcx> {
303-
&self.storage.data
304-
}
305-
306302
/// Takes (and clears) the current set of constraints. Note that
307303
/// the set of variables remains intact, but all relationships
308304
/// between them are reset. This is used during NLL checking to

compiler/rustc_llvm/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn main() {
220220
let mut cmd = Command::new(&llvm_config);
221221
cmd.arg(llvm_link_arg).arg("--libs");
222222

223-
// Don't link system libs if cross-compiling unless targetting Windows.
223+
// Don't link system libs if cross-compiling unless targeting Windows.
224224
// On Windows system DLLs aren't linked directly, instead import libraries are used.
225225
// These import libraries are independent of the host.
226226
if !is_crossed || target.contains("windows") {

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
117117
self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
118118
}
119119

120-
// FIXME(explicit_tail_calls): this currenly fails for cases where opaques are used.
120+
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
121121
// e.g.
122122
// ```
123123
// fn a() -> impl Sized { become b() } // ICE

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ impl<'a> Parser<'a> {
13361336
) -> bool {
13371337
if let ExprKind::Binary(op, l1, r1) = &inner_op.kind {
13381338
if let ExprKind::Field(_, ident) = l1.kind
1339-
&& ident.as_str().parse::<i32>().is_err()
1339+
&& !ident.is_numeric()
13401340
&& !matches!(r1.kind, ExprKind::Lit(_))
13411341
{
13421342
// The parser has encountered `foo.bar<baz`, the likelihood of the turbofish

compiler/rustc_span/src/symbol.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,12 @@ impl Ident {
27082708
pub fn is_raw_guess(self) -> bool {
27092709
self.name.can_be_raw() && self.is_reserved()
27102710
}
2711+
2712+
/// Whether this would be the identifier for a tuple field like `self.0`, as
2713+
/// opposed to a named field like `self.thing`.
2714+
pub fn is_numeric(self) -> bool {
2715+
!self.name.is_empty() && self.as_str().bytes().all(|b| b.is_ascii_digit())
2716+
}
27112717
}
27122718

27132719
/// Collect all the keywords in a given edition into a vector.

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
161161
let outlives_env = OutlivesEnvironment::new(full_env);
162162
let _ = infcx.process_registered_region_obligations(&outlives_env, |ty, _| Ok(ty));
163163

164-
let region_data =
165-
infcx.inner.borrow_mut().unwrap_region_constraints().region_constraint_data().clone();
164+
let region_data = infcx.inner.borrow_mut().unwrap_region_constraints().data().clone();
166165

167166
let vid_to_region = self.map_vid_to_region(&region_data);
168167

0 commit comments

Comments
 (0)