Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cca2865
sess: `-Zbranch-protection` is a target modifier
davidtwco Jan 29, 2026
aa7d812
remove `internal_impls_macro` feature
cyrgani Mar 17, 2026
e350a56
move features into the correct section
cyrgani Feb 24, 2026
c8a2c46
bootstrap: Optionally print a backtrace if a command fails
jyn514 Mar 16, 2026
74c51ce
Don't emit `missing_doc_code_examples` on impl items
GuillaumeGomez Mar 18, 2026
6d3b780
Add more tests for rustdoc `missing_doc_code_examples` lint
GuillaumeGomez Mar 18, 2026
45b22ef
tests: Activate must_not_suspend test for MutexGuard dropped before a…
Enselic Mar 18, 2026
bef4b47
Updates derive_where and removes workaround
spirali Mar 19, 2026
74776c4
Rewrite `query_ensure_result`.
nnethercote Mar 19, 2026
cec0a68
Resolve paths for `impl` restrictions using `smart_resolve_path`
CoCo-Japan-pan Mar 19, 2026
4a60dae
Add UI tests for path resolution errors of `impl` restrictions
CoCo-Japan-pan Mar 19, 2026
082cdf7
Preserve braces around `self` in use tree pretty printing
aytey Mar 19, 2026
c777685
Fix whitespace after fragment specifiers in macro pretty printing
aytey Mar 19, 2026
e9740a4
Insert space after float literal ending with `.` in pretty printer
aytey Mar 19, 2026
caad6ee
tests: Add regression test for async closures involving HRTBs
Enselic Mar 19, 2026
46a04b3
Rollup merge of #152909 - davidtwco:branch-protection-target-modifier…
JonathanBrouwer Mar 19, 2026
86d74f8
Rollup merge of #153556 - CoCo-Japan-pan:impl-restriction-lowering, r…
JonathanBrouwer Mar 19, 2026
82ab6bb
Rollup merge of #154048 - GuillaumeGomez:missing_doc_code_examples-im…
JonathanBrouwer Mar 19, 2026
c667bb6
Rollup merge of #153992 - ferrocene:jyn/bootstrap-backtrace, r=jieyou…
JonathanBrouwer Mar 19, 2026
4ae63ed
Rollup merge of #154019 - cyrgani:feature-clean, r=joboet
JonathanBrouwer Mar 19, 2026
f9f6210
Rollup merge of #154059 - Enselic:dropped-mutex-guard, r=Kivooeo
JonathanBrouwer Mar 19, 2026
43457c6
Rollup merge of #154075 - nnethercote:rewrite-query_ensure_result, r=…
JonathanBrouwer Mar 19, 2026
7ab6483
Rollup merge of #154082 - spirali:fix-derive-where, r=lqd
JonathanBrouwer Mar 19, 2026
a31ca19
Rollup merge of #154084 - aytey:fix-use-self-braces, r=Kivooeo
JonathanBrouwer Mar 19, 2026
882df51
Rollup merge of #154086 - aytey:fix-float-range-spacing, r=Kivooeo
JonathanBrouwer Mar 19, 2026
13eb546
Rollup merge of #154087 - aytey:fix-fragment-specifier-whitespace, r=…
JonathanBrouwer Mar 19, 2026
8b70af1
Rollup merge of #154109 - Enselic:unifying-function-types-involving-h…
JonathanBrouwer Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Insert space after float literal ending with . in pretty printer
The pretty printer was collapsing unsuffixed float literals (like `0.`)
with adjacent dot tokens, producing ambiguous or invalid output:

- `0. ..45.` (range) became `0...45.`
- `0. ..=360.` (inclusive range) became `0...=360.`
- `0. .to_string()` (method call) became `0..to_string()`

The fix inserts a space after an unsuffixed float literal ending with
`.` when it appears as the start expression of a range operator or the
receiver of a method call or field access, preventing the trailing dot
from merging with the following `.`, `..`, or `..=` token. This is
skipped when the expression is already parenthesized, since the closing
`)` naturally provides separation.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
  • Loading branch information
aytey committed Mar 19, 2026
commit e9740a4be5cf4e89accacae0bd868557d942d247
48 changes: 37 additions & 11 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,15 @@ impl<'a> State<'a> {
//
// loop { break x; }.method();
//
self.print_expr_cond_paren(
receiver,
receiver.precedence() < ExprPrecedence::Unambiguous,
fixup.leftmost_subexpression_with_dot(),
);
let needs_paren = receiver.precedence() < ExprPrecedence::Unambiguous;
self.print_expr_cond_paren(receiver, needs_paren, fixup.leftmost_subexpression_with_dot());

// If the receiver is an unsuffixed float literal like `0.`, insert
// a space so the `.` of the method call doesn't merge with the
// trailing dot: `0. .method()` instead of `0..method()`.
if !needs_paren && expr_ends_with_dot(receiver) {
self.word(" ");
}
self.word(".");
self.print_ident(segment.ident);
if let Some(args) = &segment.args {
Expand Down Expand Up @@ -658,11 +661,15 @@ impl<'a> State<'a> {
);
}
ast::ExprKind::Field(expr, ident) => {
let needs_paren = expr.precedence() < ExprPrecedence::Unambiguous;
self.print_expr_cond_paren(
expr,
expr.precedence() < ExprPrecedence::Unambiguous,
needs_paren,
fixup.leftmost_subexpression_with_dot(),
);
if !needs_paren && expr_ends_with_dot(expr) {
self.word(" ");
}
self.word(".");
self.print_ident(*ident);
}
Expand All @@ -685,11 +692,15 @@ impl<'a> State<'a> {
let fake_prec = ExprPrecedence::LOr;
if let Some(e) = start {
let start_fixup = fixup.leftmost_subexpression_with_operator(true);
self.print_expr_cond_paren(
e,
start_fixup.precedence(e) < fake_prec,
start_fixup,
);
let needs_paren = start_fixup.precedence(e) < fake_prec;
self.print_expr_cond_paren(e, needs_paren, start_fixup);
// If the start expression is a float literal ending with
// `.`, we need a space before `..` or `..=` so that the
// dots don't merge. E.g. `0. ..45.` must not become
// `0...45.`.
if !needs_paren && expr_ends_with_dot(e) {
self.word(" ");
}
}
match limits {
ast::RangeLimits::HalfOpen => self.word(".."),
Expand Down Expand Up @@ -1025,3 +1036,18 @@ fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> String
template.push('"');
template
}

/// Returns `true` if the printed representation of this expression ends with
/// a `.` character — specifically, an unsuffixed float literal like `0.` or
/// `45.`. This is used to insert whitespace before range operators (`..`,
/// `..=`) so that the dots don't merge (e.g. `0. ..45.` instead of `0...45.`).
fn expr_ends_with_dot(expr: &ast::Expr) -> bool {
match &expr.kind {
ast::ExprKind::Lit(token_lit) => {
token_lit.kind == token::Float
&& token_lit.suffix.is_none()
&& token_lit.symbol.as_str().ends_with('.')
}
_ => false,
}
}
8 changes: 8 additions & 0 deletions tests/pretty/float-trailing-dot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ pp-exact

fn main() {
let _ = 0. ..45.;
let _ = 0. ..=360.;
let _ = 0. ..;
let _ = 0. .to_string();
}
Loading