From bd31498ef668ee6c6ac0d2777ed5195b5f5d77e4 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Mon, 24 Apr 2017 01:19:12 -0700 Subject: [PATCH] Add compile-fail test. --- src/librustc/traits/object_safety.rs | 2 +- .../object-safety-associated-consts.rs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/object-safety-associated-consts.rs 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 @@ pub fn error_msg(&self) -> Cow<'static, str> { 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 or the MIT license +// , 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: &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() { +} -- GitLab