|
10 | 10 |
|
11 | 11 |
|
12 | 12 | use check::FnCtxt; |
13 | | -use rustc::ty::Ty; |
14 | | -use rustc::infer::{InferOk, TypeOrigin}; |
| 13 | +use rustc::infer::InferOk; |
15 | 14 | use rustc::traits::ObligationCause; |
16 | | -use rustc::ty; |
17 | 15 |
|
18 | 16 | use syntax::ast; |
19 | 17 | use syntax_pos::{self, Span}; |
20 | 18 | use rustc::hir; |
21 | 19 | use rustc::hir::def::Def; |
22 | | -use rustc::ty::{self, AssociatedItem}; |
| 20 | +use rustc::ty::{self, Ty, AssociatedItem}; |
23 | 21 | use errors::DiagnosticBuilder; |
24 | 22 |
|
25 | 23 | use super::method::probe; |
@@ -81,24 +79,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
81 | 79 | if let Err(e) = self.try_coerce(expr, checked_ty, self.diverges.get(), expected) { |
82 | 80 | let cause = self.misc(expr.span); |
83 | 81 | let expr_ty = self.resolve_type_vars_with_obligations(checked_ty); |
84 | | - let suggestions = if let Some(suggestions) = self.check_ref(expr, |
85 | | - checked_ty, |
86 | | - expected) { |
87 | | - suggestions |
| 82 | + let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e); |
| 83 | + if let Some(suggestion) = self.check_ref(expr, |
| 84 | + checked_ty, |
| 85 | + expected) { |
| 86 | + err.help(&suggestion); |
88 | 87 | } else { |
89 | 88 | let mode = probe::Mode::MethodCall; |
90 | | - self.probe_for_return_type(syntax_pos::DUMMY_SP, |
91 | | - mode, |
92 | | - expected, |
93 | | - checked_ty, |
94 | | - ast::DUMMY_NODE_ID) |
| 89 | + let suggestions = self.probe_for_return_type(syntax_pos::DUMMY_SP, |
| 90 | + mode, |
| 91 | + expected, |
| 92 | + checked_ty, |
| 93 | + ast::DUMMY_NODE_ID); |
| 94 | + if suggestions.len() > 0 { |
| 95 | + err.help(&format!("here are some functions which \ |
| 96 | + might fulfill your needs:\n - {}", |
| 97 | + self.get_best_match(&suggestions).join("\n"))); |
| 98 | + } |
95 | 99 | } |
96 | | - let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e); |
97 | | - if suggestions.len() > 0 { |
98 | | - err.help(&format!("here are some functions which \ |
99 | | - might fulfill your needs:\n{}", |
100 | | - self.get_best_match(&suggestions).join("\n"))); |
101 | | - }; |
102 | 100 | err.emit(); |
103 | 101 | } |
104 | 102 | } |
@@ -188,7 +186,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
188 | 186 | self.tcx.mk_region(ty::ReStatic), |
189 | 187 | checked_ty), |
190 | 188 | }; |
191 | | - if self.try_coerce(expr, ref_ty, expected).is_ok() { |
| 189 | + if self.can_coerce(ref_ty, expected) { |
192 | 190 | if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(expr.span) { |
193 | 191 | return Some(format!("try with `{}{}`", |
194 | 192 | match mutability.mutbl { |
|
0 commit comments