From 09d9924713a119692b8b195b81bd57ee7821cb71 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 20 Jan 2015 10:58:06 +0100 Subject: librustc: hint close matches on accessing nonexisting fields --- .../compile-fail/struct-fields-hints-no-dupe.rs | 24 ++++++++++++++++++++++ src/test/compile-fail/struct-fields-hints.rs | 23 +++++++++++++++++++++ src/test/compile-fail/struct-fields-typo.rs | 24 ++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/test/compile-fail/struct-fields-hints-no-dupe.rs create mode 100644 src/test/compile-fail/struct-fields-hints.rs create mode 100644 src/test/compile-fail/struct-fields-typo.rs (limited to 'src/test') diff --git a/src/test/compile-fail/struct-fields-hints-no-dupe.rs b/src/test/compile-fail/struct-fields-hints-no-dupe.rs new file mode 100644 index 00000000000..8df9ffd6cc7 --- /dev/null +++ b/src/test/compile-fail/struct-fields-hints-no-dupe.rs @@ -0,0 +1,24 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct A { + foo : i32, + car : i32, + barr : i32 +} + +fn main() { + let a = A { + foo : 5, + bar : 42,//~ ERROR structure `A` has no field named `bar` + //~^ HELP did you mean `barr`? + car : 9, + }; +} diff --git a/src/test/compile-fail/struct-fields-hints.rs b/src/test/compile-fail/struct-fields-hints.rs new file mode 100644 index 00000000000..37001f1e60a --- /dev/null +++ b/src/test/compile-fail/struct-fields-hints.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct A { + foo : i32, + car : i32, + barr : i32 +} + +fn main() { + let a = A { + foo : 5, + bar : 42,//~ ERROR structure `A` has no field named `bar` + //~^ HELP did you mean `car`? + }; +} diff --git a/src/test/compile-fail/struct-fields-typo.rs b/src/test/compile-fail/struct-fields-typo.rs new file mode 100644 index 00000000000..c897dc55204 --- /dev/null +++ b/src/test/compile-fail/struct-fields-typo.rs @@ -0,0 +1,24 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct BuildData { + foo: isize, + bar: f32 +} + +fn main() { + let foo = BuildData { + foo: 0, + bar: 0.5, + }; + let x = foo.baa;//~ ERROR attempted access of field `baa` on type `BuildData` + //~^ HELP did you mean `bar`? + println!("{}", x); +} -- cgit 1.4.1-3-g733a5