Skip to content

Commit 4b6305c

Browse files
committedDec 10, 2019
Add more detailed suggestion
1 parent f13b8fb commit 4b6305c

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed
 

‎src/doc/rustc-guide

‎src/librustc_resolve/build_reduced_graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
719719
// These items live in both the type and value namespaces.
720720
ItemKind::Struct(ref vdata, _) => {
721721
// Define a name in the type namespace.
722-
let item_def_id = self.r.definitions.local_def_id(item.id);
723-
let res = Res::Def(DefKind::Struct, item_def_id);
722+
let def_id = self.r.definitions.local_def_id(item.id);
723+
let res = Res::Def(DefKind::Struct, def_id);
724724
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
725725

726726
// Record field names for error reporting.
@@ -757,12 +757,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
757757
}
758758

759759
ItemKind::Union(ref vdata, _) => {
760-
let item_def_id = self.r.definitions.local_def_id(item.id);
761-
let res = Res::Def(DefKind::Union, item_def_id);
760+
let def_id = self.r.definitions.local_def_id(item.id);
761+
let res = Res::Def(DefKind::Union, def_id);
762762
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
763763

764764
// Record field names for error reporting.
765-
self.insert_field_names_local(item_def_id, vdata);
765+
self.insert_field_names_local(def_id, vdata);
766766
}
767767

768768
ItemKind::Impl(.., ref impl_items) => {

‎src/librustc_resolve/late/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ impl<'a> LateResolutionVisitor<'a, '_> {
259259
if let PathSource::Expr(parent) = source {
260260
match &parent.map(|p| &p.kind) {
261261
Some(ExprKind::Call(_, args)) if args.len() > 0 => {
262-
let mut expr_kind = &args.first().unwrap().kind;
262+
let mut expr_kind = &args[0].kind;
263263
loop {
264264
match expr_kind {
265265
ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => {
266266
has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower;
267267
break;
268268
},
269-
ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; }
269+
ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind,
270270
_ => break,
271271
}
272272
}
@@ -278,7 +278,7 @@ impl<'a> LateResolutionVisitor<'a, '_> {
278278
if has_self_arg {
279279
err.span_suggestion(
280280
span,
281-
&"try calling method instead of passing `self` as parameter",
281+
&format!("try calling `{}` as a method", ident),
282282
format!("self.{}", path_str),
283283
Applicability::MachineApplicable,
284284
);

‎src/test/ui/self/suggest-self-2.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ impl Foo {
44
fn foo(&self) {
55
bar(self);
66
//~^ ERROR cannot find function `bar` in this scope
7-
//~| HELP try calling method instead of passing `self` as parameter
7+
//~| HELP try calling `bar` as a method
88

9+
bar(&&self, 102);
10+
//~^ ERROR cannot find function `bar` in this scope
11+
//~| HELP try calling `bar` as a method
912

10-
bar(&self);
13+
bar(&mut self, 102, &"str");
1114
//~^ ERROR cannot find function `bar` in this scope
12-
//~| HELP try calling method instead of passing `self` as parameter
15+
//~| HELP try calling `bar` as a method
1316

1417
bar();
1518
//~^ ERROR cannot find function `bar` in this scope

‎src/test/ui/self/suggest-self-2.stderr

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@ error[E0425]: cannot find function `bar` in this scope
22
--> $DIR/suggest-self-2.rs:5:9
33
|
44
LL | bar(self);
5-
| ^^^ help: try calling method instead of passing `self` as parameter: `self.bar`
5+
| ^^^ help: try calling `bar` as a method: `self.bar`
66

77
error[E0425]: cannot find function `bar` in this scope
8-
--> $DIR/suggest-self-2.rs:10:9
8+
--> $DIR/suggest-self-2.rs:9:9
99
|
10-
LL | bar(&self);
11-
| ^^^ help: try calling method instead of passing `self` as parameter: `self.bar`
10+
LL | bar(&&self, 102);
11+
| ^^^ help: try calling `bar` as a method: `self.bar`
1212

1313
error[E0425]: cannot find function `bar` in this scope
14-
--> $DIR/suggest-self-2.rs:14:9
14+
--> $DIR/suggest-self-2.rs:13:9
15+
|
16+
LL | bar(&mut self, 102, &"str");
17+
| ^^^ help: try calling `bar` as a method: `self.bar`
18+
19+
error[E0425]: cannot find function `bar` in this scope
20+
--> $DIR/suggest-self-2.rs:17:9
1521
|
1622
LL | bar();
1723
| ^^^ not found in this scope
1824

1925
error[E0599]: no method named `bar` found for type `&Foo` in the current scope
20-
--> $DIR/suggest-self-2.rs:17:14
26+
--> $DIR/suggest-self-2.rs:20:14
2127
|
2228
LL | self.bar();
2329
| ^^^ method not found in `&Foo`
2430

25-
error: aborting due to 4 previous errors
31+
error: aborting due to 5 previous errors
2632

2733
Some errors have detailed explanations: E0425, E0599.
2834
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)