Skip to content

Commit 316cd92

Browse files
committed
---
yaml --- r: 274130 b: refs/heads/stable c: 18b851b h: refs/heads/master
1 parent 851a213 commit 316cd92

File tree

8 files changed

+117
-27
lines changed

8 files changed

+117
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 9884ff1dfbcb776c909ba575a90736326416fa22
32+
refs/heads/stable: 18b851bc521d04cfd21b07725fbd915ad9764a6f
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/libcore/str/mod.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,34 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
244244
Ok(unsafe { from_utf8_unchecked(v) })
245245
}
246246

247+
/// Forms a str from a pointer and a length.
248+
///
249+
/// The `len` argument is the number of bytes in the string.
250+
///
251+
/// # Safety
252+
///
253+
/// This function is unsafe as there is no guarantee that the given pointer is
254+
/// valid for `len` bytes, nor whether the lifetime inferred is a suitable
255+
/// lifetime for the returned str.
256+
///
257+
/// The data must be valid UTF-8
258+
///
259+
/// `p` must be non-null, even for zero-length str.
260+
///
261+
/// # Caveat
262+
///
263+
/// The lifetime for the returned str is inferred from its usage. To
264+
/// prevent accidental misuse, it's suggested to tie the lifetime to whichever
265+
/// source lifetime is safe in the context, such as by providing a helper
266+
/// function taking the lifetime of a host value for the str, or by explicit
267+
/// annotation.
268+
/// Performs the same functionality as `from_raw_parts`, except that a mutable
269+
/// str is returned.
270+
///
271+
unsafe fn from_raw_parts_mut<'a>(p: *mut u8, len: usize) -> &'a mut str {
272+
mem::transmute::<&mut [u8], &mut str>(slice::from_raw_parts_mut(p, len))
273+
}
274+
247275
/// Converts a slice of bytes to a string slice without checking
248276
/// that the string contains valid UTF-8.
249277
///
@@ -1843,10 +1871,10 @@ impl StrExt for str {
18431871
// is_char_boundary checks that the index is in [0, .len()]
18441872
if self.is_char_boundary(mid) {
18451873
let len = self.len();
1874+
let ptr = self.as_ptr() as *mut u8;
18461875
unsafe {
1847-
let self2: &mut str = mem::transmute_copy(&self);
1848-
(self.slice_mut_unchecked(0, mid),
1849-
self2.slice_mut_unchecked(mid, len))
1876+
(from_raw_parts_mut(ptr, mid),
1877+
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
18501878
}
18511879
} else {
18521880
slice_error_fail(self, 0, mid)

branches/stable/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
510510
self.structs.insert(variant_def_id, Vec::new());
511511
}
512512

513+
// Variants are always treated as importable to allow them to be glob used.
514+
// All variants are defined in both type and value namespaces as future-proofing.
513515
let child = self.add_child(name, parent, ForbidDuplicateTypesAndValues, variant.span);
514-
// variants are always treated as importable to allow them to be glob
515-
// used
516516
child.define_value(Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id())),
517517
variant.span,
518518
DefModifiers::PUBLIC | DefModifiers::IMPORTABLE | variant_modifiers);
@@ -618,15 +618,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
618618
Def::Variant(_, variant_id) => {
619619
debug!("(building reduced graph for external crate) building variant {}",
620620
final_ident);
621-
// variants are always treated as importable to allow them to be
622-
// glob used
621+
// Variants are always treated as importable to allow them to be glob used.
622+
// All variants are defined in both type and value namespaces as future-proofing.
623623
let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
624+
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
625+
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
624626
if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
625-
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
626627
// Not adding fields for variants as they are not accessed with a self receiver
627628
self.structs.insert(variant_id, Vec::new());
628-
} else {
629-
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
630629
}
631630
}
632631
Def::Fn(..) |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
pub enum XE {
12+
XStruct { a: u8 },
13+
XTuple(u8),
14+
XUnit,
15+
}

branches/stable/src/test/compile-fail/empty-struct-braces-pat-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ fn main() {
3939
XEmpty1 => () // Not an error, `XEmpty1` is interpreted as a new binding
4040
}
4141
match xe3 {
42-
XE::XEmpty3 => () //~ ERROR no associated item named `XEmpty3` found for type
42+
XE::XEmpty3 => () //~ ERROR `XE::XEmpty3` does not name a tuple variant or a tuple struct
4343
}
4444
}

branches/stable/src/test/compile-fail/empty-struct-braces-pat-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ fn main() {
3636
E::Empty3(..) => () //~ ERROR `E::Empty3` does not name a tuple variant or a tuple struct
3737
}
3838
match xe3 {
39-
XE::XEmpty3(..) => () //~ ERROR no associated item named `XEmpty3` found for type
39+
XE::XEmpty3(..) => () //~ ERROR `XE::XEmpty3` does not name a tuple variant or a tuple
4040
}
4141
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2015 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+
// aux-build:variant-namespacing.rs
12+
13+
extern crate variant_namespacing;
14+
pub use variant_namespacing::XE::*;
15+
//~^ ERROR import `XStruct` conflicts with type in this module
16+
//~| ERROR import `XStruct` conflicts with value in this module
17+
//~| ERROR import `XTuple` conflicts with type in this module
18+
//~| ERROR import `XTuple` conflicts with value in this module
19+
//~| ERROR import `XUnit` conflicts with type in this module
20+
//~| ERROR import `XUnit` conflicts with value in this module
21+
pub use E::*;
22+
//~^ ERROR import `Struct` conflicts with type in this module
23+
//~| ERROR import `Struct` conflicts with value in this module
24+
//~| ERROR import `Tuple` conflicts with type in this module
25+
//~| ERROR import `Tuple` conflicts with value in this module
26+
//~| ERROR import `Unit` conflicts with type in this module
27+
//~| ERROR import `Unit` conflicts with value in this module
28+
29+
enum E {
30+
Struct { a: u8 },
31+
Tuple(u8),
32+
Unit,
33+
}
34+
35+
type Struct = u8;
36+
type Tuple = u8;
37+
type Unit = u8;
38+
type XStruct = u8;
39+
type XTuple = u8;
40+
type XUnit = u8;
41+
42+
const Struct: u8 = 0;
43+
const Tuple: u8 = 0;
44+
const Unit: u8 = 0;
45+
const XStruct: u8 = 0;
46+
const XTuple: u8 = 0;
47+
const XUnit: u8 = 0;
48+
49+
fn main() {}

branches/stable/src/test/run-pass/empty-struct-braces.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ fn xcrate() {
9595
let e2: XEmpty2 = XEmpty2 {};
9696
let e2: XEmpty2 = XEmpty2;
9797
let e3: XE = XE::XEmpty3 {};
98-
// FIXME: Commented out tests are waiting for PR 30882 (fixes for variant namespaces)
99-
// let e4: XE = XE::XEmpty4 {};
98+
let e4: XE = XE::XEmpty4 {};
10099
let e4: XE = XE::XEmpty4;
101100

102101
match e1 {
@@ -109,10 +108,10 @@ fn xcrate() {
109108
XE::XEmpty3 {} => {}
110109
_ => {}
111110
}
112-
// match e4 {
113-
// XE::XEmpty4 {} => {}
114-
// _ => {}
115-
// }
111+
match e4 {
112+
XE::XEmpty4 {} => {}
113+
_ => {}
114+
}
116115

117116
match e1 {
118117
XEmpty1 { .. } => {}
@@ -124,18 +123,18 @@ fn xcrate() {
124123
XE::XEmpty3 { .. } => {}
125124
_ => {}
126125
}
127-
// match e4 {
128-
// XE::XEmpty4 { .. } => {}
129-
// _ => {}
130-
// }
126+
match e4 {
127+
XE::XEmpty4 { .. } => {}
128+
_ => {}
129+
}
131130

132131
match e2 {
133132
XEmpty2 => {}
134133
}
135-
// match e4 {
136-
// XE::XEmpty4 => {}
137-
// _ => {}
138-
// }
134+
match e4 {
135+
XE::XEmpty4 => {}
136+
_ => {}
137+
}
139138

140139
let e11: XEmpty1 = XEmpty1 { ..e1 };
141140
let e22: XEmpty2 = XEmpty2 { ..e2 };

0 commit comments

Comments
 (0)