E1001#
Unused function.
This function is not used by any other part of your code, nor marked with pub
visibility.
Note that this warning might uncover other bugs in your code. For example, if there are two functions in your codebase that has similar name, you might just call the other function by mistake.
Erroneous example#
fn greeting() -> String {
"Hello!"
}
fn main {
fn local_greeting() -> String {
"Hello, world!"
}
}
Suggestion#
There are multiple ways to fix this warning:
If the function is indeed useless, you can remove the definition of the function.
If this function is at the toplevel (i.e., not local), and is part of the public API of your module, you can add the
pub
keyword to the function.pub fn greeting() -> String { "Hello!" }
If you made a typo in the function name, you can rename the function to the correct name at the call site.
There are some cases where you might want to keep the function private and
unused at the same time. In this case, you can call ignore()
on the function
to force the use of it.
fn greeting() -> String {
"Hello, world!"
}
fn init {
ignore(greeting)
}
fn main {
fn local_greeting() -> String {
"Hello, world!"
}
ignore(local_greeting)
}