2020-06-22 07:57:03 -05:00
|
|
|
// build-fail
|
2020-07-22 09:03:56 -05:00
|
|
|
// compile-flags:-Zpolymorphize=on
|
2021-08-27 11:04:57 -05:00
|
|
|
#![feature(generic_const_exprs, rustc_attrs)]
|
|
|
|
//~^ WARN the feature `generic_const_exprs` is incomplete
|
2020-06-22 07:57:03 -05:00
|
|
|
|
|
|
|
// This test checks that the polymorphization analysis correctly detects unused const
|
|
|
|
// parameters in closures.
|
|
|
|
|
|
|
|
// Function doesn't have any generic parameters to be unused.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn no_parameters() {
|
|
|
|
let _ = || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function has an unused generic parameter in parent and closure.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn unused<const T: usize>() -> usize {
|
2020-07-16 11:52:23 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
let add_one = |x: usize| x + 1;
|
2020-07-16 11:52:23 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
add_one(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function has an unused generic parameter in closure, but not in parent.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn used_parent<const T: usize>() -> usize {
|
|
|
|
let x: usize = T;
|
|
|
|
let add_one = |x: usize| x + 1;
|
2020-07-16 11:52:23 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
x + add_one(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function uses generic parameter in value of a binding in closure.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn used_binding<const T: usize>() -> usize {
|
|
|
|
let x = || {
|
|
|
|
let y: usize = T;
|
|
|
|
y
|
|
|
|
};
|
|
|
|
|
|
|
|
x()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Closure uses a value as an upvar, which used the generic parameter.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn unused_upvar<const T: usize>() -> usize {
|
|
|
|
let x: usize = T;
|
|
|
|
let y = || x;
|
2020-07-16 11:52:23 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
y()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Closure uses generic parameter in substitutions to another function.
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
pub fn used_substs<const T: usize>() -> usize {
|
|
|
|
let x = || unused::<T>();
|
|
|
|
x()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
no_parameters();
|
|
|
|
let _ = unused::<1>();
|
|
|
|
let _ = used_parent::<1>();
|
|
|
|
let _ = used_binding::<1>();
|
|
|
|
let _ = unused_upvar::<1>();
|
|
|
|
let _ = used_substs::<1>();
|
|
|
|
}
|