about summary refs log tree commit diff
path: root/src/libstd/macros.rs
AgeCommit message (Collapse)AuthorLines
2014-12-18Revise std::thread API to join by defaultAaron Turon-2/+4
This commit is part of a series that introduces a `std::thread` API to replace `std::task`. In the new API, `spawn` returns a `JoinGuard`, which by default will join the spawned thread when dropped. It can also be used to join explicitly at any time, returning the thread's result. Alternatively, the spawned thread can be explicitly detached (so no join takes place). As part of this change, Rust processes now terminate when the main thread exits, even if other detached threads are still running, moving Rust closer to standard threading models. This new behavior may break code that was relying on the previously implicit join-all. In addition to the above, the new thread API also offers some built-in support for building blocking abstractions in user space; see the module doc for details. Closes #18000 [breaking-change]
2014-12-18librustc: Always parse `macro!()`/`macro![]` as expressions if notPatrick Walton-45/+47
followed by a semicolon. This allows code like `vec![1i, 2, 3].len();` to work. This breaks code that uses macros as statements without putting semicolons after them, such as: fn main() { ... assert!(a == b) assert!(c == d) println(...); } It also breaks code that uses macros as items without semicolons: local_data_key!(foo) fn main() { println("hello world") } Add semicolons to fix this code. Those two examples can be fixed as follows: fn main() { ... assert!(a == b); assert!(c == d); println(...); } local_data_key!(foo); fn main() { println("hello world") } RFC #378. Closes #18635. [breaking-change]
2014-12-16auto merge of #19647 : nielsegberts/rust/master, r=pnkfelixbors-6/+6
The names expected and actual are not used anymore in the output. It also removes the confusion that the argument order is the opposite of junit. Bug #7330 is relevant.
2014-12-14std: Collapse SlicePrelude traitsAlex Crichton-1/+1
This commit collapses the various prelude traits for slices into just one trait: * SlicePrelude/SliceAllocPrelude => SliceExt * CloneSlicePrelude/CloneSliceAllocPrelude => CloneSliceExt * OrdSlicePrelude/OrdSliceAllocPrelude => OrdSliceExt * PartialEqSlicePrelude => PartialEqSliceExt
2014-12-14Mostly rote conversion of `proc()` to `move||` (and occasionally `Thunk::new`)Niko Matsakis-2/+2
2014-12-09Rename assert_eq arguments to left and right.Niels Egberts-6/+6
The names expected and actual are not used anymore in the output. It also removes the confusion that the argument order is the opposite of junit.
2014-11-27Fix example code for unreachable!olivren-5/+4
The previous code was giving an incorrect result (not x/3).
2014-11-26Test fixes and rebase conflictsAlex Crichton-5/+6
2014-11-25Improve documentation for unreachableSteve Klabnik-17/+33
Fixes #18876
2014-11-23std: Add a new top-level thread_local moduleAlex Crichton-22/+0
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new thread local system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: https://github.com/rust-lang/rfcs/pull/461 [breaking-change]
2014-11-20auto merge of #19071 : huonw/rust/col2column, r=nikomatsakisbors-4/+4
This macro is very rarely used, so there is no need (and it is better) for it to avoid the abbreviation. Closes rust-lang/rfcs#467.
2014-11-20Rename `col!` to `column!`.Huon Wilson-4/+4
This macro is very rarely used, so there is no need (and it is better) for it to avoid the abbreviation. Closes rust-lang/rfcs#467. [breaking-change]
2014-11-18std: Stabilize std::fmtAlex Crichton-1/+7
This commit applies the stabilization of std::fmt as outlined in [RFC 380][rfc]. There are a number of breaking changes as a part of this commit which will need to be handled to migrated old code: * A number of formatting traits have been removed: String, Bool, Char, Unsigned, Signed, and Float. It is recommended to instead use Show wherever possible or to use adaptor structs to implement other methods of formatting. * The format specifier for Boolean has changed from `t` to `b`. * The enum `FormatError` has been renamed to `Error` as well as becoming a unit struct instead of an enum. The `WriteError` variant no longer exists. * The `format_args_method!` macro has been removed with no replacement. Alter code to use the `format_args!` macro instead. * The public fields of a `Formatter` have become read-only with no replacement. Use a new formatting string to alter the formatting flags in combination with the `write!` macro. The fields can be accessed through accessor methods on the `Formatter` structure. Other than these breaking changes, the contents of std::fmt should now also all contain stability markers. Most of them are still #[unstable] or #[experimental] [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0380-stabilize-std-fmt.md [breaking-change] Closes #18904
2014-11-18implement Writer for Vec<u8>Daniel Micay-2/+1
The trait has an obvious, sensible implementation directly on vectors so the MemWriter wrapper is unnecessary. This will halt the trend towards providing all of the vector methods on MemWriter along with eliminating the noise caused by conversions between the two types. It also provides the useful default Writer methods on Vec<u8>. After the type is removed and code has been migrated, it would make sense to add a new implementation of MemWriter with seeking support. The simple use cases can be covered with vectors alone, and ones with the need for seeks can use a new MemWriter implementation.
2014-11-10Add optional messages to the unreachable macro.Michael Sproul-1/+9
Closes #18842.
2014-11-06Prelude: rename and consolidate extension traitsAaron Turon-1/+1
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](https://github.com/rust-lang/rfcs/pull/344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
2014-11-02Add error module with Error and FromError traitsAaron Turon-2/+7
As per [RFC 70](https://github.com/rust-lang/rfcs/blob/master/active/0070-error-chaining.md) Closes #17747 Note that the `error` module must live in `std` in order to refer to `String`. Note that, until multidispatch lands, the `FromError` trait cannot be usefully implemented outside of the blanket impl given here.
2014-10-30rollup merge of #18398 : aturon/lint-conventions-2Alex Crichton-2/+2
Conflicts: src/libcollections/slice.rs src/libcore/failure.rs src/libsyntax/parse/token.rs src/test/debuginfo/basic-types-mut-globals.rs src/test/debuginfo/simple-struct.rs src/test/debuginfo/trait-pointers.rs
2014-10-29Rename fail! to panic!Steve Klabnik-25/+25
https://github.com/rust-lang/rfcs/pull/221 The current terminology of "task failure" often causes problems when writing or speaking about code. You often want to talk about the possibility of an operation that returns a Result "failing", but cannot because of the ambiguity with task failure. Instead, you have to speak of "the failing case" or "when the operation does not succeed" or other circumlocutions. Likewise, we use a "Failure" header in rustdoc to describe when operations may fail the task, but it would often be helpful to separate out a section describing the "Err-producing" case. We have been steadily moving away from task failure and toward Result as an error-handling mechanism, so we should optimize our terminology accordingly: Result-producing functions should be easy to describe. To update your code, rename any call to `fail!` to `panic!` instead. Assuming you have not created your own macro named `panic!`, this will work on UNIX based systems: grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g' You can of course also do this by hand. [breaking-change]
2014-10-28Update code with new lint namesAaron Turon-2/+2
2014-10-10improve the performance of the vec![] macroDaniel Micay-9/+7
Closes #17865
2014-10-03Set the `non_uppercase_statics` lint to warn by defaultP1start-0/+2
2014-09-22auto merge of #17339 : treeman/rust/doc-things, r=alexcrichtonbors-2/+2
Also some cleanup to conform to documentation style.
2014-09-19Add enum variants to the type namespaceNick Cameron-2/+2
Change to resolve and update compiler and libs for uses. [breaking-change] Enum variants are now in both the value and type namespaces. This means that if you have a variant with the same name as a type in scope in a module, you will get a name clash and thus an error. The solution is to either rename the type or the variant.
2014-09-17rollup merge of #17326 : brson/wintestAlex Crichton-2/+2
2014-09-17doc: Cleanup.Jonas Hietala-2/+2
Remove ~~~ for code block specification. Use /// Over /** */ for doc blocks.
2014-09-16Use PATH instead of HOME in env! exampleBrian Anderson-2/+2
HOME does not exist under typical windows environments.
2014-08-23std: Use concat! and stringify! to simplify the most common assert! case.root-1/+1
With no custom message, we should just use concat! + stringify! for `assert!(expr)`. Inspired by issue #16625
2014-08-11core/std: squash dead_code warnings from fail! invocations.Huon Wilson-6/+11
The fail macro defines some function/static items internally, which got a dead_code warning when `fail!()` is used inside a dead function. This is ugly and unnecessarily reveals implementation details, so the warnings can be squashed. Fixes #16192.
2014-08-08Register new snapshot 12e0f72Niko Matsakis-34/+0
2014-08-06Use byte literals in libstdnham-1/+1
2014-07-31rustrt: Make begin_unwind take a single file/line pointerBrian Anderson-0/+33
Smaller text size.
2014-07-25Revert "Use fewer instructions for `fail!`"Brian Anderson-3/+2
This reverts commit c61f9763e2e03afbe62445877ceb3ed15e22e123. Conflicts: src/librustrt/unwind.rs src/libstd/macros.rs
2014-07-25std: Use correct conventions for statics in macrosBrian Anderson-6/+6
2014-07-25Put the struct passed to unwinding functions into a staticBrian Anderson-7/+12
Produces very clean asm, but makes bigger binaries.
2014-07-25Make most of the failure functions take &(&'static str, uint)Brian Anderson-2/+2
Passing one pointer takes less code than one pointer and an integer.
2014-07-21Use fewer instructions for `fail!`Brian Anderson-1/+1
Adds a special-case fail function, rustrt::unwind::begin_unwind_no_time_to_explain, that encapsulates the printing of the words "explicit failure". The before/after optimized assembly: ``` leaq "str\"str\"(1369)"(%rip), %rax movq %rax, 8(%rsp) movq $19, 16(%rsp) leaq 8(%rsp), %rdi movl $11, %esi callq _ZN6unwind31begin_unwind_no_time_to_explain20hd1c720cdde6a116480dE@PLT ``` ``` leaq "str\"str\"(1412)"(%rip), %rax movq %rax, 24(%rsp) movq $16, 32(%rsp) leaq "str\"str\"(1413)"(%rip), %rax movq %rax, 8(%rsp) movq $19, 16(%rsp) leaq 24(%rsp), %rdi leaq 8(%rsp), %rsi movl $11, %edx callq _ZN6unwind12begin_unwind21h15836560661922107792E ``` Before/after filesizes: rwxrwxr-x 1 brian brian 21479503 Jul 20 22:09 stage2-old/lib/librustc-4e7c5e5c.so rwxrwxr-x 1 brian brian 21475415 Jul 20 22:30 x86_64-unknown-linux-gnu/stage2/lib/librustc-4e7c5e5c.so
2014-06-30libstd: set baseline stability levels.Aaron Turon-0/+1
Earlier commits have established a baseline of `experimental` stability for all crates under the facade (so their contents are considered experimental within libstd). Since `experimental` is `allow` by default, we should use the same baseline stability for libstd itself. This commit adds `experimental` tags to all of the modules defined in `std`, and `unstable` to `std` itself.
2014-06-24librustc: Remove the fallback to `int` from typechecking.Niko Matsakis-10/+10
This breaks a fair amount of code. The typical patterns are: * `for _ in range(0, 10)`: change to `for _ in range(0u, 10)`; * `println!("{}", 3)`: change to `println!("{}", 3i)`; * `[1, 2, 3].len()`: change to `[1i, 2, 3].len()`. RFC #30. Closes #6023. [breaking-change]
2014-06-09std: Read HOME instead of USERAlex Crichton-2/+2
Apparently one of the linux bots doesn't have the USER variable defined, and this fix will likely land more quickly than a fix to the bots.
2014-06-06mk: Run doc tests with --cfg doxAlex Crichton-1/+5
There were a few examples in the macros::builtin module that weren't being run because they were being #[cfg]'d out. Closes #14697
2014-06-06Remove reference to ~str in documentationfort-1/+1
2014-05-28std: Remove format_strbuf!()Alex Crichton-8/+0
This was only ever a transitionary macro.
2014-05-27std: change select! docs from 'ports' to 'receivers'Sean McArthur-3/+3
2014-05-20Add non-utf8 byte to the bytes!() exampleTobias Bucher-1/+2
Only an example was needed, as the ability to write uints into the string is already mentioned. Fix #7102.
2014-05-17Register new snapshotsAlex Crichton-8/+0
2014-05-15Updates with core::fmt changesAlex Crichton-4/+3
1. Wherever the `buf` field of a `Formatter` was used, the `Formatter` is used instead. 2. The usage of `write_fmt` is minimized as much as possible, the `write!` macro is preferred wherever possible. 3. Usage of `fmt::write` is minimized, favoring the `write!` macro instead.
2014-05-15std: Rewrite the `write!` and `writeln!` macrosAlex Crichton-5/+12
These are reimplemented using the new `core::fmt` module.
2014-05-12librustc: Remove all uses of `~str` from librustc.Patrick Walton-0/+8
2014-05-07std: Modernize the local_data apiAlex Crichton-4/+2
This commit brings the local_data api up to modern rust standards with a few key improvements: * The `pop` and `set` methods have been combined into one method, `replace` * The `get_mut` method has been removed. All interior mutability should be done through `RefCell`. * All functionality is now exposed as a method on the keys themselves. Instead of importing std::local_data, you now use "key.replace()" and "key.get()". * All closures have been removed in favor of RAII functionality. This means that get() and get_mut() no long require closures, but rather return Option<SmartPointer> where the smart pointer takes care of relinquishing the borrow and also implements the necessary Deref traits * The modify() function was removed to cut the local_data interface down to its bare essentials (similarly to how RefCell removed set/get). [breaking-change]