From c78bfbae286174f3a07b0d0c77b702845a691931 Mon Sep 17 00:00:00 2001 From: Camelid Date: Fri, 18 Dec 2020 14:58:10 -0800 Subject: [PATCH 01/18] Use consistent punctuation for 'Prelude contents' docs --- library/std/src/prelude/mod.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs index a3776681d0349..a83c280adcb2d 100644 --- a/library/std/src/prelude/mod.rs +++ b/library/std/src/prelude/mod.rs @@ -28,35 +28,35 @@ //! The current version of the prelude (version 1) lives in //! [`std::prelude::v1`], and re-exports the following: //! -//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}, -//! marker traits that indicate fundamental properties of types. -//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}, various +//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}: +//! Marker traits that indicate fundamental properties of types. +//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: Various //! operations for both destructors and overloading `()`. -//! * [`std::mem`]::[`drop`][`mem::drop`], a convenience function for explicitly +//! * [`std::mem`]::[`drop`][`mem::drop`]: A convenience function for explicitly //! dropping a value. -//! * [`std::boxed`]::[`Box`], a way to allocate values on the heap. -//! * [`std::borrow`]::[`ToOwned`], the conversion trait that defines +//! * [`std::boxed`]::[`Box`]: A way to allocate values on the heap. +//! * [`std::borrow`]::[`ToOwned`]: The conversion trait that defines //! [`to_owned`], the generic method for creating an owned type from a //! borrowed type. -//! * [`std::clone`]::[`Clone`], the ubiquitous trait that defines +//! * [`std::clone`]::[`Clone`]: The ubiquitous trait that defines //! [`clone`][`Clone::clone`], the method for producing a copy of a value. -//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] }, the +//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: The //! comparison traits, which implement the comparison operators and are often //! seen in trait bounds. -//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}, generic +//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: Generic //! conversions, used by savvy API authors to create overloaded methods. //! * [`std::default`]::[`Default`], types that have default values. -//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`] -//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}, iterators of various +//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`], +//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: Iterators of various //! kinds. //! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a //! type which expresses the presence or absence of a value. This type is so //! commonly used, its variants are also exported. -//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}, a type +//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: A type //! for functions that may succeed or fail. Like [`Option`], its variants are //! exported as well. -//! * [`std::string`]::{[`String`], [`ToString`]}, heap allocated strings. -//! * [`std::vec`]::[`Vec`], a growable, heap-allocated vector. +//! * [`std::string`]::{[`String`], [`ToString`]}: Heap-allocated strings. +//! * [`std::vec`]::[`Vec`]: A growable, heap-allocated vector. //! //! [`mem::drop`]: crate::mem::drop //! [`std::borrow`]: crate::borrow From 4a6014bc289abd2573a4362915cbf026912f209d Mon Sep 17 00:00:00 2001 From: Camelid Date: Fri, 18 Dec 2020 15:00:09 -0800 Subject: [PATCH 02/18] Use heading style for 'The I/O Prelude' in `std::io::prelude` --- library/std/src/io/prelude.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/prelude.rs b/library/std/src/io/prelude.rs index 3baab2be37795..700f166daf77d 100644 --- a/library/std/src/io/prelude.rs +++ b/library/std/src/io/prelude.rs @@ -1,4 +1,4 @@ -//! The I/O Prelude +//! # The I/O Prelude //! //! The purpose of this module is to alleviate imports of many common I/O traits //! by adding a glob import to the top of I/O heavy modules: From 2eb4ccd3199f085b5863f85be11e552058ddaa24 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Fri, 1 Jan 2021 22:53:34 +0100 Subject: [PATCH 03/18] Improve grammar in documentation of format strings --- library/alloc/src/fmt.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/fmt.rs b/library/alloc/src/fmt.rs index 5ebc4d6c4c14a..f9424b1d74744 100644 --- a/library/alloc/src/fmt.rs +++ b/library/alloc/src/fmt.rs @@ -282,21 +282,22 @@ //! `%`. The actual grammar for the formatting syntax is: //! //! ```text -//! format_string := [ maybe-format ] * -//! maybe-format := '{' '{' | '}' '}' | +//! format_string := text [ maybe_format text ] * +//! maybe_format := '{' '{' | '}' '}' | format //! format := '{' [ argument ] [ ':' format_spec ] '}' //! argument := integer | identifier //! -//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision][type] +//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type //! fill := character //! align := '<' | '^' | '>' //! sign := '+' | '-' //! width := count //! precision := count | '*' -//! type := identifier | '?' | '' +//! type := '' | '?' | 'x?' | 'X?' | identifier //! count := parameter | integer //! parameter := argument '$' //! ``` +//! In the above grammar, `text` may not contain any `'{'` or `'}'` characters. //! //! # Formatting traits //! From 4274ba40bda3af26042d44557da9d2cdb1567880 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 5 Jan 2021 17:51:27 -0800 Subject: [PATCH 04/18] Use lowercase for prelude items --- library/std/src/prelude/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs index a83c280adcb2d..08f3ff5f253c5 100644 --- a/library/std/src/prelude/mod.rs +++ b/library/std/src/prelude/mod.rs @@ -29,34 +29,34 @@ //! [`std::prelude::v1`], and re-exports the following: //! //! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}: -//! Marker traits that indicate fundamental properties of types. -//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: Various +//! marker traits that indicate fundamental properties of types. +//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: various //! operations for both destructors and overloading `()`. -//! * [`std::mem`]::[`drop`][`mem::drop`]: A convenience function for explicitly +//! * [`std::mem`]::[`drop`][`mem::drop`]: a convenience function for explicitly //! dropping a value. -//! * [`std::boxed`]::[`Box`]: A way to allocate values on the heap. -//! * [`std::borrow`]::[`ToOwned`]: The conversion trait that defines +//! * [`std::boxed`]::[`Box`]: a way to allocate values on the heap. +//! * [`std::borrow`]::[`ToOwned`]: the conversion trait that defines //! [`to_owned`], the generic method for creating an owned type from a //! borrowed type. -//! * [`std::clone`]::[`Clone`]: The ubiquitous trait that defines +//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines //! [`clone`][`Clone::clone`], the method for producing a copy of a value. -//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: The +//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the //! comparison traits, which implement the comparison operators and are often //! seen in trait bounds. -//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: Generic +//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: generic //! conversions, used by savvy API authors to create overloaded methods. //! * [`std::default`]::[`Default`], types that have default values. //! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`], -//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: Iterators of various +//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various //! kinds. //! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a //! type which expresses the presence or absence of a value. This type is so //! commonly used, its variants are also exported. -//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: A type +//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: a type //! for functions that may succeed or fail. Like [`Option`], its variants are //! exported as well. -//! * [`std::string`]::{[`String`], [`ToString`]}: Heap-allocated strings. -//! * [`std::vec`]::[`Vec`]: A growable, heap-allocated vector. +//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings. +//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated vector. //! //! [`mem::drop`]: crate::mem::drop //! [`std::borrow`]: crate::borrow From 25a49641911c21fa3cc7071b507923e6214b71c3 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 5 Jan 2021 17:52:24 -0800 Subject: [PATCH 05/18] Use heading for `std::prelude` and not `io::prelude` The heading style for `std::prelude` is to be consistent with the headings for `std` and `core`: `# The Rust Standard Library` and `# The Rust Core Library`, respectively. --- library/std/src/io/prelude.rs | 2 +- library/std/src/prelude/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/prelude.rs b/library/std/src/io/prelude.rs index 700f166daf77d..d80643101f2ed 100644 --- a/library/std/src/io/prelude.rs +++ b/library/std/src/io/prelude.rs @@ -1,4 +1,4 @@ -//! # The I/O Prelude +//! The I/O Prelude. //! //! The purpose of this module is to alleviate imports of many common I/O traits //! by adding a glob import to the top of I/O heavy modules: diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs index 08f3ff5f253c5..eb2095b819657 100644 --- a/library/std/src/prelude/mod.rs +++ b/library/std/src/prelude/mod.rs @@ -1,4 +1,4 @@ -//! The Rust Prelude. +//! # The Rust Prelude //! //! Rust comes with a variety of things in its standard library. However, if //! you had to manually import every single thing that you used, it would be From 77b5ced3aa864d85d5dfe706c7326b6612315092 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 17 Jan 2021 14:23:25 -0500 Subject: [PATCH 06/18] Fix formatting for removed lints - Don't add backticks for the reason a lint was removed. This is almost never a code block, and when it is the backticks should be in the reason itself. - Don't assume clippy is the only tool that needs to be checked for backwards compatibility --- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_lint/src/levels.rs | 3 +-- src/test/ui-fulldeps/lint-tool-test.stderr | 18 ++++++------- src/test/ui/lint/lint-removed-cmdline.stderr | 8 +++--- src/test/ui/lint/lint-removed.stderr | 2 +- .../ui/lint/lint-unexported-no-mangle.stderr | 16 ++++++------ src/tools/clippy/tests/ui/deprecated.stderr | 26 +++++++++---------- .../clippy/tests/ui/deprecated_old.stderr | 8 +++--- 8 files changed, 41 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 3971a3099823f..b17765998807f 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -387,7 +387,7 @@ impl LintStore { Some(new_name.to_owned()), ), Some(&Removed(ref reason)) => CheckLintNameResult::Warning( - format!("lint `{}` has been removed: `{}`", complete_name, reason), + format!("lint `{}` has been removed: {}", complete_name, reason), None, ), None => match self.lint_groups.get(&*complete_name) { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index fc8f84461f991..18cd25e5d2aa3 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -311,8 +311,7 @@ impl<'s> LintLevelsBuilder<'s> { |lint| { let msg = format!( "lint name `{}` is deprecated \ - and may not have an effect in the future. \ - Also `cfg_attr(cargo-clippy)` won't be necessary anymore", + and may not have an effect in the future.", name ); lint.build(&msg) diff --git a/src/test/ui-fulldeps/lint-tool-test.stderr b/src/test/ui-fulldeps/lint-tool-test.stderr index 5e1cb4fb843fd..2260477a91d39 100644 --- a/src/test/ui-fulldeps/lint-tool-test.stderr +++ b/src/test/ui-fulldeps/lint-tool-test.stderr @@ -1,4 +1,4 @@ -warning: lint name `test_lint` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_lint` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:9:23 | LL | #![cfg_attr(foo, warn(test_lint))] @@ -6,13 +6,13 @@ LL | #![cfg_attr(foo, warn(test_lint))] | = note: `#[warn(renamed_and_removed_lints)]` on by default -warning: lint name `clippy_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `clippy_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:13:9 | LL | #![deny(clippy_group)] | ^^^^^^^^^^^^ help: change it to: `clippy::group` -warning: lint name `test_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:29:9 | LL | #[allow(test_group)] @@ -26,19 +26,19 @@ LL | #[deny(this_lint_does_not_exist)] | = note: `#[warn(unknown_lints)]` on by default -warning: lint name `test_lint` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_lint` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:9:23 | LL | #![cfg_attr(foo, warn(test_lint))] | ^^^^^^^^^ help: change it to: `clippy::test_lint` -warning: lint name `clippy_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `clippy_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:13:9 | LL | #![deny(clippy_group)] | ^^^^^^^^^^^^ help: change it to: `clippy::group` -warning: lint name `test_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:29:9 | LL | #[allow(test_group)] @@ -52,13 +52,13 @@ LL | #![plugin(lint_tool_test)] | = note: `#[warn(deprecated)]` on by default -warning: lint name `test_lint` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_lint` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:9:23 | LL | #![cfg_attr(foo, warn(test_lint))] | ^^^^^^^^^ help: change it to: `clippy::test_lint` -warning: lint name `clippy_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `clippy_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:13:9 | LL | #![deny(clippy_group)] @@ -90,7 +90,7 @@ LL | #![deny(clippy_group)] | ^^^^^^^^^^^^ = note: `#[deny(clippy::test_group)]` implied by `#[deny(clippy::group)]` -warning: lint name `test_group` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore +warning: lint name `test_group` is deprecated and may not have an effect in the future. --> $DIR/lint-tool-test.rs:29:9 | LL | #[allow(test_group)] diff --git a/src/test/ui/lint/lint-removed-cmdline.stderr b/src/test/ui/lint/lint-removed-cmdline.stderr index 1c45c38774e5a..fc2ba92479cc6 100644 --- a/src/test/ui/lint/lint-removed-cmdline.stderr +++ b/src/test/ui/lint/lint-removed-cmdline.stderr @@ -1,16 +1,16 @@ -warning: lint `raw_pointer_derive` has been removed: `using derive with raw pointers is ok` +warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | = note: requested on the command line with `-D raw_pointer_derive` -warning: lint `raw_pointer_derive` has been removed: `using derive with raw pointers is ok` +warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | = note: requested on the command line with `-D raw_pointer_derive` -warning: lint `raw_pointer_derive` has been removed: `using derive with raw pointers is ok` +warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | = note: requested on the command line with `-D raw_pointer_derive` -warning: lint `raw_pointer_derive` has been removed: `using derive with raw pointers is ok` +warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | = note: requested on the command line with `-D raw_pointer_derive` diff --git a/src/test/ui/lint/lint-removed.stderr b/src/test/ui/lint/lint-removed.stderr index 44480d84203bd..dc0515b84820b 100644 --- a/src/test/ui/lint/lint-removed.stderr +++ b/src/test/ui/lint/lint-removed.stderr @@ -1,4 +1,4 @@ -warning: lint `raw_pointer_derive` has been removed: `using derive with raw pointers is ok` +warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok --> $DIR/lint-removed.rs:6:8 | LL | #[deny(raw_pointer_derive)] diff --git a/src/test/ui/lint/lint-unexported-no-mangle.stderr b/src/test/ui/lint/lint-unexported-no-mangle.stderr index 48d9b38a99b65..66d64e8937a2b 100644 --- a/src/test/ui/lint/lint-unexported-no-mangle.stderr +++ b/src/test/ui/lint/lint-unexported-no-mangle.stderr @@ -1,32 +1,32 @@ -warning: lint `private_no_mangle_fns` has been removed: `no longer a warning, `#[no_mangle]` functions always exported` +warning: lint `private_no_mangle_fns` has been removed: no longer a warning, `#[no_mangle]` functions always exported | = note: requested on the command line with `-F private_no_mangle_fns` -warning: lint `private_no_mangle_statics` has been removed: `no longer a warning, `#[no_mangle]` statics always exported` +warning: lint `private_no_mangle_statics` has been removed: no longer a warning, `#[no_mangle]` statics always exported | = note: requested on the command line with `-F private_no_mangle_statics` -warning: lint `private_no_mangle_fns` has been removed: `no longer a warning, `#[no_mangle]` functions always exported` +warning: lint `private_no_mangle_fns` has been removed: no longer a warning, `#[no_mangle]` functions always exported | = note: requested on the command line with `-F private_no_mangle_fns` -warning: lint `private_no_mangle_statics` has been removed: `no longer a warning, `#[no_mangle]` statics always exported` +warning: lint `private_no_mangle_statics` has been removed: no longer a warning, `#[no_mangle]` statics always exported | = note: requested on the command line with `-F private_no_mangle_statics` -warning: lint `private_no_mangle_fns` has been removed: `no longer a warning, `#[no_mangle]` functions always exported` +warning: lint `private_no_mangle_fns` has been removed: no longer a warning, `#[no_mangle]` functions always exported | = note: requested on the command line with `-F private_no_mangle_fns` -warning: lint `private_no_mangle_statics` has been removed: `no longer a warning, `#[no_mangle]` statics always exported` +warning: lint `private_no_mangle_statics` has been removed: no longer a warning, `#[no_mangle]` statics always exported | = note: requested on the command line with `-F private_no_mangle_statics` -warning: lint `private_no_mangle_fns` has been removed: `no longer a warning, `#[no_mangle]` functions always exported` +warning: lint `private_no_mangle_fns` has been removed: no longer a warning, `#[no_mangle]` functions always exported | = note: requested on the command line with `-F private_no_mangle_fns` -warning: lint `private_no_mangle_statics` has been removed: `no longer a warning, `#[no_mangle]` statics always exported` +warning: lint `private_no_mangle_statics` has been removed: no longer a warning, `#[no_mangle]` statics always exported | = note: requested on the command line with `-F private_no_mangle_statics` diff --git a/src/tools/clippy/tests/ui/deprecated.stderr b/src/tools/clippy/tests/ui/deprecated.stderr index 3429317498ed6..f361db6b147da 100644 --- a/src/tools/clippy/tests/ui/deprecated.stderr +++ b/src/tools/clippy/tests/ui/deprecated.stderr @@ -1,4 +1,4 @@ -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] @@ -6,73 +6,73 @@ LL | #[warn(clippy::unstable_as_slice)] | = note: `-D renamed-and-removed-lints` implied by `-D warnings` -error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:2:8 | LL | #[warn(clippy::unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` +error: lint `clippy::misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr --> $DIR/deprecated.rs:3:8 | LL | #[warn(clippy::misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unused_collect` has been removed: ``collect` has been marked as #[must_use] in rustc and that covers all cases of this lint` +error: lint `clippy::unused_collect` has been removed: `collect` has been marked as #[must_use] in rustc and that covers all cases of this lint --> $DIR/deprecated.rs:4:8 | LL | #[warn(clippy::unused_collect)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `invalid_value`` +error: lint `clippy::invalid_ref` has been removed: superseded by rustc lint `invalid_value` --> $DIR/deprecated.rs:5:8 | LL | #[warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::into_iter_on_array` has been removed: `this lint has been uplifted to rustc and is now called `array_into_iter`` +error: lint `clippy::into_iter_on_array` has been removed: this lint has been uplifted to rustc and is now called `array_into_iter` --> $DIR/deprecated.rs:6:8 | LL | #[warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unused_label` has been removed: `this lint has been uplifted to rustc and is now called `unused_labels`` +error: lint `clippy::unused_label` has been removed: this lint has been uplifted to rustc and is now called `unused_labels` --> $DIR/deprecated.rs:7:8 | LL | #[warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::regex_macro` has been removed: `the regex! macro has been removed from the regex crate in 2018` +error: lint `clippy::regex_macro` has been removed: the regex! macro has been removed from the regex crate in 2018 --> $DIR/deprecated.rs:8:8 | LL | #[warn(clippy::regex_macro)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted to rustc and is now called `drop_bounds`` +error: lint `clippy::drop_bounds` has been removed: this lint has been uplifted to rustc and is now called `drop_bounds` --> $DIR/deprecated.rs:9:8 | LL | #[warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::temporary_cstring_as_ptr` has been removed: `this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`` +error: lint `clippy::temporary_cstring_as_ptr` has been removed: this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr` --> $DIR/deprecated.rs:10:8 | LL | #[warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::panic_params` has been removed: `this lint has been uplifted to rustc and is now called `panic_fmt`` +error: lint `clippy::panic_params` has been removed: this lint has been uplifted to rustc and is now called `panic_fmt` --> $DIR/deprecated.rs:11:8 | LL | #[warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unknown_clippy_lints` has been removed: `this lint has been integrated into the `unknown_lints` rustc lint` +error: lint `clippy::unknown_clippy_lints` has been removed: this lint has been integrated into the `unknown_lints` rustc lint --> $DIR/deprecated.rs:12:8 | LL | #[warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] diff --git a/src/tools/clippy/tests/ui/deprecated_old.stderr b/src/tools/clippy/tests/ui/deprecated_old.stderr index 2fe1facf0c72d..b8550078c4600 100644 --- a/src/tools/clippy/tests/ui/deprecated_old.stderr +++ b/src/tools/clippy/tests/ui/deprecated_old.stderr @@ -1,4 +1,4 @@ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:1:8 | LL | #[warn(unstable_as_slice)] @@ -6,19 +6,19 @@ LL | #[warn(unstable_as_slice)] | = note: `-D renamed-and-removed-lints` implied by `-D warnings` -error: lint `unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` +error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:2:8 | LL | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ -error: lint `misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` +error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr --> $DIR/deprecated_old.rs:3:8 | LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:1:8 | LL | #[warn(unstable_as_slice)] From 96e9562a7eec294be3e8c8543dbf10c83b7d25ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 18 Jan 2021 00:00:00 +0000 Subject: [PATCH 07/18] Visit only terminators when removing landing pads No functional changes intended --- compiler/rustc_mir/src/shim.rs | 2 +- compiler/rustc_mir/src/transform/mod.rs | 4 +-- .../src/transform/no_landing_pads.rs | 27 +++++-------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir/src/shim.rs index b740dfaca328d..6aaf27bdcb5f1 100644 --- a/compiler/rustc_mir/src/shim.rs +++ b/compiler/rustc_mir/src/shim.rs @@ -81,7 +81,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' MirPhase::Const, &[&[ &add_moves_for_packed_drops::AddMovesForPackedDrops, - &no_landing_pads::NoLandingPads::new(tcx), + &no_landing_pads::NoLandingPads, &remove_noop_landing_pads::RemoveNoopLandingPads, &simplify::SimplifyCfg::new("make_shim"), &add_call_guards::CriticalCallEdges, diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index 11f7e6922ccbc..e509c35de40b8 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -433,7 +433,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[ // Remove all things only needed by analysis - &no_landing_pads::NoLandingPads::new(tcx), + &no_landing_pads::NoLandingPads, &simplify_branches::SimplifyBranches::new("initial"), &remove_noop_landing_pads::RemoveNoopLandingPads, &cleanup_post_borrowck::CleanupNonCodegenStatements, @@ -441,7 +441,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc // These next passes must be executed together &add_call_guards::CriticalCallEdges, &elaborate_drops::ElaborateDrops, - &no_landing_pads::NoLandingPads::new(tcx), + &no_landing_pads::NoLandingPads, // AddMovesForPackedDrops needs to run after drop // elaboration. &add_moves_for_packed_drops::AddMovesForPackedDrops, diff --git a/compiler/rustc_mir/src/transform/no_landing_pads.rs b/compiler/rustc_mir/src/transform/no_landing_pads.rs index 83954c93c04a1..5479f0cc5861d 100644 --- a/compiler/rustc_mir/src/transform/no_landing_pads.rs +++ b/compiler/rustc_mir/src/transform/no_landing_pads.rs @@ -2,42 +2,27 @@ //! specified. use crate::transform::MirPass; -use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use rustc_target::spec::PanicStrategy; -pub struct NoLandingPads<'tcx> { - tcx: TyCtxt<'tcx>, -} - -impl<'tcx> NoLandingPads<'tcx> { - pub fn new(tcx: TyCtxt<'tcx>) -> Self { - NoLandingPads { tcx } - } -} +pub struct NoLandingPads; -impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> { +impl<'tcx> MirPass<'tcx> for NoLandingPads { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { no_landing_pads(tcx, body) } } pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - if tcx.sess.panic_strategy() == PanicStrategy::Abort { - NoLandingPads::new(tcx).visit_body(body); - } -} - -impl<'tcx> MutVisitor<'tcx> for NoLandingPads<'tcx> { - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx + if tcx.sess.panic_strategy() != PanicStrategy::Abort { + return; } - fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) { + for block in body.basic_blocks_mut() { + let terminator = block.terminator_mut(); if let Some(unwind) = terminator.kind.unwind_mut() { unwind.take(); } - self.super_terminator(terminator, location); } } From d829e40c7b11d6ba41819b59b3fd0b0bd64e06ba Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Fri, 15 Jan 2021 18:05:11 +0100 Subject: [PATCH 08/18] Improve unknown external crate error --- compiler/rustc_resolve/src/late.rs | 7 +++++++ compiler/rustc_resolve/src/lib.rs | 14 ++++++++++---- .../edition-imports-virtual-2015-gated.stderr | 2 +- .../non-existent-2.rs | 2 +- .../non-existent-2.stderr | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 9de35a8006123..cf8c19a57349a 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -244,6 +244,13 @@ impl<'a> PathSource<'a> { // "function" here means "anything callable" rather than `DefKind::Fn`, // this is not precise but usually more helpful than just "value". Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind { + // the case of `::some_crate()` + ExprKind::Path(_, path) + if path.segments.len() == 2 + && path.segments[0].ident.name == kw::PathRoot => + { + "external crate" + } ExprKind::Path(_, path) => { let mut msg = "function"; if let Some(segment) = path.segments.iter().last() { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index c5b8f7d647ca7..f405c2d727db1 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2458,8 +2458,14 @@ impl<'a> Resolver<'a> { (format!("use of undeclared crate or module `{}`", ident), None) } } else { - let mut msg = - format!("could not find `{}` in `{}`", ident, path[i - 1].ident); + let parent = path[i - 1].ident.name; + let parent = if parent == kw::PathRoot { + "crate root".to_owned() + } else { + format!("`{}`", parent) + }; + + let mut msg = format!("could not find `{}` in {}", ident, parent); if ns == TypeNS || ns == ValueNS { let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS }; if let FindBindingResult::Binding(Ok(binding)) = @@ -2467,11 +2473,11 @@ impl<'a> Resolver<'a> { { let mut found = |what| { msg = format!( - "expected {}, found {} `{}` in `{}`", + "expected {}, found {} `{}` in {}", ns.descr(), what, ident, - path[i - 1].ident + parent ) }; if binding.module().is_some() { diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr index 56cbd882cca60..06605c6f2082e 100644 --- a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `E` --> $DIR/edition-imports-virtual-2015-gated.rs:8:5 | LL | gen_gated!(); - | ^^^^^^^^^^^^^ could not find `E` in `{{root}}` + | ^^^^^^^^^^^^^ could not find `E` in crate root | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs index 4f53108b3a938..61212f299bec7 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs @@ -2,5 +2,5 @@ fn main() { let s = ::xcrate::S; - //~^ ERROR failed to resolve: could not find `xcrate` in `{{root}}` + //~^ ERROR failed to resolve: could not find `xcrate` in crate root } diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr index 7395d01d8ac44..8b2a6933f37bf 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: could not find `xcrate` in `{{root}}` +error[E0433]: failed to resolve: could not find `xcrate` in crate root --> $DIR/non-existent-2.rs:4:15 | LL | let s = ::xcrate::S; - | ^^^^^^ could not find `xcrate` in `{{root}}` + | ^^^^^^ could not find `xcrate` in crate root error: aborting due to previous error From 38b77420e9e2b08edf739a36027139688d2c9283 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Mon, 18 Jan 2021 14:01:09 +0100 Subject: [PATCH 09/18] Add tests for resolution changes --- src/test/ui/resolve/crate-called-as-function.rs | 3 +++ .../ui/resolve/crate-called-as-function.stderr | 9 +++++++++ src/test/ui/resolve/missing-in-namespace.rs | 4 ++++ src/test/ui/resolve/missing-in-namespace.stderr | 14 ++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 src/test/ui/resolve/crate-called-as-function.rs create mode 100644 src/test/ui/resolve/crate-called-as-function.stderr create mode 100644 src/test/ui/resolve/missing-in-namespace.rs create mode 100644 src/test/ui/resolve/missing-in-namespace.stderr diff --git a/src/test/ui/resolve/crate-called-as-function.rs b/src/test/ui/resolve/crate-called-as-function.rs new file mode 100644 index 0000000000000..e8f52c0c029aa --- /dev/null +++ b/src/test/ui/resolve/crate-called-as-function.rs @@ -0,0 +1,3 @@ +fn main() { + ::foo() //~ cannot find external crate `foo` in the crate root +} diff --git a/src/test/ui/resolve/crate-called-as-function.stderr b/src/test/ui/resolve/crate-called-as-function.stderr new file mode 100644 index 0000000000000..eb42349aff1b6 --- /dev/null +++ b/src/test/ui/resolve/crate-called-as-function.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find external crate `foo` in the crate root + --> $DIR/crate-called-as-function.rs:2:7 + | +LL | ::foo() + | ^^^ not found in the crate root + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/resolve/missing-in-namespace.rs b/src/test/ui/resolve/missing-in-namespace.rs new file mode 100644 index 0000000000000..e1dedb072b77b --- /dev/null +++ b/src/test/ui/resolve/missing-in-namespace.rs @@ -0,0 +1,4 @@ +fn main() { + let _map = std::hahmap::HashMap::new(); + //~^ ERROR failed to resolve: could not find `hahmap` in `std +} diff --git a/src/test/ui/resolve/missing-in-namespace.stderr b/src/test/ui/resolve/missing-in-namespace.stderr new file mode 100644 index 0000000000000..8b292aeda5074 --- /dev/null +++ b/src/test/ui/resolve/missing-in-namespace.stderr @@ -0,0 +1,14 @@ +error[E0433]: failed to resolve: could not find `hahmap` in `std` + --> $DIR/missing-in-namespace.rs:2:29 + | +LL | let _map = std::hahmap::HashMap::new(); + | ^^^^^^^ not found in `std::hahmap` + | +help: consider importing this struct + | +LL | use std::collections::HashMap; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0433`. From 9abd80c0764e9ecbb6d2e52ab89d47bcda564588 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Mon, 18 Jan 2021 23:47:01 +0100 Subject: [PATCH 10/18] Fix internal rustdoc broken links As it was suggested in #81037 `SpecFromIter` is not in the scope and therefore (even it should fail), we get a warning when we try do document private intems in `rust/library/alloc/`. This fixes #81037 by adding the trait in the scope and also adding an `allow(unused_imports)` flag so that the compiler does not complain, Since the trait is not used per se in the code, it's just needed to have properly documented docs. --- library/alloc/src/vec/spec_from_iter_nested.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 6abd4ff2a3f0a..3acee44337906 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -1,6 +1,8 @@ use core::iter::TrustedLen; use core::ptr::{self}; +#[allow(unused_imports)] +use super::SpecFromIter; use super::{SpecExtend, Vec}; /// Another specialization trait for Vec::from_iter From 20d8478864333b2633509c530b66d52ffef91fbb Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 18 Jan 2021 03:02:47 +0000 Subject: [PATCH 11/18] Fix intersperse_fold --- library/core/src/iter/adapters/intersperse.rs | 5 ++-- library/core/tests/iter.rs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/adapters/intersperse.rs b/library/core/src/iter/adapters/intersperse.rs index 1d01e9b5fb7dc..2143509d71dc7 100644 --- a/library/core/src/iter/adapters/intersperse.rs +++ b/library/core/src/iter/adapters/intersperse.rs @@ -160,7 +160,7 @@ where } fn intersperse_fold( - mut iter: Peekable, + mut iter: I, init: B, mut f: F, mut separator: G, @@ -173,8 +173,7 @@ where { let mut accum = init; - // Use `peek()` first to avoid calling `next()` on an empty iterator. - if !needs_sep || iter.peek().is_some() { + if !needs_sep { if let Some(x) = iter.next() { accum = f(accum, x); } diff --git a/library/core/tests/iter.rs b/library/core/tests/iter.rs index bc5421bfb5f8f..fa259e68a4370 100644 --- a/library/core/tests/iter.rs +++ b/library/core/tests/iter.rs @@ -3562,6 +3562,35 @@ fn test_intersperse_size_hint() { assert_eq!([].iter().intersperse(&()).size_hint(), (0, Some(0))); } +#[test] +fn test_intersperse_fold() { + let v = (1..4).intersperse(9).fold(Vec::new(), |mut acc, x| { + acc.push(x); + acc + }); + assert_eq!(v.as_slice(), [1, 9, 2, 9, 3]); + + let mut iter = (1..4).intersperse(9); + assert_eq!(iter.next(), Some(1)); + let v = iter.fold(Vec::new(), |mut acc, x| { + acc.push(x); + acc + }); + assert_eq!(v.as_slice(), [9, 2, 9, 3]); +} + +#[test] +fn test_intersperse_collect_string() { + let contents = vec![1, 2, 3]; + + let contents_string = contents + .into_iter() + .map(|id| id.to_string()) + .intersperse(", ".to_owned()) + .collect::(); + assert_eq!(contents_string, "1, 2, 3"); +} + #[test] fn test_fold_specialization_intersperse() { let mut iter = (1..2).intersperse(0); From d926147ccbd9bda51a5f0754f62811c0699621e5 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 19 Jan 2021 01:59:45 -0500 Subject: [PATCH 12/18] Remove unnecessary `after_run` function It's called at the same time and in the same place as `after_krate`, so they can be combined. --- src/librustdoc/formats/renderer.rs | 15 +++++++++------ src/librustdoc/html/render/mod.rs | 27 +++++++++++++++------------ src/librustdoc/json/mod.rs | 11 ++++++----- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index e84a9853d9b7c..c91d6decc0b67 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -38,10 +38,14 @@ crate trait FormatRenderer<'tcx>: Clone { fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>; /// Post processing hook for cleanup and dumping output to files. - fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error>; - - /// Called after everything else to write out errors. - fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>; + /// + /// A handler is available if the renderer wants to report errors. + fn after_krate( + &mut self, + krate: &clean::Crate, + cache: &Cache, + diag: &rustc_errors::Handler, + ) -> Result<(), Error>; } /// Main method for rendering a crate. @@ -104,6 +108,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( } } - format_renderer.after_krate(&krate, &cache)?; - format_renderer.after_run(diag) + format_renderer.after_krate(&krate, &cache, diag) } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 2db89e8a7ca68..fc6ec62c14f51 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -523,17 +523,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { Ok((cx, krate)) } - fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> { - Arc::get_mut(&mut self.shared).unwrap().fs.close(); - let nb_errors = self.errors.iter().map(|err| diag.struct_err(&err).emit()).count(); - if nb_errors > 0 { - Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), "")) - } else { - Ok(()) - } - } - - fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> { + fn after_krate( + &mut self, + krate: &clean::Crate, + cache: &Cache, + diag: &rustc_errors::Handler, + ) -> Result<(), Error> { let final_file = self.dst.join(&*krate.name.as_str()).join("all.html"); let settings_file = self.dst.join("settings.html"); let crate_name = krate.name; @@ -596,7 +591,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { &style_files, ); self.shared.fs.write(&settings_file, v.as_bytes())?; - Ok(()) + + // Flush pending errors. + Arc::get_mut(&mut self.shared).unwrap().fs.close(); + let nb_errors = self.errors.iter().map(|err| diag.struct_err(&err).emit()).count(); + if nb_errors > 0 { + Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), "")) + } else { + Ok(()) + } } fn mod_item_in( diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index df7ab9b7361a0..64500c1d91161 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -199,7 +199,12 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(()) } - fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> { + fn after_krate( + &mut self, + krate: &clean::Crate, + cache: &Cache, + _diag: &rustc_errors::Handler, + ) -> Result<(), Error> { debug!("Done with crate"); let mut index = (*self.index).clone().into_inner(); index.extend(self.get_trait_items(cache)); @@ -245,8 +250,4 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { serde_json::ser::to_writer(&file, &output).unwrap(); Ok(()) } - - fn after_run(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> { - Ok(()) - } } From 9272d53c5a73198436f429a1a70e5d60afa995a7 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 19 Jan 2021 12:17:58 +0000 Subject: [PATCH 13/18] Stop `fold` at first None when iterator yield --- library/core/src/iter/adapters/intersperse.rs | 2 ++ library/core/tests/iter.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/library/core/src/iter/adapters/intersperse.rs b/library/core/src/iter/adapters/intersperse.rs index 2143509d71dc7..b1170f32ba161 100644 --- a/library/core/src/iter/adapters/intersperse.rs +++ b/library/core/src/iter/adapters/intersperse.rs @@ -176,6 +176,8 @@ where if !needs_sep { if let Some(x) = iter.next() { accum = f(accum, x); + } else { + return accum; } } diff --git a/library/core/tests/iter.rs b/library/core/tests/iter.rs index fa259e68a4370..78b4d1acaf5cd 100644 --- a/library/core/tests/iter.rs +++ b/library/core/tests/iter.rs @@ -3577,6 +3577,18 @@ fn test_intersperse_fold() { acc }); assert_eq!(v.as_slice(), [9, 2, 9, 3]); + + struct NoneAtStart(i32); // Produces: None, Some(2), Some(3), None, ... + impl Iterator for NoneAtStart { + type Item = i32; + fn next(&mut self) -> Option { + self.0 += 1; + Some(self.0).filter(|i| i % 3 != 1) + } + } + + let v = NoneAtStart(0).intersperse(1000).fold(0, |a, b| a + b); + assert_eq!(v, 0); } #[test] From 203df1764c778bbe861173753071219a7cace19a Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Tue, 19 Jan 2021 23:42:18 +0900 Subject: [PATCH 14/18] Fix typo in counters.rs formating -> formatting --- compiler/rustc_mir/src/transform/coverage/counters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/transform/coverage/counters.rs b/compiler/rustc_mir/src/transform/coverage/counters.rs index b5921aac56143..272a7bf961799 100644 --- a/compiler/rustc_mir/src/transform/coverage/counters.rs +++ b/compiler/rustc_mir/src/transform/coverage/counters.rs @@ -32,7 +32,7 @@ impl CoverageCounters { } /// Activate the `DebugCounters` data structures, to provide additional debug formatting - /// features when formating `CoverageKind` (counter) values. + /// features when formatting `CoverageKind` (counter) values. pub fn enable_debug(&mut self) { self.debug_counters.enable(); } From 3fb53c2c85a12ff6e0b0667d6be547c7aab29d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Tue, 19 Jan 2021 10:11:24 +0300 Subject: [PATCH 15/18] Fix ICE in mir when evaluating SizeOf on unsized type Fixes #80742 --- compiler/rustc_mir/src/interpret/step.rs | 11 ++++--- src/test/ui/mir/issue-80742.rs | 33 +++++++++++++++++++ src/test/ui/mir/issue-80742.stderr | 42 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/mir/issue-80742.rs create mode 100644 src/test/ui/mir/issue-80742.stderr diff --git a/compiler/rustc_mir/src/interpret/step.rs b/compiler/rustc_mir/src/interpret/step.rs index 95738db1f553c..6d447acbecf34 100644 --- a/compiler/rustc_mir/src/interpret/step.rs +++ b/compiler/rustc_mir/src/interpret/step.rs @@ -264,10 +264,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { NullaryOp(mir::NullOp::SizeOf, ty) => { let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty); let layout = self.layout_of(ty)?; - assert!( - !layout.is_unsized(), - "SizeOf nullary MIR operator called for unsized type" - ); + if layout.is_unsized() { + // FIXME: This should be a span_bug (#80742) + self.tcx.sess.delay_span_bug( + self.frame().current_span(), + &format!("SizeOf nullary MIR operator called for unsized type {}", ty), + ); + } self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), dest)?; } diff --git a/src/test/ui/mir/issue-80742.rs b/src/test/ui/mir/issue-80742.rs new file mode 100644 index 0000000000000..c06d182fd567d --- /dev/null +++ b/src/test/ui/mir/issue-80742.rs @@ -0,0 +1,33 @@ +// check-fail + +// This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place + +#![allow(incomplete_features)] +#![feature(const_evaluatable_checked)] +#![feature(const_generics)] + +use std::fmt::Debug; +use std::marker::PhantomData; +use std::mem::size_of; + +struct Inline +where + [u8; size_of::() + 1]: , +{ + _phantom: PhantomData, + buf: [u8; size_of::() + 1], +} + +impl Inline +where + [u8; size_of::() + 1]: , +{ + pub fn new(val: T) -> Inline { + todo!() + } +} + +fn main() { + let dst = Inline::::new(0); //~ ERROR + //~^ ERROR +} diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/mir/issue-80742.stderr new file mode 100644 index 0000000000000..2ec0e9505288b --- /dev/null +++ b/src/test/ui/mir/issue-80742.stderr @@ -0,0 +1,42 @@ +error[E0599]: no function or associated item named `new` found for struct `Inline` in the current scope + --> $DIR/issue-80742.rs:31:36 + | +LL | / struct Inline +LL | | where +LL | | [u8; size_of::() + 1]: , +LL | | { +LL | | _phantom: PhantomData, +LL | | buf: [u8; size_of::() + 1], +LL | | } + | |_- function or associated item `new` not found for this +... +LL | let dst = Inline::::new(0); + | ^^^ function or associated item not found in `Inline` + | + ::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL + | +LL | pub trait Debug { + | --------------- doesn't satisfy `dyn Debug: Sized` + | + = note: the method `new` exists but the following trait bounds were not satisfied: + `dyn Debug: Sized` + +error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time + --> $DIR/issue-80742.rs:31:15 + | +LL | struct Inline + | - required by this bound in `Inline` +... +LL | let dst = Inline::::new(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `dyn Debug` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct Inline + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0599. +For more information about an error, try `rustc --explain E0277`. From bc6720f872f759ba25329cc0a53d6bfa2c604341 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Tue, 19 Jan 2021 18:28:33 +0100 Subject: [PATCH 16/18] Add SpecFromIter ref in the comments directly --- library/alloc/src/vec/spec_from_iter_nested.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 3acee44337906..ec390c62165a5 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -1,13 +1,11 @@ use core::iter::TrustedLen; use core::ptr::{self}; -#[allow(unused_imports)] -use super::SpecFromIter; use super::{SpecExtend, Vec}; /// Another specialization trait for Vec::from_iter /// necessary to manually prioritize overlapping specializations -/// see [`SpecFromIter`] for details. +/// see [`SpecFromIter`](super::SpecFromIter) for details. pub(super) trait SpecFromIterNested { fn from_iter(iter: I) -> Self; } From 230d5b1e5f0a7e2e75be11c2324f23445df83850 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 19 Jan 2021 21:30:49 +0100 Subject: [PATCH 17/18] Stabilize std::panic::panic_any. --- library/std/src/panic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index d18b94b6c1aef..bb08fa35d17a3 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -31,7 +31,7 @@ pub use core::panic::{Location, PanicInfo}; /// accessed later using [`PanicInfo::payload`]. /// /// See the [`panic!`] macro for more information about panicking. -#[unstable(feature = "panic_any", issue = "78500")] +#[stable(feature = "panic_any", since = "1.51.0")] #[inline] pub fn panic_any(msg: M) -> ! { crate::panicking::begin_panic(msg); From 8cac04e8b862ba144c51dd4e1e9cb47caec4632b Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 19 Jan 2021 21:41:41 +0100 Subject: [PATCH 18/18] Make 'static bound on panic_any explicit. This was already implied because Any: 'static, but this makes it explicit. --- library/std/src/panic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index bb08fa35d17a3..0f568da459bef 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -33,7 +33,7 @@ pub use core::panic::{Location, PanicInfo}; /// See the [`panic!`] macro for more information about panicking. #[stable(feature = "panic_any", since = "1.51.0")] #[inline] -pub fn panic_any(msg: M) -> ! { +pub fn panic_any(msg: M) -> ! { crate::panicking::begin_panic(msg); }