diff options
| author | Ayrton <a.munoz3327@gmail.com> | 2020-10-06 11:59:14 -0400 |
|---|---|---|
| committer | Ayrton <a.munoz3327@gmail.com> | 2020-10-27 11:04:04 -0400 |
| commit | 432ebd57efe38e691acc25570cb79acbe4956651 (patch) | |
| tree | f5177e4c87d6077658ec8d3c5701c795485e9ef7 /src/test | |
| parent | 511fe048b4ee2535961014b1be3294a771cc7e87 (diff) | |
Removed test for unhandled case in function_item_references lint
Removed test for the unhandled case of calls to `fn f<T>(x: &T)` where `x` is a function reference and is formatted as a pointer in `f`. This compiles since `&T` implements `Pointer`, but is unlikely to occur in practice. Also tweaked the lint's wording and modified tests accordingly.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/lint/function-references.rs | 61 | ||||
| -rw-r--r-- | src/test/ui/lint/function-references.stderr | 112 |
2 files changed, 85 insertions, 88 deletions
diff --git a/src/test/ui/lint/function-references.rs b/src/test/ui/lint/function-references.rs index 1a8dde85790..9ec3871e482 100644 --- a/src/test/ui/lint/function-references.rs +++ b/src/test/ui/lint/function-references.rs @@ -10,7 +10,7 @@ fn baz(x: u32, y: u32) -> u32 { x + y } unsafe fn unsafe_fn() { } extern "C" fn c_fn() { } unsafe extern "C" fn unsafe_c_fn() { } -unsafe extern fn variadic_fn(_x: u32, _args: ...) { } +unsafe extern fn variadic(_x: u32, _args: ...) { } //function references passed to these functions should never lint fn call_fn(f: &dyn Fn(u32) -> u32, x: u32) { f(x); } @@ -20,7 +20,6 @@ fn parameterized_call_fn<F: Fn(u32) -> u32>(f: &F, x: u32) { f(x); } fn print_ptr<F: Pointer>(f: F) { println!("{:p}", f); } fn bound_by_ptr_trait<F: Pointer>(_f: F) { } fn bound_by_ptr_trait_tuple<F: Pointer, G: Pointer>(_t: (F, G)) { } -fn implicit_ptr_trait<F>(f: &F) { println!("{:p}", f); } fn main() { //`let` bindings with function references shouldn't lint @@ -56,47 +55,47 @@ fn main() { //potential ways to incorrectly try printing function pointers println!("{:p}", &foo); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer print!("{:p}", &foo); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer format!("{:p}", &foo); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", &foo as *const _); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", zst_ref); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", cast_zst_ptr); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", coerced_zst_ptr); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", &fn_item); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", indirect_ref); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer println!("{:p}", &nop); - //~^ WARNING cast `nop` with `as fn()` to use it as a pointer + //~^ WARNING cast `nop` with `as fn()` to obtain a function pointer println!("{:p}", &bar); - //~^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer println!("{:p}", &baz); - //~^ WARNING cast `baz` with `as fn(_, _) -> _` to use it as a pointer + //~^ WARNING cast `baz` with `as fn(_, _) -> _` to obtain a function pointer println!("{:p}", &unsafe_fn); - //~^ WARNING cast `unsafe_fn` with `as unsafe fn()` to use it as a pointer + //~^ WARNING cast `unsafe_fn` with `as unsafe fn()` to obtain a function pointer println!("{:p}", &c_fn); - //~^ WARNING cast `c_fn` with `as extern "C" fn()` to use it as a pointer + //~^ WARNING cast `c_fn` with `as extern "C" fn()` to obtain a function pointer println!("{:p}", &unsafe_c_fn); - //~^ WARNING cast `unsafe_c_fn` with `as unsafe extern "C" fn()` to use it as a pointer - println!("{:p}", &variadic_fn); - //~^ WARNING cast `variadic_fn` with `as unsafe extern "C" fn(_, ...)` to use it as a pointer + //~^ WARNING cast `unsafe_c_fn` with `as unsafe extern "C" fn()` to obtain a function pointer + println!("{:p}", &variadic); + //~^ WARNING cast `variadic` with `as unsafe extern "C" fn(_, ...)` to obtain a function pointer println!("{:p}", &std::env::var::<String>); - //~^ WARNING cast `var` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `var` with `as fn(_) -> _` to obtain a function pointer println!("{:p} {:p} {:p}", &nop, &foo, &bar); - //~^ WARNING cast `nop` with `as fn()` to use it as a pointer - //~^^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer - //~^^^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `nop` with `as fn()` to obtain a function pointer + //~^^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer + //~^^^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer //using a function reference to call a function shouldn't lint (&bar)(1); @@ -109,10 +108,10 @@ fn main() { unsafe { //potential ways to incorrectly try transmuting function pointers std::mem::transmute::<_, usize>(&foo); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer std::mem::transmute::<_, (usize, usize)>((&foo, &bar)); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer - //~^^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer + //~^^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer //the correct way to transmute function pointers std::mem::transmute::<_, usize>(foo as fn() -> u32); @@ -121,14 +120,12 @@ fn main() { //function references as arguments required to be bound by std::fmt::Pointer should lint print_ptr(&bar); - //~^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer bound_by_ptr_trait(&bar); - //~^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer bound_by_ptr_trait_tuple((&foo, &bar)); - //~^ WARNING cast `foo` with `as fn() -> _` to use it as a pointer - //~^^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer - implicit_ptr_trait(&bar); - //~^ WARNING cast `bar` with `as fn(_) -> _` to use it as a pointer + //~^ WARNING cast `foo` with `as fn() -> _` to obtain a function pointer + //~^^ WARNING cast `bar` with `as fn(_) -> _` to obtain a function pointer //correct ways to pass function pointers as arguments bound by std::fmt::Pointer print_ptr(bar as fn(u32) -> u32); diff --git a/src/test/ui/lint/function-references.stderr b/src/test/ui/lint/function-references.stderr index bc4947b3d70..71940a1d4cf 100644 --- a/src/test/ui/lint/function-references.stderr +++ b/src/test/ui/lint/function-references.stderr @@ -1,5 +1,5 @@ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:58:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:57:22 | LL | println!("{:p}", &foo); | ^^^^ @@ -10,158 +10,158 @@ note: the lint level is defined here LL | #![warn(function_item_references)] | ^^^^^^^^^^^^^^^^^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:60:20 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:59:20 | LL | print!("{:p}", &foo); | ^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:62:21 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:61:21 | LL | format!("{:p}", &foo); | ^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:65:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:64:22 | LL | println!("{:p}", &foo as *const _); | ^^^^^^^^^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:67:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:66:22 | LL | println!("{:p}", zst_ref); | ^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:69:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:68:22 | LL | println!("{:p}", cast_zst_ptr); | ^^^^^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:71:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:70:22 | LL | println!("{:p}", coerced_zst_ptr); | ^^^^^^^^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:74:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:73:22 | LL | println!("{:p}", &fn_item); | ^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:76:22 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:75:22 | LL | println!("{:p}", indirect_ref); | ^^^^^^^^^^^^ -warning: cast `nop` with `as fn()` to use it as a pointer - --> $DIR/function-references.rs:79:22 +warning: cast `nop` with `as fn()` to obtain a function pointer + --> $DIR/function-references.rs:78:22 | LL | println!("{:p}", &nop); | ^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:81:22 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:80:22 | LL | println!("{:p}", &bar); | ^^^^ -warning: cast `baz` with `as fn(_, _) -> _` to use it as a pointer - --> $DIR/function-references.rs:83:22 +warning: cast `baz` with `as fn(_, _) -> _` to obtain a function pointer + --> $DIR/function-references.rs:82:22 | LL | println!("{:p}", &baz); | ^^^^ -warning: cast `unsafe_fn` with `as unsafe fn()` to use it as a pointer - --> $DIR/function-references.rs:85:22 +warning: cast `unsafe_fn` with `as unsafe fn()` to obtain a function pointer + --> $DIR/function-references.rs:84:22 | LL | println!("{:p}", &unsafe_fn); | ^^^^^^^^^^ -warning: cast `c_fn` with `as extern "C" fn()` to use it as a pointer - --> $DIR/function-references.rs:87:22 +warning: cast `c_fn` with `as extern "C" fn()` to obtain a function pointer + --> $DIR/function-references.rs:86:22 | LL | println!("{:p}", &c_fn); | ^^^^^ -warning: cast `unsafe_c_fn` with `as unsafe extern "C" fn()` to use it as a pointer - --> $DIR/function-references.rs:89:22 +warning: cast `unsafe_c_fn` with `as unsafe extern "C" fn()` to obtain a function pointer + --> $DIR/function-references.rs:88:22 | LL | println!("{:p}", &unsafe_c_fn); | ^^^^^^^^^^^^ -warning: cast `variadic_fn` with `as unsafe extern "C" fn(_, ...)` to use it as a pointer - --> $DIR/function-references.rs:91:22 +warning: cast `variadic` with `as unsafe extern "C" fn(_, ...)` to obtain a function pointer + --> $DIR/function-references.rs:90:22 | -LL | println!("{:p}", &variadic_fn); - | ^^^^^^^^^^^^ +LL | println!("{:p}", &variadic); + | ^^^^^^^^^ -warning: cast `var` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:93:22 +warning: cast `var` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:92:22 | LL | println!("{:p}", &std::env::var::<String>); | ^^^^^^^^^^^^^^^^^^^^^^^^ -warning: cast `nop` with `as fn()` to use it as a pointer - --> $DIR/function-references.rs:96:32 +warning: cast `nop` with `as fn()` to obtain a function pointer + --> $DIR/function-references.rs:95:32 | LL | println!("{:p} {:p} {:p}", &nop, &foo, &bar); | ^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:96:38 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:95:38 | LL | println!("{:p} {:p} {:p}", &nop, &foo, &bar); | ^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:96:44 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:95:44 | LL | println!("{:p} {:p} {:p}", &nop, &foo, &bar); | ^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:111:41 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:110:41 | LL | std::mem::transmute::<_, usize>(&foo); | ^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:113:50 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:112:50 | LL | std::mem::transmute::<_, (usize, usize)>((&foo, &bar)); | ^^^^^^^^^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:113:50 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:112:50 | LL | std::mem::transmute::<_, (usize, usize)>((&foo, &bar)); | ^^^^^^^^^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:123:15 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:122:15 | LL | print_ptr(&bar); | ^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:125:24 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:124:24 | LL | bound_by_ptr_trait(&bar); | ^^^^ -warning: cast `bar` with `as fn(_) -> _` to use it as a pointer - --> $DIR/function-references.rs:127:30 +warning: cast `bar` with `as fn(_) -> _` to obtain a function pointer + --> $DIR/function-references.rs:126:30 | LL | bound_by_ptr_trait_tuple((&foo, &bar)); | ^^^^^^^^^^^^ -warning: cast `foo` with `as fn() -> _` to use it as a pointer - --> $DIR/function-references.rs:127:30 +warning: cast `foo` with `as fn() -> _` to obtain a function pointer + --> $DIR/function-references.rs:126:30 | LL | bound_by_ptr_trait_tuple((&foo, &bar)); | ^^^^^^^^^^^^ |
