Skip to content

Commit fd0ac8e

Browse files
authored
Rollup merge of rust-lang#91503 - estebank:call-fn-span, r=michaelwoerister
Tweak "call this function" suggestion to have smaller span
2 parents 2634ab6 + 93564c3 commit fd0ac8e

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

compiler/rustc_typeck/src/check/op.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
) -> bool /* did we suggest to call a function because of missing parentheses? */ {
493493
err.span_label(span, ty.to_string());
494494
if let FnDef(def_id, _) = *ty.kind() {
495-
let source_map = self.tcx.sess.source_map();
496495
if !self.tcx.has_typeck_results(def_id) {
497496
return false;
498497
}
@@ -517,20 +516,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517516
.lookup_op_method(fn_sig.output(), &[other_ty], Op::Binary(op, is_assign))
518517
.is_ok()
519518
{
520-
if let Ok(snippet) = source_map.span_to_snippet(span) {
521-
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
522-
(format!("{}( /* arguments */ )", snippet), Applicability::HasPlaceholders)
523-
} else {
524-
(format!("{}()", snippet), Applicability::MaybeIncorrect)
525-
};
519+
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
520+
("( /* arguments */ )".to_string(), Applicability::HasPlaceholders)
521+
} else {
522+
("()".to_string(), Applicability::MaybeIncorrect)
523+
};
526524

527-
err.span_suggestion(
528-
span,
529-
"you might have forgotten to call this function",
530-
variable_snippet,
531-
applicability,
532-
);
533-
}
525+
err.span_suggestion_verbose(
526+
span.shrink_to_hi(),
527+
"you might have forgotten to call this function",
528+
variable_snippet,
529+
applicability,
530+
);
534531
return true;
535532
}
536533
}

src/test/ui/fn/fn-compare-mismatch.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ LL | let x = f == g;
99
help: you might have forgotten to call this function
1010
|
1111
LL | let x = f() == g;
12-
| ~~~
12+
| ++
1313
help: you might have forgotten to call this function
1414
|
1515
LL | let x = f == g();
16-
| ~~~
16+
| ++
1717

1818
error[E0308]: mismatched types
1919
--> $DIR/fn-compare-mismatch.rs:4:18

src/test/ui/issues/issue-59488.stderr

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ LL | foo > 12;
55
| --- ^ -- {integer}
66
| |
77
| fn() -> i32 {foo}
8-
| help: you might have forgotten to call this function: `foo()`
8+
|
9+
help: you might have forgotten to call this function
10+
|
11+
LL | foo() > 12;
12+
| ++
913

1014
error[E0308]: mismatched types
1115
--> $DIR/issue-59488.rs:14:11
@@ -23,7 +27,11 @@ LL | bar > 13;
2327
| --- ^ -- {integer}
2428
| |
2529
| fn(i64) -> i64 {bar}
26-
| help: you might have forgotten to call this function: `bar( /* arguments */ )`
30+
|
31+
help: you might have forgotten to call this function
32+
|
33+
LL | bar( /* arguments */ ) > 13;
34+
| +++++++++++++++++++
2735

2836
error[E0308]: mismatched types
2937
--> $DIR/issue-59488.rs:18:11
@@ -45,11 +53,11 @@ LL | foo > foo;
4553
help: you might have forgotten to call this function
4654
|
4755
LL | foo() > foo;
48-
| ~~~~~
56+
| ++
4957
help: you might have forgotten to call this function
5058
|
5159
LL | foo > foo();
52-
| ~~~~~
60+
| ++
5361

5462
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
5563
--> $DIR/issue-59488.rs:25:9

src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ LL | assert_eq!(a, 0);
66
| |
77
| fn() -> i32 {a}
88
| {integer}
9-
| help: you might have forgotten to call this function: `*left_val()`
109
|
1110
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
help: you might have forgotten to call this function
12+
|
13+
LL | if !(*left_val() == *right_val) {
14+
| ++
1215

1316
error[E0308]: mismatched types
1417
--> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5

0 commit comments

Comments
 (0)