@@ -2952,3 +2952,52 @@ LL + .sum::<GENERIC_ARG>() //~ ERROR type annotations needed
29522952 let renderer = renderer. theme ( OutputTheme :: Unicode ) ;
29532953 assert_data_eq ! ( renderer. render( input) , expected_unicode) ;
29542954}
2955+
2956+ #[ test]
2957+ fn suggestion_same_as_source ( ) {
2958+ let source = r#"// When the type of a method call's receiver is unknown, the span should point
2959+ // to the receiver (and not the entire call, as was previously the case before
2960+ // the fix of which this tests).
2961+
2962+ fn shines_a_beacon_through_the_darkness() {
2963+ let x: Option<_> = None; //~ ERROR type annotations needed
2964+ x.unwrap().method_that_could_exist_on_some_type();
2965+ }
2966+
2967+ fn courier_to_des_moines_and_points_west(data: &[u32]) -> String {
2968+ data.iter()
2969+ .sum::<_>() //~ ERROR type annotations needed
2970+ .to_string()
2971+ }
2972+
2973+ fn main() {}
2974+ "# ;
2975+
2976+ let input = & [
2977+ Group :: with_title ( Level :: ERROR . title ( "type annotations needed" ) . id ( "E0282" ) ) . element (
2978+ Snippet :: source ( source)
2979+ . path ( "$DIR/issue-42234-unknown-receiver-type.rs" )
2980+ . annotation ( AnnotationKind :: Primary . span ( 449 ..452 ) . label (
2981+ "cannot infer type of the type parameter `S` declared on the method `sum`" ,
2982+ ) ) ,
2983+ ) ,
2984+ Group :: with_title ( Level :: HELP . title ( "consider specifying the generic argument" ) ) . element (
2985+ Snippet :: source ( source)
2986+ . path ( "$DIR/issue-42234-unknown-receiver-type.rs" )
2987+ . line_start ( 12 )
2988+ . fold ( true )
2989+ . patch ( Patch :: new ( 452 ..457 , "::<_>" ) ) ,
2990+ ) ,
2991+ ] ;
2992+ let expected = str![ [ r#"
2993+ error[E0282]: type annotations needed
2994+ --> $DIR/issue-42234-unknown-receiver-type.rs:12:10
2995+ |
2996+ LL | .sum::<_>() //~ ERROR type annotations needed
2997+ | ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
2998+ |
2999+ help: consider specifying the generic argument
3000+ "# ] ] ;
3001+ let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
3002+ assert_data_eq ! ( renderer. render( input) , expected) ;
3003+ }
0 commit comments