From cf8f3796578b5423d9465ff0d1e8327668753cca Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Mon, 28 May 2018 23:31:55 +0700 Subject: [PATCH 1/8] Add lint on cast Fn to numerical. --- clippy_lints/src/types.rs | 16 ++++++++++++++++ tests/ui/types_fn_to_int.rs | 10 ++++++++++ tests/ui/types_fn_to_int.stderr | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/ui/types_fn_to_int.rs create mode 100644 tests/ui/types_fn_to_int.stderr diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 168086d574a3..f5cbcfb6b008 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -975,6 +975,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { }, } } + + match &cast_from.sty { + ty::TyFnDef(..) | + ty::TyFnPtr(..) => { + if cast_to.is_numeric() && cast_to.sty != ty::TyUint(UintTy::Usize){ + span_lint( + cx, + UNNECESSARY_CAST, + expr.span, + "casting Fn not to usize may truncate the value", + ); + } + } + _ => () + } + if_chain!{ if let ty::TyRawPtr(from_ptr_ty) = &cast_from.sty; if let ty::TyRawPtr(to_ptr_ty) = &cast_to.sty; diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs new file mode 100644 index 000000000000..250307e54b78 --- /dev/null +++ b/tests/ui/types_fn_to_int.rs @@ -0,0 +1,10 @@ +#![feature(tool_attributes)] +enum Foo { + A(usize), + B +} + +fn main() { + let x = Foo::A; + let y = x as i32; +} diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr new file mode 100644 index 000000000000..dffcf0083029 --- /dev/null +++ b/tests/ui/types_fn_to_int.stderr @@ -0,0 +1,10 @@ +error: casting Fn not to usize may truncate the value + --> $DIR/types_fn_to_int.rs:9:13 + | +9 | let y = x as i32; + | ^^^^^^^^ + | + = note: `-D unnecessary-cast` implied by `-D warnings` + +error: aborting due to previous error + From 01be53f92939df92ac7cb48d8b2a9713744e7b6e Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Mon, 28 May 2018 23:49:38 +0700 Subject: [PATCH 2/8] Little fix for test --- tests/ui/types_fn_to_int.rs | 1 - tests/ui/types_fn_to_int.stderr | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs index 250307e54b78..fadedcef9f21 100644 --- a/tests/ui/types_fn_to_int.rs +++ b/tests/ui/types_fn_to_int.rs @@ -1,4 +1,3 @@ -#![feature(tool_attributes)] enum Foo { A(usize), B diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index dffcf0083029..519b77633861 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -1,7 +1,7 @@ error: casting Fn not to usize may truncate the value - --> $DIR/types_fn_to_int.rs:9:13 + --> $DIR/types_fn_to_int.rs:8:13 | -9 | let y = x as i32; +8 | let y = x as i32; | ^^^^^^^^ | = note: `-D unnecessary-cast` implied by `-D warnings` From f6e0388e089669e89e162f1040cde048d34f52a4 Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Tue, 29 May 2018 22:56:38 +0700 Subject: [PATCH 3/8] Change lint type to unique and add the suggestion. --- clippy_lints/src/lib.rs | 1 + clippy_lints/src/types.rs | 28 ++++++++++++++++++++++++---- tests/ui/types_fn_to_int.stderr | 8 ++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index efba3b695772..96fa907ecb42 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -673,6 +673,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { types::UNIT_ARG, types::UNIT_CMP, types::UNNECESSARY_CAST, + types::FN_TO_NUMERIC_CAST, unicode::ZERO_WIDTH_SPACE, unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME, unused_io_amount::UNUSED_IO_AMOUNT, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index f5cbcfb6b008..9c33b91789a3 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -679,6 +679,23 @@ declare_clippy_lint! { "cast to the same type, e.g. `x as i32` where `x: i32`" } +/// **What it does:** Checks for casts function pointer to the numeric type. +/// +/// **Why is this bad?** Cast pointer not to usize truncate value. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// fn test_fn() -> i16; +/// let _ = test_fn as i32 +/// ``` +declare_clippy_lint! { + pub FN_TO_NUMERIC_CAST, + correctness, + "cast function pointer to the numeric type" +} + /// **What it does:** Checks for casts from a less-strictly-aligned pointer to a /// more-strictly-aligned pointer /// @@ -891,7 +908,8 @@ impl LintPass for CastPass { CAST_POSSIBLE_WRAP, CAST_LOSSLESS, UNNECESSARY_CAST, - CAST_PTR_ALIGNMENT + CAST_PTR_ALIGNMENT, + FN_TO_NUMERIC_CAST ) } } @@ -980,11 +998,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { ty::TyFnDef(..) | ty::TyFnPtr(..) => { if cast_to.is_numeric() && cast_to.sty != ty::TyUint(UintTy::Usize){ - span_lint( + span_lint_and_sugg( cx, - UNNECESSARY_CAST, + FN_TO_NUMERIC_CAST, expr.span, - "casting Fn not to usize may truncate the value", + &format!("casting a Fn to {} may truncate the function address value.", cast_to), + "if you need address of function, use cast to `usize` instead:", + format!("{} as usize", &snippet(cx, ex.span, "x")) ); } } diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index 519b77633861..8f0b2c645235 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -1,10 +1,14 @@ -error: casting Fn not to usize may truncate the value +error: casting a Fn to i32 may truncate the function address value. --> $DIR/types_fn_to_int.rs:8:13 | 8 | let y = x as i32; | ^^^^^^^^ | - = note: `-D unnecessary-cast` implied by `-D warnings` + = note: #[deny(fn_to_numeric_cast)] on by default +help: if you need address of function, use cast to `usize` instead: + | +8 | let y = x as usize; + | ^^^^^^^^^^ error: aborting due to previous error From e4b2a97401f0139751f926fd1479898494b20a80 Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Wed, 30 May 2018 07:55:48 +0700 Subject: [PATCH 4/8] weird thing --- clippy_lints/src/types.rs | 5 +++-- tests/ui/types_fn_to_int.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 9c33b91789a3..940a360ca183 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1002,8 +1002,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { cx, FN_TO_NUMERIC_CAST, expr.span, - &format!("casting a Fn to {} may truncate the function address value.", cast_to), - "if you need address of function, use cast to `usize` instead:", + &format!("casting a `{}` to `{}` may truncate the function address value.", cast_from, cast_to), + // &format!("if you need address of function, use cast zz `usize`:"), + &format!("if you need the address of the function, z consider:"), format!("{} as usize", &snippet(cx, ex.span, "x")) ); } diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs index fadedcef9f21..f37a82f0d71c 100644 --- a/tests/ui/types_fn_to_int.rs +++ b/tests/ui/types_fn_to_int.rs @@ -3,7 +3,16 @@ enum Foo { B } +fn bar() -> i32 { + 0i32 +} + fn main() { let x = Foo::A; let y = x as i32; + + let z = bar as u32; + + //let c = || {0i32}; + //let ac = c as u32; } From b69520f5fd1309741445fe069edca9e4b1e6d48c Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Wed, 30 May 2018 11:48:46 +0700 Subject: [PATCH 5/8] Fixes for suggestion message, tests and lint explanation. --- clippy_lints/src/types.rs | 7 +++---- tests/ui/types_fn_to_int.rs | 3 --- tests/ui/types_fn_to_int.stderr | 34 +++++++++++++++++++++------------ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 940a360ca183..fc65ebcc1471 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -679,9 +679,9 @@ declare_clippy_lint! { "cast to the same type, e.g. `x as i32` where `x: i32`" } -/// **What it does:** Checks for casts function pointer to the numeric type. +/// **What it does:** Checks for casts of a function pointer to a numeric type except `usize`. /// -/// **Why is this bad?** Cast pointer not to usize truncate value. +/// **Why is this bad?** Casting a function pointer to something other than `usize` could truncate the address value. /// /// **Known problems:** None. /// @@ -1003,8 +1003,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { FN_TO_NUMERIC_CAST, expr.span, &format!("casting a `{}` to `{}` may truncate the function address value.", cast_from, cast_to), - // &format!("if you need address of function, use cast zz `usize`:"), - &format!("if you need the address of the function, z consider:"), + "if you need the address of the function, consider :", format!("{} as usize", &snippet(cx, ex.span, "x")) ); } diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs index f37a82f0d71c..0cce65798133 100644 --- a/tests/ui/types_fn_to_int.rs +++ b/tests/ui/types_fn_to_int.rs @@ -12,7 +12,4 @@ fn main() { let y = x as i32; let z = bar as u32; - - //let c = || {0i32}; - //let ac = c as u32; } diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index 8f0b2c645235..d5e8ad8bbb29 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -1,14 +1,24 @@ -error: casting a Fn to i32 may truncate the function address value. - --> $DIR/types_fn_to_int.rs:8:13 - | -8 | let y = x as i32; - | ^^^^^^^^ - | - = note: #[deny(fn_to_numeric_cast)] on by default -help: if you need address of function, use cast to `usize` instead: - | -8 | let y = x as usize; - | ^^^^^^^^^^ +error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function address value. + --> $DIR/types_fn_to_int.rs:12:13 + | +12 | let y = x as i32; + | ^^^^^^^^ + | + = note: #[deny(fn_to_numeric_cast)] on by default +help: if you need the address of the function, consider : + | +12 | let y = x as usize; + | ^^^^^^^^^^ -error: aborting due to previous error +error: casting a `fn() -> i32 {bar}` to `u32` may truncate the function address value. + --> $DIR/types_fn_to_int.rs:14:13 + | +14 | let z = bar as u32; + | ^^^^^^^^^^ +help: if you need the address of the function, consider : + | +14 | let z = bar as usize; + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors From e6811b9c26726fa5c001c45c76b53137cf1570a3 Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Wed, 30 May 2018 16:55:03 +0700 Subject: [PATCH 6/8] Fix 'help' message --- clippy_lints/src/types.rs | 2 +- tests/ui/types_fn_to_int.stderr | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index fc65ebcc1471..0fe5f24f8d49 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1003,7 +1003,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { FN_TO_NUMERIC_CAST, expr.span, &format!("casting a `{}` to `{}` may truncate the function address value.", cast_from, cast_to), - "if you need the address of the function, consider :", + "if you need the address of the function, consider", format!("{} as usize", &snippet(cx, ex.span, "x")) ); } diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index d5e8ad8bbb29..a3a1abcc681a 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -2,23 +2,15 @@ error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function --> $DIR/types_fn_to_int.rs:12:13 | 12 | let y = x as i32; - | ^^^^^^^^ + | ^^^^^^^^ help: if you need the address of the function, consider: `x as usize` | = note: #[deny(fn_to_numeric_cast)] on by default -help: if you need the address of the function, consider : - | -12 | let y = x as usize; - | ^^^^^^^^^^ error: casting a `fn() -> i32 {bar}` to `u32` may truncate the function address value. --> $DIR/types_fn_to_int.rs:14:13 | 14 | let z = bar as u32; - | ^^^^^^^^^^ -help: if you need the address of the function, consider : - | -14 | let z = bar as usize; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` error: aborting due to 2 previous errors From ded2576957e69599073df0c05b5dea7405b36a94 Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Thu, 31 May 2018 09:00:13 +0700 Subject: [PATCH 7/8] Add one more test --- tests/ui/types_fn_to_int.rs | 1 + tests/ui/types_fn_to_int.stderr | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs index 0cce65798133..927f2149f304 100644 --- a/tests/ui/types_fn_to_int.rs +++ b/tests/ui/types_fn_to_int.rs @@ -10,6 +10,7 @@ fn bar() -> i32 { fn main() { let x = Foo::A; let y = x as i32; + let y1 = Foo::A as i32; let z = bar as u32; } diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index a3a1abcc681a..0643230470d9 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -6,11 +6,17 @@ error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function | = note: #[deny(fn_to_numeric_cast)] on by default +error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function address value. + --> $DIR/types_fn_to_int.rs:13:14 + | +13 | let y1 = Foo::A as i32; + | ^^^^^^^^^^^^^ help: if you need the address of the function, consider: `Foo::A as usize` + error: casting a `fn() -> i32 {bar}` to `u32` may truncate the function address value. - --> $DIR/types_fn_to_int.rs:14:13 + --> $DIR/types_fn_to_int.rs:15:13 | -14 | let z = bar as u32; +15 | let z = bar as u32; | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors From 24ab207671b0ac61c3b2008f9557a56cd4191efc Mon Sep 17 00:00:00 2001 From: Victor Korkin Date: Fri, 1 Jun 2018 23:08:11 +0700 Subject: [PATCH 8/8] Divide FN_TO_NUMERIC lint into two. FN_TO_NUMERIC_CAST_WITH_TRUNCATION is correctness check FN_TO_NUMERIC_CAST is only style check --- clippy_lints/src/types.rs | 56 ++++++++++++++++++++++------ tests/ui/types_fn_to_int.rs | 14 +++++-- tests/ui/types_fn_to_int.stderr | 66 +++++++++++++++++++++++++++------ 3 files changed, 109 insertions(+), 27 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 0fe5f24f8d49..c309503ee381 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -679,9 +679,9 @@ declare_clippy_lint! { "cast to the same type, e.g. `x as i32` where `x: i32`" } -/// **What it does:** Checks for casts of a function pointer to a numeric type except `usize`. +/// **What it does:** Checks for casts of a function pointer to a numeric type not enough to store address. /// -/// **Why is this bad?** Casting a function pointer to something other than `usize` could truncate the address value. +/// **Why is this bad?** Casting a function pointer to not eligable type could truncate the address value. /// /// **Known problems:** None. /// @@ -691,8 +691,25 @@ declare_clippy_lint! { /// let _ = test_fn as i32 /// ``` declare_clippy_lint! { - pub FN_TO_NUMERIC_CAST, + pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION, correctness, + "cast function pointer to the numeric type with value truncation" +} + +/// **What it does:** Checks for casts of a function pointer to a numeric type except `usize`. +/// +/// **Why is this bad?** Casting a function pointer to something other than `usize` is not a good style. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// fn test_fn() -> i16; +/// let _ = test_fn as i128 +/// ``` +declare_clippy_lint! { + pub FN_TO_NUMERIC_CAST, + style, "cast function pointer to the numeric type" } @@ -909,7 +926,8 @@ impl LintPass for CastPass { CAST_LOSSLESS, UNNECESSARY_CAST, CAST_PTR_ALIGNMENT, - FN_TO_NUMERIC_CAST + FN_TO_NUMERIC_CAST, + FN_TO_NUMERIC_CAST_WITH_TRUNCATION, ) } } @@ -998,14 +1016,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { ty::TyFnDef(..) | ty::TyFnPtr(..) => { if cast_to.is_numeric() && cast_to.sty != ty::TyUint(UintTy::Usize){ - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST, - expr.span, - &format!("casting a `{}` to `{}` may truncate the function address value.", cast_from, cast_to), - "if you need the address of the function, consider", - format!("{} as usize", &snippet(cx, ex.span, "x")) - ); + let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); + let pointer_nbits = cx.tcx.data_layout.pointer_size.bits(); + if to_nbits < pointer_nbits || (to_nbits == pointer_nbits && cast_to.is_signed()) { + span_lint_and_sugg( + cx, + FN_TO_NUMERIC_CAST_WITH_TRUNCATION, + expr.span, + &format!("casting a `{}` to `{}` may truncate the function address value.", cast_from, cast_to), + "if you need the address of the function, consider", + format!("{} as usize", &snippet(cx, ex.span, "x")) + ); + } else { + span_lint_and_sugg( + cx, + FN_TO_NUMERIC_CAST, + expr.span, + &format!("casting a `{}` to `{}` is bad style.", cast_from, cast_to), + "if you need the address of the function, consider", + format!("{} as usize", &snippet(cx, ex.span, "x")) + ); + + }; } } _ => () diff --git a/tests/ui/types_fn_to_int.rs b/tests/ui/types_fn_to_int.rs index 927f2149f304..8387586c3e94 100644 --- a/tests/ui/types_fn_to_int.rs +++ b/tests/ui/types_fn_to_int.rs @@ -9,8 +9,14 @@ fn bar() -> i32 { fn main() { let x = Foo::A; - let y = x as i32; - let y1 = Foo::A as i32; - - let z = bar as u32; + let _y = x as i32; + let _y1 = Foo::A as i32; + let _y = x as u32; + let _z = bar as u32; + let _y = bar as i64; + let _y = bar as u64; + let _z = Foo::A as i128; + let _z = Foo::A as u128; + let _z = bar as i128; + let _z = bar as u128; } diff --git a/tests/ui/types_fn_to_int.stderr b/tests/ui/types_fn_to_int.stderr index 0643230470d9..bbdf4ce2e70a 100644 --- a/tests/ui/types_fn_to_int.stderr +++ b/tests/ui/types_fn_to_int.stderr @@ -1,22 +1,66 @@ error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function address value. - --> $DIR/types_fn_to_int.rs:12:13 + --> $DIR/types_fn_to_int.rs:12:14 | -12 | let y = x as i32; - | ^^^^^^^^ help: if you need the address of the function, consider: `x as usize` +12 | let _y = x as i32; + | ^^^^^^^^ help: if you need the address of the function, consider: `x as usize` | - = note: #[deny(fn_to_numeric_cast)] on by default + = note: #[deny(fn_to_numeric_cast_with_truncation)] on by default error: casting a `fn(usize) -> Foo {Foo::A}` to `i32` may truncate the function address value. - --> $DIR/types_fn_to_int.rs:13:14 + --> $DIR/types_fn_to_int.rs:13:15 | -13 | let y1 = Foo::A as i32; - | ^^^^^^^^^^^^^ help: if you need the address of the function, consider: `Foo::A as usize` +13 | let _y1 = Foo::A as i32; + | ^^^^^^^^^^^^^ help: if you need the address of the function, consider: `Foo::A as usize` + +error: casting a `fn(usize) -> Foo {Foo::A}` to `u32` may truncate the function address value. + --> $DIR/types_fn_to_int.rs:14:14 + | +14 | let _y = x as u32; + | ^^^^^^^^ help: if you need the address of the function, consider: `x as usize` error: casting a `fn() -> i32 {bar}` to `u32` may truncate the function address value. - --> $DIR/types_fn_to_int.rs:15:13 + --> $DIR/types_fn_to_int.rs:15:14 + | +15 | let _z = bar as u32; + | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` + +error: casting a `fn() -> i32 {bar}` to `i64` may truncate the function address value. + --> $DIR/types_fn_to_int.rs:16:14 + | +16 | let _y = bar as i64; + | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` + +error: casting a `fn() -> i32 {bar}` to `u64` is bad style. + --> $DIR/types_fn_to_int.rs:17:14 + | +17 | let _y = bar as u64; + | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` + | + = note: `-D fn-to-numeric-cast` implied by `-D warnings` + +error: casting a `fn(usize) -> Foo {Foo::A}` to `i128` is bad style. + --> $DIR/types_fn_to_int.rs:18:14 + | +18 | let _z = Foo::A as i128; + | ^^^^^^^^^^^^^^ help: if you need the address of the function, consider: `Foo::A as usize` + +error: casting a `fn(usize) -> Foo {Foo::A}` to `u128` is bad style. + --> $DIR/types_fn_to_int.rs:19:14 + | +19 | let _z = Foo::A as u128; + | ^^^^^^^^^^^^^^ help: if you need the address of the function, consider: `Foo::A as usize` + +error: casting a `fn() -> i32 {bar}` to `i128` is bad style. + --> $DIR/types_fn_to_int.rs:20:14 + | +20 | let _z = bar as i128; + | ^^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` + +error: casting a `fn() -> i32 {bar}` to `u128` is bad style. + --> $DIR/types_fn_to_int.rs:21:14 | -15 | let z = bar as u32; - | ^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` +21 | let _z = bar as u128; + | ^^^^^^^^^^^ help: if you need the address of the function, consider: `bar as usize` -error: aborting due to 3 previous errors +error: aborting due to 10 previous errors