From b7772e6c9e27cb4bbdcb735789b937dc63ca189b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 19 Aug 2018 21:06:43 +0200 Subject: [PATCH] convert-id: tests for const gating. --- .../ui/rfc-2306/convert-id-const-no-gate.rs | 17 ++++++++++++++++ .../rfc-2306/convert-id-const-no-gate.stderr | 10 ++++++++++ .../ui/rfc-2306/convert-id-const-with-gate.rs | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/test/ui/rfc-2306/convert-id-const-no-gate.rs create mode 100644 src/test/ui/rfc-2306/convert-id-const-no-gate.stderr create mode 100644 src/test/ui/rfc-2306/convert-id-const-with-gate.rs diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.rs b/src/test/ui/rfc-2306/convert-id-const-no-gate.rs new file mode 100644 index 00000000000..545c179dec9 --- /dev/null +++ b/src/test/ui/rfc-2306/convert-id-const-no-gate.rs @@ -0,0 +1,17 @@ +// Copyright 2018 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. + +// This test should fail since identity is not stable as a const fn yet. + +#![feature(convert_id)] + +fn main() { + const _FOO: u8 = ::std::convert::identity(42u8); +} diff --git a/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr b/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr new file mode 100644 index 00000000000..dfd8619d875 --- /dev/null +++ b/src/test/ui/rfc-2306/convert-id-const-no-gate.stderr @@ -0,0 +1,10 @@ +error: `std::convert::identity` is not yet stable as a const fn + --> $DIR/convert-id-const-no-gate.rs:16:22 + | +LL | const _FOO: u8 = ::std::convert::identity(42u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: in Nightly builds, add `#![feature(const_convert_id)]` to the crate attributes to enable + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2306/convert-id-const-with-gate.rs b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs new file mode 100644 index 00000000000..c546f11914f --- /dev/null +++ b/src/test/ui/rfc-2306/convert-id-const-with-gate.rs @@ -0,0 +1,20 @@ +// Copyright 2018 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. + +// This test should pass since we've opted into 'identity' as an +// unstable const fn. + +// compile-pass + +#![feature(convert_id, const_convert_id)] + +fn main() { + const _FOO: u8 = ::std::convert::identity(42u8); +}