Fix ICE caused by invalid spans for shrink_file#148735
Conversation
|
cc @Muscraft |
| WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } | ||
| WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } | ||
| WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } |
There was a problem hiding this comment.
I have worries that this will not pass aarch64-msvc-1 the same way it was in my PR
There was a problem hiding this comment.
ah, it do have the same issue.
There was a problem hiding this comment.
so, I read the discussion on zulip, seems there is another standalone bug. so is it a temprary way we skip Windows for this testcase(and add it back after that bug is fixed)?
There was a problem hiding this comment.
These warnings are coming from this call to is_different. The reason this is happening with AnnotateSnippetEmitter and not HumanEmitter is because HumanEmitter checks for source code availability before it calls is_different. Changing lines 353 to 368 in annotate_snippet_emitter_writer.rs to the following fixes the issue:
let lo = subst.parts.iter().map(|part| part.span.lo()).min()?;
let lo_file = sm.lookup_source_file(lo);
let hi = subst.parts.iter().map(|part| part.span.hi()).max()?;
let hi_file = sm.lookup_source_file(hi);
// The different spans might belong to different contexts, if so ignore suggestion.
if lo_file.stable_id != hi_file.stable_id {
return None;
}
// We can't splice anything if the source is unavailable.
if !sm.ensure_source_file_source_present(&lo_file) {
return None;
}
// Account for cases where we are suggesting the same code that's already
// there. This shouldn't happen often, but in some cases for multipart
// suggestions it's much easier to handle it here than in the origin.
subst.parts.retain(|p| is_different(sm, &p.snippet, p.span));
if subst.parts.is_empty() { None } else { Some(subst) }There was a problem hiding this comment.
yes, this can fix the issue.
I have a question, the old code invoke should_show_source_code to check with ignored_directories_in_source_blocks, we don't need this anymore?
There was a problem hiding this comment.
updated the code and tests.
@Kivooeo i'm not sure whether your PR could be unblocked by this commit, you can have a try.
There was a problem hiding this comment.
yes, this can fix the issue. I have a question, the old code invoke
should_show_source_codeto check withignored_directories_in_source_blocks, we don't need this anymore?
I switched it so that it would match splice_lines, which is where I got the solution from. Going back to using should_show_source_code to maintain consistency with the old code would be a perfectly reasonable thing to do.
|
@bors try jobs=aarch64-msvc-1 |
This comment has been minimized.
This comment has been minimized.
Fix ICE caused by invalid spans for shrink_file try-job: aarch64-msvc-1
This comment has been minimized.
This comment has been minimized.
|
💔 Test for eca91bd failed: CI. Failed jobs:
|
|
r=me once the comments are addressed. @rustbot author |
7262408 to
725b213
Compare
…=Muscraft Prefer to use file.stable_id over file.name from source map From rust-lang#148735 (comment) r? `@Muscraft`
Rollup merge of #148792 - chenyukang:yukang-fix-file-name, r=Muscraft Prefer to use file.stable_id over file.name from source map From #148735 (comment) r? `@Muscraft`
Prefer to use file.stable_id over file.name from source map From rust-lang/rust#148735 (comment) r? `@Muscraft`
|
@bors r=nnethercote |
Rollup of 7 pull requests Successful merges: - #147701 (rustdoc: don't ignore path distance for doc aliases) - #148735 (Fix ICE caused by invalid spans for shrink_file) - #148839 (fix rtsan_nonblocking_async lint closure ICE) - #148846 (add a test for combining RPIT with explicit tail calls) - #148872 (fix: Do not ICE when missing match arm with ill-formed subty is met) - #148880 (Remove explicit install of `eslint` inside of `tidy`'s Dockerfile) - #148883 (bootstrap: dont require cmake if local-rebuild is enabled) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #148735 - chenyukang:yukang-fix-ice-148732, r=nnethercote Fix ICE caused by invalid spans for shrink_file Fixes #148732 There are two issues in this function: 1. the original issue is caused by a typo error, which is fixed in the first commit 2. another different ice(Patch span `7..7` is beyond the end of buffer `0`) will be reported after fixing the first one, is caused by spans cross file boundaries due to macro expansion. It is fixed in the second commit. r? `@nnethercote` edited: also fixes #148684, added a new testcase for it in the last commit.
|
Bors no, this is already merged. @bors r- retry |
Prefer to use file.stable_id over file.name from source map From rust-lang/rust#148735 (comment) r? `@Muscraft`
Fixes #148732
There are two issues in this function:
7..7is beyond the end of buffer0) will be reported after fixing the first one, is caused by spans cross file boundaries due to macro expansion. It is fixed in the second commit.r? @nnethercote
edited: also fixes #148684, added a new testcase for it in the last commit.