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

@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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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()

6 participants