]> git.lizzy.rs Git - rust.git/commitdiff
Don't try to suggest fields of an enum
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 13 Apr 2015 16:27:58 +0000 (19:27 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 13 Apr 2015 16:29:23 +0000 (19:29 +0300)
Fixes #24365

src/librustc_typeck/check/mod.rs
src/test/compile-fail/issue-24365.rs [new file with mode: 0644]

index 862c454a3883360eabacd2cb7af2641c50a58843..ed8c82e05e50bfbb98404326d710df340f1597ba 100644 (file)
@@ -2691,8 +2691,8 @@ fn check_field<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
                             actual)
                 },
                 expr_t, None);
-            if let Some(t) = ty::ty_to_def_id(expr_t) {
-                suggest_field_names(t, field, tcx, vec![]);
+            if let ty::ty_struct(did, _) = expr_t.sty {
+                suggest_field_names(did, field, tcx, vec![]);
             }
         }
 
diff --git a/src/test/compile-fail/issue-24365.rs b/src/test/compile-fail/issue-24365.rs
new file mode 100644 (file)
index 0000000..a4df42a
--- /dev/null
@@ -0,0 +1,29 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub enum Attribute {
+    Code {attr_name_idx: u16},
+}
+
+pub enum Foo {
+    Bar
+}
+
+fn test(a: Foo) {
+    println!("{}", a.b); //~ ERROR attempted access of field
+}
+
+fn main() {
+    let x = Attribute::Code {
+        attr_name_idx: 42,
+    };
+    let z = (&x).attr_name_idx; //~ ERROR attempted access of field
+    let y = x.attr_name_idx; //~ ERROR attempted access of field
+}