summary refs log tree commit diff
path: root/src/libstd/macros.rs
AgeCommit message (Collapse)AuthorLines
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]
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-3/+3
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-01Remove useless assert! caseSteven Fackler-5/+0
2014-05-01Add debug_assert and debug_assert_eq macrosSteven Fackler-0/+52
I also switched some `assert!` calls over to `debug_assert!`. Closes #12049. RFC: 0015-assert
2014-04-21Fix misspellings in comments.Joseph Crail-1/+1
2014-04-14Use new attribute syntax in python files in src/etc too (#13478)Manish Goregaokar-2/+2
2014-04-09std: use a `match` in `assert_eq!` to extend the lifetime of the args.Huon Wilson-7/+9
This enables assert_eq!(foo.collect::<Vec<...>>().as_slice(), &[1,2,3,4]); to work, by extending the lifetime of the .as_slice() rvalue.
2014-04-08std: make vec!() macro handle a trailing commaKang Seonghoon-1/+2
Fixes #12910.
2014-04-03std: Document builtin syntax extensionsAlex Crichton-0/+259
These syntax extensions need a place to be documented, and this starts passing a `--cfg dox` parameter to `rustdoc` when building and testing documentation in order to document macros so that they have no effect on the compiled crate, but only documentation. Closes #5605
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-1/+1
Closes #2569
2014-03-20rename std::vec_ng -> std::vecDaniel Micay-2/+2
Closes #12771
2014-03-15log: Introduce liblog, the old std::loggingAlex Crichton-101/+12
This commit moves all logging out of the standard library into an external crate. This crate is the new crate which is responsible for all logging macros and logging implementation. A few reasons for this change are: * The crate map has always been a bit of a code smell among rust programs. It has difficulty being loaded on almost all platforms, and it's used almost exclusively for logging and only logging. Removing the crate map is one of the end goals of this movement. * The compiler has a fair bit of special support for logging. It has the __log_level() expression as well as generating a global word per module specifying the log level. This is unfairly favoring the built-in logging system, and is much better done purely in libraries instead of the compiler itself. * Initialization of logging is much easier to do if there is no reliance on a magical crate map being available to set module log levels. * If the logging library can be written outside of the standard library, there's no reason that it shouldn't be. It's likely that we're not going to build the highest quality logging library of all time, so third-party libraries should be able to provide just as high-quality logging systems as the default one provided in the rust distribution. With a migration such as this, the change does not come for free. There are some subtle changes in the behavior of liblog vs the previous logging macros: * The core change of this migration is that there is no longer a physical log-level per module. This concept is still emulated (it is quite useful), but there is now only a global log level, not a local one. This global log level is a reflection of the maximum of all log levels specified. The previously generated logging code looked like: if specified_level <= __module_log_level() { println!(...) } The newly generated code looks like: if specified_level <= ::log::LOG_LEVEL { if ::log::module_enabled(module_path!()) { println!(...) } } Notably, the first layer of checking is still intended to be "super fast" in that it's just a load of a global word and a compare. The second layer of checking is executed to determine if the current module does indeed have logging turned on. This means that if any module has a debug log level turned on, all modules with debug log levels get a little bit slower (they all do more expensive dynamic checks to determine if they're turned on or not). Semantically, this migration brings no change in this respect, but runtime-wise, this will have a perf impact on some code. * A `RUST_LOG=::help` directive will no longer print out a list of all modules that can be logged. This is because the crate map will no longer specify the log levels of all modules, so the list of modules is not known. Additionally, warnings can no longer be provided if a malformed logging directive was supplied. The new "hello world" for logging looks like: #[phase(syntax, link)] extern crate log; fn main() { debug!("Hello, world!"); }
2014-03-13std: Rename Chan/Port types and constructorAlex Crichton-10/+10
* Chan<T> => Sender<T> * Port<T> => Receiver<T> * Chan::new() => channel() * constructor returns (Sender, Receiver) instead of (Receiver, Sender) * local variables named `port` renamed to `rx` * local variables named `chan` renamed to `tx` Closes #11765
2014-03-07std: stop `vec!()` warning about unused mutability.Huon Wilson-3/+5
If no arguments are given to `vec!` then no pushes are emitted and so the compiler (rightly) complains that the mutability of `temp` is never used. This behaviour is rather annoying for users.
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-1/+1
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-28auto merge of #12616 : alexcrichton/rust/size, r=huonwbors-1/+8
I've been playing around with code size when linking to libstd recently, and these were some findings I found that really helped code size. I started out by eliminating all I/O implementations from libnative and instead just return an unimplemented error. In doing so, a `fn main() {}` executable was ~378K before this patch, and about 170K after the patch. These size wins are all pretty minor, but they all seemed pretty reasonable to me. With native I/O not stubbed out, this takes the size of an LTO executable from 675K to 400K.
2014-02-28std: Flag run_fmt() as #[inline(always)]Alex Crichton-1/+8
This function is a tiny wrapper that LLVM doesn't want to inline, and it ends up causing more bloat than necessary. The bloat is pretty small, but it's a win of at least 7k for small executables, and I imagine that the number goes up as there are more calls to fail!().
2014-02-27std: Export the select! macroAlex Crichton-0/+44
Mark it as #[experimental] for now. In theory this attribute will be read in the future. I believe that the implementation is solid enough for general use, although I would not be surprised if there were bugs in it still. I think that it's at the point now where public usage of it will start to uncover hopefully the last few remaining bugs. Closes #12044
2014-02-21libstd: Implement some convenience methods on vectorsPatrick Walton-0/+10
2014-02-20Mass rename if_ok! to try!Alex Crichton-1/+1
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-19rustdoc: Handle links to reexported itemsAlex Crichton-2/+5
When building up our path cache, we don't plaster over a path which was previously inserted if we're inserting a non-public-item thing. Closes #11678
2014-02-19rustdoc: Show macros in documentationAlex Crichton-0/+172
Any macro tagged with #[macro_export] will be showed in the documentation for that module. This also documents all the existing macros inside of std::macros. Closes #3163 cc #5605 Closes #9954