-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Snippet rework #14724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Snippet rework #14724
Conversation
|
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
|
The first two commits are mainly renames. The third commit has all the actual changes. |
91b8913 to
b336277
Compare
|
Looking at Why is this not part of rustc in the first place? |
This comment has been minimized.
This comment has been minimized.
clippy_utils/src/source.rs
Outdated
| /// Handle to a source file's text and a range within that file. | ||
| /// | ||
| /// With debug assertions the range is checked to be a valid substring of the source text. Without | ||
| /// assertions `None` will be returned from various functions when accessing the substring of the | ||
| /// source text fails. | ||
| #[derive(Clone)] | ||
| pub struct SourceFileRange { | ||
| file: SourceText, | ||
| range: Range<RelativeBytePos>, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both SourceFileRange and SourceText can represent subsets of a source file, could they be merged into a single type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing so would require that SourceFileRange always validate it's range. The main point of SourceText is that it's definitely a valid string.
They're also serving two different purpose. One is a substring of the source text, the other is a movable view of a whole file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always validating doesn't seem so bad to me, API wise it's some extra ?ing when using with_lo/with_hi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're still modelling two completely different things. Even if only one of them is exposed using both to implement it is still useful.
clippy_lints/src/ranges.rs
Outdated
| && let Some(span) = new_lhs.span.map_span(cx, |file| { | ||
| let src = file.with_hi(span.hi()).src_text()?; | ||
| // Do not continue if we have mismatched number of parens, otherwise the suggestion is wrong | ||
| src.matches('(').count() == src.matches(')').count() | ||
| (src.matches('(').count() == src.matches(')').count()).then_some(file) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_hi mutating file here is confusing, there's similar elsewhere with trim_start/trim_end
Reusing names of non mutating methods while also returning a value makes it difficult to realise what's happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, those need to be renamed.
ae6dc9d to
8fe48da
Compare
This comment has been minimized.
This comment has been minimized.
|
No changes for 0cff672 |
This is blocking #14724 changelog: none
f0d6813 to
b89b849
Compare
This comment has been minimized.
This comment has been minimized.
d6dcaef to
dfd4cf7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b21e0f0 to
3f4330b
Compare
This comment has been minimized.
This comment has been minimized.
3f6aaae to
bf9f4e9
Compare
|
The API has changed again; this time to support splitting a range. Changes include:
I might switch the range editing functions to be on the range, but that means an extra trait will need to be imported everywhere. |
This is blocking #14724 as it triggers the debug assertions it adds. The inter item span parsing was introduced to solve #12197. This is better handled by just not linting anything within bodies. changelog: [`missing_docs_in_private_items`]: Don't lint items in bodies and automatically derived impls changelog: [`missing_docs_in_private_items`]: Better detect when things are accessible from the crate root changelog: [`missing_docs_in_private_items`]: Lint unnameable items which are accessible outside the crate
bf9f4e9 to
fe0912a
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
1ca84e8 to
0fce0bc
Compare
fce32d4 to
51934e2
Compare
Rename `get_source_text` and `check_source_text` to `get_text` and `check_text`.
51934e2 to
0cff672
Compare
This is a further rework of our snippet accessing/creating code.
The general design goals with this:
changelog: None