-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.