@@ -2793,3 +2793,111 @@ LL | let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
2793
2793
let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
2794
2794
assert_data_eq ! ( renderer. render( input) , expected) ;
2795
2795
}
2796
+
2797
+ #[ test]
2798
+ fn short_error_format1 ( ) {
2799
+ // tests/ui/short-error-format.rs
2800
+
2801
+ let source = r#"//@ compile-flags: --error-format=short
2802
+
2803
+ fn foo(_: u32) {}
2804
+
2805
+ fn main() {
2806
+ foo("Bonjour".to_owned());
2807
+ let x = 0u32;
2808
+ x.salut();
2809
+ }
2810
+ "# ;
2811
+
2812
+ let input = Level :: ERROR
2813
+ . header ( "mismatched types" )
2814
+ . id ( "E0308" )
2815
+ . group (
2816
+ Group :: new ( ) . element (
2817
+ Snippet :: source ( source)
2818
+ . origin ( "$DIR/short-error-format.rs" )
2819
+ . fold ( true )
2820
+ . annotation (
2821
+ AnnotationKind :: Primary
2822
+ . span ( 80 ..100 )
2823
+ . label ( "expected `u32`, found `String`" ) ,
2824
+ )
2825
+ . annotation (
2826
+ AnnotationKind :: Context
2827
+ . span ( 76 ..79 )
2828
+ . label ( "arguments to this function are incorrect" ) ,
2829
+ ) ,
2830
+ ) ,
2831
+ )
2832
+ . group (
2833
+ Group :: new ( )
2834
+ . element ( Level :: NOTE . title ( "function defined here" ) )
2835
+ . element (
2836
+ Snippet :: source ( source)
2837
+ . origin ( "$DIR/short-error-format.rs" )
2838
+ . fold ( true )
2839
+ . annotation ( AnnotationKind :: Context . span ( 48 ..54 ) . label ( "" ) )
2840
+ . annotation ( AnnotationKind :: Primary . span ( 44 ..47 ) ) ,
2841
+ ) ,
2842
+ ) ;
2843
+
2844
+ let expected = str![ [ r#"
2845
+ error[E0308]: mismatched types
2846
+ --> $DIR/short-error-format.rs:6:9
2847
+ |
2848
+ LL | foo("Bonjour".to_owned());
2849
+ | --- ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `String`
2850
+ | |
2851
+ | arguments to this function are incorrect
2852
+ |
2853
+ note: function defined here
2854
+ --> $DIR/short-error-format.rs:3:4
2855
+ |
2856
+ LL | fn foo(_: u32) {}
2857
+ | ^^^ ------
2858
+ "# ] ] ;
2859
+ let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
2860
+ assert_data_eq ! ( renderer. render( input) , expected) ;
2861
+ }
2862
+
2863
+ #[ test]
2864
+ fn short_error_format2 ( ) {
2865
+ // tests/ui/short-error-format.rs
2866
+
2867
+ let source = r#"//@ compile-flags: --error-format=short
2868
+
2869
+ fn foo(_: u32) {}
2870
+
2871
+ fn main() {
2872
+ foo("Bonjour".to_owned());
2873
+ let x = 0u32;
2874
+ x.salut();
2875
+ }
2876
+ "# ;
2877
+
2878
+ let input = Level :: ERROR
2879
+ . header ( "no method named `salut` found for type `u32` in the current scope" )
2880
+ . id ( "E0599" )
2881
+ . group (
2882
+ Group :: new ( ) . element (
2883
+ Snippet :: source ( source)
2884
+ . origin ( "$DIR/short-error-format.rs" )
2885
+ . fold ( true )
2886
+ . annotation (
2887
+ AnnotationKind :: Primary
2888
+ . span ( 127 ..132 )
2889
+ . label ( "method not found in `u32`" ) ,
2890
+ ) ,
2891
+ ) ,
2892
+ ) ;
2893
+
2894
+ let expected = str![ [ r#"
2895
+ error[E0599]: no method named `salut` found for type `u32` in the current scope
2896
+ --> $DIR/short-error-format.rs:8:7
2897
+ |
2898
+ LL | x.salut();
2899
+ | ^^^^^ method not found in `u32`
2900
+ "# ] ] ;
2901
+ let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
2902
+ assert_data_eq ! ( renderer. render( input) , expected) ;
2903
+ }
0 commit comments