1
Fork 0

mir: unused_generic_params query

This commit implements the `unused_generic_params` query, an initial
version of polymorphization which detects when an item does not use
generic parameters and is being needlessly monomorphized as a result.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood 2020-06-22 13:57:03 +01:00
parent 47756bb0fa
commit 2989fea88a
No known key found for this signature in database
GPG key ID: 2592E76C87381FD9
44 changed files with 1627 additions and 84 deletions

View file

@ -0,0 +1,33 @@
// build-fail
// compile-flags: -Zpolymorphize-errors
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
// This test checks that the polymorphization analysis correctly detects unused const
// parameters in functions.
// Function doesn't have any generic parameters to be unused.
pub fn no_parameters() {}
// Function has an unused generic parameter.
pub fn unused<const T: usize>() {
//~^ ERROR item has unused generic parameters
}
// Function uses generic parameter in value of a binding.
pub fn used_binding<const T: usize>() -> usize {
let x: usize = T;
x
}
// Function uses generic parameter in substitutions to another function.
pub fn used_substs<const T: usize>() {
unused::<T>()
}
fn main() {
no_parameters();
unused::<1>();
used_binding::<1>();
used_substs::<1>();
}