feat: inline const as literal by viktorlott · Pull Request #14925 · rust-lang/ru...
source link: https://github.com/rust-lang/rust-analyzer/pull/14925
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Contributor
Assist: inline_const_as_literal
Evaluate and inline const variable as literal.
const STRING: &str = "Hello, World!";
fn something() -> &'static str {
STR$0ING
}
->
const STRING: &str = "Hello, World!";
fn something() -> &'static str {
"Hello, World!"
}
added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label
force-pushed the inline-const-expr-as-static-str
branch
6 times, most recently
from
489d5e0
to
1e803cc
Compare
Member
Interesting assist. Why it's name is limited to string literals? I think the current code works with integers and other kinds of literals without any changes, and with some trivial changes it could support arrays and tuples (supporting structs and enums are a little harder I think) |
Contributor
Author
That was actually my initial intention, but I decided to scope it to
|
Member
It's fine if this PR only supports
By those, you mean expressions that contains closures? I guess those are theoretically impossible to support. For adt the problem is private fields, unresolved names, names that need to be imported and similar things, so I think it should avoid ADTs. |
force-pushed the inline-const-expr-as-static-str
branch
2 times, most recently
from
579db63
to
ae3be8e
Compare
changed the title
feat: inline const expr as static str
feat: inline const as literal
force-pushed the inline-const-expr-as-static-str
branch
3 times, most recently
from
21d83a5
to
d68d11e
Compare
crates/ide-assists/src/handlers/inline_const_as_literal.rs
Outdated Show resolved
crates/ide-assists/src/handlers/inline_const_as_literal.rs
Outdated Show resolved
Comment on lines
+683 to +713
fn inline_const_as_literal_expr_as_str_lit_not_applicable() { |
||
check_assist_not_applicable( |
||
inline_const_as_literal, |
||
r#" |
Can you also add some negative tests for cases that their type is not supported (adt, closure, ...)?
Contributor
Author
Absolutely,
Are the newly added tests enough, or should I add more variance to them?
Member
#14947 fixes some of the |
Contributor
Author
Great! I'll take a look at your comments after work |
Member
Thanks! |
Collaborator
Test successful - checks-actions |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No one assigned
None yet
No milestone
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK