Skip to content

Commit bd31498

Browse files
committed
Add compile-fail test.
1 parent 86b1067 commit bd31498

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustc/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl ObjectSafetyViolation {
5858
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
5959
format!("method `{}` has generic type parameters", name).into(),
6060
ObjectSafetyViolation::AssociatedConst(name) =>
61-
format!("the trait cannot contain associated consts, such as `{}`", name),
61+
format!("the trait cannot contain associated consts like `{}`", name),
6262
}
6363
}
6464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we correctly prevent users from making trait objects
12+
// from traits with associated consts.
13+
14+
trait Bar {
15+
const X: usize;
16+
}
17+
18+
fn make_bar<T:Bar>(t: &T) -> &Bar {
19+
//~^ ERROR E0038
20+
//~| NOTE the trait cannot contain associated consts like `X`
21+
//~| NOTE the trait `Bar` cannot be made into an object
22+
t
23+
}
24+
25+
fn main() {
26+
}

0 commit comments

Comments
 (0)