-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Assignees
@madsmtm
Description
Code
struct LlamaModel; impl LlamaModel { fn chat_template(&self) -> Result<&str, ()> { todo!() } } fn template_from_str(_x: &str) { } fn main() { let model = LlamaModel; template_from_str(&model.chat_template); }
Current output
Compiling playground v0.0.1 (/playground) error[E0609]: no field `chat_template` on type `Model` --> src/main.rs:15:30 | 15 | template_from_str(&model.chat_template); | ^^^^^^^^^^^^^ unknown field For more information about this error, try `rustc --explain E0609`. error: could not compile `playground` (bin "playground") due to 1 previous error
Desired output
Compiling playground v0.0.1 (/playground) error[E0615]: attempted to take value of method `chat_template` on type `Model` --> src/main.rs:11:11 | 11 | template_from_str(&model.chat_template); | ^^^^^^^^^^^^^ method, not a field | help: use parentheses to call the method | 11 | template_from_str(&model.chat_template()); | ++ For more information about this error, try `rustc --explain E0615`. error: could not compile `playground` (bin "playground") due to 1 previous error
Rationale and extra context
A friend pointed this out while working with llama_cpp
that they accidentally passed the reference to a method, instead of calling the method. It would be nice if the compiler could suggest to call the method instead of thinking that it is a missing field.
Rust Version
$ rustc --version --verbose rustc 1.89.0 (29483883e 2025年08月04日) binary: rustc commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2 commit-date: 2025年08月04日 host: aarch64-apple-darwin release: 1.89.0 LLVM version: 20.1.7
Anything else?
No response