-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement format_args
#2489
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
Implement format_args
#2489
Conversation
Oh... nice, but If I remember correctly, fn main() {
format!(concat!("ABC","DEF"));
} |
I don't think that really matters for now, I ignore the format string anyway 😅 (Edit: Yeah, it's just the format string being eagerly expanded...) |
I think it is because : We should set it to |
Just setting it to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
crates/ra_hir/src/source_binder.rs
Outdated
let parent_ancestors: Box<dyn Iterator<Item = InFile<SyntaxNode>>> = | ||
Box::new(parent_node.into_iter().flat_map(move |n| ancestors_with_macros(db, n.as_ref()))); | ||
node.value.ancestors().map(move |n| file.with_value(n)).chain(parent_ancestors) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this will be a hugely important function in the end, so, if you feel like it, you can implement a struct-based non-allocating iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maaaybe even in the form of inherent method on InFile
?
The problem seems to be here, we're not getting an expr ID 😕 |
Just enough to fix the huge amount of type mismatches they cause.
I assume it was previously required because `len` was not const, but that doesn't seem to be a problem anymore.
SourceAnalyzer didn't work properly within expression macro expansions because it didn't find the enclosing function. Fix this by going up the expansion chain to find ancestors. This makes the test work, but apparently in real usage it's still not working.
cff286d
to
c80dc0a
Compare
crates/ra_hir_expand/src/lib.rs
Outdated
self, | ||
db: &'a impl crate::db::AstDatabase, | ||
) -> impl Iterator<Item = InFile<SyntaxNode>> + 'a { | ||
SyntaxNodeAncestorsWithMacros { db, node: Some(self) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, seems like std::iter::successors
would also work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, actually...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, this feels very similar to .contexts
in IntelliJ Rust: https://github.com/intellij-rust/intellij-rust/blob/39daa3ea0df34255a434bdb24f27fed41f4d2df7/src/main/kotlin/org/rust/lang/core/psi/ext/PsiElement.kt#L31-L34
ff90b55
to
b2c01f4
Compare
bors r+ |
2489: Implement `format_args` r=flodiebold a=flodiebold This fixes a huge amount of type mismatches (because every format call was a type mismatch so far); I also hoped to get go to def working within `format!` etc., and the test says it should, but in practice it still doesn't seem to... Also remove the `len` parameter from `Name::new_inline_ascii`, which I'm assuming was only there because of `const fn` limitations? cc @edwin0cheng Co-authored-by: Florian Diebold <[email protected]>
Build succeeded
|
This fixes a huge amount of type mismatches (because every format call was a type mismatch so far); I also hoped to get go to def working within
format!
etc., and the test says it should, but in practice it still doesn't seem to...Also remove the
len
parameter fromName::new_inline_ascii
, which I'm assuming was only there because ofconst fn
limitations?cc @edwin0cheng