Do not mention missing PartialOrd impl when involving uncalled fns

This commit is contained in:
Esteban Küber 2019-04-17 14:37:50 -07:00
parent 70f130954d
commit 8f77a035a4
4 changed files with 14 additions and 19 deletions

View File

@ -332,8 +332,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
op.node.as_str(), op.node.as_str(),
lhs_ty); lhs_ty);
let mut involves_fn = false;
if !lhs_expr.span.eq(&rhs_expr.span) { if !lhs_expr.span.eq(&rhs_expr.span) {
self.add_type_neq_err_label( involves_fn |= self.add_type_neq_err_label(
&mut err, &mut err,
lhs_expr.span, lhs_expr.span,
lhs_ty, lhs_ty,
@ -341,7 +342,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
op, op,
is_assign is_assign
); );
self.add_type_neq_err_label( involves_fn |= self.add_type_neq_err_label(
&mut err, &mut err,
rhs_expr.span, rhs_expr.span,
rhs_ty, rhs_ty,
@ -410,7 +411,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"`{}` might need a bound for `{}`", "`{}` might need a bound for `{}`",
lhs_ty, missing_trait lhs_ty, missing_trait
)); ));
} else if !suggested_deref { } else if !suggested_deref && !involves_fn {
err.note(&format!( err.note(&format!(
"an implementation of `{}` might \ "an implementation of `{}` might \
be missing for `{}`", be missing for `{}`",
@ -437,7 +438,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
other_ty: Ty<'tcx>, other_ty: Ty<'tcx>,
op: hir::BinOp, op: hir::BinOp,
is_assign: IsAssign, is_assign: IsAssign,
) { ) -> bool {
err.span_label(span, ty.to_string()); err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = ty.sty { if let FnDef(def_id, _) = ty.sty {
let source_map = self.tcx.sess.source_map(); let source_map = self.tcx.sess.source_map();
@ -481,8 +482,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
variable_snippet, variable_snippet,
applicability, applicability,
); );
return true;
} }
} }
false
} }
fn check_str_addition( fn check_str_addition(

View File

@ -5,8 +5,6 @@ LL | let x = f == g;
| - ^^ - fn() {main::g} | - ^^ - fn() {main::g}
| | | |
| fn() {main::f} | 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 help: you might have forgotten to call this function
| |
LL | let x = f() == g; LL | let x = f() == g;

View File

@ -10,17 +10,17 @@ fn bar(a: i64) -> i64 {
fn main() { fn main() {
foo > 12; foo > 12;
//~^ ERROR 12:9: 12:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369] //~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR 12:11: 12:13: mismatched types [E0308] //~| ERROR mismatched types [E0308]
bar > 13; bar > 13;
//~^ ERROR 16:9: 16:10: binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369] //~^ ERROR binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369]
//~| ERROR 16:11: 16:13: mismatched types [E0308] //~| ERROR mismatched types [E0308]
foo > foo; 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; foo > bar;
//~^ ERROR 23:9: 23:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369] //~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR 23:11: 23:14: mismatched types [E0308] //~| ERROR mismatched types [E0308]
} }

View File

@ -6,8 +6,6 @@ LL | foo > 12;
| | | |
| fn() -> i32 {foo} | fn() -> i32 {foo}
| help: you might have forgotten to call this function: `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 error[E0308]: mismatched types
--> $DIR/issue-59488.rs:12:11 --> $DIR/issue-59488.rs:12:11
@ -26,8 +24,6 @@ LL | bar > 13;
| | | |
| fn(i64) -> i64 {bar} | fn(i64) -> i64 {bar}
| help: you might have forgotten to call this function: `bar( /* arguments */ )` | 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 error[E0308]: mismatched types
--> $DIR/issue-59488.rs:16:11 --> $DIR/issue-59488.rs:16:11
@ -45,8 +41,6 @@ LL | foo > foo;
| --- ^ --- fn() -> i32 {foo} | --- ^ --- fn() -> i32 {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 help: you might have forgotten to call this function
| |
LL | foo() > foo; LL | foo() > foo;