@@ -1844,6 +1844,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441844 field,
18451845 expr_t,
18461846 expr,
1847+ None ,
18471848 ) ;
18481849 }
18491850 err. emit ( ) ;
@@ -1870,9 +1871,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18701871 } ;
18711872 let expr_snippet =
18721873 self . tcx . sess . source_map ( ) . span_to_snippet ( expr. span ) . unwrap_or ( String :: new ( ) ) ;
1873- if expr_is_call && expr_snippet. starts_with ( "(" ) && expr_snippet. ends_with ( ")" ) {
1874- let after_open = expr. span . lo ( ) + rustc_span:: BytePos ( 1 ) ;
1875- let before_close = expr. span . hi ( ) - rustc_span:: BytePos ( 1 ) ;
1874+ let is_wrapped = expr_snippet. starts_with ( "(" ) && expr_snippet. ends_with ( ")" ) ;
1875+ let after_open = expr. span . lo ( ) + rustc_span:: BytePos ( 1 ) ;
1876+ let before_close = expr. span . hi ( ) - rustc_span:: BytePos ( 1 ) ;
1877+
1878+ if expr_is_call && is_wrapped {
18761879 err. multipart_suggestion (
18771880 "remove wrapping parentheses to call the method" ,
18781881 vec ! [
@@ -1882,12 +1885,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18821885 Applicability :: MachineApplicable ,
18831886 ) ;
18841887 } else if !self . expr_in_place ( expr. hir_id ) {
1888+ // Suggest call parentheses inside the wrapping parentheses
1889+ let span = if is_wrapped {
1890+ expr. span . with_lo ( after_open) . with_hi ( before_close)
1891+ } else {
1892+ expr. span
1893+ } ;
18851894 self . suggest_method_call (
18861895 & mut err,
18871896 "use parentheses to call the method" ,
18881897 field,
18891898 expr_t,
18901899 expr,
1900+ Some ( span) ,
18911901 ) ;
18921902 } else {
18931903 err. help ( "methods are immutable and cannot be assigned to" ) ;
0 commit comments