Description
Reproduce Steps
- Create a project using
cargo new test_rust
- Edit the
lib.rs
file to:
pub trait HasArea {
fn area(&self) -> f64 {
0f64
}
}
pub fn print_area<T: HasArea>(shape: T) -> f64{
shape.area()
}
fn main() {
struct Square {
side: f64,
}
impl HasArea for Square {
fn area(&self) -> f64 {
self.side * self.side
}
}
let s = Square {
side: 20f64,
};
let b = print_area(s);
println!("Area: {}", b);
}
Basically, it defines a trait and a generic method which accepts it as an argument.
3. Run rustc -g src/lib.rs
to compile it and run gdb lib
to debug. It could step into the print_area()
function and the result is correct as well.
4. If I move the main()
function into a standalone file main.rs
and referece this library using external crate test_rust
, call cargo build
to build the library(I already set the debug flag in Cargo.toml
) and run rustc -g -extern test_rust=target/libXXXX main.rs
. I could not debug into the print_area()
function, though the running result is correct. In gdb, it just goes to next line instead of going to the function definition.
Please note if I don't use generic for the function, both cases are working as expected.
OS
Archlinux x86_64
Rust version
rustc 0.13.0-nightly (81eeec0 2014-11-21 23:16:48 +0000)
binary: rustc
commit-hash: 81eeec0
commit-date: 2014-11-21 23:16:48 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly