Skip to content

Commit 2b0ceb8

Browse files
committed
Auto merge of rust-lang#134839 - dtolnay:rollup-1jm11rl, r=dtolnay
Rollup of 4 pull requests Successful merges: - rust-lang#134823 (Fix typos) - rust-lang#134827 (Some random region tweaks) - rust-lang#134833 (Skip parenthesis if `.` makes statement boundary unambiguous) - rust-lang#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

+20-12
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

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

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

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

-4
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

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

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

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

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

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

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18431843
// a global and a non-global where-clause.
18441844
//
18451845
// Our handling of where-bounds is generally fairly messy but necessary for backwards
1846-
// compatability, see #50825 for why we need to handle global where-bounds like this.
1846+
// compatibility, see #50825 for why we need to handle global where-bounds like this.
18471847
let is_global = |c: ty::PolyTraitPredicate<'tcx>| c.is_global() && !c.has_bound_vars();
18481848
let param_candidates = candidates
18491849
.iter()

library/alloc/tests/sort/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn check_is_sorted<T: Ord + Clone + Debug, S: Sort>(v: &mut [T]) {
3333
known_good_stable_sort::sort(known_good_sorted_vec.as_mut_slice());
3434

3535
if is_small_test {
36-
eprintln!("Orginal: {:?}", v_orig);
36+
eprintln!("Original: {:?}", v_orig);
3737
eprintln!("Expected: {:?}", known_good_sorted_vec);
3838
eprintln!("Got: {:?}", v);
3939
} else {

library/core/benches/num/int_pow/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! pow_bench_template {
2525
let mut exp_iter = black_box(&exp_array).into_iter();
2626

2727
(0..ITERATIONS).fold((0 as IntType, false), |acc, _| {
28-
// Sometimes constants don't propogate all the way to the
28+
// Sometimes constants don't propagate all the way to the
2929
// inside of the loop, so we call a custom expression every cycle
3030
// rather than iter::repeat(CONST)
3131
let base: IntType = $base_macro!(base_iter);

tests/ui-fulldeps/pprust-parenthesis-insertion.rs

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static EXPRS: &[&str] = &[
7777
// These mean different things.
7878
"if let _ = true && false {}",
7979
"if let _ = (true && false) {}",
80+
// Parentheses to call a named field, but not an unnamed field.
81+
"(self.fun)()",
82+
"self.0()",
8083
// Conditions end at the first curly brace, so struct expressions need to be
8184
// parenthesized. Except in a match guard, where conditions end at arrow.
8285
"if let _ = (Struct {}) {}",
@@ -108,6 +111,10 @@ static EXPRS: &[&str] = &[
108111
"{ (match 2 {})() - 1 }",
109112
"{ (match 2 {})[0] - 1 }",
110113
"{ (loop {}) - 1 }",
114+
"match 2 { _ => (loop {}) - 1 }",
115+
// No eager statement boundary if followed by `.` or `?`.
116+
"{ loop {}.to_string() - 1 }",
117+
"match 2 { _ => loop {}.to_string() - 1 }",
111118
// Angle bracket is eagerly parsed as a path's generic argument list.
112119
"(2 as T) < U",
113120
"(2 as T<U>) < V", // FIXME: no parentheses needed.

0 commit comments

Comments
 (0)