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

IDE Assist for &str -> String #11383

Closed
gleich opened this issue Jan 31, 2022 · 7 comments · Fixed by #12696
Closed

IDE Assist for &str -> String #11383

gleich opened this issue Jan 31, 2022 · 7 comments · Fixed by #12696
Assignees
Labels
A-diagnostics diagnostics / error reporting E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@gleich
Copy link

gleich commented Jan 31, 2022

Hello, rust analyzer maintainers! It would be awesome to have an IDE assist feature in which a user could convert a &str to a String by essentially just wrapping it in String::from() (or .to_string(), whatever would be best). I would be interested in adding myself if it ends up getting accepted by the RA team.

@Veykril
Copy link
Member

Veykril commented Jan 31, 2022

An assist for a trivial(and very specific task) like this seems unlikely to be of much value. This sounds more like the task for a custom completion snippet:

    "rust-analyzer.completion.snippets": {
        "String::from": {
            "postfix": "strfrom",
            "body": "String::from(${receiver})",
            "scope": "expr",
        },
    },

On the other hand, we should already show a to_string completion for you when putting a . after a &str variable.

@flodiebold
Copy link
Member

An assist for a trivial(and very specific task) like this seems unlikely to be of much value

Slightly disagree, once we have a diagnostic saying "this expects a String, but got a &str", then it makes sense to give a quickfix for that.

@Veykril
Copy link
Member

Veykril commented Jan 31, 2022

Yes of course, I was solely thinking of assists, not diagnostic quickfixes. Having a diagnostic quickfix here certainly makes sense.

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Jan 31, 2022
@flodiebold flodiebold added the S-actionable Someone could pick this issue up and work on it right now label Mar 31, 2022
@flodiebold
Copy link
Member

@flodiebold flodiebold added the E-has-instructions Issue has some instructions and pointers to code to get started label Mar 31, 2022
@harpsword
Copy link
Contributor

harpsword commented Apr 28, 2022

2022-04-28.20.57.18.mov

I found out that this feature already exists.

@flodiebold
Copy link
Member

That's a quickfix coming from rustc, not rust-analyzer.

@Rustin170506
Copy link
Member

Rustin170506 commented Jul 5, 2022

@rustbot claim
I'll try to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants