about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/traits/object_safety.rs2
-rw-r--r--src/test/compile-fail/object-safety-associated-consts.rs26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs
index f51711d0310..90260d17372 100644
--- a/src/librustc/traits/object_safety.rs
+++ b/src/librustc/traits/object_safety.rs
@@ -58,7 +58,7 @@ impl ObjectSafetyViolation {
             ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
                 format!("method `{}` has generic type parameters", name).into(),
             ObjectSafetyViolation::AssociatedConst(name) =>
-                format!("the trait cannot contain associated consts, such as `{}`", name),
+                format!("the trait cannot contain associated consts like `{}`", name),
         }
     }
 }
diff --git a/src/test/compile-fail/object-safety-associated-consts.rs b/src/test/compile-fail/object-safety-associated-consts.rs
new file mode 100644
index 00000000000..e38187fe86a
--- /dev/null
+++ b/src/test/compile-fail/object-safety-associated-consts.rs
@@ -0,0 +1,26 @@
+// Copyright 2014 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.
+
+// Check that we correctly prevent users from making trait objects
+// from traits with associated consts.
+
+trait Bar {
+    const X: usize;
+}
+
+fn make_bar<T:Bar>(t: &T) -> &Bar {
+        //~^ ERROR E0038
+        //~| NOTE the trait cannot contain associated consts like `X`
+        //~| NOTE the trait `Bar` cannot be made into an object
+    t
+}
+
+fn main() {
+}