asifshah
You should NEVER use WD-40 on firearms, even air-powered ones. The Kerosene combusts with friction from the bullet in the barrel raising pressures in the barrel to dangerous levels. I've already destroyed a gasket on my Diana air rifle once, and it wasn't a pretty sight.
In any case, WD-40 is a "Water Displacement (WD)" product that can eat through rust and remove water, but other than that, I don't think it can hold off rust indefinitely.
If I want to store a gun for a long time, I dismantle it, apply machine oil to it liberally, and then store the parts in a plastic bag. You can keep your guns rust-free for decades like this.