polymorphize: visit promoted MIR
This commit makes polymorphization visited the MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
1e0e618cfb
commit
659d44a3b4
@ -245,6 +245,13 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UsedGenericParametersVisitor<'a, 'tcx> {
|
||||
self.unused_parameters.clear(param.index);
|
||||
false
|
||||
}
|
||||
ty::ConstKind::Unevaluated(_, _, Some(p)) => {
|
||||
// If there is a promoted, don't look at the substs - since it will always contain
|
||||
// the generic parameters, instead, traverse the promoted MIR.
|
||||
let promoted = self.tcx.promoted_mir(self.def_id);
|
||||
self.visit_body(&promoted[p]);
|
||||
false
|
||||
}
|
||||
_ => c.super_visit_with(self),
|
||||
}
|
||||
}
|
||||
|
12
src/test/ui/polymorphization/promoted-function-1.rs
Normal file
12
src/test/ui/polymorphization/promoted-function-1.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// build-fail
|
||||
// compile-flags: -Zpolymorphize=on
|
||||
#![crate_type = "lib"]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
fn foo<'a>(_: &'a ()) {}
|
||||
|
||||
#[rustc_polymorphize_error]
|
||||
pub fn test<T>() {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
foo(&());
|
||||
}
|
8
src/test/ui/polymorphization/promoted-function-1.stderr
Normal file
8
src/test/ui/polymorphization/promoted-function-1.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/promoted-function-1.rs:9:8
|
||||
|
|
||||
LL | pub fn test<T>() {
|
||||
| ^^^^ - generic parameter `T` is unused
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,4 +1,6 @@
|
||||
// run-pass
|
||||
// compile-flags:-Zpolymorphize=on
|
||||
|
||||
fn fop<T>() {}
|
||||
|
||||
fn bar<T>() -> &'static fn() {
|
||||
|
@ -17,6 +17,7 @@ fn foo<T: Default>() {
|
||||
fn foo2<T: Default>() {
|
||||
let _: T = Default::default();
|
||||
(|| {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
let call: extern "rust-call" fn(_, _) = Fn::call;
|
||||
call(&|| {}, ());
|
||||
//~^ ERROR item has unused generic parameters
|
||||
|
@ -17,7 +17,7 @@ LL | (|| Box::new(|| {}) as Box<dyn Fn()>)();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/unsized_cast.rs:21:15
|
||||
--> $DIR/unsized_cast.rs:22:15
|
||||
|
|
||||
LL | fn foo2<T: Default>() {
|
||||
| - generic parameter `T` is unused
|
||||
@ -25,5 +25,19 @@ LL | fn foo2<T: Default>() {
|
||||
LL | call(&|| {}, ());
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/unsized_cast.rs:19:5
|
||||
|
|
||||
LL | fn foo2<T: Default>() {
|
||||
| - generic parameter `T` is unused
|
||||
LL | let _: T = Default::default();
|
||||
LL | / (|| {
|
||||
LL | |
|
||||
LL | | let call: extern "rust-call" fn(_, _) = Fn::call;
|
||||
LL | | call(&|| {}, ());
|
||||
LL | |
|
||||
LL | | })();
|
||||
| |______^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user