Skip to content

Conversation

@chenyukang
Copy link
Member

@chenyukang chenyukang commented Nov 9, 2025

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.

@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2025

rustc_errors::annotate_snippet_emitter_writer was changed

cc @Muscraft

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 9, 2025
Comment on lines 1 to 3
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" }) }
Copy link
Member

Choose a reason for hiding this comment

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

I have worries that this will not pass aarch64-msvc-1 the same way it was in my PR

cc: #general > Windows path normalization in tests

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, it do have the same issue.

Copy link
Member Author

@chenyukang chenyukang Nov 10, 2025

Choose a reason for hiding this comment

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

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)?

Copy link
Member

Choose a reason for hiding this comment

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

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) }

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated the code and tests.
@Kivooeo i'm not sure whether your PR could be unblocked by this commit, you can have a try.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I'll try later today

Copy link
Member

Choose a reason for hiding this comment

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

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?

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.

@Kivooeo
Copy link
Member

Kivooeo commented Nov 9, 2025

@bors try jobs=aarch64-msvc-1

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 9, 2025
Fix ICE caused by invalid spans for shrink_file

try-job: aarch64-msvc-1
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 9, 2025

💔 Test for eca91bd failed: CI. Failed jobs:

@nnethercote
Copy link
Contributor

r=me once the comments are addressed.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2025
@chenyukang chenyukang force-pushed the yukang-fix-ice-148732 branch from 7262408 to 725b213 Compare November 10, 2025 01:23
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 11, 2025
…=Muscraft

Prefer to use file.stable_id over file.name from source map

From rust-lang#148735 (comment)

r? `@Muscraft`
rust-timer added a commit that referenced this pull request Nov 11, 2025
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`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 12, 2025
Prefer to use file.stable_id over file.name from source map

From rust-lang/rust#148735 (comment)

r? `@Muscraft`
@chenyukang
Copy link
Member Author

@bors r=nnethercote

@bors
Copy link
Collaborator

bors commented Nov 13, 2025

📌 Commit 4a2c9a1 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2025
bors added a commit that referenced this pull request Nov 13, 2025
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
@bors bors merged commit 06b18db into rust-lang:main Nov 13, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 13, 2025
@bors
Copy link
Collaborator

bors commented Nov 13, 2025

⌛ Testing commit 4a2c9a1 with merge 5dbf406...

rust-timer added a commit that referenced this pull request Nov 13, 2025
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.
@Zalathar
Copy link
Member

Bors no, this is already merged.

@bors r- retry

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE assertion failed: line_index < lines.len() ICE line_index < lines.len()

8 participants