Add more detailed suggestion

This commit is contained in:
Janusz Marcinkiewicz 2019-12-09 16:05:45 +01:00
parent 8d189ed2f1
commit 8e5b2c80d3
5 changed files with 29 additions and 20 deletions

@ -1 +1 @@
Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b
Subproject commit 7c56708aab7986ca390221e8e8902f7de7f9b076

View File

@ -759,8 +759,8 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
// These items live in both the type and value namespaces.
ItemKind::Struct(ref vdata, _) => {
// Define a name in the type namespace.
let item_def_id = self.r.definitions.local_def_id(item.id);
let res = Res::Def(DefKind::Struct, item_def_id);
let def_id = self.r.definitions.local_def_id(item.id);
let res = Res::Def(DefKind::Struct, def_id);
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
// Record field names for error reporting.
@ -798,12 +798,12 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
}
ItemKind::Union(ref vdata, _) => {
let item_def_id = self.r.definitions.local_def_id(item.id);
let res = Res::Def(DefKind::Union, item_def_id);
let def_id = self.r.definitions.local_def_id(item.id);
let res = Res::Def(DefKind::Union, def_id);
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
// Record field names for error reporting.
self.insert_field_names_local(item_def_id, vdata);
self.insert_field_names_local(def_id, vdata);
}
ItemKind::Trait(..) => {

View File

@ -265,14 +265,14 @@ pub(crate) fn smart_resolve_report_errors(
if let PathSource::Expr(parent) = source {
match &parent.map(|p| &p.kind) {
Some(ExprKind::Call(_, args)) if args.len() > 0 => {
let mut expr_kind = &args.first().unwrap().kind;
let mut expr_kind = &args[0].kind;
loop {
match expr_kind {
ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => {
has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower;
break;
},
ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; }
ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind,
_ => break,
}
}
@ -284,7 +284,7 @@ pub(crate) fn smart_resolve_report_errors(
if has_self_arg {
err.span_suggestion(
span,
&"try calling method instead of passing `self` as parameter",
&format!("try calling `{}` as a method", ident),
format!("self.{}", path_str),
Applicability::MachineApplicable,
);

View File

@ -4,12 +4,15 @@ impl Foo {
fn foo(&self) {
bar(self);
//~^ ERROR cannot find function `bar` in this scope
//~| HELP try calling method instead of passing `self` as parameter
//~| HELP try calling `bar` as a method
bar(&self);
bar(&&self, 102);
//~^ ERROR cannot find function `bar` in this scope
//~| HELP try calling method instead of passing `self` as parameter
//~| HELP try calling `bar` as a method
bar(&mut self, 102, &"str");
//~^ ERROR cannot find function `bar` in this scope
//~| HELP try calling `bar` as a method
bar();
//~^ ERROR cannot find function `bar` in this scope

View File

@ -2,27 +2,33 @@ error[E0425]: cannot find function `bar` in this scope
--> $DIR/suggest-self-2.rs:5:9
|
LL | bar(self);
| ^^^ help: try calling method instead of passing `self` as parameter: `self.bar`
| ^^^ help: try calling `bar` as a method: `self.bar`
error[E0425]: cannot find function `bar` in this scope
--> $DIR/suggest-self-2.rs:10:9
--> $DIR/suggest-self-2.rs:9:9
|
LL | bar(&self);
| ^^^ help: try calling method instead of passing `self` as parameter: `self.bar`
LL | bar(&&self, 102);
| ^^^ help: try calling `bar` as a method: `self.bar`
error[E0425]: cannot find function `bar` in this scope
--> $DIR/suggest-self-2.rs:14:9
--> $DIR/suggest-self-2.rs:13:9
|
LL | bar(&mut self, 102, &"str");
| ^^^ help: try calling `bar` as a method: `self.bar`
error[E0425]: cannot find function `bar` in this scope
--> $DIR/suggest-self-2.rs:17:9
|
LL | bar();
| ^^^ not found in this scope
error[E0599]: no method named `bar` found for type `&Foo` in the current scope
--> $DIR/suggest-self-2.rs:17:14
--> $DIR/suggest-self-2.rs:20:14
|
LL | self.bar();
| ^^^ method not found in `&Foo`
error: aborting due to 4 previous errors
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0425, E0599.
For more information about an error, try `rustc --explain E0425`.