Skip to content

Instantly share code, notes, and snippets.

@osyoyu
Last active December 10, 2023 15:53
Show Gist options
  • Save osyoyu/36d306f0366eba40b1acd7305e5dba11 to your computer and use it in GitHub Desktop.
Save osyoyu/36d306f0366eba40b1acd7305e5dba11 to your computer and use it in GitHub Desktop.
associated function `new` is never used
// a/mymod.rs ではなく mymod.rs をむりやり使う
#[path="./mymod.rs"]
pub mod mymod;
// こっちも
#[path="./mymod.rs"]
pub mod mymod;
% cargo build
Compiling hello v0.1.0 (/home/osyoyu/Development/hello)
warning: struct `Foo` is never constructed
--> src/./mymod.rs:1:12
|
1 | pub struct Foo {}
| ^^^
|
= note: `#[warn(dead_code)]` on by default
warning: associated function `new` is never used
--> src/./mymod.rs:3:12
|
2 | impl Foo {
| -------- associated function in this implementation
3 | pub fn new() { }
| ^^^
warning: `hello` (bin "hello") generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.07s
mod a;
mod b;
fn main() {
let _ = a::mymod::Foo::new();
println!("Hello, world!");
}
// a::mymod::Foo と b::mymod::Foo の両方の実装になっていて、
// b::mymod::Foo は呼び出されていないので warning になる
pub struct Foo {}
impl Foo {
pub fn new() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment