about summary refs log tree commit diff
path: root/src
AgeCommit message (Collapse)AuthorLines
2017-11-08get() example should use get() not get_mut()John Ford-4/+4
I'm really new to Rust, this is the first thing I've ever actually pushed to github in a rust project, so please double check that it's correct. I noticed that the in-doc example for the string's get() function was referring to get_mut(). Looks like a copy/paste issue. ```rust fn main() { let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); } ``` results in: ``` jhford-work:~/rust/redish $ cat get-example.rs fn main() { let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); } jhford-work:~/rust/redish $ rustc get-example.rs jhford-work:~/rust/redish $ ./get-example ; echo $? 0 ``` I did not build an entire rust toolchain as I'm not totally sure how to do that.
2017-11-08Auto merge of #45205 - rkruppe:saturating-casts, r=eddybbors-16/+535
Saturating casts between integers and floats Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](https://github.com/rust-lang/rust/issues/10184#issuecomment-299229143) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`. Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts. Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above. Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation. cc #10184 #41799 fixes #45134
2017-11-08Auto merge of #45866 - JohnColanduoni:issue-45731, r=alexcrichtonbors-0/+46
Disable `mmap` in `libbacktrace` on Apple platforms Fixes #45731 libbacktrace uses mmap if available to map ranges of the files containing debug information. On macOS `mmap` will succeed even if the mapped range does not exist, and a SIGBUS (with an unusual EXC_BAD_ACCESS code 10) will occur when the program attempts to page in the memory. To combat this we force `libbacktrace` to be built with the simple `read` based fallback on Apple platforms.
2017-11-08Disable u128 <-> float tests on emscriptenRobin Kruppe-29/+39
2017-11-08Auto merge of #45575 - michaelwoerister:tweak-inline-trans-items, r=nikomatsakisbors-407/+520
Only instantiate inline- and const-fns if they are referenced (again). It seems that we have regressed on not translating `#[inline]` functions unless they are actually used. This should bring back this optimization. I also added a regression test this time so it doesn't happen again accidentally. Fixes #40392. r? @alexcrichton UPDATE & PSA --------------------- This patch **makes translation very lazy** -- in general this is a good thing (we don't want the compiler to do unnecessary work) but it has two consequences: 1. Some error messages are only generated when an item is actually translated. Consequently, this patch will lead to more cases where the compiler will only start emitting errors when the erroneous function is actually used. This has always been true to some extend (e.g. when passing generic values to an intrinsic) but since this is something user-facing it's worth mentioning. 2. When writing tests, one has to make sure that the functions in question are actually generated. In other words, it must not be dead code. This can usually be achieved by either 1. making sure the function is exported from the resulting binary or 2. by making sure the function is called from something that is exported (or `main()`). Note that it depends on the crate type what functions are exported: 1. For rlibs and dylibs everything that is reachable from the outside is exported. 2. For executables, cdylibs, and staticlibs, items are only exported if they are additionally `#[no_mangle]` or have an `#[export_name]`. The commits in this PR contain many examples of how tests can be updated to comply to the new requirements.
2017-11-08Disable `mmap` in `libbacktrace` on Apple platformsJohn Colanduoni-0/+46
Fixes #45731 libbacktrace uses mmap if available to map ranges of the files containing debug information. On macOS `mmap` will succeed even if the mapped range does not exist, and a SIGBUS (with an unusual EXC_BAD_ACCESS code 10) will occur when the program attempts to page in the memory. To combat this we force `libbacktrace` to be built with the simple `read` based fallback on Apple platforms.
2017-11-08Update fastcall-inreg codegen test so that functions actually get instantiated.Michael Woerister-7/+7
2017-11-08Auto merge of #45862 - GuillaumeGomez:rollup, r=GuillaumeGomezbors-37/+276
Rollup of 4 pull requests - Successful merges: #45582, #45766, #45830, #45849 - Failed merges:
2017-11-08Rollup merge of #45849 - GuillaumeGomez:more-shortcut, r=QuietMisdreavusGuillaume Gomez-2/+4
Add "-" shortcut Fixes #45847. r? @Havvy
2017-11-08Rollup merge of #45830 - pornel:dosglobs, r=dtolnayGuillaume Gomez-0/+4
Warn about lack of args glob expansion in Windows shell Because all shells on Linux/macOS expand globs, and even MinGW on Windows emulates this behavior, it's easy to forget that Windows by itself doesn't support glob expansion. This PR documents this cross-platform difference.
2017-11-08Rollup merge of #45766 - GuillaumeGomez:trait-methods-list, r=QuietMisdreavusGuillaume Gomez-31/+198
Add more elements in the sidebar Fixes #45740. r? @rust-lang/docs
2017-11-08Rollup merge of #45582 - GuillaumeGomez:doc-unix-missing-links, r=frewsxcvGuillaume Gomez-4/+70
Add missing links and examples r? @rust-lang/docs
2017-11-08Auto merge of #45735 - tirr-c:issue-45730, r=arielb1bors-23/+111
Forbid casting to/from a pointer of unknown kind Fixes #45730. Before, it ICE'd when `pointer_kind` encountered `TyInfer`.
2017-11-08Auto merge of #45379 - cuviper:unit_from_iter, r=alexcrichtonbors-0/+32
impl FromIterator<()> for () This just collapses all unit items from an iterator into one. This is more useful when combined with higher-level abstractions, like collecting to a `Result<(), E>` where you only care about errors: ```rust use std::io::*; data = vec![1, 2, 3, 4, 5]; let res: Result<()> = data.iter() .map(|x| writeln!(stdout(), "{}", x)) .collect(); assert!(res.is_ok()); ```
2017-11-07Add more elements in the sidebarGuillaume Gomez-31/+198
2017-11-07Add "-" shortcutGuillaume Gomez-2/+4
2017-11-07Auto merge of #44932 - cuviper:unsized-ptr-is_null, r=alexcrichtonbors-6/+63
Remove `T: Sized` on pointer `as_ref()` and `as_mut()` `NonZero::is_zero()` was already casting all pointers to thin `*mut u8` to check for null. The same test on unsized fat pointers can also be used with `as_ref()` and `as_mut()` to get fat references. (This PR formerly changed `is_null()` too, but checking just the data pointer is not obviously correct for trait objects, especially if `*const self` sorts of methods are ever allowed.)
2017-11-07Add missing links and examplesGuillaume Gomez-4/+70
2017-11-07Clean upRobin Kruppe-32/+26
2017-11-07Implement more efficient saturationRobin Kruppe-71/+63
2017-11-07Make trans const eval error on overflow and NaN, matching HIR const eval.Robin Kruppe-80/+154
2017-11-07Extract (f32::MAX + 0.5 ULP) constantRobin Kruppe-6/+15
2017-11-07Fix bug in rustc_apfloatRobin Kruppe-1/+1
2017-11-07Saturating casts between integers and floats (both directions).Robin Kruppe-13/+453
This affects regular code generation as well as constant evaluation in trans, but not the HIR constant evaluator because that one returns an error for overflowing casts and NaN-to-int casts. That error is conservatively correct and we should be careful to not accept more code in constant expressions. The changes to code generation are guarded by a new -Z flag, to be able to evaluate the performance impact. The trans constant evaluation changes are unconditional because they have no run time impact and don't affect type checking either.
2017-11-07Auto merge of #45822 - kennytm:rollup, r=kennytmbors-74/+479
Rollup of 9 pull requests - Successful merges: #45470, #45588, #45682, #45714, #45751, #45764, #45778, #45782, #45784 - Failed merges:
2017-11-07Warn about non-portability of glob patternsKornel-0/+4
2017-11-07Always treat #[rustc_std_internal_symbol]s as root TransItems.Michael Woerister-1/+5
2017-11-07Rollup merge of #45784 - harpocrates:fix/print-parens-cast-lt, r=kennytmkennytm-0/+64
Pretty print parens around casts on the LHS of `<`/`<<` When pretty printing a cast expression occuring on the LHS of a `<` or `<<` expression, we should add parens around the cast. Otherwise, the `<`/`<<` gets interpreted as the beginning of the generics for the type on the RHS of the cast. Consider: $ cat parens_cast.rs macro_rules! negative { ($e:expr) => { $e < 0 } } fn main() { negative!(1 as i32); } Before this PR, the output of the following is not valid Rust: $ rustc -Z unstable-options --pretty=expanded parens_cast.rs #![feature(prelude_import)] #![no_std] #[prelude_import] use std::prelude::v1::*; #[macro_use] extern crate std as std; macro_rules! negative(( $ e : expr ) => { $ e < 0 }); fn main() { 1 as i32 < 0; } After this PR, the output of the following is valid Rust: $ rustc -Z unstable-options --pretty=expanded parens_cast.rs #![feature(prelude_import)] #![no_std] #[prelude_import] use std::prelude::v1::*; #[macro_use] extern crate std as std; macro_rules! negative(( $ e : expr ) => { $ e < 0 }); fn main() { (1 as i32) < 0; } I've gone through several README/wiki style documents but I'm still not sure where to test this though. I'm not even sure if this sort of thing is tested...
2017-11-07Rollup merge of #45782 - frewsxcv:frewsxcv-shorthands-helpers, r=manishearthkennytm-13/+35
Display all emission types in error msg if user inputs invalid option. before: ``` > rustc --emit foo error: unknown emission type: `foo` ``` after: ``` > rustc --emit foo error: unknown emission type: `foo` - expected one of: `llvm-bc`, `asm`, `llvm-ir`, `mir`, `obj`, `metadata`, `link`, `dep-info` ```
2017-11-07Rollup merge of #45778 - Havvy:patch-1, r=steveklabnikkennytm-1/+1
Update reference link in doc's 404 It's currently linking to a page that says it's on the page I'm changing the link too.
2017-11-07Rollup merge of #45764 - QuietMisdreavus:rustdoc-doctest-lints, r=GuillaumeGomezkennytm-8/+16
rustdoc: add #[allow(unused)] to every doctest More information in #45750 - this is behavior that was documented but not actually implemented. I also reordered how outer attributes are applied to doctests. Previously, attributes from `#![doc(test(attr(...)))]` would be applied *after* attributes from within the test itself, meaning if a doctest tried to override lints that would be set crate-wide, it wouldn't work at all. This gives a better scope of how lints can be applied. Closes #45750
2017-11-07Rollup merge of #45751 - estebank:issue-44684, r=nikomatsakiskennytm-42/+95
Handle anon lifetime arg being returned with named lifetime return type When there's a lifetime mismatch between an argument with an anonymous lifetime being returned in a method with a return type that has a named lifetime, show specialized lifetime error pointing at argument with a hint to give it an explicit lifetime matching the return type. ``` error[E0621]: explicit lifetime required in the type of `other` --> file2.rs:21:21 | 17 | fn bar(&self, other: Foo) -> Foo<'a> { | ----- consider changing the type of `other` to `Foo<'a>` ... 21 | other | ^^^^^ lifetime `'a` required ``` Follow up to #44124 and #42669. Fix #44684.
2017-11-07Rollup merge of #45714 - sdroege:thread-panic-docs, r=dtolnaykennytm-5/+9
Update the std::thread docs and clarify that panics can nowadays be caught
2017-11-07Rollup merge of #45682 - RalfJung:rwlock-guards, r=alexcrichtonkennytm-3/+8
RwLock guards are Sync if T is Currently, the compiler requires `T` to also be `Send`. There is no reason for that. `&Rw{Read,Write}LockGuard` only provides a shared referenced to `T`, sending that across threads is safe if `T` is `Sync`. Cc @oconnor663
2017-11-07Rollup merge of #45588 - Keruspe:master, r=alexcrichtonkennytm-2/+5
rustbuild: don't try to install rls if ToolState is not Testing We already do that for the Dist Step so we would end up trying to install something that we didn't dist.
2017-11-07Rollup merge of #45470 - GuillaumeGomez:unix-metadata-ext, r=QuietMisdreavuskennytm-0/+246
add missing docs for MetadataExt r? @rust-lang/docs
2017-11-07Auto merge of #45666 - Amanieu:tls-model, r=alexcrichtonbors-13/+84
Allow overriding the TLS model This PR adds the ability to override the default "global-dynamic" TLS model with a more specific one through a target json option or a command-line option. This allows for better code generation in certain situations. This is similar to the `-ftls-model=` option in GCC and Clang.
2017-11-07Fix some rebasing fallout.Michael Woerister-5/+8
2017-11-07Don't duplicate logic of when an Instance requests to be inlined.Michael Woerister-7/+5
2017-11-07Update run-make tests.Michael Woerister-2/+16
2017-11-07Update mir-opt tests.Michael Woerister-5/+20
2017-11-07Update compile-fail tests.Michael Woerister-33/+36
2017-11-07Update codegen tests.Michael Woerister-20/+20
2017-11-07Fix incremental tests after change to instantiation strategy.Michael Woerister-275/+285
2017-11-07incr.comp.: Improve error message for unknown fingerprint.Michael Woerister-1/+6
2017-11-07Update invalid inline arg test.Michael Woerister-1/+3
2017-11-07Add regression tests for non-instantiation of inline and const fns.Michael Woerister-0/+45
2017-11-07Update codegen-unit tests.Michael Woerister-47/+47
2017-11-07Fix translation item collection for inline and const fns.Michael Woerister-10/+24
2017-11-07Auto merge of #45620 - ollie27:rustdoc_impl_generic_dupe, r=QuietMisdreavusbors-4/+29
rustdoc: Fix duplicated impls with generics The same type can appear multiple times in impls so we need to use a set to avoid adding it multiple times. Fixes: #45584