Skip to content

Commit 3e81213

Browse files
committed
---
yaml --- r: 227679 b: refs/heads/try c: c8a0b0e h: refs/heads/master i: 227677: a1dfd18 227675: 53daa1b 227671: 4948d0d 227663: e6f329c 227647: 7ab28f8 v: v3
1 parent fc8e59b commit 3e81213

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 0230a530ce54102325537dc63dcabc45f5935771
4+
refs/heads/try: c8a0b0eece9e3ac852413bc715f788261a217e74
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc_typeck/check/method/suggest.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,42 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
7373
// snippet
7474
};
7575

76-
// Determine if the field can be used as a function in some way
77-
let fn_once_trait_did = match cx.lang_items.require(FnOnceTraitLangItem) {
78-
Ok(trait_did) => trait_did,
79-
Err(err) => cx.sess.fatal(&err[..])
80-
};
76+
fn span_stored_function() {
77+
cx.sess.span_note(span, &format!("use `({0}.{1})(...)` if you meant to call \
78+
the function stored in the `{1}` field",
79+
expr_string, item_name));
80+
}
8181

82-
let field_ty = ty::lookup_field_type(cx, did, field.id, substs);
83-
let field_ty_substs = Substs::new_trait(vec![fcx.inh.infcx.next_ty_var()],
84-
Vec::new(),
85-
field_ty);
86-
let trait_ref = ty::TraitRef::new(fn_once_trait_did,
87-
cx.mk_substs(field_ty_substs));
88-
let poly_trait_ref = trait_ref.to_poly_trait_ref();
89-
let obligation = Obligation::misc(span,
90-
fcx.body_id,
91-
poly_trait_ref.as_predicate());
92-
let mut selcx = SelectionContext::new(fcx.infcx(), fcx);
93-
94-
if selcx.evaluate_obligation(&obligation) {
95-
cx.sess.span_note(span,
96-
&format!("use `({0}.{1})(...)` if you meant to call the \
97-
function stored in the `{1}` field",
98-
expr_string, item_name));
99-
} else {
82+
fn span_did_you_mean() {
10083
cx.sess.span_note(span, &format!("did you mean to write `{0}.{1}`?",
10184
expr_string, item_name));
10285
}
86+
87+
// Determine if the field can be used as a function in some way
88+
let field_ty = ty::lookup_field_type(cx, did, field.id, substs);
89+
if let Ok(fn_once_trait_did) = cx.lang_items.require(FnOnceTraitLangItem) {
90+
let fn_once_substs = Substs::new_trait(vec![fcx.inh.infcx.next_ty_var()],
91+
Vec::new(),
92+
field_ty);
93+
let trait_ref = ty::TraitRef::new(fn_once_trait_did,
94+
cx.mk_substs(fn_once_substs));
95+
let poly_trait_ref = trait_ref.to_poly_trait_ref();
96+
let obligation = Obligation::misc(span,
97+
fcx.body_id,
98+
poly_trait_ref.as_predicate());
99+
let mut selcx = SelectionContext::new(fcx.infcx(), fcx);
100+
101+
if selcx.evaluate_obligation(&obligation) {
102+
span_stored_function();
103+
} else {
104+
span_did_you_mean();
105+
}
106+
} else {
107+
match field_ty.sty {
108+
ty::TyClosure(_,_) | ty::TyFnPtr(_,_) => span_stored_function(),
109+
_ => span_did_you_mean(),
110+
}
111+
}
103112
}
104113
}
105114

0 commit comments

Comments
 (0)