- Notifications
You must be signed in to change notification settings - Fork 14.1k
Description
Godbolt repro: https://rust.godbolt.org/z/caG4MEjsr
With -Copt-level=s and -Copt-level=z the functions <Vec<T> as Deref>::deref and <Vec<T> as AsRef<[T]>>::as_ref show up in the output pointlessly. Similarly for the mut versions (AsMut, DerefMut, etc), and a few similar methods I tried (Borrow::borrow for example).
There are probably some other similar issues too (it seems a lot of our library code is optimized for -Copt-level=3 rather than with size optimizations...).
Note that this can end up with a lot of copies of these functions, since you get at least one for each T you use Vec<T>::deref with, which is basically one for each T you put in a Vec.
Also note that these get fully optimized away on both -Copt-level=3 and -Copt-level=2.
One way to fix this is probably to make these #[inline(always)], but it seems weird that these would show up at all, so perhaps there's a better way which can fix the issue more broadly.