Skip to content

Rollup of 21 pull requests #27206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 59 commits into from
Closed
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fc16c3e
Improve the expected constant integer error message
jawline Jul 4, 2015
3a009cb
Merge branch 'master' of https://github.com/mmjack/rust
jawline Jul 4, 2015
f395b2b
Make the message slightly clearer
jawline Jul 4, 2015
8c5ffd3
Reduce line length
jawline Jul 4, 2015
02dd732
Self.sess -> txc.sess
jawline Jul 5, 2015
4872463
Remove 'valid' from error
jawline Jul 5, 2015
affbc72
Modified to add 'found' to error message instead
jawline Jul 19, 2015
b684826
add test for #20162
apasel422 Jul 19, 2015
871ccfb
Add a test for #26468
dotdash Jul 20, 2015
9bb6545
add test for #14229
apasel422 Jul 20, 2015
4c73dbd
add test for #19404
apasel422 Jul 20, 2015
31a62d3
s/has gained/has not gained/g
pfalabella Jul 20, 2015
a7e5c63
add test for #10436
apasel422 Jul 20, 2015
3ae7b72
Fix wording nit for E0253
AlisdairO Jul 20, 2015
27fc0f2
Document iterators in std::io
steveklabnik Jul 20, 2015
686d326
Add diagnostics for E0172, fix inline error message for E0139
AlisdairO Jul 19, 2015
7e7ec6b
Document structures in std::io::utils
steveklabnik Jul 20, 2015
9e18326
Update docs for take and broadcast
steveklabnik Jul 20, 2015
a29c834
Add travis config to TRPL: release channels
steveklabnik Jul 21, 2015
eb39df0
Improve documentation for std::io::BufWriter
steveklabnik Jul 20, 2015
0eb7303
Add E0403 error explanation
GuillaumeGomez Jul 17, 2015
cd385cb
Add E0405 error explanation
GuillaumeGomez Jul 17, 2015
bc79f20
Add E0404 error explanation
GuillaumeGomez Jul 17, 2015
9581154
Add E0407 error explanation
GuillaumeGomez Jul 17, 2015
c13295b
Add E0428 error explanation
GuillaumeGomez Jul 17, 2015
d2aee95
Expand documentation for IntoInnerError
steveklabnik Jul 20, 2015
94b8f28
Improve documentation for std::io::LineWriter
steveklabnik Jul 20, 2015
2e919b4
Add E0433 error explanation
GuillaumeGomez Jul 17, 2015
e6c058e
Rename 'link-args' to 'advanced-linking', add intro
aidanhs May 21, 2015
e5c1884
Note possiblities of empty extern blocks (based on #12575)
aidanhs May 21, 2015
e6d8434
add test for #14382
apasel422 Jul 20, 2015
a5c7b96
Add info about usage of 'unsafe' keyword in bindings to foreign inter…
Jul 21, 2015
48870d4
rust -> Rust
Jul 21, 2015
cf1e078
Klabnik nit-picks ;)
ticki Jul 21, 2015
7af865b
Static linking
aidanhs May 21, 2015
692a2d5
musl static linking not glibc
aidanhs Jun 15, 2015
231438a
Additional notes to link-args
aidanhs Jun 15, 2015
18f115c
update compile-fail test for #21174 to account for #27127
apasel422 Jul 21, 2015
e4402d9
Rollup merge of #26778 - jawline:master, r=pnkfelix
steveklabnik Jul 21, 2015
70eb2a1
Rollup merge of #27084 - GuillaumeGomez:patch-2, r=brson
steveklabnik Jul 21, 2015
30b8684
Rollup merge of #27127 - AlisdairO:diagnostics172, r=Manishearth
steveklabnik Jul 21, 2015
3b41959
Rollup merge of #27131 - apasel422:issue-20162, r=arielb1
steveklabnik Jul 21, 2015
837e8a9
Rollup merge of #27140 - dotdash:test-26468, r=luqmana
steveklabnik Jul 21, 2015
d8a9faa
Rollup merge of #27146 - apasel422:issue-14229, r=alexcrichton
steveklabnik Jul 21, 2015
57edbf1
Rollup merge of #27147 - apasel422:issue-19404, r=alexcrichton
steveklabnik Jul 21, 2015
7061db6
Rollup merge of #27151 - pfalabella:patch-2, r=steveklabnik
steveklabnik Jul 21, 2015
b76a0ec
Rollup merge of #27154 - apasel422:issue-10436, r=Gankro
steveklabnik Jul 21, 2015
3af02c1
Rollup merge of #27155 - steveklabnik:doc_std_io_buf_writer, r=alexcr…
steveklabnik Jul 21, 2015
268470d
Rollup merge of #27156 - AlisdairO:diagnostics253, r=Manishearth
steveklabnik Jul 21, 2015
def1dd1
Rollup merge of #27157 - steveklabnik:doc_std_io_iterators, r=alexcri…
steveklabnik Jul 21, 2015
542b7d1
Rollup merge of #27158 - apasel422:issue-14382, r=alexcrichton
steveklabnik Jul 21, 2015
eb1826e
Rollup merge of #27164 - steveklabnik:doc_io_utils, r=alexcrichton
steveklabnik Jul 21, 2015
bc27905
Rollup merge of #27166 - steveklabnik:doc_std_io_linewriter, r=alexcr…
steveklabnik Jul 21, 2015
26626e9
Rollup merge of #27167 - steveklabnik:doc_std_io_take, r=alexcrichton
steveklabnik Jul 21, 2015
6f7d9a5
Rollup merge of #27170 - steveklabnik:doc_std_io_intoinnererror, r=al…
steveklabnik Jul 21, 2015
8cf4f46
Rollup merge of #27175 - steveklabnik:channels_plus_travis, r=alexcri…
steveklabnik Jul 21, 2015
93543ca
Rollup merge of #27193 - aidanhs:aphs-advanced-linking-doc, r=alexcri…
steveklabnik Jul 21, 2015
93018bb
Rollup merge of #27201 - Ticki:master, r=steveklabnik
steveklabnik Jul 21, 2015
263c2ae
Rollup merge of #27202 - apasel422:issue-21174, r=alexcrichton
steveklabnik Jul 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
@@ -1636,6 +1636,10 @@ The type of a function declared in an extern block is `extern "abi" fn(A1, ...,
An) -> R`, where `A1...An` are the declared types of its arguments and `R` is
the declared return type.

It is valid to add the `link` attribute on an empty extern block. You can use
this to satisfy the linking requirements of extern blocks elsewhere in your code
(including upstream crates) instead of adding the attribute to each extern block.

## Visibility and Privacy

These two terms are often used interchangeably, and what they are attempting to
2 changes: 1 addition & 1 deletion src/doc/trpl/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@
* [No stdlib](no-stdlib.md)
* [Intrinsics](intrinsics.md)
* [Lang items](lang-items.md)
* [Link args](link-args.md)
* [Advanced linking](advanced-linking.md)
* [Benchmark Tests](benchmark-tests.md)
* [Box Syntax and Patterns](box-syntax-and-patterns.md)
* [Slice Patterns](slice-patterns.md)
151 changes: 151 additions & 0 deletions src/doc/trpl/advanced-linking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
% Advanced Linking

The common cases of linking with Rust have been covered earlier in this book,
but supporting the range of linking possibilities made available by other
languages is important for Rust to achieve seamless interaction with native
libraries.

# Link args

There is one other way to tell `rustc` how to customize linking, and that is via
the `link_args` attribute. This attribute is applied to `extern` blocks and
specifies raw flags which need to get passed to the linker when producing an
artifact. An example usage would be:

``` no_run
#![feature(link_args)]

#[link_args = "-foo -bar -baz"]
extern {}
# fn main() {}
```

Note that this feature is currently hidden behind the `feature(link_args)` gate
because this is not a sanctioned way of performing linking. Right now `rustc`
shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC),
so it makes sense to provide extra command line
arguments, but this will not always be the case. In the future `rustc` may use
LLVM directly to link native libraries, in which case `link_args` will have no
meaning. You can achieve the same effect as the `link-args` attribute with the
`-C link-args` argument to `rustc`.

It is highly recommended to *not* use this attribute, and rather use the more
formal `#[link(...)]` attribute on `extern` blocks instead.

# Static linking

Static linking refers to the process of creating output that contain all
required libraries and so don't need libraries installed on every system where
you want to use your compiled project. Pure-Rust dependencies are statically
linked by default so you can use created binaries and libraries without
installing the Rust everywhere. By contrast, native libraries
(e.g. `libc` and `libm`) usually dynamically linked, but it is possible to
change this and statically link them as well.

Linking is a very platform dependent topic — on some platforms, static linking
may not be possible at all! This section assumes some basic familiarity with
linking on your platform of choice.

## Linux

By default, all Rust programs on Linux will link to the system `libc` along with
a number of other libraries. Let's look at an example on a 64-bit Linux machine
with GCC and `glibc` (by far the most common `libc` on Linux):

``` text
$ cat example.rs
fn main() {}
$ rustc example.rs
$ ldd example
linux-vdso.so.1 => (0x00007ffd565fd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa81889c000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa81867e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa818475000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa81825f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa817e9a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa818cf9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa817b93000)
```

Dynamic linking on Linux can be undesirable if you wish to use new library
features on old systems or target systems which do not have the required
dependencies for your program to run.

Static linking is supported via an alternative `libc`, `musl` - this must be
enabled at Rust compile-time with some prerequisites available. You can compile
your own version of Rust with `musl` enabled and install it into a custom
directory with the instructions below:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this Rust is trying to compile this code block.

$ mkdir musldist
$ PREFIX=$(pwd)/musldist
$
$ # Build musl
$ wget http://www.musl-libc.org/releases/musl-1.1.10.tar.gz
[...]
$ tar xf musl-1.1.10.tar.gz
$ cd musl-1.1.10/
musl-1.1.10 $ ./configure --disable-shared --prefix=$PREFIX
[...]
musl-1.1.10 $ make
[...]
musl-1.1.10 $ make install
[...]
musl-1.1.10 $ cd ..
$ du -h musldist/lib/libc.a
2.2M musldist/lib/libc.a
$
$ # Build libunwind.a
$ wget http://llvm.org/releases/3.6.1/llvm-3.6.1.src.tar.xz
$ tar xf llvm-3.6.1.src.tar.xz
$ cd llvm-3.6.1.src/projects/
llvm-3.6.1.src/projects $ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk/ libcxxabi
llvm-3.6.1.src/projects $ svn co http://llvm.org/svn/llvm-project/libunwind/trunk/ libunwind
llvm-3.6.1.src/projects $ sed -i 's#^\(include_directories\).*$#\0\n\1(../libcxxabi/include)#' libunwind/CMakeLists.txt
llvm-3.6.1.src/projects $ mkdir libunwind/build
llvm-3.6.1.src/projects $ cd libunwind/build
llvm-3.6.1.src/projects/libunwind/build $ cmake -DLLVM_PATH=../../.. -DLIBUNWIND_ENABLE_SHARED=0 ..
llvm-3.6.1.src/projects/libunwind/build $ make
llvm-3.6.1.src/projects/libunwind/build $ cp lib/libunwind.a $PREFIX/lib/
llvm-3.6.1.src/projects/libunwind/build $ cd cd ../../../../
$ du -h musldist/lib/libunwind.a
164K musldist/lib/libunwind.a
$
$ # Build musl-enabled rust
$ git clone https://github.com/rust-lang/rust.git muslrust
$ cd muslrust
muslrust $ ./configure --target=x86_64-unknown-linux-musl --musl-root=$PREFIX --prefix=$PREFIX
muslrust $ make
muslrust $ make install
muslrust $ cd ..
$ du -h musldist/bin/rustc
12K musldist/bin/rustc
```

You now have a build of a `musl`-enabled Rust! Because we've installed it to a
custom prefix we need to make sure our system can the binaries and appropriate
libraries when we try and run it:

```
$ export PATH=$PREFIX/bin:$PATH
$ export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
```

Let's try it out!

```
$ echo 'fn main() { println!("hi!"); panic!("failed"); }' > example.rs
$ rustc --target=x86_64-unknown-linux-musl example.rs
$ ldd example
not a dynamic executable
$ ./example
hi!
thread '<main>' panicked at 'failed', example.rs:1
```

Success! This binary can be copied to almost any Linux machine with the same
machine architecture and run without issues.

`cargo build` also permits the `--target` option so you should be able to build
your crates as normal. However, you may need to recompile your native libraries
against `musl` before they can be linked against.
8 changes: 4 additions & 4 deletions src/doc/trpl/ffi.md
Original file line number Diff line number Diff line change
@@ -340,7 +340,7 @@ libraries:
Note that frameworks are only available on OSX targets.

The different `kind` values are meant to differentiate how the native library
participates in linkage. From a linkage perspective, the rust compiler creates
participates in linkage. From a linkage perspective, the Rust compiler creates
two flavors of artifacts: partial (rlib/staticlib) and final (dylib/binary).
Native dynamic library and framework dependencies are propagated to the final
artifact boundary, while static library dependencies are not propagated at
@@ -350,9 +350,9 @@ artifact.
A few examples of how this model can be used are:

* A native build dependency. Sometimes some C/C++ glue is needed when writing
some rust code, but distribution of the C/C++ code in a library format is just
some Rust code, but distribution of the C/C++ code in a library format is just
a burden. In this case, the code will be archived into `libfoo.a` and then the
rust crate would declare a dependency via `#[link(name = "foo", kind =
Rust crate would declare a dependency via `#[link(name = "foo", kind =
"static")]`.

Regardless of the flavor of output for the crate, the native static library
@@ -361,7 +361,7 @@ A few examples of how this model can be used are:

* A normal dynamic dependency. Common system libraries (like `readline`) are
available on a large number of systems, and often a static copy of these
libraries cannot be found. When this dependency is included in a rust crate,
libraries cannot be found. When this dependency is included in a Rust crate,
partial targets (like rlibs) will not link to the library, but when the rlib
is included in a final target (like a binary), the native library will be
linked in.
25 changes: 0 additions & 25 deletions src/doc/trpl/link-args.md

This file was deleted.

23 changes: 23 additions & 0 deletions src/doc/trpl/release-channels.md
Original file line number Diff line number Diff line change
@@ -43,3 +43,26 @@ This will help alert the team in case there’s an accidental regression.
Additionally, testing against nightly can catch regressions even sooner, and so
if you don’t mind a third build, we’d appreciate testing against all channels.

As an example, many Rust programmers use [Travis](https://travis-ci.org/) to
test their crates, which is free for open source projects. Travis [supports
Rust directly][travis], and you can use a `.travis.yml` file like this to
test on all channels:

```yaml
language: rust
rust:
- nightly
- beta
- stable

matrix:
allow_failures:
- rust: nightly
```

[travis]: http://docs.travis-ci.com/user/languages/rust/

With this configuration, Travis will test all three channels, but if something
breaks on nightly, it won’t fail your build. A similar configuration is
recommended for any CI system, check the documentation of the one you’re
using for more details.
10 changes: 7 additions & 3 deletions src/doc/trpl/unsafe.md
Original file line number Diff line number Diff line change
@@ -100,10 +100,14 @@ that you normally can not do. Just three. Here they are:

That’s it. It’s important that `unsafe` does not, for example, ‘turn off the
borrow checker’. Adding `unsafe` to some random Rust code doesn’t change its
semantics, it won’t just start accepting anything.
semantics, it won’t just start accepting anything. But it will let you write
things that _do_ break some of the rules.

But it will let you write things that _do_ break some of the rules. Let’s go
over these three abilities in order.
You will also encounter the `unsafe` keyword when writing bindings to foreign
(non-Rust) interfaces. You're encouraged to write a safe, native Rust interface
around the methods provided by the library.

Let’s go over the basic three abilities listed, in order.

## Access or update a `static mut`

8 changes: 4 additions & 4 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
@@ -2555,7 +2555,7 @@ impl<I: RandomAccessIterator, F> RandomAccessIterator for Inspect<I, F>
#[unstable(feature = "iter_unfold")]
#[derive(Clone)]
#[deprecated(since = "1.2.0",
reason = "has gained enough traction to retain its position \
reason = "has not gained enough traction to retain its position \
in the standard library")]
#[allow(deprecated)]
pub struct Unfold<St, F> {
@@ -2567,7 +2567,7 @@ pub struct Unfold<St, F> {

#[unstable(feature = "iter_unfold")]
#[deprecated(since = "1.2.0",
reason = "has gained enough traction to retain its position \
reason = "has not gained enough traction to retain its position \
in the standard library")]
#[allow(deprecated)]
impl<A, St, F> Unfold<St, F> where F: FnMut(&mut St) -> Option<A> {
@@ -3018,7 +3018,7 @@ type IterateState<T, F> = (F, Option<T>, bool);
/// from a given seed value.
#[unstable(feature = "iter_iterate")]
#[deprecated(since = "1.2.0",
reason = "has gained enough traction to retain its position \
reason = "has not gained enough traction to retain its position \
in the standard library")]
#[allow(deprecated)]
pub type Iterate<T, F> = Unfold<IterateState<T, F>, fn(&mut IterateState<T, F>) -> Option<T>>;
@@ -3027,7 +3027,7 @@ pub type Iterate<T, F> = Unfold<IterateState<T, F>, fn(&mut IterateState<T, F>)
/// repeated applications of the given function `f`.
#[unstable(feature = "iter_iterate")]
#[deprecated(since = "1.2.0",
reason = "has gained enough traction to retain its position \
reason = "has not gained enough traction to retain its position \
in the standard library")]
#[allow(deprecated)]
pub fn iterate<T, F>(seed: T, f: F) -> Iterate<T, F> where
2 changes: 1 addition & 1 deletion src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
if from_tc.interior_param() || to_tc.interior_param() {
span_err!(self.tcx.sess, span, E0139,
"cannot transmute to or from a type that contains \
type parameters in its interior");
unsubstituted type parameters");
return;
}

16 changes: 8 additions & 8 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ use metadata::csearch;
use middle;
use middle::cast;
use middle::check_const;
use middle::const_eval::{self, ConstVal};
use middle::const_eval::{self, ConstVal, ErrKind};
use middle::def::{self, DefMap, ExportMap};
use middle::dependency_format;
use middle::fast_reject;
@@ -6098,20 +6098,20 @@ impl<'tcx> ctxt<'tcx> {
found);
}
Err(err) => {
let err_description = err.description();
let found = match count_expr.node {
let err_msg = match count_expr.node {
ast::ExprPath(None, ast::Path {
global: false,
ref segments,
..
}) if segments.len() == 1 =>
format!("{}", "found variable"),
_ =>
format!("but {}", err_description),
format!("found variable"),
_ => match err.kind {
ErrKind::MiscCatchAll => format!("but found {}", err.description()),
_ => format!("but {}", err.description())
}
};
span_err!(self.sess, count_expr.span, E0307,
"expected constant integer for repeat count, {}",
found);
"expected constant integer for repeat count, {}", err_msg);
}
}
0
Loading