Skip to content

Do not mention missing PartialOrd impl when involving uncalled fns #60051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
op.node.as_str(),
lhs_ty);

let mut involves_fn = false;
if !lhs_expr.span.eq(&rhs_expr.span) {
self.add_type_neq_err_label(
involves_fn |= self.add_type_neq_err_label(
&mut err,
lhs_expr.span,
lhs_ty,
rhs_ty,
op,
is_assign
);
self.add_type_neq_err_label(
involves_fn |= self.add_type_neq_err_label(
&mut err,
rhs_expr.span,
rhs_ty,
Expand Down Expand Up @@ -410,7 +411,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"`{}` might need a bound for `{}`",
lhs_ty, missing_trait
));
} else if !suggested_deref {
} else if !suggested_deref && !involves_fn {
err.note(&format!(
"an implementation of `{}` might \
be missing for `{}`",
Expand All @@ -429,6 +430,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(lhs_ty, rhs_ty, return_ty)
}

/// If one of the types is an uncalled function and calling it would yield the other type,
/// suggest calling the function. Returns wether a suggestion was given.
fn add_type_neq_err_label(
&self,
err: &mut errors::DiagnosticBuilder<'_>,
Expand All @@ -437,7 +440,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
other_ty: Ty<'tcx>,
op: hir::BinOp,
is_assign: IsAssign,
) {
) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = ty.sty {
let source_map = self.tcx.sess.source_map();
Expand Down Expand Up @@ -481,8 +484,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
variable_snippet,
applicability,
);
return true;
}
}
false
}

fn check_str_addition(
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/fn/fn-compare-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ LL | let x = f == g;
| - ^^ - fn() {main::g}
| |
| fn() {main::f}
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `fn() {main::f}`
help: you might have forgotten to call this function
|
LL | let x = f() == g;
Expand Down
14 changes: 7 additions & 7 deletions src/test/ui/issues/issue-59488.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ fn bar(a: i64) -> i64 {

fn main() {
foo > 12;
//~^ ERROR 12:9: 12:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR 12:11: 12:13: mismatched types [E0308]
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR mismatched types [E0308]

bar > 13;
//~^ ERROR 16:9: 16:10: binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369]
//~| ERROR 16:11: 16:13: mismatched types [E0308]
//~^ ERROR binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369]
//~| ERROR mismatched types [E0308]

foo > foo;
//~^ ERROR 20:9: 20:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]

foo > bar;
//~^ ERROR 23:9: 23:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR 23:11: 23:14: mismatched types [E0308]
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR mismatched types [E0308]
}
6 changes: 0 additions & 6 deletions src/test/ui/issues/issue-59488.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ LL | foo > 12;
| |
| fn() -> i32 {foo}
| help: you might have forgotten to call this function: `foo()`
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`

error[E0308]: mismatched types
--> $DIR/issue-59488.rs:12:11
Expand All @@ -26,8 +24,6 @@ LL | bar > 13;
| |
| fn(i64) -> i64 {bar}
| help: you might have forgotten to call this function: `bar( /* arguments */ )`
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `fn(i64) -> i64 {bar}`

error[E0308]: mismatched types
--> $DIR/issue-59488.rs:16:11
Expand All @@ -45,8 +41,6 @@ LL | foo > foo;
| --- ^ --- fn() -> i32 {foo}
| |
| fn() -> i32 {foo}
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
help: you might have forgotten to call this function
|
LL | foo() > foo;
Expand Down