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

+3
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

+1-1
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

+1-1
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

+3-3
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

+67-1
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

+7-39
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

+1
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

+1-1
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(),

src/librustc/middle/privacy.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use syntax::ast::NodeId;
2121
// Accessibility levels, sorted in ascending order
2222
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
2323
pub enum AccessLevel {
24+
// Superset of Reachable used to mark impl Trait items.
25+
ReachableFromImplTrait,
2426
// Exported items + items participating in various kinds of public interfaces,
2527
// but not directly nameable. For example, if function `fn f() -> T {...}` is
2628
// public, then type `T` is reachable. Its values can be obtained by other crates
@@ -40,7 +42,7 @@ pub struct AccessLevels<Id = NodeId> {
4042

4143
impl<Id: Hash + Eq> AccessLevels<Id> {
4244
pub fn is_reachable(&self, id: Id) -> bool {
43-
self.map.contains_key(&id)
45+
self.map.get(&id) >= Some(&AccessLevel::Reachable)
4446
}
4547
pub fn is_exported(&self, id: Id) -> bool {
4648
self.map.get(&id) >= Some(&AccessLevel::Exported)

src/librustc/middle/reachable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
434434
// Step 2: Mark all symbols that the symbols on the worklist touch.
435435
reachable_context.propagate();
436436

437+
debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols);
438+
437439
// Return the set of reachable symbols.
438440
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
439441
}

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
21052105
region
21062106
} else {
21072107
// Do not even print 'static
2108-
"".to_owned()
2108+
String::new()
21092109
};
21102110
write!(fmt, "&{}{}{:?}", region, kind_str, place)
21112111
}

src/librustc/session/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
10511051
"perform LLVM link-time optimizations"),
10521052
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
10531053
"select target processor (rustc --print target-cpus for details)"),
1054-
target_feature: String = ("".to_string(), parse_string, [TRACKED],
1054+
target_feature: String = (String::new(), parse_string, [TRACKED],
10551055
"target specific attributes (rustc --print target-features for details)"),
10561056
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
10571057
"a list of extra LLVM passes to run (space separated)"),
@@ -1085,7 +1085,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
10851085
"choose the code model to use (rustc --print code-models for details)"),
10861086
metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
10871087
"metadata to mangle symbol names with"),
1088-
extra_filename: String = ("".to_string(), parse_string, [UNTRACKED],
1088+
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
10891089
"extra data to put in each output filename"),
10901090
codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
10911091
"divide crate into N units to optimize in parallel"),
@@ -1992,7 +1992,7 @@ pub fn build_session_options_and_crate_config(
19921992
};
19931993
if cg.target_feature == "help" {
19941994
prints.push(PrintRequest::TargetFeatures);
1995-
cg.target_feature = "".to_string();
1995+
cg.target_feature = String::new();
19961996
}
19971997
if cg.relocation_model.as_ref().map_or(false, |s| s == "help") {
19981998
prints.push(PrintRequest::RelocationModels);

src/librustc/traits/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
472472
if len > 5 {
473473
format!("\nand {} others", len - 4)
474474
} else {
475-
"".to_owned()
475+
String::new()
476476
}
477477
));
478478
}
@@ -917,7 +917,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
917917
remove_refs);
918918

919919
err.span_suggestion_short_with_applicability(
920-
sp, &format_str, String::from(""), Applicability::MachineApplicable
920+
sp, &format_str, String::new(), Applicability::MachineApplicable
921921
);
922922
break;
923923
}
@@ -1116,7 +1116,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11161116
.collect::<Vec<String>>()
11171117
.join(", "))
11181118
} else {
1119-
"".to_owned()
1119+
String::new()
11201120
},
11211121
);
11221122
err.span_suggestion_with_applicability(

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ impl IntercrateAmbiguityCause {
120120
&IntercrateAmbiguityCause::DownstreamCrate { ref trait_desc, ref self_desc } => {
121121
let self_desc = if let &Some(ref ty) = self_desc {
122122
format!(" for type `{}`", ty)
123-
} else { "".to_string() };
123+
} else { String::new() };
124124
format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc)
125125
}
126126
&IntercrateAmbiguityCause::UpstreamCrateUpdate { ref trait_desc, ref self_desc } => {
127127
let self_desc = if let &Some(ref ty) = self_desc {
128128
format!(" for type `{}`", ty)
129-
} else { "".to_string() };
129+
} else { String::new() };
130130
format!("upstream crates may add new impl of trait `{}`{} \
131131
in future versions",
132132
trait_desc, self_desc)

src/librustc/util/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) {
213213
let mb = n as f64 / 1_000_000.0;
214214
format!("; rss: {}MB", mb.round() as usize)
215215
}
216-
None => "".to_owned(),
216+
None => String::new(),
217217
};
218218
println!("{}time: {}{}\t{}",
219219
" ".repeat(indentation),

src/librustc/util/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ macro_rules! define_categories {
7373
(format!("{:.2}",
7474
(((hits as f32) / (total as f32)) * 100.0)), total.to_string())
7575
} else {
76-
("".into(), "".into())
76+
(String::new(), String::new())
7777
};
7878

7979
writeln!(

src/librustc_borrowck/borrowck/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
8787
.span_suggestion_short_with_applicability(
8888
mut_span,
8989
"remove this `mut`",
90-
"".to_owned(),
90+
String::new(),
9191
Applicability::MachineApplicable)
9292
.emit();
9393
}

0 commit comments

Comments
 (0)