]> git.lizzy.rs Git - rust.git/log
rust.git
9 years agoReplaced a comment mentioning a fixed issue
Markus Westerlind [Sun, 14 Jun 2015 16:24:52 +0000 (18:24 +0200)]
Replaced a comment mentioning a fixed issue

Replaced it with a comment mentioning the rationale for checking the discriminants first.

9 years agoUtilize discriminant_value for more efficient deriving
Markus [Fri, 12 Jun 2015 07:41:06 +0000 (09:41 +0200)]
Utilize discriminant_value for more efficient deriving

The new code generated for deriving on enums looks something like this:

```rust
let __self0_vi = unsafe {
    std::intrinsics::discriminant_value(&self) } as i32;
let __self1_vi = unsafe {
    std::intrinsics::discriminant_value(&__arg1) } as i32;
let __self2_vi = unsafe {
    std::intrinsics::discriminant_value(&__arg2) } as i32;
///
if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
    match (...) {
        (Variant1, Variant1, ...) => Body1
        (Variant2, Variant2, ...) => Body2,
        ...
        _ => ::core::intrinsics::unreachable()
    }
}
else {
    ... // catch-all remainder can inspect above variant index values.
}
```
This helps massively for C-like enums since they will be compiled as a
single comparison giving observed speedups of up to 8x. For more complex
enums the speedup is more difficult to measure but it should not be
slower to generate code this way regardless.

9 years agoAuto merge of #26253 - steveklabnik:remove_old_ignored_tests, r=brson
bors [Sat, 13 Jun 2015 10:08:51 +0000 (10:08 +0000)]
Auto merge of #26253 - steveklabnik:remove_old_ignored_tests, r=brson

Two commits here: one which removes a bunch of tests, and re-enables a few that work.

Second updates the syntax of one of the failing tests. It still doesn't pass, but at least it compiles.

9 years agoAuto merge of #26118 - tshepang:define-trait, r=steveklabnik
bors [Sat, 13 Jun 2015 08:34:12 +0000 (08:34 +0000)]
Auto merge of #26118 - tshepang:define-trait, r=steveklabnik

I saw a variation of this definition in [an article](http://pcwalton.github.io/blog/2012/08/08/a-gentle-introduction-to-traits-in-rust) by @pcwalton.

9 years agoAuto merge of #26108 - Marwes:field_pun_docs, r=steveklabnik
bors [Sat, 13 Jun 2015 07:00:26 +0000 (07:00 +0000)]
Auto merge of #26108 - Marwes:field_pun_docs, r=steveklabnik

Adds a mention for the short form pattern syntax. Now without creating a PR to my own fork!

#25779

9 years agoAuto merge of #26248 - steveklabnik:remove_2061, r=alexcrichton
bors [Sat, 13 Jun 2015 03:29:40 +0000 (03:29 +0000)]
Auto merge of #26248 - steveklabnik:remove_2061, r=alexcrichton

This test was added on Nov 1, 2012:
https://github.com/rust-lang/rust/commit/0069bd2f4612b744ab3731b4c1db13c2f3202185#diff-b516ff69faf8886c48e6f5e833c2548c

and then ignored on the same day:
https://github.com/rust-lang/rust/commit/a90020fe8dd8be8615df82e6294408bfed82a767#diff-b516ff69faf8886c48e6f5e833c2548c

and never unignored again.

9 years agoAuto merge of #26247 - steveklabnik:remove_4120, r=alexcrichton
bors [Sat, 13 Jun 2015 01:23:26 +0000 (01:23 +0000)]
Auto merge of #26247 - steveklabnik:remove_4120, r=alexcrichton

This test originated from an ICE in Rust 0.4:
https://github.com/rust-lang/rust/commit/373504a7ac6801293ae65316625ace667842f5b8#diff-214656000770dff71c8165d051c3f027

it was ignored one day later:
https://github.com/rust-lang/rust/commit/1fa2b9980fabff3227d5e5915d1180a0f6922d37#diff-214656000770dff71c8165d051c3f027

and then never enabled again. I think we're safe without it.

9 years agoAuto merge of #26160 - alexcrichton:revert-rc-as-ref, r=aturon
bors [Fri, 12 Jun 2015 23:05:06 +0000 (23:05 +0000)]
Auto merge of #26160 - alexcrichton:revert-rc-as-ref, r=aturon

This is a revert of PR #26008 which caused the unintended breakage reported in #26096. We may want to add these implementations in the long run, but for now this revert allows us to take some more time to evaluate the impact of such a change (e.g. run it through crater).

Closes #26096

9 years agoAuto merge of #25844 - alexcrichton:stabilize-fs-features, r=aturon
bors [Fri, 12 Jun 2015 21:31:37 +0000 (21:31 +0000)]
Auto merge of #25844 - alexcrichton:stabilize-fs-features, r=aturon

This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.

* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size

The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.

As some minor cleanup, some deprecated and unstable fs apis were also removed:

* File::path
* Metadata::accessed
* Metadata::modified

Features that were explicitly left unstable include:

* fs::WalkDir - the semantics of this were not considered in the recent fs
  expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
  the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
  question as it always returns a verbatim path. Additionally the Unix
  implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
  this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.

9 years agoAuto merge of #26232 - eefriedman:rename-sty, r=nrc
bors [Fri, 12 Jun 2015 19:57:27 +0000 (19:57 +0000)]
Auto merge of #26232 - eefriedman:rename-sty, r=nrc

Use camel-case naming, and use names which actually make sense in modern Rust.

9 years agoAuto merge of #26221 - sanxiyn:wf-span, r=arielb1
bors [Fri, 12 Jun 2015 18:25:55 +0000 (18:25 +0000)]
Auto merge of #26221 - sanxiyn:wf-span, r=arielb1

When checking field types of struct or enum definitions, use spans for field types instead of the entire item.

9 years agoUpdate dead-code-closure-bang
Steve Klabnik [Fri, 12 Jun 2015 18:15:57 +0000 (14:15 -0400)]
Update dead-code-closure-bang

This stdlib function went away, so update it to use current syntax.

9 years agoignore-test cleanup
Steve Klabnik [Fri, 12 Jun 2015 17:36:41 +0000 (13:36 -0400)]
ignore-test cleanup

Most of these are old, but some specific messages for specific tests:

* trait-contravariant-self.rs: failed due to a soundess hole:
  https://github.com/rust-lang/rust/commit/05e3248a7974f55b64f75a2483b37ff8c001a4ff

* process-detatch: https://github.com/rust-lang/rust/commit/15966c3c1f99810ac81053769651776a67181dae
  says "this test is being ignored until signals are implemented" That's
  not happening for a long time, and when it is, we'll write tests for
  it.

* deep-vector{,2}.rs: "too big for our poor macro infrastructure", and has
  been ignored over a year.

* borrowck-nested-calls.rs's FIXME #6268 was closed in favor of
  rust-lang/rfcs#811

* issue-15167.rs works properly now
* issue-9737.rs works properly now
* match-var-hygiene.rs works properly now

Addresses a chunk of #3965

9 years agoCleanup: rename middle::ty::sty and its variants.
Eli Friedman [Thu, 11 Jun 2015 23:21:46 +0000 (16:21 -0700)]
Cleanup: rename middle::ty::sty and its variants.

Use camel-case naming, and use names which actually make sense in modern Rust.

9 years agoRemove ignored test for #2061
Steve Klabnik [Fri, 12 Jun 2015 17:02:50 +0000 (13:02 -0400)]
Remove ignored test for #2061

This test was added on Nov 1, 2012:
https://github.com/rust-lang/rust/commit/0069bd2f4612b744ab3731b4c1db13c2f3202185#diff-b516ff69faf8886c48e6f5e833c2548c

and then ignored on the same day:
https://github.com/rust-lang/rust/commit/a90020fe8dd8be8615df82e6294408bfed82a767#diff-b516ff69faf8886c48e6f5e833c2548c

and never unignored again.

9 years agoRemove ignore'd test for old ICE
Steve Klabnik [Fri, 12 Jun 2015 16:42:41 +0000 (12:42 -0400)]
Remove ignore'd test for old ICE

This test originated from an ICE in Rust 0.4:
https://github.com/rust-lang/rust/commit/373504a7ac6801293ae65316625ace667842f5b8#diff-214656000770dff71c8165d051c3f027

it was ignored one day later:
https://github.com/rust-lang/rust/commit/1fa2b9980fabff3227d5e5915d1180a0f6922d37#diff-214656000770dff71c8165d051c3f027

and then never enabled again. I think we're safe without it.

9 years agoMention the short form pattern syntax in the book
Markus Westerlind [Mon, 8 Jun 2015 21:18:32 +0000 (23:18 +0200)]
Mention the short form pattern syntax in the book

Explains short form pattern syntax and then introduces the longer
pattern matching as a rebinding of the fields instead.

 #25779

9 years agoAuto merge of #26245 - mbrubeck:extern, r=steveklabnik
bors [Fri, 12 Jun 2015 15:15:11 +0000 (15:15 +0000)]
Auto merge of #26245 - mbrubeck:extern, r=steveklabnik

r? @steveklabnik

9 years ago[reference] Fix typo in extern fn section
Matt Brubeck [Fri, 12 Jun 2015 15:08:48 +0000 (08:08 -0700)]
[reference] Fix typo in extern fn section

9 years agoAdd tests for tuple-like structs and dictionary-like enum variants
Seo Sanghyeon [Fri, 12 Jun 2015 12:09:17 +0000 (21:09 +0900)]
Add tests for tuple-like structs and dictionary-like enum variants

9 years agoUse more precise span when checking type definitions
Seo Sanghyeon [Thu, 11 Jun 2015 16:44:42 +0000 (01:44 +0900)]
Use more precise span when checking type definitions

9 years agoAuto merge of #26238 - Manishearth:rollup, r=Manishearth
bors [Fri, 12 Jun 2015 06:25:49 +0000 (06:25 +0000)]
Auto merge of #26238 - Manishearth:rollup, r=Manishearth

- Successful merges: #24495, #26229, #26231
- Failed merges:

9 years agoRollup merge of #26231 - reem:patch-2, r=Gankro
Manish Goregaokar [Fri, 12 Jun 2015 06:25:37 +0000 (11:55 +0530)]
Rollup merge of #26231 - reem:patch-2, r=Gankro

r? @steveklabnik

9 years agoRollup merge of #26229 - Stebalien:versionless-book, r=steveklabnik
Manish Goregaokar [Fri, 12 Jun 2015 06:25:37 +0000 (11:55 +0530)]
Rollup merge of #26229 - Stebalien:versionless-book, r=steveklabnik

They're forever doomed to be out-of-date. Also, don't assume the user is
installing a particular version.

r? @steveklabnik

9 years agoRollup merge of #24495 - nathanl:nathanl-explain-bin-flag, r=steveklabnik
Manish Goregaokar [Fri, 12 Jun 2015 06:25:37 +0000 (11:55 +0530)]
Rollup merge of #24495 - nathanl:nathanl-explain-bin-flag, r=steveklabnik

Explain the --bin flag in terms of the difference
between shipping binary and library code

I'm not sure if my explanation is even quite correct, but as a newbie coming from Ruby, this is my best guess. (In Rubyland, libraries always ship with the source code because there's no other form you can ship. :) )

9 years agoAuto merge of #26224 - mcast:doc-travis2buildbot, r=steveklabnik
bors [Fri, 12 Jun 2015 04:38:02 +0000 (04:38 +0000)]
Auto merge of #26224 - mcast:doc-travis2buildbot, r=steveklabnik

Suggesting this because I was confused by what is now visible from the Travis CI / buildbot split.

Found the hint  in bors comments on d911936d
Couldn't find anything on https://internals.rust-lang.org/

9 years agoAuto merge of #26226 - alexcrichton:fix-msvc-dist, r=brson
bors [Fri, 12 Jun 2015 01:36:55 +0000 (01:36 +0000)]
Auto merge of #26226 - alexcrichton:fix-msvc-dist, r=brson

Right now the distribution tarball for MSVC only includes the *.dll files for
the supporting libraries, but not the corresponding *.lib files which allow
actually linking to the dll. This means that the current MSVC nightlies cannot
produce dynamically linked binaries as the *.lib files are not available to link
against.

This commit modifies the `LIB_GLOB` used to copy the files around to include the
`lib` variant of the `dll`.

9 years agoAuto merge of #26225 - arielb1:raw-self, r=eddyb
bors [Fri, 12 Jun 2015 00:00:27 +0000 (00:00 +0000)]
Auto merge of #26225 - arielb1:raw-self, r=eddyb

This can't be made to work with the current setup.

Technically a [breaking-change], but a simple bug fix.

Fixes #26194.

9 years agoAdd Terminal.com to the list of companies using rust in production.
Jonathan Reem [Thu, 11 Jun 2015 23:07:34 +0000 (16:07 -0700)]
Add Terminal.com to the list of companies using rust in production.

9 years agoAuto merge of #26199 - swgillespie:issue-26092, r=alexcrichton
bors [Thu, 11 Jun 2015 21:35:10 +0000 (21:35 +0000)]
Auto merge of #26199 - swgillespie:issue-26092, r=alexcrichton

`driver::build_output_filenames` calls `file_stem` on a PathBuf obtained from the output file compiler flag. It's possible to pass the empty string to this compiler flag. When file_stem is called on an empty Path, it returns None, which is unwrapped and the compiler panics.

This change modifies the `unwrap` to an `unwrap_or` so that the empty string is passed through the compilation pipeline until it reaches `trans::back::write_output_file`, which will emit an appropriate error.

Instead of panicking, the error that is emitted now is:

```
$ rustc -o "" thing.rs
error: could not write output to : No such file or directory
```

The `:` is a little strange, but it /is/ reporting the filename (the empty string) correctly, I suppose. Both gcc and clang hand the output file to ld, which emits a similar error message when faced with the empty string as an output file:

```
$ clang -o "" thing.c
ld: can't open output file for writing: , errno=2 for architecture x86_64
```

This PR also adds a test for this, in `run-make`. This fixes issue #26092.

9 years agoDon't link to specific versions of rust in the book.
Steven Allen [Thu, 11 Jun 2015 21:30:04 +0000 (17:30 -0400)]
Don't link to specific versions of rust in the book.

They're forever doomed to be out-of-date. Also, don't assume the user is
installing a particular version.

9 years agomk: Tweak the LIB_GLOB for MSVC
Alex Crichton [Thu, 11 Jun 2015 20:50:56 +0000 (13:50 -0700)]
mk: Tweak the LIB_GLOB for MSVC

Right now the distribution tarball for MSVC only includes the *.dll files for
the supporting libraries, but not the corresponding *.lib files which allow
actually linking to the dll. This means that the current MSVC nightlies cannot
produce dynamically linked binaries as the *.lib files are not available to link
against.

This commit modifies the `LIB_GLOB` used to copy the files around to include the
`lib` variant of the `dll`.

9 years agoPrevent raw pointers from being used as an explicit self
Ariel Ben-Yehuda [Thu, 11 Jun 2015 20:45:27 +0000 (23:45 +0300)]
Prevent raw pointers from being used as an explicit self

This can't be made to work with the current setup.

Fixes #26194.

9 years agopoint to buildbot
Matthew Astley [Thu, 11 Jun 2015 09:26:19 +0000 (10:26 +0100)]
point to buildbot

Since 7b6ecc00

9 years agoAuto merge of #26190 - Veedrac:no-iter, r=alexcrichton
bors [Thu, 11 Jun 2015 18:10:08 +0000 (18:10 +0000)]
Auto merge of #26190 - Veedrac:no-iter, r=alexcrichton

Pull request for #26188.

9 years agoAuto merge of #26212 - Manishearth:rollup, r=Manishearth
bors [Thu, 11 Jun 2015 16:33:53 +0000 (16:33 +0000)]
Auto merge of #26212 - Manishearth:rollup, r=Manishearth

- Successful merges: #26181, #26184, #26189, #26191, #26195, #26202
- Failed merges:

9 years agoAuto merge of #26197 - dhuseby:fixing_morestack_breakage, r=brson
bors [Thu, 11 Jun 2015 14:57:13 +0000 (14:57 +0000)]
Auto merge of #26197 - dhuseby:fixing_morestack_breakage, r=brson

Revision 021e483 broke the BSD builds.  This fixes it for Bitrig and probably the others.

9 years agoExplain the `--bin` flag more clearly
Nathan Long [Thu, 16 Apr 2015 10:16:52 +0000 (06:16 -0400)]
Explain the `--bin` flag more clearly

9 years agoAuto merge of #26184 - aepsil0n:error-desc-funcargs, r=alexcrichton
bors [Thu, 11 Jun 2015 13:17:19 +0000 (13:17 +0000)]
Auto merge of #26184 - aepsil0n:error-desc-funcargs, r=alexcrichton

These errors all relate to type checking, specifically the number of function arguments, and occur in librustc_typeck::check::check_argument_types.

Resolves part of #24407.

9 years agoConver reborrows to .iter() calls where appropriate
Joshua Landau [Thu, 11 Jun 2015 12:56:07 +0000 (13:56 +0100)]
Conver reborrows to .iter() calls where appropriate

9 years agoAuto merge of #26177 - jooert:fix26169, r=alexcrichton
bors [Thu, 11 Jun 2015 11:41:24 +0000 (11:41 +0000)]
Auto merge of #26177 - jooert:fix26169, r=alexcrichton

Closes #26169.

r? @steveklabnik

9 years agoAuto merge of #26172 - nham:add_E0116, r=alexcrichton
bors [Thu, 11 Jun 2015 10:06:38 +0000 (10:06 +0000)]
Auto merge of #26172 - nham:add_E0116, r=alexcrichton

Also improves the wording of the E0133 description.

cc #24407

9 years agoAuto merge of #26159 - alexcrichton:tweak-process-lowering-raising, r=brson
bors [Thu, 11 Jun 2015 08:22:39 +0000 (08:22 +0000)]
Auto merge of #26159 - alexcrichton:tweak-process-lowering-raising, r=brson

* Slate these features to be stable in 1.2 instead of 1.1 (not being backported)
* Have the `FromRawFd` implementations follow the contract of the `FromRawFd`
  trait by taking ownership of the primitive specified.
* Refactor the implementations slightly to remove the `unreachable!` blocks as
  well as separating the stdio representation of `std::process` from
  `std::sys::process`.

cc #25494

9 years agoRollup merge of #26202 - nham:revise_E0072, r=alexcrichton
Manish Goregaokar [Thu, 11 Jun 2015 07:20:54 +0000 (12:50 +0530)]
Rollup merge of #26202 - nham:revise_E0072, r=alexcrichton

Converts the size calculation in the explanation from a fenced code block to an indented one. I think it looks better when not rendered, and is the same rendered.

9 years agoRollup merge of #26195 - tshepang:patch-1, r=alexcrichton
Manish Goregaokar [Thu, 11 Jun 2015 07:20:53 +0000 (12:50 +0530)]
Rollup merge of #26195 - tshepang:patch-1, r=alexcrichton

9 years agoRollup merge of #26191 - jimblandy:master, r=steveklabnik
Manish Goregaokar [Thu, 11 Jun 2015 07:20:53 +0000 (12:50 +0530)]
Rollup merge of #26191 - jimblandy:master, r=steveklabnik

In the discussion of returning closures, it seems like the example code got simplified, but only the later copies got fixed. The final working code has `factory` returning `|x| x + num`, but the earlier code has `|x| vec.push(x)`.

The first form seemed to have more distracting characteristics, and the code wasn't right anyway, so I changed them to all use the second form, and updated the error messages.

r? @steveklabnik

9 years agoRollup merge of #26189 - bluss:iter-once-clone, r=Gankro
Manish Goregaokar [Thu, 11 Jun 2015 07:20:53 +0000 (12:50 +0530)]
Rollup merge of #26189 - bluss:iter-once-clone, r=Gankro

core: impl Clone for option::IntoIter and iter::Once

9 years agoRollup merge of #26184 - aepsil0n:error-desc-funcargs, r=alexcrichton
Manish Goregaokar [Thu, 11 Jun 2015 07:20:53 +0000 (12:50 +0530)]
Rollup merge of #26184 - aepsil0n:error-desc-funcargs, r=alexcrichton

These errors all relate to type checking, specifically the number of function arguments, and occur in librustc_typeck::check::check_argument_types.

Resolves part of #24407.

9 years agoRollup merge of #26181 - Stebalien:fix-26178, r=steveklabnik
Manish Goregaokar [Thu, 11 Jun 2015 07:20:52 +0000 (12:50 +0530)]
Rollup merge of #26181 - Stebalien:fix-26178, r=steveklabnik

The list of in-production users is probably incomplete. It's based on a [post](https://www.reddit.com/r/rust/comments/2x567m/who_is_using_rust_or_what_projects_that_are/cox7eby) by /u/mozilla_kmc

closes #26178

9 years agoAuto merge of #26155 - dhuseby:fixing_bitrig_net_tests, r=alexcrichton
bors [Thu, 11 Jun 2015 06:46:25 +0000 (06:46 +0000)]
Auto merge of #26155 - dhuseby:fixing_bitrig_net_tests, r=alexcrichton

… congruent due to rounding errors

@semarie this affected both openbsd and bitrig.  it seems the correct solution is to switch to fixed point arithmetic in the timeout code, the same as freebsd.

9 years agoAuto merge of #26154 - pmarcelll:master, r=Gankro
bors [Thu, 11 Jun 2015 05:05:20 +0000 (05:05 +0000)]
Auto merge of #26154 - pmarcelll:master, r=Gankro

Various methods in both libcore/char.rs and librustc_unicode/char.rs were previously marked with #[inline], now every method is marked in char's impl blocks.
Partially fixes #26124.
EDIT: I'm not familiar with pull reqests (yet), apparently Github added my second commit to thit PR...
Fixes #26124

9 years agoAuto merge of #26122 - bluss:borrow-box, r=alexcrichton
bors [Thu, 11 Jun 2015 03:25:45 +0000 (03:25 +0000)]
Auto merge of #26122 - bluss:borrow-box, r=alexcrichton

Implement Borrow<T> and BorrowMut<T> for Box<T: ?Sized>

9 years agoRevise the E0072 explanation.
Nick Hamann [Thu, 11 Jun 2015 02:36:32 +0000 (21:36 -0500)]
Revise the E0072 explanation.

9 years agofix #26092 by returning an empty OS string when the output file path has no file_stem
swgillespie [Thu, 11 Jun 2015 01:18:04 +0000 (18:18 -0700)]
fix #26092 by returning an empty OS string when the output file path has no file_stem

9 years agoAuto merge of #25839 - bluss:str-split-at-impl, r=alexcrichton
bors [Thu, 11 Jun 2015 00:22:27 +0000 (00:22 +0000)]
Auto merge of #25839 - bluss:str-split-at-impl, r=alexcrichton

Implement RFC rust-lang/rfcs#1123

Add str method str::split_at(mid: usize) -> (&str, &str).

Also a minor cleanup in the collections::str module. Remove redundant slicing of self.

9 years agoAuto merge of #25777 - shepmaster:cstring-return-to-c, r=alexcrichton
bors [Wed, 10 Jun 2015 22:37:38 +0000 (22:37 +0000)]
Auto merge of #25777 - shepmaster:cstring-return-to-c, r=alexcrichton

As far as I was able to determine, it's currently *impossible* to allocate a C NUL-terminated string in Rust and then return it to C (transferring ownership), without leaking memory. There is support for passing the string to C (borrowing).

To complicate matters, it's not possible for the C code to just call `free` on the allocated string, due to the different allocators in use.

`CString` has no way to recreate itself from a pointer. This commit adds one. This is complicated a bit because Rust `Vec`s want the pointer, size, and capacity.

To deal with that, another method to shrink and "leak" the `CString` to a `char *` is also provided.

We can then use `strlen` to determine the length of the string, which must match the capacity.

**TODO**

- [x] Improve documentation
- [x] Add stability markers
- [x] Convert to `Box<[u8]>`

### Example code

With this example code:

```rust
#![feature(libc)]
#![feature(cstr_to_str)]
#![feature(c_str_memory)]

extern crate libc;

use std::ffi::{CStr,CString};

#[no_mangle]
pub extern fn reverse(s: *const libc::c_char) -> *const libc::c_char {
    let s = unsafe { CStr::from_ptr(s) };
    let s2 = s.to_str().unwrap();
    let s3: String = s2.chars().rev().collect();
    let s4 = CString::new(s3).unwrap();
    s4.into_ptr()
}

#[no_mangle]
pub extern fn cleanup(s: *const libc::c_char) {
    unsafe { CString::from_ptr(s) };
}
```

Compiled using `rustc --crate-type dylib str.rs`, I was able to link against it from C (`gcc -L. -l str str.c -o str`):

```c
#include <stdio.h>

extern char *reverse(char *);
extern void cleanup(char *);

int main() {
  char *s = reverse("Hello, world!");
  printf("%s\n", s);
  cleanup(s);
}
```

As well as dynamically link via Ruby:

```ruby
require 'fiddle'
require 'fiddle/import'

module LibSum
  extend Fiddle::Importer

  dlload './libstr.dylib'
  extern 'char* reverse(char *)'
  extern 'void cleanup(char *)'
end

s = LibSum.reverse("hello, world!")
puts s
LibSum.cleanup(s)
```

9 years agodoc: typo fix
Tshepang Lekhonkhobe [Wed, 10 Jun 2015 22:19:45 +0000 (00:19 +0200)]
doc: typo fix

9 years agoAuto merge of #24689 - SimonSapin:formatter-write-char, r=alexcrichton
bors [Wed, 10 Jun 2015 21:02:08 +0000 (21:02 +0000)]
Auto merge of #24689 - SimonSapin:formatter-write-char, r=alexcrichton

This is the logical next step after #24661, but I’m less sure about this one.

r? @alexcrichton

9 years agoFix examples for returning closures.
Jim Blandy [Wed, 10 Jun 2015 20:17:49 +0000 (13:17 -0700)]
Fix examples for returning closures.

9 years agoRemoved many pointless calls to *iter() and iter_mut()
Joshua Landau [Wed, 10 Jun 2015 16:22:20 +0000 (17:22 +0100)]
Removed many pointless calls to *iter() and iter_mut()

9 years agoHave std::fmt::Formatter implement std::fmt::Write.
Simon Sapin [Wed, 10 Jun 2015 19:41:34 +0000 (21:41 +0200)]
Have std::fmt::Formatter implement std::fmt::Write.

9 years agocore: impl Clone for option::IntoIter and iter::Once
Ulrik Sverdrup [Wed, 10 Jun 2015 18:57:39 +0000 (20:57 +0200)]
core: impl Clone for option::IntoIter and iter::Once

9 years agoAuto merge of #26182 - Manishearth:rollup, r=Manishearth
bors [Wed, 10 Jun 2015 18:41:42 +0000 (18:41 +0000)]
Auto merge of #26182 - Manishearth:rollup, r=Manishearth

- Successful merges: #26142, #26143, #26145, #26146, #26164, #26174
- Failed merges:

9 years agoAdd a write_char method to std::fmt::Formatter.
Simon Sapin [Wed, 22 Apr 2015 12:18:02 +0000 (14:18 +0200)]
Add a write_char method to std::fmt::Formatter.

This is the logical next step after #24661, but I’m less sure about this one.

9 years agoAdd error explanation for E0057, E0059–E0061
Eduard Bopp [Wed, 10 Jun 2015 18:16:37 +0000 (20:16 +0200)]
Add error explanation for E0057, E0059–E0061

These errors all relate to type checking, specifically the number of function
arguments, and occur in librustc_typeck::check::check_argument_types.

9 years agofixes __morestack symbol problem on BSDs
Dave Huseby [Wed, 10 Jun 2015 17:20:57 +0000 (10:20 -0700)]
fixes __morestack symbol problem on BSDs

9 years agodisabling socking timing tests because openbsd/bitrig get/set are not congruent due...
Dave Huseby [Tue, 9 Jun 2015 16:36:17 +0000 (09:36 -0700)]
disabling socking timing tests because openbsd/bitrig get/set are not congruent due to rounding errors

9 years agoRollup merge of #26174 - mcast:trpl-assignment-empty-tuple, r=steveklabnik
Manish Goregaokar [Wed, 10 Jun 2015 16:37:10 +0000 (22:07 +0530)]
Rollup merge of #26174 - mcast:trpl-assignment-empty-tuple, r=steveklabnik

Doc patch for #26120.  Extra words here, because "value" is repeated.

I haven't read about whether/how it should go to stable (sorry), but I think it would help newcomers.

Thanks,

9 years agoRollup merge of #26164 - tafia:early-dedup, r=Gankro
Manish Goregaokar [Wed, 10 Jun 2015 16:37:10 +0000 (22:07 +0530)]
Rollup merge of #26164 - tafia:early-dedup, r=Gankro

No need to dedup if there is only 1 element in the vec, can early return

9 years agoRollup merge of #26146 - steveklabnik:remove_unsafe_pointer, r=Gankro
Manish Goregaokar [Wed, 10 Jun 2015 16:37:10 +0000 (22:07 +0530)]
Rollup merge of #26146 - steveklabnik:remove_unsafe_pointer, r=Gankro

Using two terms for one thing is confusing, these are called 'raw pointers' today.

9 years agoRollup merge of #26145 - steveklabnik:gh25853, r=brson
Manish Goregaokar [Wed, 10 Jun 2015 16:37:10 +0000 (22:07 +0530)]
Rollup merge of #26145 - steveklabnik:gh25853, r=brson

Fixes #25853

9 years agoRollup merge of #26143 - steveklabnik:gh25851, r=alexcrichton
Manish Goregaokar [Wed, 10 Jun 2015 16:37:09 +0000 (22:07 +0530)]
Rollup merge of #26143 - steveklabnik:gh25851, r=alexcrichton

Still some references left to this old term, I've updated them to say boxes.

Related to #25851

9 years agoRollup merge of #26142 - steveklabnik:gh25850, r=Gankro
Manish Goregaokar [Wed, 10 Jun 2015 16:37:09 +0000 (22:07 +0530)]
Rollup merge of #26142 - steveklabnik:gh25850, r=Gankro

Fixes #25850

9 years agoRust is now post-1.0
Steven Allen [Wed, 10 Jun 2015 15:47:44 +0000 (11:47 -0400)]
Rust is now post-1.0

closes #26178

9 years agoImprove examples for atomic types.
Johannes Oertel [Wed, 10 Jun 2015 14:53:09 +0000 (16:53 +0200)]
Improve examples for atomic types.

Swap arguments of `assert_eq!` calls, insert additional assertions
here and there.
Closes #26169.

9 years agomend bad Markdown
Matthew Astley [Wed, 10 Jun 2015 15:15:24 +0000 (16:15 +0100)]
mend bad Markdown

9 years agoAuto merge of #26141 - eddyb:ast_map, r=nikomatsakis
bors [Wed, 10 Jun 2015 11:38:04 +0000 (11:38 +0000)]
Auto merge of #26141 - eddyb:ast_map, r=nikomatsakis

Gets libsyntax one step closer to running on stable (see #24518).
Closes #24757, erickt's previous attempt at this.

9 years agoAuto merge of #26153 - dotdash:issue26127, r=luqmana
bors [Wed, 10 Jun 2015 10:05:39 +0000 (10:05 +0000)]
Auto merge of #26153 - dotdash:issue26127, r=luqmana

Fixes #26127

9 years agotrpl: why (assignment == empty tuple) #26120
Matthew Astley [Wed, 10 Jun 2015 09:59:36 +0000 (10:59 +0100)]
trpl: why (assignment == empty tuple) #26120

9 years agoRevise E0133 description.
Nick Hamann [Wed, 10 Jun 2015 05:37:36 +0000 (00:37 -0500)]
Revise E0133 description.

Tweaks some of the wording so it reads better.

9 years agoAdd explanation for E0116 and update the error message.
Nick Hamann [Tue, 9 Jun 2015 08:05:24 +0000 (03:05 -0500)]
Add explanation for E0116 and update the error message.

Also updates the reference on this point.

9 years agocollections: Remove redundant slicing for str
Ulrik Sverdrup [Wed, 27 May 2015 20:57:10 +0000 (22:57 +0200)]
collections: Remove redundant slicing for str

This is a remnant from a previous implementation of the str methods.
Using `self` is fine now.

9 years agoAdd str::split_at
Ulrik Sverdrup [Tue, 9 Jun 2015 09:23:22 +0000 (11:23 +0200)]
Add str::split_at

Implement RFC rust-lang/rfcs#1123

Add str method str::split_at(mid: usize) -> (&str, &str).

9 years agoAuto merge of #26137 - steveklabnik:gh25623, r=alexcrichton
bors [Wed, 10 Jun 2015 06:59:31 +0000 (06:59 +0000)]
Auto merge of #26137 - steveklabnik:gh25623, r=alexcrichton

Fixes #25623

I am bad with BNF, so I may have messed this up, but that's what review is for!

9 years agoAuto merge of #26130 - steveklabnik:gh25986, r=alexcrichton
bors [Wed, 10 Jun 2015 05:28:03 +0000 (05:28 +0000)]
Auto merge of #26130 - steveklabnik:gh25986, r=alexcrichton

This can be confusing when whitespace is the separator

Fixes #25986

9 years agoAuto merge of #26058 - Kimundi:issue15609, r=nikomatsakis
bors [Wed, 10 Jun 2015 03:15:16 +0000 (03:15 +0000)]
Auto merge of #26058 - Kimundi:issue15609, r=nikomatsakis

Closes #15609

9 years agoearly return if 1 element
Johann Tuffe [Wed, 10 Jun 2015 02:51:48 +0000 (10:51 +0800)]
early return if 1 element

No need to dedup if there is only 1 element in the vec, can early return

9 years agoAuto merge of #26055 - arielb1:smart-fold, r=nikomatsakis
bors [Wed, 10 Jun 2015 01:44:59 +0000 (01:44 +0000)]
Auto merge of #26055 - arielb1:smart-fold, r=nikomatsakis

Before:
581.72user 4.75system 7:42.74elapsed 126%CPU (0avgtext+0avgdata 1176224maxresident)k
llvm took 359.183

After:
550.63user 5.09system 7:20.28elapsed 126%CPU (0avgtext+0avgdata 1165516maxresident)k
llvm took 354.801

9 years agostd: Tweak process raising/lowering implementations
Alex Crichton [Tue, 9 Jun 2015 23:41:14 +0000 (16:41 -0700)]
std: Tweak process raising/lowering implementations

* Slate these features to be stable in 1.2 instead of 1.1 (not being backported)
* Have the `FromRawFd` implementations follow the contract of the `FromRawFd`
  trait by taking ownership of the primitive specified.
* Refactor the implementations slightly to remove the `unreachable!` blocks as
  well as separating the stdio representation of `std::process` from
  `std::sys::process`.

9 years agostd: Stabilize a number of new fs features
Alex Crichton [Wed, 27 May 2015 23:29:55 +0000 (16:29 -0700)]
std: Stabilize a number of new fs features

This commit stabilizes the following APIs, slating them all to be cherry-picked
into the 1.1 release.

* fs::FileType (and transitively the derived trait implementations)
* fs::Metadata::file_type
* fs::FileType::is_dir
* fs::FileType::is_file
* fs::FileType::is_symlink
* fs::DirEntry::metadata
* fs::DirEntry::file_type
* fs::DirEntry::file_name
* fs::set_permissions
* fs::symlink_metadata
* os::raw::{self, *}
* os::{android, bitrig, linux, ...}::raw::{self, *}
* os::{android, bitrig, linux, ...}::fs::MetadataExt
* os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat
* os::unix::fs::PermissionsExt
* os::unix::fs::PermissionsExt::mode
* os::unix::fs::PermissionsExt::set_mode
* os::unix::fs::PermissionsExt::from_mode
* os::unix::fs::OpenOptionsExt
* os::unix::fs::OpenOptionsExt::mode
* os::unix::fs::DirEntryExt
* os::unix::fs::DirEntryExt::ino
* os::windows::fs::MetadataExt
* os::windows::fs::MetadataExt::file_attributes
* os::windows::fs::MetadataExt::creation_time
* os::windows::fs::MetadataExt::last_access_time
* os::windows::fs::MetadataExt::last_write_time
* os::windows::fs::MetadataExt::file_size

The `os::unix::fs::Metadata` structure was also removed entirely, moving all of
its associated methods into the `os::unix::fs::MetadataExt` trait instead. The
methods are all marked as `#[stable]` still.

As some minor cleanup, some deprecated and unstable fs apis were also removed:

* File::path
* Metadata::accessed
* Metadata::modified

Features that were explicitly left unstable include:

* fs::WalkDir - the semantics of this were not considered in the recent fs
  expansion RFC.
* fs::DirBuilder - it's still not 100% clear if the naming is right here and if
  the set of functionality exposed is appropriate.
* fs::canonicalize - the implementation on Windows here is specifically in
  question as it always returns a verbatim path. Additionally the Unix
  implementation is susceptible to buffer overflows on long paths unfortunately.
* fs::PathExt - as this is just a convenience trait, it is not stabilized at
  this time.
* fs::set_file_times - this funciton is still waiting on a time abstraction.

9 years agoModify String::push to reallocate more conservatively in case of the character's...
marcell [Wed, 10 Jun 2015 00:03:56 +0000 (02:03 +0200)]
Modify String::push to reallocate more conservatively in case of the character's UTF-8 representation is bigger than 1 byte

9 years agoRevert "Added AsRef implementations for Arc and Rc"
Alex Crichton [Tue, 9 Jun 2015 23:47:45 +0000 (16:47 -0700)]
Revert "Added AsRef implementations for Arc and Rc"

This reverts commit 7f3ae0aa26d24100379ae0f3eef29916a32f4e79.

9 years agosyntax: move ast_map to librustc.
Eduard Burtescu [Tue, 9 Jun 2015 23:40:45 +0000 (02:40 +0300)]
syntax: move ast_map to librustc.

9 years agoAuto merge of #25836 - steveklabnik:gh25305, r=alexcrichton
bors [Tue, 9 Jun 2015 23:11:25 +0000 (23:11 +0000)]
Auto merge of #25836 - steveklabnik:gh25305, r=alexcrichton

Fixes #25794

9 years agoUse the correct type of undef value for ignored return values in trans_named_tuple_co...
Björn Steinbrink [Tue, 9 Jun 2015 22:07:47 +0000 (00:07 +0200)]
Use the correct type of undef value for ignored return values in trans_named_tuple_constructor

Fixes #26127

9 years agoAdd missing #[inline] to methods related to char.
marcell [Tue, 9 Jun 2015 21:58:00 +0000 (23:58 +0200)]
Add missing #[inline] to methods related to char.

9 years agoAuto merge of #26150 - steveklabnik:rollup, r=steveklabnik
bors [Tue, 9 Jun 2015 21:36:03 +0000 (21:36 +0000)]
Auto merge of #26150 - steveklabnik:rollup, r=steveklabnik

- Successful merges: #26111, #26125, #26129, #26131, #26132, #26133, #26134, #26136, #26140, #26144
- Failed merges:

9 years agoRollup merge of #26144 - steveklabnik:static_doc_fix, r=alexcrichton
Steve Klabnik [Tue, 9 Jun 2015 21:24:45 +0000 (17:24 -0400)]
Rollup merge of #26144 - steveklabnik:static_doc_fix, r=alexcrichton

Fixes #25851

I am 99% sure this is true for all `static`s and not just `static mut`, yes?

9 years agoRollup merge of #26140 - steveklabnik:gh25803, r=alexcrichton
Steve Klabnik [Tue, 9 Jun 2015 21:24:45 +0000 (17:24 -0400)]
Rollup merge of #26140 - steveklabnik:gh25803, r=alexcrichton

As this example got changed, we stopped showing how to return self as
the first example, so this text is outdated.

Fixes #25803

9 years agoRollup merge of #26136 - steveklabnik:gh25597, r=alexcrichton
Steve Klabnik [Tue, 9 Jun 2015 21:24:44 +0000 (17:24 -0400)]
Rollup merge of #26136 - steveklabnik:gh25597, r=alexcrichton

Fixes #25597