Commit Graph

416 Commits

Author SHA1 Message Date
Ralf Jung
44c135b6a9 use MaybeUninit in core::fmt
Code by @japaric, I just split it into individual commits
2018-11-23 22:50:20 +01:00
Tshepang Lekhonkhobe
af6c871fa1 doc: make core::fmt::Error example more simple 2018-10-13 19:28:18 +02:00
Scott McMurray
0a3bd9b6ab Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
Ralf Jung
e37d6d37e7 Revert "Auto merge of #53508 - japaric:maybe-uninit, r=RalfJung"
This reverts commit c6e3d7fa31, reversing
changes made to 4591a245c7.
2018-09-29 09:50:50 +02:00
Jorge Aparicio
851acdd22d core: fix deprecated warnings 2018-09-22 21:01:21 +02:00
kennytm
9dfb95b11f
Rollup merge of #53636 - frewsxcv:frewsxcv-nth, r=rkruppe
Prefer `.nth(n)` over `.skip(n).next()`.

Found by clippy.
2018-08-24 19:24:44 +08:00
Guillaume Gomez
2cc2e01e04 Add missing fmt examples 2018-08-23 20:20:58 +02:00
Corey Farwell
9e0ff24b6d Prefer .nth(n) over .skip(n).next().
Found by clippy.
2018-08-23 09:35:49 -04:00
ljedrz
8646a17143 Enforce #![deny(bare_trait_objects)] in src/libcore 2018-07-25 10:21:41 +09:00
Zack M. Davis
057715557b migrate codebase to ..= inclusive range patterns
These were stabilized in March 2018's #47813, and are the Preferred Way
to Do It going forward (q.v. #51043).
2018-06-26 07:53:30 -07:00
Guillaume Gomez
804984836e Reexport fmt::Alignment into std 2018-06-03 17:04:48 +02:00
Guillaume Gomez
fb447f118d Stabilize Formatter alignment 2018-05-27 14:07:43 +02:00
Guillaume Gomez
6ff9409637 Add more missing examples for Formatter 2018-05-24 22:27:19 +02:00
Manish Goregaokar
6e49c837f6 Add explanation for #[must_use] on Debug builders 2018-05-07 10:26:28 -07:00
Kornel
1e38eee63b Suggest more helpful formatting string 2018-05-05 11:50:02 +01:00
Guillaume Gomez
30e3f1a620 Add more doc aliases 2018-04-26 12:56:10 +02:00
Felix S. Klock II
fadabd6fbb Revert stabilization of feature(never_type).
This commit is just covering the feature gate itself and the tests
that made direct use of `!` and thus need to opt back into the
feature.

A follow on commit brings back the other change that motivates the
revert: Namely, going back to the old rules for falling back to `()`.
2018-04-20 18:09:28 +02:00
Alex Crichton
2bb5b5c07c core: Remove an implicit panic from Formatter::pad
The expression `&s[..i]` in general can panic if `i` is out of bounds or not on
a character boundary for a string, and this caused the codegen for
`Formatter::pad` to be a bit larger than it otherwise needed to be. This commit
replaces this with `s.get(..i).unwrap_or(&s)` which while having different
behavior if `i` is out of bounds has a much smaller code footprint and otherwise
avoids the need for `unsafe` code.
2018-04-13 07:04:24 -07:00
Alex Burka
93a3e93bf3
tweak fmt::Arguments docs
Remove an outdated claim about passing something or other to a function. Also swap the variable names in the example.
2018-04-03 09:11:41 -04:00
Tim Neumann
fc9dfda6ad
Rollup merge of #49103 - glandium:uninitialized, r=cramertj
Use an uninitialized buffer in GenericRadix::fmt_int, like in Display::fmt for numeric types

The code using a slice of that buffer is only ever going to use
bytes that are subsequently initialized.
2018-03-26 15:14:56 +02:00
kennytm
8c1535f115
Rollup merge of #49229 - Centril:doc/format_args_display_debug, r=steveklabnik
Document format_args! / Arguments<'a> behavior wrt. Display and Debug

This is a follow up PR to #49067 , this documents the behavior of `format_args!` (i.e: `Argument<'a>`) wrt. `Display` and `Debug`.

r? @steveklabnik
2018-03-25 01:26:37 +08:00
Alex Crichton
db2dde9a41 Rollup merge of #49102 - glandium:decimal, r=aturon
Remove core::fmt::num::Decimal

Before ebf9e1aaf6, it was used for Display::fmt, but ebf9e1aaf6 replaced
that with a faster implementation, and nothing else uses it.
2018-03-23 10:16:09 -07:00
Mazdak Farrokhzad
613fb8bc2c document format_args! - fix trailing whitespace 2018-03-22 10:06:17 +01:00
Mazdak Farrokhzad
5201e7cf8a document format_args! behavior wrt. Display and Debug 2018-03-21 07:31:39 +01:00
kennytm
63ab36190d
Rollup merge of #49099 - glandium:master, r=sfackler
Use associated consts for GenericRadix base and prefix

The trait being private, this does not imply an API change.
2018-03-20 07:15:22 +08:00
bors
152217d29c Auto merge of #48978 - SimonSapin:debug-hex, r=KodrAus
Add hexadecimal formatting of integers with fmt::Debug

This can be used for integers within a larger types which implements Debug (possibly through derive) but not fmt::UpperHex or fmt::LowerHex.

```rust
assert!(format!("{:02x?}", b"Foo\0") == "[46, 6f, 6f, 00]");
assert!(format!("{:02X?}", b"Foo\0") == "[46, 6F, 6F, 00]");
```

RFC: https://github.com/rust-lang/rfcs/pull/2226

The new formatting string syntax (`x?` and `X?`) is insta-stable in this PR because I don’t know how to change a built-in proc macro’s behavior based of a feature gate. I can look into adding that, but I also strongly suspect that keeping this feature unstable for a time period would not be useful as possibly no-one would use it during that time.

This PR does not add the new (public) `fmt::Formatter` proposed in the API because:

* There was some skepticism on response to this part of the RFC
* It is not possible to implement as-is without larger changes to `fmt`, because `Formatter` at the moment has no easy way to tell apart for example `Octal` from `Binary`: it only has a function pointer for the relevant `fmt()` method.

If some integer-like type outside of `std` want to implement this behavior, another RFC will likely need to propose a different public API for `Formatter`.
2018-03-19 02:38:19 +00:00
Mike Hommey
b910d6b93c Use associated consts for GenericRadix base and prefix 2018-03-17 15:49:37 +09:00
Mike Hommey
38cbdcd0b1 Use an uninitialized buffer in GenericRadix::fmt_int, like in Display::fmt for numeric types
The code using a slice of that buffer is only ever going to use
bytes that are subsequently initialized.
2018-03-17 10:42:34 +09:00
Mike Hommey
9e62681912 Remove core::fmt::num::Decimal
Before ebf9e1aaf6, it was used for Display::fmt, but ebf9e1aaf6 replaced
that with a faster implementation, and nothing else uses it.
2018-03-17 10:32:31 +09:00
bors
5ebf74851d Auto merge of #47630 - canndrew:exhaustive-patterns, r=nikomatsakis
Stabilise feature(never_type). Introduce feature(exhaustive_patterns)

This stabilizes `!`, removing the feature gate as well as the old defaulting-to-`()` behavior. The pattern exhaustiveness checks which were covered by `feature(never_type)` have been moved behind a new `feature(exhaustive_patterns)` gate.
2018-03-14 23:43:04 +00:00
kennytm
c144fb79cd
Rollup merge of #48970 - GuillaumeGomez:doc-examples, r=QuietMisdreavus
Add missing examples

r? @QuietMisdreavus
2018-03-15 00:15:49 +08:00
Andrew Cann
a704624ef5 change never_type stabilisation version 2018-03-14 12:44:51 +08:00
Andrew Cann
32ddb30715 Fix version number 2018-03-14 12:44:51 +08:00
Andrew Cann
a9fc3901b0 stabilise feature(never_type)
Replace feature(never_type) with feature(exhaustive_patterns).
feature(exhaustive_patterns) only covers the pattern-exhaustives checks
that used to be covered by feature(never_type)
2018-03-14 12:44:51 +08:00
Simon Sapin
4897935e86 Add hexadecimal formatting of integers with fmt::Debug
This can be used for integers within a larger types which implements Debug
(possibly through derive) but not fmt::UpperHex or fmt::LowerHex.

```rust
assert!(format!("{:02x?}", b"Foo\0") == "[46, 6f, 6f, 00]");
assert!(format!("{:02X?}", b"Foo\0") == "[46, 6F, 6F, 00]");
```

RFC: https://github.com/rust-lang/rfcs/pull/2226
2018-03-13 14:53:06 +01:00
Guillaume Gomez
da257b8fec Add missing examples 2018-03-12 22:42:23 +01:00
Guillaume Gomez
bda5a45793 Add missing links 2018-03-12 20:47:34 +01:00
Esteban Küber
621e61bff9 Add filter to detect local crates for rustc_on_unimplemented 2018-02-01 15:06:21 -08:00
penpalperson
deba3890c5 Changed back inline markings. 2018-01-30 05:31:38 -07:00
penpalperson
81e49597bf Added inline to fmt for debug implementations of primitives. 2018-01-28 21:55:05 -07:00
Guillaume Gomez
93969734f6 Add missing links 2018-01-08 14:16:16 +01:00
kennytm
16095b3601 Rollup merge of #46831 - Diggsey:float-debug-fmt, r=dtolnay
Always `Debug` floats with a decimal point

Fixes #30967

r? @dtolnay
2017-12-20 21:21:59 +08:00
bors
6dbf0ba691 Auto merge of #46233 - SimonSapin:fmt-debuglist-flags, r=sfackler
Make fmt::DebugList and friends forward formatting parameters

For example, formatting slice of integers with `{:04?}` should zero-pad each integer.

This also affects every use of `#[derive(Debug)]`.
2017-12-20 06:38:15 +00:00
Diggory Blake
3e98f18280 Always print floats with a decimal point with the Debug formatter 2017-12-19 01:35:35 +00:00
Andrew Cann
b9df045b79 Rename never_type_impls gate to never_type 2017-12-12 14:03:03 +08:00
David Ross
2c98378ace
Reject '2' as a binary digit in internals of 'b' formatting
I don't believe the previous code `0 ... 2` would run into any real problems, but it seems confusing to read, given that '2' is never a valid binary digit.

As far as I can tell this code is only ever called from within another private method in the trait which has logic to never hand it '2' anyways. I thought we could change this for clarity anyways.
2017-11-28 21:35:18 -08:00
kennytm
83a6f38556 Rollup merge of #46285 - SimonSapin:twos-complement, r=GuillaumeGomez
Document non-obvious behavior of fmt::UpperHex & co for negative integers

Before stabilization I’d have suggested changing the behavior,  but that time is past.
2017-11-28 03:16:50 +08:00
Simon Sapin
bf08789510 Keep access to private Formatter fields in Formatter methods 2017-11-27 14:37:40 +01:00
Simon Sapin
a326d8d1ba Document non-obvious behavior of fmt::UpperHex & co for negative integers
Before stabilization I’d have suggested changing the behavior,
but that time is past.
2017-11-26 22:53:03 +01:00
Simon Sapin
5e11c8fc2b Deprecate the Formatter::flags method, fix #46237 2017-11-26 22:45:28 +01:00