Skip to content

chain: drop redundant check - #7095

Open
matthewhughes934 wants to merge 1 commit into
rust-lang:mainfrom
matthewhughes934:chain-refactor-2
Open

chain: drop redundant check#7095
matthewhughes934 wants to merge 1 commit into
rust-lang:mainfrom
matthewhughes934:chain-refactor-2

Conversation

@matthewhughes934

@matthewhughes934 matthewhughes934 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

In the code: chain_item is a child in the chain, and not the root,
e.g. 1.foo.bar in root.1.foo.bar. So the question is, can a
try!(..) expression appear there, e.g. root.try!(something).0? My
conclusion is that it cannot: firstly note try! is not a valid
identifier (because of the !), so working through the possible chain
types (see pop_expr_chain):

  • MethodCallExpression → Expression . PathExprSegment ( CallParams? )
    (e.g. root.some_method()): PathExprSegment starts with a
    PathIdentSegment, starts with a IDENTIFIER: try! doesn't match
  • FieldExpression → Expression . IDENTIFIER (e.g. root.sub): try!
    doesn't match
  • TupleIndexingExpression → Expression . TUPLE_INDEX (e.g. root.0):
    tuple index is repeated decimal digits: try! doesn't match
  • keywords:.await, .use, .yield: try! doesn't
    match

Of course a: try! can be the root of a chain try!(foo).bar is
perfectly valid.

This fixes an issue: as previously, if the use_try_shorthand config
was set we would skip over any comments in any children of the chain,
so they would be dropped. The added test case covers this situation.

Fixes: #6121

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

@rustbot rustbot added the S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. label Sep 2, 2026
@matthewhughes934
matthewhughes934 force-pushed the chain-refactor-2 branch 2 times, most recently from 52e60e9 to 44c2cc3 Compare September 2, 2026 21:13
@matthewhughes934
matthewhughes934 marked this pull request as ready for review September 2, 2026 21:13
@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Sep 2, 2026
@ytmimi

ytmimi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@matthewhughes934 Not a huge deal, but since we've added the LLM disclosure checkboxes to our PR template it would be nice to see them checked on all PRs going forward.

Note that we've adopted rust-lang/rust's LLM policy

@ytmimi

ytmimi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Also, when referencing issues or PRs for this repo in commit messages it's probably best to use rust-lang/rustfmt#6121 so that this doesn't accidentally refer to a rust-lang/rust issue or PR when we sync back up with that repo. Would you mind updating the commit message?

@jieyouxu

jieyouxu commented Sep 3, 2026

Copy link
Copy Markdown
Member

Also, when referencing issues or PRs for this repo in commit messages it's probably best to use rust-lang/rustfmt#6121 so that this doesn't accidentally refer to a rust-lang/rust issue or PR when we sync back up with that repo. Would you mind updating the commit message?

Hm, triagebot has a detection/message for that.

EDIT: #7098, we just didn't enable it on this repo.

@jieyouxu jieyouxu mentioned this pull request Sep 3, 2026
2 tasks
In the code: `chain_item` is a _child_ in the chain, and not the root,
e.g. `1.foo.bar` in `root.1.foo.bar`. So the question is, can a
`try!(..)` expression appear there, e.g. `root.try!(something).0`? My
conclusion is that it cannot: firstly note `try!` is not a valid
identifier (because of the `!`), so working through the possible chain
types (see `pop_expr_chain`):

* `MethodCallExpression → Expression . PathExprSegment ( CallParams? )`
  (e.g. `root.some_method()`): `PathExprSegment` starts with a
  `PathIdentSegment`, starts with a `IDENTIFIER`: `try!` doesn't match
* `FieldExpression → Expression . IDENTIFIER` (e.g. `root.sub`): `try!`
  doesn't match
* `TupleIndexingExpression → Expression . TUPLE_INDEX` (e.g. `root.0`):
  tuple index is repeated decimal digits: `try!` doesn't match
* keywords:`.await`, `.use`, `.yield`: `try!` doesn't
  match

Of course a: `try!` can be the _root_ of a chain `try!(foo).bar` is
perfectly valid.

This fixes an issue: as previously, if the `use_try_shorthand` config
was set we would skip over any comments in any children of the chain,
so they would be dropped. The added test case covers this situation.

Fixes: rust-lang#6121
@matthewhughes934

Copy link
Copy Markdown
Contributor Author

since we've added the LLM disclosure checkboxes to our PR template it would be nice to see them checked on all PRs going forward.

👍 restored that. I have some muscle memory from keeping the PR description in sync with commits where I'll just git log --format='%b' | xclipb locally -> edit the PR description -> highlight all -> replace, so I'll be careful to keep that trailing bit there.

Hm, triagebot has a detection/message for that.

If the commit can potentially end up in rust-lang/rust (this is what the repo syncing does I think?). Then I think I should make an effort to disambiguate it there too, but triagebot won't be able to help me with that 🥲

I've update the description/commit for both those things

Comment thread src/chains.rs
// FIXME: Figure out the way to get a correct span when converting `try!` to `?`.
let handle_comment =
!(context.config.use_try_shorthand() || is_tries(comment_snippet.trim()));
let handle_comment = !is_tries(comment_snippet.trim());

@ytmimi ytmimi Sep 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description didn't fully help me understand why this is a redundant check. Can you try to explain it differently?

Also, is it fine to just remove the FIXME comment?

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use_try_shorthand = true disallows formatting on chains with comments

4 participants