From f82ca8b0efa64bc33ed811b34c83a21aeb2950d1 Mon Sep 17 00:00:00 2001 From: David Ross Date: Sat, 15 Feb 2020 16:20:53 -0800 Subject: [PATCH] Add more error cases to issue 35813 tests --- .../parser/issue-35813-postfix-after-cast.rs | 100 ++++++++-- .../issue-35813-postfix-after-cast.stderr | 183 +++++++++++++----- 2 files changed, 225 insertions(+), 58 deletions(-) diff --git a/src/test/ui/parser/issue-35813-postfix-after-cast.rs b/src/test/ui/parser/issue-35813-postfix-after-cast.rs index dd608b263ec6..0083a475ddfb 100644 --- a/src/test/ui/parser/issue-35813-postfix-after-cast.rs +++ b/src/test/ui/parser/issue-35813-postfix-after-cast.rs @@ -1,5 +1,6 @@ // edition:2018 #![crate_type = "lib"] +#![feature(type_ascription)] use std::future::Future; use std::pin::Pin; @@ -7,47 +8,122 @@ use std::pin::Pin; // errors and parse such that further code gives useful errors. pub fn index_after_as_cast() { vec![1, 2, 3] as Vec[0]; - //~^ ERROR: casts followed by index operators are not supported + //~^ ERROR: casts cannot be followed by indexing + vec![1, 2, 3]: Vec[0]; + //~^ ERROR: casts cannot be followed by indexing } pub fn index_after_cast_to_index() { (&[0]) as &[i32][0]; - //~^ ERROR: casts followed by index operators are not supported + //~^ ERROR: casts cannot be followed by indexing + (&[0i32]): &[i32; 1][0]; + //~^ ERROR: casts cannot be followed by indexing +} + +pub fn cast_after_cast() { + if 5u64 as i32 as u16 == 0u16 { + + } + if 5u64: u64: u64 == 0u64 { + + } + let _ = 5u64: u64: u64 as u8 as i8 == 9i8; + let _ = 0i32: i32: i32; + let _ = 0 as i32: i32; + let _ = 0i32: i32 as i32; + let _ = 0 as i32 as i32; + let _ = 0i32: i32: i32 as u32 as i32; } // this tests that the precedence for `!x as Y.Z` is still what we expect pub fn precedence() { let x: i32 = &vec![1, 2, 3] as &Vec[0]; - //~^ ERROR: casts followed by index operators are not supported + //~^ ERROR: casts cannot be followed by indexing +} + +pub fn method_calls() { + 0 as i32.max(0); + //~^ ERROR: casts cannot be followed by a method call + 0: i32.max(0); + //~^ ERROR: casts cannot be followed by a method call } pub fn complex() { let _ = format!( - "{}", - if true { 33 } else { 44 } as i32.max(0) - //~^ ERROR: casts followed by method call expressions are not supported + "{} and {}", + if true { 33 } else { 44 } as i32.max(0), + //~^ ERROR: casts cannot be followed by a method call + if true { 33 } else { 44 }: i32.max(0) + //~^ ERROR: casts cannot be followed by a method call ); } pub fn in_condition() { if 5u64 as i32.max(0) == 0 { - //~^ ERROR: casts followed by method call expressions are not supported + //~^ ERROR: casts cannot be followed by a method call + } + if 5u64: u64.max(0) == 0 { + //~^ ERROR: casts cannot be followed by a method call } } pub fn inside_block() { let _ = if true { 5u64 as u32.max(0) == 0 - //~^ ERROR: casts followed by method call expressions are not supported + //~^ ERROR: casts cannot be followed by a method call + } else { false }; + let _ = if true { + 5u64: u64.max(0) == 0 + //~^ ERROR: casts cannot be followed by a method call } else { false }; } static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]); -//~^ ERROR: casts followed by index operators are not supported +//~^ ERROR: casts cannot be followed by indexing + +static bar2: &[i32] = &(&[1i32,2,3]: &[i32; 3][0..1]); +//~^ ERROR: casts cannot be followed by indexing + + +pub fn cast_then_try() -> Result { + Err(0u64) as Result?; + //~^ ERROR: casts cannot be followed by ? + Err(0u64): Result?; + //~^ ERROR: casts cannot be followed by ? + Ok(1) +} + + +pub fn cast_then_call() { + type F = fn(u8); + // type ascription won't actually do [unique drop fn type] -> fn(u8) casts. + let drop_ptr = drop as fn(u8); + drop as F(); + //~^ ERROR: parenthesized type parameters may only be used with a `Fn` trait [E0214] + drop_ptr: F(); + //~^ ERROR: parenthesized type parameters may only be used with a `Fn` trait [E0214] +} + +pub fn cast_to_fn_should_work() { + let drop_ptr = drop as fn(u8); + drop as fn(u8); + drop_ptr: fn(u8); +} + +pub fn parens_after_cast_error() { + let drop_ptr = drop as fn(u8); + drop as fn(u8)(0); + //~^ ERROR: casts cannot be followed by a function call + drop_ptr: fn(u8)(0); + //~^ ERROR: casts cannot be followed by a function call +} pub async fn cast_then_await() { Box::pin(noop()) as Pin>>.await; - //~^ ERROR: casts followed by awaits are not supported + //~^ ERROR: casts cannot be followed by `.await` + + Box::pin(noop()): Pin>.await; + //~^ ERROR: casts cannot be followed by `.await` } pub async fn noop() {} @@ -59,5 +135,7 @@ pub struct Foo { pub fn struct_field() { Foo::default() as Foo.bar; - //~^ ERROR: casts followed by field access expressions are not supported + //~^ ERROR: cannot be followed by a field access + Foo::default(): Foo.bar; + //~^ ERROR: cannot be followed by a field access } diff --git a/src/test/ui/parser/issue-35813-postfix-after-cast.stderr b/src/test/ui/parser/issue-35813-postfix-after-cast.stderr index 9459e076ea0c..ec6c4eb81073 100644 --- a/src/test/ui/parser/issue-35813-postfix-after-cast.stderr +++ b/src/test/ui/parser/issue-35813-postfix-after-cast.stderr @@ -1,74 +1,163 @@ -error: casts followed by index operators are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:9:5 +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:10:5 | LL | vec![1, 2, 3] as Vec[0]; - | -------------------------^^^ - | | - | help: try surrounding the expression with parentheses: `(vec![1, 2, 3] as Vec)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(vec![1, 2, 3] as Vec)` -error: casts followed by index operators are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:14:5 +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:12:5 + | +LL | vec![1, 2, 3]: Vec[0]; + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(vec![1, 2, 3]: Vec)` + +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:17:5 | LL | (&[0]) as &[i32][0]; - | ----------------^^^ - | | - | help: try surrounding the expression with parentheses: `((&[0]) as &[i32])` + | ^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `((&[0]) as &[i32])` -error: casts followed by index operators are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:20:18 +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:19:5 + | +LL | (&[0i32]): &[i32; 1][0]; + | ^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `((&[0i32]): &[i32; 1])` + +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:40:18 | LL | let x: i32 = &vec![1, 2, 3] as &Vec[0]; - | ---------------------------^^^ - | | - | help: try surrounding the expression with parentheses: `(&vec![1, 2, 3] as &Vec)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&vec![1, 2, 3] as &Vec)` -error: casts followed by method call expressions are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:33:8 +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:45:5 + | +LL | 0 as i32.max(0); + | ^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32)` + +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:47:5 + | +LL | 0: i32.max(0); + | ^^^^^^ help: try surrounding the expression in parentheses: `(0: i32)` + +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:62:8 | LL | if 5u64 as i32.max(0) == 0 { - | -----------^^^^^^^ - | | - | help: try surrounding the expression with parentheses: `(5u64 as i32)` + | ^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64 as i32)` -error: casts followed by method call expressions are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:40:9 +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:65:8 + | +LL | if 5u64: u64.max(0) == 0 { + | ^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64: u64)` + +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:72:9 | LL | 5u64 as u32.max(0) == 0 - | -----------^^^^^^^ - | | - | help: try surrounding the expression with parentheses: `(5u64 as u32)` + | ^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64 as u32)` -error: casts followed by index operators are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:45:24 +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:76:9 + | +LL | 5u64: u64.max(0) == 0 + | ^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64: u64)` + +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:81:24 | LL | static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]); - | ------------------^^^^^^ - | | - | help: try surrounding the expression with parentheses: `(&[1,2,3] as &[i32])` + | ^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&[1,2,3] as &[i32])` -error: casts followed by awaits are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:49:5 +error: casts cannot be followed by indexing + --> $DIR/issue-35813-postfix-after-cast.rs:84:25 + | +LL | static bar2: &[i32] = &(&[1i32,2,3]: &[i32; 3][0..1]); + | ^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&[1i32,2,3]: &[i32; 3])` + +error: casts cannot be followed by ? + --> $DIR/issue-35813-postfix-after-cast.rs:89:5 + | +LL | Err(0u64) as Result?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Err(0u64) as Result)` + +error: casts cannot be followed by ? + --> $DIR/issue-35813-postfix-after-cast.rs:91:5 + | +LL | Err(0u64): Result?; + | ^^^^^^^^^-^^^^^^^^^^^^^^^^ + | | + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: casts cannot be followed by a function call + --> $DIR/issue-35813-postfix-after-cast.rs:115:5 + | +LL | drop as fn(u8)(0); + | ^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(drop as fn(u8))` + +error: casts cannot be followed by a function call + --> $DIR/issue-35813-postfix-after-cast.rs:117:5 + | +LL | drop_ptr: fn(u8)(0); + | ^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(drop_ptr: fn(u8))` + +error: casts cannot be followed by `.await` + --> $DIR/issue-35813-postfix-after-cast.rs:122:5 | LL | Box::pin(noop()) as Pin>>.await; - | -----------------------------------------------------^^^^^^ - | | - | help: try surrounding the expression with parentheses: `(Box::pin(noop()) as Pin>>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Box::pin(noop()) as Pin>>)` -error: casts followed by field access expressions are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:61:5 +error: casts cannot be followed by `.await` + --> $DIR/issue-35813-postfix-after-cast.rs:125:5 + | +LL | Box::pin(noop()): Pin>.await; + | ^^^^^^^^^^^^^^^^-^^^^^^^^^^^^ + | | + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: casts cannot be followed by a field access + --> $DIR/issue-35813-postfix-after-cast.rs:137:5 | LL | Foo::default() as Foo.bar; - | ---------------------^^^^ - | | - | help: try surrounding the expression with parentheses: `(Foo::default() as Foo)` + | ^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Foo::default() as Foo)` -error: casts followed by method call expressions are not supported - --> $DIR/issue-35813-postfix-after-cast.rs:27:9 +error: casts cannot be followed by a field access + --> $DIR/issue-35813-postfix-after-cast.rs:139:5 | -LL | if true { 33 } else { 44 } as i32.max(0) - | ---------------------------------^^^^^^^ - | | - | help: try surrounding the expression with parentheses: `(if true { 33 } else { 44 } as i32)` +LL | Foo::default(): Foo.bar; + | ^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Foo::default(): Foo)` -error: aborting due to 9 previous errors +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:54:9 + | +LL | if true { 33 } else { 44 } as i32.max(0), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(if true { 33 } else { 44 } as i32)` +error: casts cannot be followed by a method call + --> $DIR/issue-35813-postfix-after-cast.rs:56:9 + | +LL | if true { 33 } else { 44 }: i32.max(0) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(if true { 33 } else { 44 }: i32)` + +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-35813-postfix-after-cast.rs:101:13 + | +LL | drop as F(); + | ^^^ only `Fn` traits may use parentheses + +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-35813-postfix-after-cast.rs:103:15 + | +LL | drop_ptr: F(); + | ^^^ only `Fn` traits may use parentheses + +error: aborting due to 25 previous errors + +For more information about this error, try `rustc --explain E0214`.