From abadece3ba2dba032fa7752e88fcf58289c240ac Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 13 Jun 2013 13:28:24 +1000 Subject: std: remove the invalid NullTerminatedStr instance for &'static str. A slice of a 'static str is still 'static, but doesn't necessarily have the null terminator. --- src/test/bench/shootout-fasta-redux.rs | 2 +- .../static-slice-not-null-terminated.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/static-slice-not-null-terminated.rs (limited to 'src/test') diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 3d5fc01afa6..9e90541baab 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -93,7 +93,7 @@ impl RepeatFasta { let stdout = self.stdout; let alu_len = self.alu.len(); let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8); - let alu: &[u8] = self.alu.as_bytes_with_null(); + let alu: &[u8] = self.alu.as_bytes(); copy_memory(buf, alu, alu_len); copy_memory(vec::mut_slice(buf, alu_len, buf.len()), diff --git a/src/test/compile-fail/static-slice-not-null-terminated.rs b/src/test/compile-fail/static-slice-not-null-terminated.rs new file mode 100644 index 00000000000..3cfaa57d540 --- /dev/null +++ b/src/test/compile-fail/static-slice-not-null-terminated.rs @@ -0,0 +1,21 @@ +// 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. + +fn main() { + let _ = (~"foo").as_bytes_with_null(); + let _ = (@"foo").as_bytes_with_null(); + + // a plain static slice is null terminated, but such a slice can + // be sliced shorter (i.e. become non-null terminated) and still + // have the static lifetime + let foo: &'static str = "foo"; + let _ = foo.as_bytes_with_null(); + //~^ ERROR does not implement any method in scope named `as_bytes_with_null` +} -- cgit 1.4.1-3-g733a5