]> git.lizzy.rs Git - rust.git/commitdiff
Cleanly error for non-const expression in associated const
authormatthewjasper <mjjasper1@gmail.com>
Thu, 19 Oct 2017 18:48:57 +0000 (19:48 +0100)
committermatthewjasper <mjjasper1@gmail.com>
Thu, 19 Oct 2017 18:48:57 +0000 (19:48 +0100)
src/librustc_resolve/lib.rs
src/test/compile-fail/issue-44239.rs [new file with mode: 0644]

index 4aab43cbec701cfd0a87bcfb33e3d275172ea4c5..c7ec1d072d0854fe733c9cb1ece2ac4135a5bfeb 100644 (file)
@@ -2084,7 +2084,9 @@ fn resolve_implementation(&mut self,
                                                             ValueNS,
                                                             impl_item.span,
                                             |n, s| ResolutionError::ConstNotMemberOfTrait(n, s));
-                                        visit::walk_impl_item(this, impl_item);
+                                        this.with_constant_rib(|this|
+                                            visit::walk_impl_item(this, impl_item)
+                                        );
                                     }
                                     ImplItemKind::Method(ref sig, _) => {
                                         // If this is a trait impl, ensure the method
diff --git a/src/test/compile-fail/issue-44239.rs b/src/test/compile-fail/issue-44239.rs
new file mode 100644 (file)
index 0000000..131c652
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2017 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.
+
+fn main() {
+    let n = 0;
+
+    struct Foo;
+    impl Foo {
+        const N: usize = n;
+        //~^ ERROR attempt to use a non-constant value
+    }
+}