|
| 1 | +use annotate_snippets::{ |
| 2 | + renderer::DecorStyle, AnnotationKind, Group, Level, Patch, Renderer, Snippet, |
| 3 | +}; |
| 4 | + |
| 5 | +fn main() { |
| 6 | + let source = r#" |
| 7 | +#![allow(dead_code)] |
| 8 | +struct U <T> { |
| 9 | + wtf: Option<Box<U<T>>>, |
| 10 | + x: T, |
| 11 | +} |
| 12 | +fn main() { |
| 13 | + U { |
| 14 | + wtf: Some(Box(U { |
| 15 | + wtf: None, |
| 16 | + x: (), |
| 17 | + })), |
| 18 | + x: () |
| 19 | + }; |
| 20 | + let _ = std::collections::HashMap(); |
| 21 | + let _ = std::collections::HashMap {}; |
| 22 | + let _ = Box {}; |
| 23 | +} |
| 24 | +"#; |
| 25 | + |
| 26 | + let report = &[ |
| 27 | + Group::with_title(Level::ERROR.primary_title( |
| 28 | + "cannot construct `Box<_, _>` with struct literal syntax due to private fields", |
| 29 | + )) |
| 30 | + .element( |
| 31 | + Snippet::source(source) |
| 32 | + .path("$DIR/multi-suggestion.rs") |
| 33 | + .annotation(AnnotationKind::Primary.span(295..298)), |
| 34 | + ) |
| 35 | + .element(Level::NOTE.message("private fields `0` and `1` that were not provided")), |
| 36 | + Group::with_title(Level::HELP.secondary_title( |
| 37 | + "you might have meant to use an associated function to build this type", |
| 38 | + )) |
| 39 | + .element( |
| 40 | + Snippet::source(source) |
| 41 | + .path("$DIR/multi-suggestion.rs") |
| 42 | + .patch(Patch::new(298..301, "::new(_)")), |
| 43 | + ) |
| 44 | + .element( |
| 45 | + Snippet::source(source) |
| 46 | + .path("$DIR/multi-suggestion.rs") |
| 47 | + .patch(Patch::new(298..301, "::new_uninit()")), |
| 48 | + ) |
| 49 | + .element( |
| 50 | + Snippet::source(source) |
| 51 | + .path("$DIR/multi-suggestion.rs") |
| 52 | + .patch(Patch::new(298..301, "::new_zeroed()")), |
| 53 | + ) |
| 54 | + .element( |
| 55 | + Snippet::source(source) |
| 56 | + .path("$DIR/multi-suggestion.rs") |
| 57 | + .patch(Patch::new(298..301, "::new_in(_, _)")), |
| 58 | + ) |
| 59 | + .element(Level::NOTE.no_name().message("and 12 other candidates")), |
| 60 | + Group::with_title(Level::HELP.secondary_title("consider using the `Default` trait")) |
| 61 | + .element( |
| 62 | + Snippet::source(source) |
| 63 | + .path("$DIR/multi-suggestion.rs") |
| 64 | + .patch(Patch::new(295..295, "<")) |
| 65 | + .patch(Patch::new( |
| 66 | + 298..301, |
| 67 | + " as std::default::Default>::default()", |
| 68 | + )), |
| 69 | + ), |
| 70 | + ]; |
| 71 | + |
| 72 | + let renderer = Renderer::styled().decor_style(DecorStyle::Unicode); |
| 73 | + anstream::println!("{}", renderer.render(report)); |
| 74 | +} |
0 commit comments