Skip to content

Reorder span_suggestions to appear below main labels #40851 #41698

Closed
@gaurikholkar-zz

Description

@gaurikholkar-zz

In #40851, owing to the the fact that suggestions have been moved inline, no doubt is a good idea. But in the case where the span of the suggestion and the span of the main comment coincide, it currently causes the suggestion to appear before the main comment, which seems suboptimal. We should reorder suggestions so they appear below other labels.

Here is the example,

fn main() {
    let v = vec![String::from("oh no")];
    
    let e = v[0];
}
error[E0507]: cannot move out of indexed content
 --> ex1.rs:4:13
  |
4 |     let e = v[0];
  |             ^^^^
  |             |
  |             help: consider using a reference instead `&v[0]`
  |             cannot move out of indexed content

error: aborting due to previous error

In the move_error.rs

let initializer =
                    e.init.as_ref().expect("should have an initializer to get an error");
                if let Ok(snippet) = bccx.tcx.sess.codemap().span_to_snippet(initializer.span) {
                    err.span_suggestion(initializer.span,
                                        "consider using a reference instead",format!("&{}", snippet));
                }
            }

cc @nikomatsakis @estebank

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions