Skip to content

Commit 5cd23ac

Browse files
committed
---
yaml --- r: 226014 b: refs/heads/stable c: 3f8a70b h: refs/heads/master v: v3
1 parent 0718616 commit 5cd23ac

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 9adb3dfdcb2cab7a10d7ac7a48170672b3961fe8
32+
refs/heads/stable: 3f8a70b613d9e41dc6db11f1d267025bb26bf73d
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,35 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
5959
None);
6060

6161
// If the item has the name of a field, give a help note
62-
if let (&ty::TyStruct(did, substs), Some(_)) = (&rcvr_ty.sty, rcvr_expr) {
62+
if let (&ty::TyStruct(did, substs), Some(expr)) = (&rcvr_ty.sty, rcvr_expr) {
6363
let fields = ty::lookup_struct_fields(cx, did);
6464

6565
if let Some(field) = fields.iter().find(|f| f.name == item_name) {
66+
let expr_string = match cx.sess.codemap().span_to_snippet(expr.span) {
67+
Ok(expr_string) => expr_string,
68+
_ => "s".into() // default to generic placeholder for expression
69+
};
6670

71+
// TODO Fix when closure note is displayed
72+
// below commented code from eddyb on irc
73+
// let substs = subst::Substs::new_trait(vec![fcx.inh.infcx.next_ty_var()], Vec::new(), field_ty);
74+
// let trait_ref = ty::TraitRef::new(trait_def_id, fcx.tcx().mk_substs(substs));
75+
// let poly_trait_ref = trait_ref.to_poly_trait_ref();
76+
// let obligation = traits::Obligation::misc(span, fcx.body_id, poly_trait_ref.as_predicate());
77+
// let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx);
78+
// if selcx.evaluate_obligation(&obligation) { /* suggest */ }
79+
6780
match ty::lookup_field_type(cx, did, field.id, substs).sty {
6881
ty::TyClosure(_, _) | ty::TyBareFn(_,_) => {
6982
cx.sess.span_note(span,
7083
&format!("use `({0}.{1})(...)` if you meant to call the \
7184
function stored in the `{1}` field",
72-
ty::item_path_str(cx, did), item_name));
85+
expr_string, item_name));
7386
},
7487
_ => {
7588
cx.sess.span_note(span,
7689
&format!("did you mean to write `{0}.{1}`?",
77-
ty::item_path_str(cx, did), item_name));
90+
expr_string, item_name));
7891
},
7992
};
8093
}

branches/stable/src/test/compile-fail/issue-18343.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,30 @@ struct Obj<F> where F: FnMut() -> u32 {
1313
nfn: usize,
1414
}
1515

16+
struct S<F> where F: FnMut() -> u32 {
17+
v: Obj<F>,
18+
}
19+
1620
fn func() -> u32 {
1721
0
1822
}
1923

2024
fn main() {
21-
let o = Obj { closure: || 42 };
25+
let o = Obj { closure: || 42, nfn: 42 };
2226
o.closure(); //~ ERROR no method named `closure` found
23-
//~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
24-
let x = o.nfn(); //~ ERROR no method named `closure` found
25-
//~^ NOTE did you mean `o.nfn`?
27+
//~^ NOTE use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
2628

27-
let b = Obj { closure: func };
29+
// TODO move these to a new test for #2392
30+
let x = o.nfn(); //~ ERROR no method named `nfn` found
31+
//~^ NOTE did you mean to write `o.nfn`?
32+
33+
let b = Obj { closure: func, nfn: 5 };
2834
b.closure(); //~ ERROR no method named `closure` found
29-
//~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
35+
//~^ NOTE use `(b.closure)(...)` if you meant to call the function stored in the `closure` field
36+
37+
let s = S { v: b };
38+
s.v.closure();//~ ERROR no method named `closure` found
39+
//~^ NOTE use `(s.v.closure)(...)` if you meant to call the function stored in the `closure` field
40+
s.v.nfn();//~ ERROR no method named `nfn` found
41+
//~^ NOTE did you mean to write `s.v.nfn`?
3042
}

0 commit comments

Comments
 (0)