|
1 |
| -use annotate_snippets::{Annotation, AnnotationKind, Group, Level, Patch, Renderer, Snippet}; |
| 1 | +use annotate_snippets::{ |
| 2 | + Annotation, AnnotationKind, Group, Level, Padding, Patch, Renderer, Snippet, |
| 3 | +}; |
2 | 4 |
|
3 | 5 | use annotate_snippets::renderer::OutputTheme;
|
4 | 6 | use snapbox::{assert_data_eq, str};
|
@@ -2823,3 +2825,130 @@ error:
|
2823 | 2825 | let renderer = Renderer::plain().theme(OutputTheme::Unicode);
|
2824 | 2826 | assert_data_eq!(renderer.render(input), expected_unicode);
|
2825 | 2827 | }
|
| 2828 | + |
| 2829 | +#[test] |
| 2830 | +fn padding_last_in_group() { |
| 2831 | + let source = r#"// When the type of a method call's receiver is unknown, the span should point |
| 2832 | +// to the receiver (and not the entire call, as was previously the case before |
| 2833 | +// the fix of which this tests). |
| 2834 | +
|
| 2835 | +fn shines_a_beacon_through_the_darkness() { |
| 2836 | + let x: Option<_> = None; //~ ERROR type annotations needed |
| 2837 | + x.unwrap().method_that_could_exist_on_some_type(); |
| 2838 | +} |
| 2839 | +
|
| 2840 | +fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { |
| 2841 | + data.iter() |
| 2842 | + .sum::<_>() //~ ERROR type annotations needed |
| 2843 | + .to_string() |
| 2844 | +} |
| 2845 | +
|
| 2846 | +fn main() {} |
| 2847 | +"#; |
| 2848 | + |
| 2849 | + let input = &[ |
| 2850 | + Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")) |
| 2851 | + .element( |
| 2852 | + Snippet::source(source) |
| 2853 | + .path("$DIR/issue-42234-unknown-receiver-type.rs") |
| 2854 | + .annotation(AnnotationKind::Primary.span(449..452).label( |
| 2855 | + "cannot infer type of the type parameter `S` declared on the method `sum`", |
| 2856 | + )), |
| 2857 | + ) |
| 2858 | + .element(Padding), |
| 2859 | + ]; |
| 2860 | + |
| 2861 | + let expected_ascii = str![[r#" |
| 2862 | +error[E0282]: type annotations needed |
| 2863 | + --> $DIR/issue-42234-unknown-receiver-type.rs:12:10 |
| 2864 | + | |
| 2865 | +LL | .sum::<_>() //~ ERROR type annotations needed |
| 2866 | + | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` |
| 2867 | + | |
| 2868 | +"#]]; |
| 2869 | + let renderer = Renderer::plain().anonymized_line_numbers(true); |
| 2870 | + assert_data_eq!(renderer.render(input), expected_ascii); |
| 2871 | + |
| 2872 | + let expected_unicode = str![[r#" |
| 2873 | +error[E0282]: type annotations needed |
| 2874 | + ╭▸ $DIR/issue-42234-unknown-receiver-type.rs:12:10 |
| 2875 | + │ |
| 2876 | +LL │ .sum::<_>() //~ ERROR type annotations needed |
| 2877 | + │ ━━━ cannot infer type of the type parameter `S` declared on the method `sum` |
| 2878 | + ╰╴ |
| 2879 | +"#]]; |
| 2880 | + let renderer = renderer.theme(OutputTheme::Unicode); |
| 2881 | + assert_data_eq!(renderer.render(input), expected_unicode); |
| 2882 | +} |
| 2883 | + |
| 2884 | +#[test] |
| 2885 | +fn padding_last_in_group_with_group_after() { |
| 2886 | + let source = r#"// When the type of a method call's receiver is unknown, the span should point |
| 2887 | +// to the receiver (and not the entire call, as was previously the case before |
| 2888 | +// the fix of which this tests). |
| 2889 | +
|
| 2890 | +fn shines_a_beacon_through_the_darkness() { |
| 2891 | + let x: Option<_> = None; //~ ERROR type annotations needed |
| 2892 | + x.unwrap().method_that_could_exist_on_some_type(); |
| 2893 | +} |
| 2894 | +
|
| 2895 | +fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { |
| 2896 | + data.iter() |
| 2897 | + .sum::<_>() //~ ERROR type annotations needed |
| 2898 | + .to_string() |
| 2899 | +} |
| 2900 | +
|
| 2901 | +fn main() {} |
| 2902 | +"#; |
| 2903 | + |
| 2904 | + let input = &[ |
| 2905 | + Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")) |
| 2906 | + .element( |
| 2907 | + Snippet::source(source) |
| 2908 | + .path("$DIR/issue-42234-unknown-receiver-type.rs") |
| 2909 | + .annotation(AnnotationKind::Primary.span(449..452).label( |
| 2910 | + "cannot infer type of the type parameter `S` declared on the method `sum`", |
| 2911 | + )), |
| 2912 | + ) |
| 2913 | + .element(Padding), |
| 2914 | + Group::with_title(Level::HELP.title("consider specifying the generic argument")).element( |
| 2915 | + Snippet::source(source) |
| 2916 | + .path("$DIR/issue-42234-unknown-receiver-type.rs") |
| 2917 | + .line_start(12) |
| 2918 | + .fold(true) |
| 2919 | + .patch(Patch::new(452..457, "::<GENERIC_ARG>")), |
| 2920 | + ), |
| 2921 | + ]; |
| 2922 | + |
| 2923 | + let expected_ascii = str![[r#" |
| 2924 | +error[E0282]: type annotations needed |
| 2925 | + --> $DIR/issue-42234-unknown-receiver-type.rs:12:10 |
| 2926 | + | |
| 2927 | +LL | .sum::<_>() //~ ERROR type annotations needed |
| 2928 | + | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` |
| 2929 | + | |
| 2930 | +help: consider specifying the generic argument |
| 2931 | + | |
| 2932 | +LL - .sum::<_>() //~ ERROR type annotations needed |
| 2933 | +LL + .sum::<GENERIC_ARG>() //~ ERROR type annotations needed |
| 2934 | + | |
| 2935 | +"#]]; |
| 2936 | + let renderer = Renderer::plain().anonymized_line_numbers(true); |
| 2937 | + assert_data_eq!(renderer.render(input), expected_ascii); |
| 2938 | + |
| 2939 | + let expected_unicode = str![[r#" |
| 2940 | +error[E0282]: type annotations needed |
| 2941 | + ╭▸ $DIR/issue-42234-unknown-receiver-type.rs:12:10 |
| 2942 | + │ |
| 2943 | +LL │ .sum::<_>() //~ ERROR type annotations needed |
| 2944 | + │ ━━━ cannot infer type of the type parameter `S` declared on the method `sum` |
| 2945 | + ╰╴ |
| 2946 | +help: consider specifying the generic argument |
| 2947 | + ╭╴ |
| 2948 | +LL - .sum::<_>() //~ ERROR type annotations needed |
| 2949 | +LL + .sum::<GENERIC_ARG>() //~ ERROR type annotations needed |
| 2950 | + ╰╴ |
| 2951 | +"#]]; |
| 2952 | + let renderer = renderer.theme(OutputTheme::Unicode); |
| 2953 | + assert_data_eq!(renderer.render(input), expected_unicode); |
| 2954 | +} |
0 commit comments