Skip to content

Commit 727eabd

Browse files
committed
Auto merge of #53662 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests Successful merges: - #53311 (Window Mutex: Document that we properly initialize the SRWLock) - #53503 (Discourage overuse of mem::forget) - #53545 (Fix #50865: ICE on impl-trait returning functions reaching private items) - #53559 (add macro check for lint) - #53562 (Lament the invincibility of the Turbofish) - #53563 (use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into()) - #53592 (docs: minor stylistic changes to str/string docs) - #53594 (Update RELEASES.md to include clippy-preview) - #53600 (Fix a grammatical mistake in "expected generic arguments" errors) - #53614 (update nomicon and book) - #53617 (tidy: Stop requiring a license header) - #53618 (Add missing fmt examples) - #53636 (Prefer `.nth(n)` over `.skip(n).next()`.) - #53644 (Use SmallVec for SmallCStr) - #53664 (Remove unnecessary closure in rustc_mir/build/mod.rs) - #53666 (Added rustc_codegen_llvm to compiler documentation.)
2 parents 61b0072 + c6039de commit 727eabd

File tree

114 files changed

+382
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+382
-305
lines changed

RELEASES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Misc
3939
will demote `deny` and `forbid` lints to `warn`.
4040
- [`rustc` and `rustdoc` will now have the exit code of `1` if compilation
4141
fails, and `101` if there is a panic.][52197]
42+
- [A preview of clippy has been made available through rustup.][51122]
43+
You can install the preview with `rustup component add clippy-preview`
4244

4345
Compatibility Notes
4446
-------------------
@@ -64,6 +66,7 @@ Compatibility Notes
6466
[51619]: https://github.com/rust-lang/rust/pull/51619/
6567
[51656]: https://github.com/rust-lang/rust/pull/51656/
6668
[51178]: https://github.com/rust-lang/rust/pull/51178/
69+
[51122]: https://github.com/rust-lang/rust/pull/51122
6770
[50494]: https://github.com/rust-lang/rust/pull/50494/
6871
[cargo/5614]: https://github.com/rust-lang/cargo/pull/5614/
6972
[cargo/5723]: https://github.com/rust-lang/cargo/pull/5723/

src/bootstrap/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl Step for Rustc {
712712

713713
// Find dependencies for top level crates.
714714
let mut compiler_crates = HashSet::new();
715-
for root_crate in &["rustc", "rustc_driver"] {
715+
for root_crate in &["rustc", "rustc_driver", "rustc_codegen_llvm"] {
716716
let interned_root_crate = INTERNER.intern_str(root_crate);
717717
find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
718718
}

src/doc/nomicon

src/liballoc/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl str {
513513
unsafe { String::from_utf8_unchecked(slice.into_vec()) }
514514
}
515515

516-
/// Create a [`String`] by repeating a string `n` times.
516+
/// Creates a new [`String`] by repeating a string `n` times.
517517
///
518518
/// [`String`]: string/struct.String.html
519519
///

src/liballoc/string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl String {
752752
self.vec
753753
}
754754

755-
/// Extracts a string slice containing the entire string.
755+
/// Extracts a string slice containing the entire `String`.
756756
///
757757
/// # Examples
758758
///
@@ -1454,8 +1454,8 @@ impl String {
14541454
self.vec.clear()
14551455
}
14561456

1457-
/// Creates a draining iterator that removes the specified range in the string
1458-
/// and yields the removed chars.
1457+
/// Creates a draining iterator that removes the specified range in the `String`
1458+
/// and yields the removed `chars`.
14591459
///
14601460
/// Note: The element range is removed even if the iterator is not
14611461
/// consumed until the end.

src/libcore/fmt/mod.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,36 @@ impl<'a> Formatter<'a> {
11321132
///
11331133
/// This function will correctly account for the flags provided as well as
11341134
/// the minimum width. It will not take precision into account.
1135+
///
1136+
/// # Examples
1137+
///
1138+
/// ```
1139+
/// use std::fmt;
1140+
///
1141+
/// struct Foo { nb: i32 };
1142+
///
1143+
/// impl Foo {
1144+
/// fn new(nb: i32) -> Foo {
1145+
/// Foo {
1146+
/// nb,
1147+
/// }
1148+
/// }
1149+
/// }
1150+
///
1151+
/// impl fmt::Display for Foo {
1152+
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1153+
/// // We need to remove "-" from the number output.
1154+
/// let tmp = self.nb.abs().to_string();
1155+
///
1156+
/// formatter.pad_integral(self.nb > 0, "Foo ", &tmp)
1157+
/// }
1158+
/// }
1159+
///
1160+
/// assert_eq!(&format!("{}", Foo::new(2)), "2");
1161+
/// assert_eq!(&format!("{}", Foo::new(-1)), "-1");
1162+
/// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1");
1163+
/// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
1164+
/// ```
11351165
#[stable(feature = "rust1", since = "1.0.0")]
11361166
pub fn pad_integral(&mut self,
11371167
is_nonnegative: bool,
@@ -1232,7 +1262,7 @@ impl<'a> Formatter<'a> {
12321262
// If our string is longer that the precision, then we must have
12331263
// truncation. However other flags like `fill`, `width` and `align`
12341264
// must act as always.
1235-
if let Some((i, _)) = s.char_indices().skip(max).next() {
1265+
if let Some((i, _)) = s.char_indices().nth(max) {
12361266
// LLVM here can't prove that `..i` won't panic `&s[..i]`, but
12371267
// we know that it can't panic. Use `get` + `unwrap_or` to avoid
12381268
// `unsafe` and otherwise don't emit any panic-related code
@@ -1381,12 +1411,48 @@ impl<'a> Formatter<'a> {
13811411

13821412
/// Writes some data to the underlying buffer contained within this
13831413
/// formatter.
1414+
///
1415+
/// # Examples
1416+
///
1417+
/// ```
1418+
/// use std::fmt;
1419+
///
1420+
/// struct Foo;
1421+
///
1422+
/// impl fmt::Display for Foo {
1423+
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1424+
/// formatter.write_str("Foo")
1425+
/// // This is equivalent to:
1426+
/// // write!(formatter, "Foo")
1427+
/// }
1428+
/// }
1429+
///
1430+
/// assert_eq!(&format!("{}", Foo), "Foo");
1431+
/// assert_eq!(&format!("{:0>8}", Foo), "Foo");
1432+
/// ```
13841433
#[stable(feature = "rust1", since = "1.0.0")]
13851434
pub fn write_str(&mut self, data: &str) -> Result {
13861435
self.buf.write_str(data)
13871436
}
13881437

13891438
/// Writes some formatted information into this instance.
1439+
///
1440+
/// # Examples
1441+
///
1442+
/// ```
1443+
/// use std::fmt;
1444+
///
1445+
/// struct Foo(i32);
1446+
///
1447+
/// impl fmt::Display for Foo {
1448+
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1449+
/// formatter.write_fmt(format_args!("Foo {}", self.0))
1450+
/// }
1451+
/// }
1452+
///
1453+
/// assert_eq!(&format!("{}", Foo(-1)), "Foo -1");
1454+
/// assert_eq!(&format!("{:0>8}", Foo(2)), "Foo 2");
1455+
/// ```
13901456
#[stable(feature = "rust1", since = "1.0.0")]
13911457
pub fn write_fmt(&mut self, fmt: Arguments) -> Result {
13921458
write(self.buf, fmt)

src/libcore/mem.rs

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ use ops::{Deref, DerefMut, CoerceUnsized};
2929
#[stable(feature = "rust1", since = "1.0.0")]
3030
pub use intrinsics::transmute;
3131

32-
/// Leaks a value: takes ownership and "forgets" about the value **without running
33-
/// its destructor**.
32+
/// Takes ownership and "forgets" about the value **without running its destructor**.
3433
///
3534
/// Any resources the value manages, such as heap memory or a file handle, will linger
36-
/// forever in an unreachable state.
35+
/// forever in an unreachable state. However, it does not guarantee that pointers
36+
/// to this memory will remain valid.
3737
///
38-
/// If you want to dispose of a value properly, running its destructor, see
38+
/// * If you want to leak memory, see [`Box::leak`][leak].
39+
/// * If you want to obtain a raw pointer to the memory, see [`Box::into_raw`][into_raw].
40+
/// * If you want to dispose of a value properly, running its destructor, see
3941
/// [`mem::drop`][drop].
4042
///
4143
/// # Safety
@@ -59,15 +61,6 @@ pub use intrinsics::transmute;
5961
///
6062
/// # Examples
6163
///
62-
/// Leak some heap memory by never deallocating it:
63-
///
64-
/// ```
65-
/// use std::mem;
66-
///
67-
/// let heap_memory = Box::new(3);
68-
/// mem::forget(heap_memory);
69-
/// ```
70-
///
7164
/// Leak an I/O object, never closing the file:
7265
///
7366
/// ```no_run
@@ -137,38 +130,13 @@ pub use intrinsics::transmute;
137130
/// }
138131
/// ```
139132
///
140-
/// ## Use case 3
141-
///
142-
/// You are transferring ownership across a [FFI] boundary to code written in
143-
/// another language. You need to `forget` the value on the Rust side because Rust
144-
/// code is no longer responsible for it.
145-
///
146-
/// ```no_run
147-
/// use std::mem;
148-
///
149-
/// extern "C" {
150-
/// fn my_c_function(x: *const u32);
151-
/// }
152-
///
153-
/// let x: Box<u32> = Box::new(3);
154-
///
155-
/// // Transfer ownership into C code.
156-
/// unsafe {
157-
/// my_c_function(&*x);
158-
/// }
159-
/// mem::forget(x);
160-
/// ```
161-
///
162-
/// In this case, C code must call back into Rust to free the object. Calling C's `free`
163-
/// function on a [`Box`][box] is *not* safe! Also, `Box` provides an [`into_raw`][into_raw]
164-
/// method which is the preferred way to do this in practice.
165-
///
166133
/// [drop]: fn.drop.html
167134
/// [uninit]: fn.uninitialized.html
168135
/// [clone]: ../clone/trait.Clone.html
169136
/// [swap]: fn.swap.html
170137
/// [FFI]: ../../book/first-edition/ffi.html
171138
/// [box]: ../../std/boxed/struct.Box.html
139+
/// [leak]: ../../std/boxed/struct.Box.html#method.leak
172140
/// [into_raw]: ../../std/boxed/struct.Box.html#method.into_raw
173141
/// [ub]: ../../reference/behavior-considered-undefined.html
174142
#[inline]

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ impl_stable_hash_for!(enum traits::Reveal {
10911091
});
10921092

10931093
impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1094+
ReachableFromImplTrait,
10941095
Reachable,
10951096
Exported,
10961097
Public

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13301330
s
13311331
};
13321332
let var_description = match var_origin {
1333-
infer::MiscVariable(_) => "".to_string(),
1333+
infer::MiscVariable(_) => String::new(),
13341334
infer::PatternRegion(_) => " for pattern".to_string(),
13351335
infer::AddrOfRegion(_) => " for borrow expression".to_string(),
13361336
infer::Autoref(_) => " for autoref".to_string(),

0 commit comments

Comments
 (0)