-
Notifications
You must be signed in to change notification settings - Fork 13.4k
source_span_for_markdown_range: fix utf8 violation #141666
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
source_span_for_markdown_range: fix utf8 violation #141666
Conversation
We need a regression test. |
yes, I was under the impression you were working on that (well, a MCVE for the issue). if you want me to do it, i can. |
I triggered the issue with |
Alright, I think I should be able to throw something together. |
This comment has been minimized.
This comment has been minimized.
my initial ideas for how to trigger this crash were unsuccessful, might be easier to just throw treereduce-rustc at it or something. also not sure if you had the bug happen on unmodified sysinfo or if there was some change you made. |
See #141665 (comment) for a minimal repro involving |
3194bc1
to
74b1eb3
Compare
@fmease do you think we could just add a regression test to the clippy test suite? either as a followup PR or via submodules. |
Isn't it possible to create a span in a unit test and then run our function on it? |
A unit test would almost certainly work, but I'm not sure the proper way to get a |
@@ -570,7 +570,12 @@ pub fn source_span_for_markdown_range( | |||
{ | |||
// If there is either a match in a previous fragment, or | |||
// multiple matches in this fragment, there is ambiguity. | |||
if match_data.is_none() && !snippet[match_start + 1..].contains(pat) { | |||
// the snippet cannot be zero-sized, |
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.
Also please don't split your comments so much. It makes much harder to read. You have up to 100 columns, make use of it.
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.
I was trying to use semantic line breaks, but maybe i went a bit overboard. I also am using a laptop with a fairly small screen.
That's a good point. I suppose there are such unit tests in the compiler making use of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The new code should have exactly identical behavior to the old code, but without the crash. I thought I fixed the inconsistentcy, but the tests are still failing, which means something changed which shouldn't have. |
Ok, it looks like initializing TyCtx for a unit test is prohibativly complex, but the good news is we don't actually need TyCtx, we just need EDIT: the symbols are never read, so we can just use placeholder values |
Ok, added unit tests and fixed my very silly mistake, will squash once CI passes. also, sidenote, I think the single raw doc fragment case might be broken. a test like |
it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.
9d48ae2
to
a8b5e70
Compare
Nice, thanks! @bors r+ rollup |
…or_markdown_range-bug-141665, r=GuillaumeGomez source_span_for_markdown_range: fix utf8 violation it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test. fixes rust-lang#141665 r? `@GuillaumeGomez`
Rollup of 9 pull requests Successful merges: - #140370 (Improve diagnostics for usage of qualified paths within tuple struct exprs/pats) - #141224 (terminology: allocated object → allocation) - #141622 (implement `va_arg` for `powerpc`) - #141666 (source_span_for_markdown_range: fix utf8 violation) - #141789 (Exclude `CARGO_HOME` from `generate-copyright` in-tree determination) - #141823 (Drive-by refactor: use `OnceCell` for the reverse region SCC graph) - #141834 (Add unimplemented `current_dll_path()` for WASI) - #141846 (Fix TLS model on bootstrap for cygwin) - #141852 (resolve if-let-chain FIXME on bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #141666 - lolbinarycat:rustdoc-source_span_for_markdown_range-bug-141665, r=GuillaumeGomez source_span_for_markdown_range: fix utf8 violation it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test. fixes #141665 r? ``@GuillaumeGomez``
it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.
fixes #141665
r? @GuillaumeGomez