From 94ef079be68e4275776347a7bd02a2f8624c5d77 Mon Sep 17 00:00:00 2001 From: Bill Myers Date: Sun, 9 Jun 2013 00:04:48 +0200 Subject: [PATCH 1/2] treat owned traits and closures as non-Const, fixes #7013 Owned traits and closures can contain any type, including those that do not satisfy Const, and thus must not satisfy Const themselves. --- src/librustc/middle/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index c51fba8a62b71..b177aa34bdf6f 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1940,7 +1940,7 @@ pub impl TypeContents { } fn nonconst(_cx: ctxt) -> TypeContents { - TC_MUTABLE + TC_MUTABLE + TC_OWNED_CLOSURE } fn moves_by_default(&self, cx: ctxt) -> bool { From 3fcc7b2c07f1f61e4d1d9d4aa6ad363879fef952 Mon Sep 17 00:00:00 2001 From: Bill Myers Date: Sun, 9 Jun 2013 00:13:52 +0200 Subject: [PATCH 2/2] test that owned traits are not const, tests #7013 --- .../compile-fail/owned-trait-not-const.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/compile-fail/owned-trait-not-const.rs diff --git a/src/test/compile-fail/owned-trait-not-const.rs b/src/test/compile-fail/owned-trait-not-const.rs new file mode 100644 index 0000000000000..55daaa59b25e2 --- /dev/null +++ b/src/test/compile-fail/owned-trait-not-const.rs @@ -0,0 +1,23 @@ +// Copyright 2013 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. + +extern mod std; + +pub trait Foo +{ +} + +fn c(_: T) {} + +fn test(a: ~Foo) { + c(a); //~ ERROR instantiating a type parameter with an incompatible type `~Foo`, which does not fulfill `Const` +} + +fn main() { }