Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better user experience when attempting to call associated functions with dot notation #54308

Merged
merged 1 commit into from
Oct 1, 2018

Conversation

dsciarra
Copy link
Contributor

@dsciarra dsciarra commented Sep 17, 2018

Closes #22692

@rust-highfive
Copy link
Collaborator

r? @zackmdavis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 17, 2018
@rust-highfive

This comment has been minimized.

@csmoe
Copy link
Member

csmoe commented Sep 18, 2018

cc @estebank

@csmoe csmoe changed the title Fix for 22692 Better user experience when attempting to call associated functions with dot notation Sep 18, 2018
Copy link
Member

@zackmdavis zackmdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! Some revisions will be needed for tests to pass.

In addition to having the issue number in the commit message and PR description, a brief summary of the change (not more than 72 characters) is also useful for future readers of the repository history; you can edit the commit message with git commit --amend.

src/librustc_resolve/lib.rs Outdated Show resolved Hide resolved
src/librustc_resolve/lib.rs Outdated Show resolved Hide resolved
@zackmdavis zackmdavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2018
@Centril
Copy link
Contributor

Centril commented Sep 18, 2018

Note: we don't call these "static method"s but rather "associated function"s. Methods are only those which you may call with dot notation. Therefore it may be confusing to call them "static method" in error messages.

@TimNN

This comment has been minimized.

@dsciarra
Copy link
Contributor Author

The build is still failing locally, it would be nice if you can have a second look ;)

@zackmdavis zackmdavis added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 27, 2018
@rust-highfive

This comment has been minimized.

err.span_suggestion_with_applicability(
parent.span,
"incorrect associated function syntax",
format!("try {}::{}()?",
Copy link
Member

@zackmdavis zackmdavis Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsciarra The third argument to the span_suggestion_ methods should be a code snippet to replace the span passed as the first argument. We're going to need something more like

err.span_suggestion_with_applicability(
    parent.span,
    "use `::` to access an associated function",
    format!("{}::{}", path_str, path_assignment.ident),
    Applicability::MaybeIncorrect
);

(But this probably isn't literally correct as written. In the UI test output, it looks like our span includes the call args (here, just ()), which we don't want to replace.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need to get part of the literal code, you can use Codemap::span_to_snippet to get it, like done here:

if let Ok(src) = cm.span_to_snippet(sp) {

@dsciarra
Copy link
Contributor Author

Is there a better way to write this?

src/librustc_resolve/lib.rs Outdated Show resolved Hide resolved
src/test/ui/resolve/issue-22692.stderr Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor

Is there a better way to write this?

Other than the inline comment, it seems reasonable to me.

@estebank
Copy link
Contributor

estebank commented Oct 1, 2018

@bors r+ rollup

🎉🎉🎉

@bors
Copy link
Contributor

bors commented Oct 1, 2018

📌 Commit 0390736 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Oct 1, 2018
Better user experience when attempting to call associated functions with dot notation

Closes rust-lang#22692
bors added a commit that referenced this pull request Oct 1, 2018
Rollup of 13 pull requests

Successful merges:

 - #53784 (Document that slices cannot be larger than `isize::MAX` bytes)
 - #54308 (Better user experience when attempting to call associated functions with dot notation)
 - #54488 (in which we include attributes in unused `extern crate` suggestion spans)
 - #54544 (Indicate how to move value out of Box in docs.)
 - #54623 (Added help message for `impl_trait_in_bindings` feature gate)
 - #54641 (A few cleanups and minor improvements to rustc/infer)
 - #54656 (Correct doc for WorkQueue<T>::pop().)
 - #54674 (update miri)
 - #54676 (Remove `-Z disable_ast_check_for_mutation_in_guard`)
 - #54679 (Improve bug! message for impossible case in Relate)
 - #54681 (Rename sanitizer runtime libraries on OSX)
 - #54708 (Make ./x.py help <cmd> invoke ./x.py <cmd> -h on its own)
 - #54713 (Add nightly check for tool_lints warning)
@bors bors merged commit 0390736 into rust-lang:master Oct 1, 2018
@dsciarra dsciarra deleted the issue-22692 branch October 1, 2018 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants