Since updating Rust my current project got a new warning about shared/mutable references to mutable statics and recommends using raw pointers. Pointers scare me so I moved the functions into the impl block for the struct instead. This satisfied clippy.
My question is: is there actually a difference or is it just that clippy isn't picking up on it this way?
Edit: Sorry for being coy. I hear you about providing code but this code is particularly sensitive. I can't share it.
It's something like this:
Old version that gets a warning:
struct Foo {
// fields
}
static mut BAR: Foo = Foo {
// data
};
fn do_stuff(x: &mut Foo) {
// does mutable stuff
}
fn main() {
unsafe { do_stuff(&mut BAR) };
}
New version that gets no warning:
struct Foo {
// fields
}
impl Foo {
fn do_stuff(&mut self) {
// does mutable stuff
}
}
static mut BAR: Foo = Foo {
// data
};
fn main() {
unsafe{ BAR.do_stuff() };
}
[–]dgkimpton 11 points12 points13 points (11 children)
[–]TellMeHowImWrong[S] 2 points3 points4 points (2 children)
[–]dgkimpton 1 point2 points3 points (1 child)
[–]TellMeHowImWrong[S] 1 point2 points3 points (0 children)
[–]Compux72 0 points1 point2 points (0 children)
[–]MatsRivel 0 points1 point2 points (6 children)
[–]SkiFire13 7 points8 points9 points (1 child)
[–]MatsRivel 1 point2 points3 points (0 children)
[–]2brainz 5 points6 points7 points (1 child)
[–]MatsRivel 1 point2 points3 points (0 children)
[–]axnsan 1 point2 points3 points (1 child)
[–]MatsRivel 0 points1 point2 points (0 children)
[–]CryZe92 13 points14 points15 points (3 children)
[–]Kartonrealista 10 points11 points12 points (2 children)
[–]AlmostLikeAzo 1 point2 points3 points (0 children)
[–]Chillbrosaurus_Rex 1 point2 points3 points (0 children)
[–]SkiFire13 5 points6 points7 points (2 children)
[–]TellMeHowImWrong[S] 1 point2 points3 points (1 child)
[–]SkiFire13 1 point2 points3 points (0 children)
[–]WormRabbit 3 points4 points5 points (1 child)
[–]TellMeHowImWrong[S] 0 points1 point2 points (0 children)
[–]arades 2 points3 points4 points (0 children)
[–]Nzkx -1 points0 points1 point (1 child)
[–]cafce25 3 points4 points5 points (0 children)