- Notifications
You must be signed in to change notification settings - Fork47
Description
I'm currently trying to move the suggestions of the following diagnostic over from Rust to annotate-snippet:
error[E0382]: use of moved value: `x` --> /code/rust/src/test/ui/annotate-snippet/suggestion.rs:4:5 | 4 | let x = vec![1]; | - move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait 7 | let y = x; | - value moved here 9 | x; //~ ERROR use of moved value | ^ value used here after moveIn short, from Rust I can only get aVec that contains the three lines with the annotations. ThisVec containsonly the lines with annotations and no other lines around it. Something similar to this:
[ Line { line_index: 4, annotations: [ Annotation { start_col: 8, end_col: 9, label: "move occurs because ...", }, ], }, Line { line_index: 7, annotations: [ Annotation { start_col: 11, end_col: 12, label: "value moved here", }, ], }, // etc..]I'm currently mapping this to annotate-snippets by turning eachLine into aSlice and then callingDisplayList::from(snippet) at the end.
The problem is that eachSlice has theorigin at the top:
error[E0382]: use of moved value: `x` --> /code/rust/src/test/ui/annotate-snippet/suggestion.rs:4:8 | 4 | let x = vec![1]; | ^ move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait | ::: /code/rust/src/test/ui/annotate-snippet/suggestion.rs:7:12 | 7 | let y = x; | ^ value moved here | ::: /code/rust/src/test/ui/annotate-snippet/suggestion.rs:9:4 | 9 | x; //~ ERROR use of moved value | ^ value used here after moveIf I set the origin of consecutive slices toNone there will still be extra empty padding lines:
error[E0382]: use of moved value: `x` --> /code/rust/src/test/ui/annotate-snippet/suggestion.rs:5:8 |LL | let x = vec![1]; | ^ move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait | |LL | let y = x; | ^ value moved here | |LL | x; //~ ERROR use of moved value | ^ value used here after move |I'm not sure what the original idea for aSlice was, but it seems like the best approach for those rustc annotations?
I can see three ways to solve this currently:
- annotate-snippets doesn't add empty padding lines if the
originisNone - annotate-snippets removes the origin and empty padding lines of consecutive Slices that have the same origin. This means annotate-snippet would have to compare the
originof each Slice to origin of the previous Slice. - We implement
From<Snippet> for DisplayListby ourselves in rustc.
I would love to hear your thoughts on this before I continue with the annotations =)