Skip to content

Rollup of 11 pull requests #22842

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 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0685e7a
Added section on `cargo new` to "Hello Cargo!" chapter.
jxcl Feb 23, 2015
f49fd40
Removed `{}` and small wording fixes to "Hello Cargo!" chapter.
jxcl Feb 23, 2015
18878b1
std: Require `&mut self` for Iterator::all
alexcrichton Feb 25, 2015
64581cf
Change span_help calls to fileline_help where appropriate
ivanradanov Feb 24, 2015
7074346
Change MarkerTrait to be invariant. This is a (small) loss of express…
nikomatsakis Feb 25, 2015
07dc8d6
Result::or : avoid over-specializing the type
codyps Feb 25, 2015
5dd001b
Fix overflow in precise_time_ns() on Windows,
vadimcn Feb 24, 2015
65b0655
Added documentation of backslash ending string literals.
jxcl Feb 24, 2015
f618e2e
Changed prose to assert_eq! macro.
jxcl Feb 26, 2015
d9bdc43
Fix up build warnings about use of []
bossmc Feb 26, 2015
9cdb256
remove the redundant else branch
Feb 26, 2015
704ce1d
Revert hacks and add test for LLVM aborts due to empty aggregates.
eddyb Feb 26, 2015
c3b8125
Add check for unbounded due to non-regular types in dropck.
pnkfelix Feb 24, 2015
ed18e6b
Add regression test for issue 22443.
pnkfelix Feb 24, 2015
e87cc59
Rollup merge of #22732 - jxcl:cargo-new, r=steveklabnik
steveklabnik Feb 26, 2015
9b041b7
Rollup merge of #22748 - jxcl:string-backslash, r=steveklabnik
steveklabnik Feb 26, 2015
839f0a3
Rollup merge of #22764 - ivanradanov:fileline_help, r=huonw
steveklabnik Feb 26, 2015
41c6c35
Rollup merge of #22777 - pnkfelix:issue-22443, r=nikomatsakis
steveklabnik Feb 26, 2015
152e490
Rollup merge of #22788 - vadimcn:fix-precise_time_ns, r=pnkfelix
steveklabnik Feb 26, 2015
50a2225
Rollup merge of #22795 - alexcrichton:issue-22617, r=huonw
steveklabnik Feb 26, 2015
5883d63
Rollup merge of #22809 - nikomatsakis:issue-22655-infinite-recursion,…
steveklabnik Feb 26, 2015
66ced05
Rollup merge of #22817 - jmesmon:result-or-type, r=huonw
steveklabnik Feb 26, 2015
b8d6a81
Rollup merge of #22824 - bossmc:build-warnings, r=alexcrichton
steveklabnik Feb 26, 2015
fa66eb3
Rollup merge of #22833 - laijs:remove-redundant-else-branch, r=dotdash
steveklabnik Feb 26, 2015
f943de9
Rollup merge of #22837 - eddyb:issue-21721, r=dotdash
steveklabnik Feb 26, 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
15 changes: 14 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ nonzero_dec: '1' | '2' | '3' | '4'

A _character literal_ is a single Unicode character enclosed within two
`U+0027` (single-quote) characters, with the exception of `U+0027` itself,
which must be _escaped_ by a preceding U+005C character (`\`).
which must be _escaped_ by a preceding `U+005C` character (`\`).

##### String literals

Expand All @@ -311,6 +311,19 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two
which must be _escaped_ by a preceding `U+005C` character (`\`), or a _raw
string literal_.

A multi-line string literal may be defined by terminating each line with a
`U+005C` character (`\`) immediately before the newline. This causes the
`U+005C` character, the newline, and all whitespace at the beginning of the
next line to be ignored.

```rust
let a = "foobar";
let b = "foo\
bar";

assert_eq!(a,b);
```

##### Character escapes

Some additional _escapes_ are available in either character or non-raw string
Expand Down
66 changes: 62 additions & 4 deletions src/doc/trpl/hello-cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ the Cargo
README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies)
for specific instructions about installing it.

## Converting to Cargo

Let's convert Hello World to Cargo.

To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
configuration file, and put our source file in the right place. Let's
do that part first:

```{bash}
```bash
$ mkdir src
$ mv main.rs src/main.rs
```
Expand All @@ -36,7 +38,7 @@ place for everything, and everything in its place.

Next, our configuration file:

```{bash}
```bash
$ editor Cargo.toml
```

Expand Down Expand Up @@ -73,7 +75,7 @@ well as what it is named.

Once you have this file in place, we should be ready to build! Try this:

```{bash}
```bash
$ cargo build
Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world)
$ ./target/hello_world
Expand Down Expand Up @@ -103,6 +105,62 @@ That's it! We've successfully built `hello_world` with Cargo. Even though our
program is simple, it's using much of the real tooling that you'll use for the
rest of your Rust career.

## A New Project

You don't have to go through this whole process every time you want to start a new
project! Cargo has the ability to make a bare-bones project directory in which you
can start developing right away.

To start a new project with Cargo, use `cargo new`:

```bash
$ cargo new hello_world --bin
```

We're passing `--bin` because we're making a binary program: if we
were making a library, we'd leave it off.

Let's check out what Cargo has generated for us:

```bash
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs

1 directory, 2 files
```

If you don't have the `tree` command, you can probably get it from your distro's package
manager. It's not necessary, but it's certainly useful.

This is all we need to get started. First, let's check out `Cargo.toml`:

```toml
[package]

name = "hello_world"
version = "0.0.1"
authors = ["Your Name <[email protected]>"]
```

Cargo has populated this file with reasonable defaults based off the arguments you gave
it and your `git` global configuration. You may notice that Cargo has also initialized
the `hello_world` directory as a `git` repository.

Here's what's in `src/main.rs`:

```rust
fn main() {
println!("Hello, world!");
}
```

Cargo has generated a "Hello World!" for us, and you're ready to start coding! A
much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide.html).

Now that you've got the tools down, let's actually learn more about the Rust
language itself. These are the basics that will serve you well through the rest
of your time with Rust.
of your time with Rust.
6 changes: 2 additions & 4 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ pub trait IteratorExt: Iterator + Sized {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn all<F>(self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool {
for x in self { if !f(x) { return false; } }
fn all<F>(&mut self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool {
for x in self.by_ref() { if !f(x) { return false; } }
true
}

Expand Down Expand Up @@ -1637,8 +1637,6 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
for x in self.iter.by_ref() {
if (self.predicate)(&x) {
return Some(x);
} else {
continue
}
}
None
Expand Down
8 changes: 7 additions & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ macro_rules! impls{
/// any methods, but instead is used to gate access to data.
///
/// FIXME. Better documentation needed here!
pub trait MarkerTrait : PhantomFn<Self> { }
pub trait MarkerTrait : PhantomFn<Self,Self> { }
// ~~~~~ <-- FIXME(#22806)?
//
// Marker trait has been made invariant so as to avoid inf recursion,
// but we should ideally solve the underlying problem. That's a bit
// complicated.

impl<T:?Sized> MarkerTrait for T { }

/// `PhantomFn` is a marker trait for use with traits that contain
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ impl<T, E> Result<T, E> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn or(self, res: Result<T, E>) -> Result<T, E> {
pub fn or<F>(self, res: Result<T, F>) -> Result<T, F> {
match self {
Ok(_) => self,
Ok(v) => Ok(v),
Err(_) => res,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub fn test_and_then() {

#[test]
pub fn test_or() {
assert_eq!(op1().or(Ok(667)).unwrap(), 666);
assert_eq!(op1().or(Ok::<_, &'static str>(667)).unwrap(), 666);
assert_eq!(op1().or(Err("bad")).unwrap(), 666);

assert_eq!(op2().or(Ok(667)).unwrap(), 667);
assert_eq!(op2().or(Ok::<_, &'static str>(667)).unwrap(), 667);
assert_eq!(op2().or(Err("bad")).unwrap_err(), "bad");
}

Expand Down
6 changes: 1 addition & 5 deletions src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ pub trait Reseeder<R> {
/// Reseed an RNG using a `Default` instance. This reseeds by
/// replacing the RNG with the result of a `Default::default` call.
#[derive(Copy)]
pub struct ReseedWithDefault { __hack: [u8; 0] }
// FIXME(#21721) used to be an unit struct but that can cause
// certain LLVM versions to abort during optimizations.
#[allow(non_upper_case_globals)]
pub const ReseedWithDefault: ReseedWithDefault = ReseedWithDefault { __hack: [] };
pub struct ReseedWithDefault;

impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
fn reseed(&mut self, rng: &mut R) {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,8 @@ impl LintPass for UnconditionalRecursion {
for call in &self_call_spans {
sess.span_note(*call, "recursive call site")
}
sess.span_help(sp, "a `loop` may express intention better if this is on purpose")
sess.fileline_help(sp, "a `loop` may express intention \
better if this is on purpose")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl<'a> Context<'a> {
}
}
if self.rejected_via_kind.len() > 0 {
self.sess.span_help(self.span, "please recompile this crate using \
self.sess.fileline_help(self.span, "please recompile this crate using \
--crate-type lib");
let mismatches = self.rejected_via_kind.iter();
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/macro_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
}
"plugin" => {
self.sess.span_err(attr.span, "#[plugin] on `extern crate` is deprecated");
self.sess.span_help(attr.span, &format!("use a crate attribute instead, \
self.sess.fileline_help(attr.span, &format!("use a crate attribute instead, \
i.e. #![plugin({})]",
item.ident.as_str()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astconv_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
Some(d) => d.full_def()
};
if let def::DefPrimTy(nty) = def {
Some(prim_ty_to_ty(tcx, &path.segments[], nty))
Some(prim_ty_to_ty(tcx, &path.segments[..], nty))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
"pattern binding `{}` is named the same as one \
of the variants of the type `{}`",
&token::get_ident(ident.node), ty_to_string(cx.tcx, pat_ty));
span_help!(cx.tcx.sess, p.span,
fileline_help!(cx.tcx.sess, p.span,
"if you meant to match on a variant, \
consider making the path in the pattern qualified: `{}::{}`",
ty_to_string(cx.tcx, pat_ty), &token::get_ident(ident.node));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
// Does the required lifetime have a nice name we can print?
span_err!(self.tcx.sess, origin.span(), E0309,
"{} may not live long enough", labeled_user_string);
self.tcx.sess.span_help(
self.tcx.sess.fileline_help(
origin.span(),
&format!(
"consider adding an explicit lifetime bound `{}: {}`...",
Expand All @@ -456,7 +456,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
// Does the required lifetime have a nice name we can print?
span_err!(self.tcx.sess, origin.span(), E0310,
"{} may not live long enough", labeled_user_string);
self.tcx.sess.span_help(
self.tcx.sess.fileline_help(
origin.span(),
&format!(
"consider adding an explicit lifetime bound `{}: 'static`...",
Expand All @@ -468,7 +468,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
span_err!(self.tcx.sess, origin.span(), E0311,
"{} may not live long enough",
labeled_user_string);
self.tcx.sess.span_help(
self.tcx.sess.fileline_help(
origin.span(),
&format!(
"consider adding an explicit lifetime bound for `{}`",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3896,7 +3896,7 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>)
let types_a = substs_a.types.get_slice(subst::TypeSpace);
let types_b = substs_b.types.get_slice(subst::TypeSpace);

let pairs = types_a.iter().zip(types_b.iter());
let mut pairs = types_a.iter().zip(types_b.iter());

pairs.all(|(&a, &b)| same_type(a, b))
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn note_move_destination(bccx: &BorrowckCtxt,
bccx.span_note(
move_to_span,
"attempting to move value to here");
bccx.span_help(
bccx.fileline_help(
move_to_span,
&format!("to prevent the move, \
use `ref {0}` or `ref mut {0}` to capture value by \
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
ol,
moved_lp_msg,
pat_ty.user_string(self.tcx)));
self.tcx.sess.span_help(span,
self.tcx.sess.fileline_help(span,
"use `ref` to override");
}

Expand Down Expand Up @@ -675,7 +675,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
moved_lp_msg,
expr_ty.user_string(self.tcx),
suggestion));
self.tcx.sess.span_help(expr_span, help);
self.tcx.sess.fileline_help(expr_span, help);
}
}

Expand Down Expand Up @@ -741,6 +741,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
self.tcx.sess.span_help(s, m);
}

pub fn fileline_help(&self, s: Span, m: &str) {
self.tcx.sess.fileline_help(s, m);
}

pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String {
match err.code {
err_mutbl => {
Expand Down Expand Up @@ -870,7 +874,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}

if is_closure {
self.tcx.sess.span_help(
self.tcx.sess.fileline_help(
span,
"closures behind references must be called via `&mut`");
}
Expand Down
31 changes: 19 additions & 12 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} else {
let msg = format!("use of undeclared trait name `{}`",
self.path_names_to_string(trait_path, path_depth));
self.resolve_error(trait_path.span, &msg[]);
self.resolve_error(trait_path.span, &msg[..]);
Err(())
}
}
Expand Down Expand Up @@ -4115,10 +4115,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
uses it like a function name",
path_name));

self.session.span_help(expr.span,
&format!("Did you mean to write: \
`{} {{ /* fields */ }}`?",
path_name));
let msg = format!("Did you mean to write: \
`{} {{ /* fields */ }}`?",
path_name);
if self.emit_errors {
self.session.fileline_help(expr.span, &msg);
} else {
self.session.span_help(expr.span, &msg);
}
} else {
// Write the result into the def map.
debug!("(resolving expr) resolved `{}`",
Expand Down Expand Up @@ -4146,18 +4150,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
match type_res.map(|r| r.base_def) {
Some(DefTy(struct_id, _))
if self.structs.contains_key(&struct_id) => {
self.resolve_error(expr.span,
self.resolve_error(expr.span,
&format!("`{}` is a structure name, but \
this expression \
uses it like a function name",
path_name));

self.session.span_help(expr.span,
&format!("Did you mean to write: \
`{} {{ /* fields */ }}`?",
path_name));

}
let msg = format!("Did you mean to write: \
`{} {{ /* fields */ }}`?",
path_name);
if self.emit_errors {
self.session.fileline_help(expr.span, &msg);
} else {
self.session.span_help(expr.span, &msg);
}
}
_ => {
// Keep reporting some errors even if they're ignored above.
self.resolve_path(expr.id, path, 0, ValueNS, true);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fn gate_simd_ffi(tcx: &ty::ctxt, decl: &ast::FnDecl, ty: &ty::BareFnTy) {
&format!("use of SIMD type `{}` in FFI is highly experimental and \
may result in invalid code",
pprust::ty_to_string(ast_ty)));
tcx.sess.span_help(ast_ty.span,
tcx.sess.fileline_help(ast_ty.span,
"add #![feature(simd_ffi)] to the crate attributes to enable");
}
};
Expand Down
Loading