Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e541b2e
Add E0551 long error explanation
GuillaumeGomez Sep 30, 2019
62f1fb3
Update ui tests
GuillaumeGomez Sep 30, 2019
6c9f218
Disable stack probe when thread sanitizer is enabled
tmiasko Oct 4, 2019
4414068
Correctly estimate required space for string
AnthonyMikh Oct 5, 2019
5497ba1
When suggesting assoc function with type params, include turbofish
estebank Oct 5, 2019
3166ce8
Account for derefs when suggesting assoc function
estebank Oct 5, 2019
4c32d47
Remove loaded_from_cache map from DepGraph
Mark-Simulacrum Oct 6, 2019
90c456e
Remove `force!`.
nnethercote Oct 2, 2019
8f707c3
Remove `krate!`.
nnethercote Oct 2, 2019
1183d60
Remove `def_id!`.
nnethercote Oct 2, 2019
9267d9f
Remove `force_ex!`.
nnethercote Oct 7, 2019
28b0e1d
Add long error explanation for E0495
GuillaumeGomez Sep 12, 2019
96efaad
update ui tests
GuillaumeGomez Sep 12, 2019
61d92a0
Add long error explanation for E0567
GuillaumeGomez Oct 7, 2019
6608e4a
Update ui tests
GuillaumeGomez Oct 7, 2019
6f211f1
Rollup merge of #64404 - GuillaumeGomez:err-E0495, r=Dylan-DPC
Centril Oct 8, 2019
7153c92
Rollup merge of #64918 - GuillaumeGomez:long-err-explanation-E0551, r…
Centril Oct 8, 2019
3c5f8a1
Rollup merge of #65102 - tmiasko:tsan-probe-stack, r=alexcrichton
Centril Oct 8, 2019
153d3c3
Rollup merge of #65120 - AnthonyMikh:fix_65119, r=estebank
Centril Oct 8, 2019
58bfe3b
Rollup merge of #65145 - estebank:turbofish-assoc-fn-call, r=varkor
Centril Oct 8, 2019
f2dc346
Rollup merge of #65162 - Mark-Simulacrum:no-cache-loading-map, r=mich…
Centril Oct 8, 2019
0d17de8
Rollup merge of #65176 - nnethercote:rm-query-macros, r=michaelwoerister
Centril Oct 8, 2019
3246ab2
Rollup merge of #65179 - GuillaumeGomez:long-err-explanation-E0567, r…
Centril Oct 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Account for derefs when suggesting assoc function
  • Loading branch information
estebank committed Oct 5, 2019
commit 3166ce81ec664a0982937050fcedeb3d8538f686
21 changes: 19 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(span, "this is an associated function, not a method");
}
if static_sources.len() == 1 {
let ty_str = if let Some(CandidateSource::ImplSource(
impl_did,
)) = static_sources.get(0) {
// When the "method" is resolved through dereferencing, we really want the
// original type that has the associated function for accurate suggestions.
// (#61411)
let ty = self.impl_self_ty(span, *impl_did).ty;
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
// Use `actual` as it will have more `substs` filled in.
self.ty_to_value_string(actual.peel_refs())
}
_ => self.ty_to_value_string(ty.peel_refs()),
}
} else {
self.ty_to_value_string(actual.peel_refs())
};
if let SelfSource::MethodCall(expr) = source {
err.span_suggestion(
expr.span.to(span),
"use associated function syntax instead",
format!("{}::{}", self.ty_to_value_string(actual), item_name),
format!("{}::{}", ty_str, item_name),
Applicability::MachineApplicable,
);
} else {
err.help(&format!(
"try with `{}::{}`",
self.ty_to_value_string(actual),
ty_str,
item_name,
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-3707.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | self.boom();
| -----^^^^
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `&Obj::boom`
| help: use associated function syntax instead: `Obj::boom`
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `Obj`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::cell::RefCell;

struct HasAssocMethod;

impl HasAssocMethod {
fn hello() {}
}
fn main() {
let shared_state = RefCell::new(HasAssocMethod);
let state = shared_state.borrow_mut();
state.hello();
//~^ ERROR no method named `hello` found for type `std::cell::RefMut<'_, HasAssocMethod>`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0599]: no method named `hello` found for type `std::cell::RefMut<'_, HasAssocMethod>` in the current scope
--> $DIR/suggest-assoc-fn-call-with-turbofish-through-deref.rs:11:11
|
LL | state.hello();
| ------^^^^^
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `HasAssocMethod::hello`
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `HasAssocMethod`
--> $DIR/suggest-assoc-fn-call-with-turbofish-through-deref.rs:6:5
|
LL | fn hello() {}
| ^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.