Skip to content

Commit 4a8d9e0

Browse files
committed
---
yaml --- r: 159226 b: refs/heads/snap-stage3 c: 4ab2235 h: refs/heads/master v: v3
1 parent 5c1a647 commit 4a8d9e0

File tree

15 files changed

+175
-111
lines changed

15 files changed

+175
-111
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 40fb87d40f681f5356af42175fc7b85da387f037
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: fcf9fb61574a415653fa0c787058972312ce1235
4+
refs/heads/snap-stage3: 4ab22355d4d186d5eec52be0f980034685411d04
55
refs/heads/try: f58aad6dce273570fb130b4df008ef9acd5a5be2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcollections/slice.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
use self::Direction::*;
9191
use alloc::boxed::Box;
92+
use core::borrow::{BorrowFrom, BorrowFromMut};
9293
use core::cmp;
9394
use core::kinds::Sized;
9495
use core::mem::size_of;
@@ -647,6 +648,16 @@ impl<T> SliceAllocPrelude<T> for [T] {
647648
}
648649
}
649650

651+
#[unstable = "trait is unstable"]
652+
impl<T> BorrowFrom<Vec<T>> for [T] {
653+
fn borrow_from(owned: &Vec<T>) -> &[T] { owned[] }
654+
}
655+
656+
#[unstable = "trait is unstable"]
657+
impl<T> BorrowFromMut<Vec<T>> for [T] {
658+
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { owned[mut] }
659+
}
660+
650661
/// Unsafe operations
651662
pub mod raw {
652663
pub use core::slice::raw::{buf_as_slice, mut_buf_as_slice};

branches/snap-stage3/src/libcollections/str.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
pub use self::MaybeOwned::*;
5555
use self::RecompositionState::*;
5656
use self::DecompositionType::*;
57-
57+
use core::borrow::BorrowFrom;
5858
use core::default::Default;
5959
use core::fmt;
6060
use core::cmp;
@@ -604,6 +604,11 @@ impl<'a> fmt::Show for MaybeOwned<'a> {
604604
}
605605
}
606606

607+
#[unstable = "trait is unstable"]
608+
impl BorrowFrom<String> for str {
609+
fn borrow_from(owned: &String) -> &str { owned[] }
610+
}
611+
607612
/// Unsafe string operations.
608613
pub mod raw {
609614
pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
//! A module for working with borrowed data.
12+
//!
13+
//! # The `BorrowFrom` traits
14+
//!
15+
//! In general, there may be several ways to "borrow" a piece of data. The
16+
//! typical ways of borrowing a type `T` are `&T` (a shared borrow) and `&mut T`
17+
//! (a mutable borrow). But types like `Vec<T>` provide additional kinds of
18+
//! borrows: the borrowed slices `&[T]` and `&mut [T]`.
19+
//!
20+
//! When writing generic code, it is often desirable to abstract over all ways
21+
//! of borrowing data from a given type. That is the role of the `BorrowFrom`
22+
//! trait: if `T: BorrowFrom<U>`, then `&T` can be borrowed from `&U`. A given
23+
//! type can be borrowed as multiple different types. In particular, `Vec<T>:
24+
//! BorrowFrom<Vec<T>>` and `[T]: BorrowFrom<Vec<T>>`.
25+
//!
26+
//! # The `ToOwned` trait
27+
//!
28+
//! Some types make it possible to go from borrowed to owned, usually by
29+
//! implementing the `Clone` trait. But `Clone` works only for going from `&T`
30+
//! to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data
31+
//! from any borrow of a given type.
32+
//!
33+
//! # The `Cow` (clone-on-write) type
34+
//!
35+
//! The type `Cow` is a smart pointer providing clone-on-write functionality: it
36+
//! can enclose and provide immutable access to borrowed data, and clone the
37+
//! data lazily when mutation or ownership is required. The type is designed to
38+
//! work with general borrowed data via the `BorrowFrom` trait.
39+
//!
40+
//! `Cow` implements both `Deref` and `DerefMut`, which means that you can call
41+
//! methods directly on the data it encloses. The first time a mutable reference
42+
//! is required, the data will be cloned (via `to_owned`) if it is not
43+
//! already owned.
44+
45+
#![unstable = "recently added as part of collections reform"]
46+
47+
use clone::Clone;
48+
use kinds::Sized;
49+
use ops::Deref;
50+
51+
/// A trait for borrowing data.
52+
pub trait BorrowFrom<Sized? Owned> for Sized? {
53+
/// Immutably borrow from an owned value.
54+
fn borrow_from(owned: &Owned) -> &Self;
55+
}
56+
57+
/// A trait for mutably borrowing data.
58+
pub trait BorrowFromMut<Sized? Owned> for Sized? : BorrowFrom<Owned> {
59+
/// Mutably borrow from an owned value.
60+
fn borrow_from_mut(owned: &mut Owned) -> &mut Self;
61+
}
62+
63+
impl<Sized? T> BorrowFrom<T> for T {
64+
fn borrow_from(owned: &T) -> &T { owned }
65+
}
66+
67+
impl<Sized? T> BorrowFromMut<T> for T {
68+
fn borrow_from_mut(owned: &mut T) -> &mut T { owned }
69+
}
70+
71+
impl BorrowFrom<&'static str> for str {
72+
fn borrow_from<'a>(owned: &'a &'static str) -> &'a str { &**owned }
73+
}
74+
75+
/// A generalization of Clone to borrowed data.
76+
pub trait ToOwned<Owned> for Sized?: BorrowFrom<Owned> {
77+
/// Create owned data from borrowed data, usually by copying.
78+
fn to_owned(&self) -> Owned;
79+
}
80+
81+
impl<T> ToOwned<T> for T where T: Clone {
82+
fn to_owned(&self) -> T { self.clone() }
83+
}
84+
85+
/// A clone-on-write smart pointer.
86+
pub enum Cow<'a, T, B: 'a> where B: ToOwned<T> {
87+
/// Borrowed data.
88+
Borrowed(&'a B),
89+
90+
/// Owned data.
91+
Owned(T)
92+
}
93+
94+
impl<'a, T, B> Cow<'a, T, B> where B: ToOwned<T> {
95+
/// Acquire a mutable reference to the owned form of the data.
96+
///
97+
/// Copies the data if it is not already owned.
98+
pub fn to_mut(&mut self) -> &mut T {
99+
match *self {
100+
Borrowed(borrowed) => {
101+
*self = Owned(borrowed.to_owned());
102+
self.to_mut()
103+
}
104+
Owned(ref mut owned) => owned
105+
}
106+
}
107+
108+
/// Extract the owned data.
109+
///
110+
/// Copies the data if it is not already owned.
111+
pub fn into_owned(self) -> T {
112+
match self {
113+
Borrowed(borrowed) => borrowed.to_owned(),
114+
Owned(owned) => owned
115+
}
116+
}
117+
}
118+
119+
impl<'a, T, B> Deref<B> for Cow<'a, T, B> where B: ToOwned<T> {
120+
fn deref(&self) -> &B {
121+
match *self {
122+
Borrowed(borrowed) => borrowed,
123+
Owned(ref owned) => BorrowFrom::borrow_from(owned)
124+
}
125+
}
126+
}

branches/snap-stage3/src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub mod default;
108108
pub mod any;
109109
pub mod atomic;
110110
pub mod bool;
111+
pub mod borrow;
111112
pub mod cell;
112113
pub mod char;
113114
pub mod panicking;

branches/snap-stage3/src/librustc/back/link.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,7 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
728728
if sess.target.target.options.morestack {
729729
ab.add_native_library("morestack").unwrap();
730730
}
731-
if !sess.target.target.options.no_compiler_rt {
732-
ab.add_native_library("compiler-rt").unwrap();
733-
}
731+
ab.add_native_library("compiler-rt").unwrap();
734732

735733
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
736734
let mut all_native_libs = vec![];

branches/snap-stage3/src/librustc/lint/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ impl LintPass for UnusedAttributes {
623623
"link",
624624
"link_name",
625625
"link_section",
626-
"linkage",
627626
"no_builtins",
628627
"no_mangle",
629628
"no_split_stack",

branches/snap-stage3/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use driver::config::{NoDebugInfo, FullDebugInfo};
3636
use driver::driver::{CrateAnalysis, CrateTranslation, ModuleTranslation};
3737
use driver::session::Session;
3838
use lint;
39-
use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param};
39+
use llvm::{BasicBlockRef, ValueRef, Vector, get_param};
4040
use llvm;
4141
use metadata::{csearch, encoder, loader};
4242
use middle::astencode;
@@ -2137,32 +2137,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TransItemVisitor<'a, 'tcx> {
21372137
}
21382138
}
21392139

2140-
pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
2141-
// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
2142-
// applicable to variable declarations and may not really make sense for
2143-
// Rust code in the first place but whitelist them anyway and trust that
2144-
// the user knows what s/he's doing. Who knows, unanticipated use cases
2145-
// may pop up in the future.
2146-
//
2147-
// ghost, dllimport, dllexport and linkonce_odr_autohide are not supported
2148-
// and don't have to be, LLVM treats them as no-ops.
2149-
match name {
2150-
"appending" => Some(llvm::AppendingLinkage),
2151-
"available_externally" => Some(llvm::AvailableExternallyLinkage),
2152-
"common" => Some(llvm::CommonLinkage),
2153-
"extern_weak" => Some(llvm::ExternalWeakLinkage),
2154-
"external" => Some(llvm::ExternalLinkage),
2155-
"internal" => Some(llvm::InternalLinkage),
2156-
"linkonce" => Some(llvm::LinkOnceAnyLinkage),
2157-
"linkonce_odr" => Some(llvm::LinkOnceODRLinkage),
2158-
"private" => Some(llvm::PrivateLinkage),
2159-
"weak" => Some(llvm::WeakAnyLinkage),
2160-
"weak_odr" => Some(llvm::WeakODRLinkage),
2161-
_ => None,
2162-
}
2163-
}
2164-
2165-
21662140
/// Enum describing the origin of an LLVM `Value`, for linkage purposes.
21672141
pub enum ValueOrigin {
21682142
/// The LLVM `Value` is in this context because the corresponding item was
@@ -2200,23 +2174,6 @@ pub fn update_linkage(ccx: &CrateContext,
22002174
OriginalTranslation => {},
22012175
}
22022176

2203-
match id {
2204-
Some(id) => {
2205-
let item = ccx.tcx().map.get(id);
2206-
if let ast_map::NodeItem(i) = item {
2207-
if let Some(name) = attr::first_attr_value_str_by_name(i.attrs[], "linkage") {
2208-
if let Some(linkage) = llvm_linkage_by_name(name.get()) {
2209-
llvm::SetLinkage(llval, linkage);
2210-
} else {
2211-
ccx.sess().span_fatal(i.span, "invalid linkage specified");
2212-
}
2213-
return;
2214-
}
2215-
}
2216-
}
2217-
_ => {}
2218-
}
2219-
22202177
match id {
22212178
Some(id) if ccx.reachable().contains(&id) => {
22222179
llvm::SetLinkage(llval, llvm::ExternalLinkage);

branches/snap-stage3/src/librustc/middle/trans/foreign.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111

1212
use back::{link};
13-
use llvm::{ValueRef, CallConv, get_param};
13+
use llvm::{ValueRef, CallConv, Linkage, get_param};
1414
use llvm;
1515
use middle::weak_lang_items;
16-
use middle::trans::base::{llvm_linkage_by_name, push_ctxt};
16+
use middle::trans::base::push_ctxt;
1717
use middle::trans::base;
1818
use middle::trans::build::*;
1919
use middle::trans::cabi;
@@ -101,6 +101,31 @@ pub fn llvm_calling_convention(ccx: &CrateContext,
101101
}
102102
}
103103

104+
pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
105+
// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
106+
// applicable to variable declarations and may not really make sense for
107+
// Rust code in the first place but whitelist them anyway and trust that
108+
// the user knows what s/he's doing. Who knows, unanticipated use cases
109+
// may pop up in the future.
110+
//
111+
// ghost, dllimport, dllexport and linkonce_odr_autohide are not supported
112+
// and don't have to be, LLVM treats them as no-ops.
113+
match name {
114+
"appending" => Some(llvm::AppendingLinkage),
115+
"available_externally" => Some(llvm::AvailableExternallyLinkage),
116+
"common" => Some(llvm::CommonLinkage),
117+
"extern_weak" => Some(llvm::ExternalWeakLinkage),
118+
"external" => Some(llvm::ExternalLinkage),
119+
"internal" => Some(llvm::InternalLinkage),
120+
"linkonce" => Some(llvm::LinkOnceAnyLinkage),
121+
"linkonce_odr" => Some(llvm::LinkOnceODRLinkage),
122+
"private" => Some(llvm::PrivateLinkage),
123+
"weak" => Some(llvm::WeakAnyLinkage),
124+
"weak_odr" => Some(llvm::WeakODRLinkage),
125+
_ => None,
126+
}
127+
}
128+
104129
pub fn register_static(ccx: &CrateContext,
105130
foreign_item: &ast::ForeignItem) -> ValueRef {
106131
let ty = ty::node_id_to_type(ccx.tcx(), foreign_item.id);

branches/snap-stage3/src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ extern crate rustrt;
141141

142142
pub use core::any;
143143
pub use core::bool;
144+
pub use core::borrow;
144145
pub use core::cell;
145146
pub use core::clone;
146147
#[cfg(not(test))] pub use core::cmp;

branches/snap-stage3/src/libsyntax/feature_gate.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
182182
"`#[thread_local]` is an experimental feature, and does not \
183183
currently handle destructors. There is no corresponding \
184184
`#[task_local]` mapping to the task model");
185-
} else if attr.name().equiv(&("linkage")) {
186-
self.gate_feature("linkage", i.span,
187-
"the `linkage` attribute is experimental \
188-
and not portable across platforms")
189185
}
190186
}
191187
match i.node {

branches/snap-stage3/src/test/compile-fail/linkage4.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

branches/snap-stage3/src/test/run-make/linkage-attr-on-static/Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

branches/snap-stage3/src/test/run-make/linkage-attr-on-static/bar.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

branches/snap-stage3/src/test/run-make/linkage-attr-on-static/foo.c

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)