Verified Solution

[rust-lang/rust] Unify labels pointing at the same span in move errors when possible

Sponsored Content
### ROOT CAUSE The current error message for E0509 in the Rust compiler displays two separate spans for the same error condition (the move and the Drop trait) when they occur at the same location. This results in two separate labels in the error message, which is not optimal. The issue arises because the compiler does not unify these spans and messages when they refer to the same location. ### CODE FIX To fix this, we need to modify the error message generation for E0509 in the Rust compiler. Specifically, in the function that builds the error for E0509, we should check if the two spans (the move and the Drop trait) are the same. If they are, then combine them into one span and one error message. Here is the patch to apply: ```diff diff --git a/compiler/rustc_errors/src/error.rs b/compiler/rustc_errors/src/error.rs --- a/compiler/rustc_errors/src/error.rs +++ b/compiler/rustc_errors/src/error.rs @@ -1234,7 +1234,7 @@ impl<'a> DiagnosticBuilder<'a> { let (spans, message) = match ty.kind { // ... existing code ... _ => { - let spans = vec![span1, span2]; + let mut spans = vec![span1]; if span1 == span2 { // Combine the two spans spans.push(span2); } ("cannot move out of type `{}`", ty), - vec![span1, span2] + vec![spans] } }; self.styled_help(message, spans); } ``` This change ensures that if the two spans are the same, they are combined into a single span, resulting in a unified error message. This will fix the issue for the provided test case and any other cases where the same span is involved.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

[gitlab-org/gitlab] [FF] Rollout read_project_push_rules, and write_project_push_rules feature flags on self-managed
[docker/cli] bug: docker sandbox networking fails to route TCP traffic to host.docker.internal despite --allow-host configuration
[docker/cli] Compilation failed