Skip to content

Commit

Permalink
sess: disable polymorphisation
Browse files Browse the repository at this point in the history
This commit disables polymorphisation to resolve regressions related to
closures which inherit unused generic parameters and are then used in
casts or reflection.

Signed-off-by: David Wood <david@davidtw.co>
  • Loading branch information
davidtwco committed Jul 22, 2020
1 parent 90e941a commit f39ed20
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/librustc_session/options.rs
Expand Up @@ -949,7 +949,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
(default: PLT is disabled if full relro is enabled)"),
polonius: bool = (false, parse_bool, [UNTRACKED],
"enable polonius-based borrow-checker (default: no)"),
polymorphize: bool = (true, parse_bool, [TRACKED],
polymorphize: bool = (false, parse_bool, [TRACKED],
"perform polymorphization analysis"),
pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
"a single extra argument to prepend the linker invocation (can be used several times)"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen-units/item-collection/static-init.rs
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on

#![feature(start)]

Expand Down
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on

#![deny(dead_code)]
#![feature(start)]
Expand Down
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=lazy -Copt-level=1
// compile-flags:-Zpolymorphize=on -Zprint-mono-items=lazy -Copt-level=1
// ignore-tidy-linelength

#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/const_parameters/closures.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(const_generics, rustc_attrs)]
//~^ WARN the feature `const_generics` is incomplete

Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/polymorphization/const_parameters/closures.stderr
@@ -1,5 +1,5 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closures.rs:2:12
--> $DIR/closures.rs:3:12
|
LL | #![feature(const_generics, rustc_attrs)]
| ^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![feature(const_generics, rustc_attrs)]
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error: item has unused generic parameters
--> $DIR/closures.rs:18:19
--> $DIR/closures.rs:19:19
|
LL | pub fn unused<const T: usize>() -> usize {
| - generic parameter `T` is unused
Expand All @@ -17,13 +17,13 @@ LL | let add_one = |x: usize| x + 1;
| ^^^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:16:8
--> $DIR/closures.rs:17:8
|
LL | pub fn unused<const T: usize>() -> usize {
| ^^^^^^ - generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:27:19
--> $DIR/closures.rs:28:19
|
LL | pub fn used_parent<const T: usize>() -> usize {
| - generic parameter `T` is unused
Expand All @@ -32,7 +32,7 @@ LL | let add_one = |x: usize| x + 1;
| ^^^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:47:13
--> $DIR/closures.rs:48:13
|
LL | pub fn unused_upvar<const T: usize>() -> usize {
| - generic parameter `T` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/const_parameters/functions.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(const_generics, rustc_attrs)]
//~^ WARN the feature `const_generics` is incomplete

Expand Down
@@ -1,5 +1,5 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/functions.rs:2:12
--> $DIR/functions.rs:3:12
|
LL | #![feature(const_generics, rustc_attrs)]
| ^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![feature(const_generics, rustc_attrs)]
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error: item has unused generic parameters
--> $DIR/functions.rs:14:8
--> $DIR/functions.rs:15:8
|
LL | pub fn unused<const T: usize>() {
| ^^^^^^ - generic parameter `T` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/drop_shims/simple.rs
@@ -1,4 +1,5 @@
// check-pass
// compile-flags:-Zpolymorphize=on

pub struct OnDrop<F: Fn()>(pub F);

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/drop_shims/transitive.rs
@@ -1,4 +1,5 @@
// check-pass
// compile-flags:-Zpolymorphize=on

pub struct OnDrop<F: Fn()>(pub F);

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/generators.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(const_generics, generators, generator_trait, rustc_attrs)]
//~^ WARN the feature `const_generics` is incomplete

Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/polymorphization/generators.stderr
@@ -1,5 +1,5 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/generators.rs:2:12
--> $DIR/generators.rs:3:12
|
LL | #![feature(const_generics, generators, generator_trait, rustc_attrs)]
| ^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![feature(const_generics, generators, generator_trait, rustc_attrs)]
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error: item has unused generic parameters
--> $DIR/generators.rs:35:5
--> $DIR/generators.rs:36:5
|
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
| - generic parameter `T` is unused
Expand All @@ -21,13 +21,13 @@ LL | | }
| |_____^

error: item has unused generic parameters
--> $DIR/generators.rs:33:8
--> $DIR/generators.rs:34:8
|
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
| ^^^^^^^^^^^ - generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/generators.rs:61:5
--> $DIR/generators.rs:62:5
|
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
| - generic parameter `T` is unused
Expand All @@ -40,7 +40,7 @@ LL | | }
| |_____^

error: item has unused generic parameters
--> $DIR/generators.rs:59:8
--> $DIR/generators.rs:60:8
|
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
| ^^^^^^^^^^^^ - generic parameter `T` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/lifetimes.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(rustc_attrs)]

// This test checks that the polymorphization analysis doesn't break when the
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/polymorphization/lifetimes.stderr
@@ -1,11 +1,11 @@
error: item has unused generic parameters
--> $DIR/lifetimes.rs:9:8
--> $DIR/lifetimes.rs:10:8
|
LL | pub fn unused<'a, T>(_: &'a u32) {
| ^^^^^^ - generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/lifetimes.rs:16:19
--> $DIR/lifetimes.rs:17:19
|
LL | pub fn used<'a, T: Default>(_: &'a u32) -> u32 {
| - generic parameter `T` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/normalized_sig_types.rs
@@ -1,4 +1,5 @@
// build-pass
// compile-flags:-Zpolymorphize=on

pub trait ParallelIterator: Sized {
fn drive<C: Consumer<()>>(_: C) {
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/predicates.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(rustc_attrs)]

// This test checks that `T` is considered used in `foo`, because it is used in a predicate for
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/polymorphization/predicates.stderr
@@ -1,5 +1,5 @@
error: item has unused generic parameters
--> $DIR/predicates.rs:8:4
--> $DIR/predicates.rs:9:4
|
LL | fn bar<I>() {
| ^^^ - generic parameter `I` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/type_parameters/closures.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(stmt_expr_attributes, rustc_attrs)]

// This test checks that the polymorphization analysis correctly detects unused type
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/polymorphization/type_parameters/closures.stderr
@@ -1,5 +1,5 @@
error: item has unused generic parameters
--> $DIR/closures.rs:18:19
--> $DIR/closures.rs:19:19
|
LL | pub fn unused<T>() -> u32 {
| - generic parameter `T` is unused
Expand All @@ -8,13 +8,13 @@ LL | let add_one = |x: u32| x + 1;
| ^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:15:8
--> $DIR/closures.rs:16:8
|
LL | pub fn unused<T>() -> u32 {
| ^^^^^^ - generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:27:19
--> $DIR/closures.rs:28:19
|
LL | pub fn used_parent<T: Default>() -> u32 {
| - generic parameter `T` is unused
Expand All @@ -23,7 +23,7 @@ LL | let add_one = |x: u32| x + 1;
| ^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:93:23
--> $DIR/closures.rs:94:23
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand All @@ -35,7 +35,7 @@ LL | let add_one = |x: u32| x + 1;
| ^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:91:12
--> $DIR/closures.rs:92:12
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand All @@ -44,7 +44,7 @@ LL | pub fn unused_all<G: Default>() -> u32 {
| ^^^^^^^^^^ - generic parameter `G` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:127:23
--> $DIR/closures.rs:128:23
|
LL | pub fn used_impl<G: Default>() -> u32 {
| - generic parameter `G` is unused
Expand All @@ -58,13 +58,13 @@ LL | | };
| |_________^

error: item has unused generic parameters
--> $DIR/closures.rs:125:12
--> $DIR/closures.rs:126:12
|
LL | pub fn used_impl<G: Default>() -> u32 {
| ^^^^^^^^^ - generic parameter `G` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:114:23
--> $DIR/closures.rs:115:23
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand All @@ -78,7 +78,7 @@ LL | | };
| |_________^

error: item has unused generic parameters
--> $DIR/closures.rs:112:12
--> $DIR/closures.rs:113:12
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/type_parameters/functions.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(rustc_attrs)]

// This test checks that the polymorphization analysis correctly detects unused type
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/polymorphization/type_parameters/functions.stderr
@@ -1,11 +1,11 @@
error: item has unused generic parameters
--> $DIR/functions.rs:13:8
--> $DIR/functions.rs:14:8
|
LL | pub fn unused<T>() {
| ^^^^^^ - generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/functions.rs:44:12
--> $DIR/functions.rs:45:12
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand All @@ -14,7 +14,7 @@ LL | pub fn unused_impl() {
| ^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/functions.rs:50:12
--> $DIR/functions.rs:51:12
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand All @@ -23,7 +23,7 @@ LL | pub fn unused_both<G: Default>() {
| ^^^^^^^^^^^ - generic parameter `G` is unused

error: item has unused generic parameters
--> $DIR/functions.rs:62:12
--> $DIR/functions.rs:63:12
|
LL | impl<F: Default> Foo<F> {
| - generic parameter `F` is unused
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/polymorphization/unsized_cast.rs
@@ -1,4 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
#![feature(fn_traits, rustc_attrs, unboxed_closures)]

// This test checks that the polymorphization analysis considers a closure
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/polymorphization/unsized_cast.stderr
@@ -1,5 +1,5 @@
error: item has unused generic parameters
--> $DIR/unsized_cast.rs:10:18
--> $DIR/unsized_cast.rs:11:18
|
LL | fn foo<T: Default>() {
| - generic parameter `T` is unused
Expand All @@ -8,7 +8,7 @@ LL | (|| Box::new(|| {}) as Box<dyn Fn()>)();
| ^^^^^

error: item has unused generic parameters
--> $DIR/unsized_cast.rs:10:5
--> $DIR/unsized_cast.rs:11:5
|
LL | fn foo<T: Default>() {
| - generic parameter `T` is unused
Expand All @@ -17,7 +17,7 @@ LL | (|| Box::new(|| {}) as Box<dyn Fn()>)();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/unsized_cast.rs:20:15
--> $DIR/unsized_cast.rs:21:15
|
LL | fn foo2<T: Default>() {
| - generic parameter `T` is unused
Expand Down

0 comments on commit f39ed20

Please sign in to comment.