Skip to content

Commit

Permalink
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
lundibundi committed Jul 19, 2019
1 parent 469b7a9 commit c6735a6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/test/ui/typeck/typeck_type_placeholder_item_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
fn test1() -> _ { Some(42) }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

const TEST2: _ = 42u32;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

const TEST3: _ = Some(42);
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

trait Test4 {
const TEST4: _ = 42;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

struct Test5;

impl Test5 {
const TEST5: _ = 13;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}

pub fn main() {
let _: Option<usize> = test1();
let _: f64 = test1();
Expand Down
38 changes: 37 additions & 1 deletion src/test/ui/typeck/typeck_type_placeholder_item_help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ LL | fn test1() -> _ { Some(42) }
| not allowed in type signatures
| help: replace `_` with the correct return type: `std::option::Option<i32>`

error: aborting due to previous error
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:7:14
|
LL | const TEST2: _ = 42u32;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `u32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:10:14
|
LL | const TEST3: _ = Some(42);
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `std::option::Option<i32>`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:14:18
|
LL | const TEST4: _ = 42;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item_help.rs:21:18
|
LL | const TEST5: _ = 13;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0121`.

0 comments on commit c6735a6

Please sign in to comment.