diff options
| author | Without Boats <woboats@gmail.com> | 2017-04-24 01:19:12 -0700 |
|---|---|---|
| committer | Without Boats <woboats@gmail.com> | 2017-04-24 01:19:12 -0700 |
| commit | bd31498ef668ee6c6ac0d2777ed5195b5f5d77e4 (patch) | |
| tree | c130396204f4f2367e0db07bb32b88e8a3e5e613 | |
| parent | 86b10671dbb7edf4090cb04476b4da205fd892b2 (diff) | |
Add compile-fail test.
| -rw-r--r-- | src/librustc/traits/object_safety.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/object-safety-associated-consts.rs | 26 |
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() { +} |
