From 54a6d4edbc56d99ecf6a461975acceb219b8a2d8 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Sun, 20 Nov 2022 14:19:12 -0800 Subject: [PATCH 01/10] Add `#![deny(unsafe_op_in_unsafe_fn)]` in liballoc tests --- library/alloc/tests/boxed.rs | 41 ++++++++++++++++++++++++++++++------ library/alloc/tests/lib.rs | 1 + library/alloc/tests/vec.rs | 3 ++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index 9e5123be98990..af49826ff30a3 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -102,8 +102,18 @@ unsafe impl const Allocator for ConstAllocator { let new_ptr = self.allocate(new_layout)?; if new_layout.size() > 0 { - new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), old_layout.size()); - self.deallocate(ptr, old_layout); + // Safety: `new_ptr` is valid for writes and `ptr` for reads of + // `old_layout.size()`, because `new_layout.size() >= + // old_layout.size()` (which is an invariant that must be upheld by + // callers). + unsafe { + new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), old_layout.size()); + } + // Safety: `ptr` is never used again is also an invariant which must + // be upheld by callers. + unsafe { + self.deallocate(ptr, old_layout); + } } Ok(new_ptr) } @@ -114,12 +124,21 @@ unsafe impl const Allocator for ConstAllocator { old_layout: Layout, new_layout: Layout, ) -> Result, AllocError> { - let new_ptr = self.grow(ptr, old_layout, new_layout)?; + // Safety: Invariants of `grow_zeroed` and `grow` are the same, and must + // be enforced by callers. + let new_ptr = unsafe { self.grow(ptr, old_layout, new_layout)? }; if new_layout.size() > 0 { let old_size = old_layout.size(); let new_size = new_layout.size(); let raw_ptr = new_ptr.as_mut_ptr(); - raw_ptr.add(old_size).write_bytes(0, new_size - old_size); + // Safety: + // - `grow` returned Ok, so the returned pointer must be valid for + // `new_size` bytes + // - `new_size` must be larger than `old_size`, which is an + // invariant which must be upheld by callers. + unsafe { + raw_ptr.add(old_size).write_bytes(0, new_size - old_size); + } } Ok(new_ptr) } @@ -137,8 +156,18 @@ unsafe impl const Allocator for ConstAllocator { let new_ptr = self.allocate(new_layout)?; if new_layout.size() > 0 { - new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), new_layout.size()); - self.deallocate(ptr, old_layout); + // Safety: `new_ptr` and `ptr` are valid for reads/writes of + // `new_layout.size()` because of the invariants of shrink, which + // include `new_layout.size()` being smaller than (or equal to) + // `old_layout.size()`. + unsafe { + new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), new_layout.size()); + } + // Safety: `ptr` is never used again is also an invariant which must + // be upheld by callers. + unsafe { + self.deallocate(ptr, old_layout); + } } Ok(new_ptr) } diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index d066ec03ee57e..d6d2b055b2395 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -48,6 +48,7 @@ #![feature(once_cell)] #![feature(drain_keep_rest)] #![deny(fuzzy_provenance_casts)] +#![deny(unsafe_op_in_unsafe_fn)] use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index e027118704478..7ebed0d5ca699 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1089,7 +1089,8 @@ fn test_into_iter_drop_allocator() { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - System.deallocate(ptr, layout) + // Safety: Invariants passed to caller. + unsafe { System.deallocate(ptr, layout) } } } From bed85a424650fbd96049a586e9ea707c0555d0ae Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 23 Nov 2022 16:30:50 -0500 Subject: [PATCH 02/10] unstable-book: Add page for the `abi_efiapi` feature --- .../src/language-features/abi-efiapi.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/doc/unstable-book/src/language-features/abi-efiapi.md diff --git a/src/doc/unstable-book/src/language-features/abi-efiapi.md b/src/doc/unstable-book/src/language-features/abi-efiapi.md new file mode 100644 index 0000000000000..11ef0cfdb1422 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/abi-efiapi.md @@ -0,0 +1,23 @@ +# `abi_efiapi` + +The tracking issue for this feature is: [#65815] + +[#65815]: https://github.com/rust-lang/rust/issues/65815 + +------------------------ + +The `efiapi` calling convention can be used for defining a function with +an ABI compatible with the UEFI Interfaces as defined in the [UEFI +Specification]. + +Example: + +```rust +#![feature(abi_efiapi)] + +extern "efiapi" { fn f1(); } + +extern "efiapi" fn f2() { todo!() } +``` + +[UEFI Specification]: https://uefi.org/specs/UEFI/2.10/ From 89271352741e54c08c89fe19b6832666a29a932d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 24 Nov 2022 18:45:02 +0000 Subject: [PATCH 03/10] Assert that we don't capture escaping bound vars in Fn trait selection --- .../src/traits/select/confirmation.rs | 13 ++++++++----- .../rustc_trait_selection/src/traits/select/mod.rs | 14 +++++++++----- compiler/rustc_trait_selection/src/traits/util.rs | 6 +++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index c0edbebed54ee..8f473ebb452ce 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -693,16 +693,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let gen_sig = substs.as_generator().poly_sig(); - // (1) Feels icky to skip the binder here, but OTOH we know - // that the self-type is an generator type and hence is + // NOTE: The self-type is a generator type and hence is // in fact unparameterized (or at least does not reference any - // regions bound in the obligation). Still probably some - // refactoring could make this nicer. + // regions bound in the obligation). + let self_ty = obligation + .predicate + .self_ty() + .no_bound_vars() + .expect("unboxed closure type should not capture bound vars from the predicate"); let trait_ref = super::util::generator_trait_ref_and_outputs( self.tcx(), obligation.predicate.def_id(), - obligation.predicate.skip_binder().self_ty(), // (1) + self_ty, gen_sig, ) .map_bound(|(trait_ref, ..)| trait_ref); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 9fe13fe296a16..2a1494e8952a1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2271,15 +2271,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?closure_sig); - // (1) Feels icky to skip the binder here, but OTOH we know - // that the self-type is an unboxed closure type and hence is + // NOTE: The self-type is an unboxed closure type and hence is // in fact unparameterized (or at least does not reference any - // regions bound in the obligation). Still probably some - // refactoring could make this nicer. + // regions bound in the obligation). + let self_ty = obligation + .predicate + .self_ty() + .no_bound_vars() + .expect("unboxed closure type should not capture bound vars from the predicate"); + closure_trait_ref_and_return_type( self.tcx(), obligation.predicate.def_id(), - obligation.predicate.skip_binder().self_ty(), // (1) + self_ty, closure_sig, util::TupleArgumentsFlag::No, ) diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 20d8a7a742c3a..a496cea0b005b 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -298,11 +298,11 @@ pub fn closure_trait_ref_and_return_type<'tcx>( sig: ty::PolyFnSig<'tcx>, tuple_arguments: TupleArgumentsFlag, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> { + assert!(!self_ty.has_escaping_bound_vars()); let arguments_tuple = match tuple_arguments { TupleArgumentsFlag::No => sig.skip_binder().inputs()[0], TupleArgumentsFlag::Yes => tcx.intern_tup(sig.skip_binder().inputs()), }; - debug_assert!(!self_ty.has_escaping_bound_vars()); let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]); sig.map_bound(|sig| (trait_ref, sig.output())) } @@ -313,7 +313,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>( self_ty: Ty<'tcx>, sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> { - debug_assert!(!self_ty.has_escaping_bound_vars()); + assert!(!self_ty.has_escaping_bound_vars()); let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]); sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty)) } @@ -324,7 +324,7 @@ pub fn future_trait_ref_and_outputs<'tcx>( self_ty: Ty<'tcx>, sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> { - debug_assert!(!self_ty.has_escaping_bound_vars()); + assert!(!self_ty.has_escaping_bound_vars()); let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty]); sig.map_bound(|sig| (trait_ref, sig.return_ty)) } From c7330c9fe82b698831105fd31f611fb46586fd3c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 24 Nov 2022 19:37:03 +0000 Subject: [PATCH 04/10] Also check that fn pointer candidates don't have escaping bound vars --- .../rustc_trait_selection/src/traits/select/confirmation.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 8f473ebb452ce..db0f230cf8dca 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -606,7 +606,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?obligation, "confirm_fn_pointer_candidate"); // Okay to skip binder; it is reintroduced below. - let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); + let self_ty = self + .infcx + .shallow_resolve(obligation.self_ty().no_bound_vars()) + .expect("fn pointer should not capture bound vars from predicate"); let sig = self_ty.fn_sig(self.tcx()); let trait_ref = closure_trait_ref_and_return_type( self.tcx(), From d945967779f8f4c72cb50e0793b039e36ecb9213 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 24 Nov 2022 19:55:47 +0000 Subject: [PATCH 05/10] Remove comment, simplify since we asserted fn ptr Self type has no bound vars --- .../src/traits/select/confirmation.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index db0f230cf8dca..e46441001b54d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -605,7 +605,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { { debug!(?obligation, "confirm_fn_pointer_candidate"); - // Okay to skip binder; it is reintroduced below. let self_ty = self .infcx .shallow_resolve(obligation.self_ty().no_bound_vars()) @@ -624,15 +623,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Confirm the `type Output: Sized;` bound that is present on `FnOnce` let cause = obligation.derived_cause(BuiltinDerivedObligation); - // The binder on the Fn obligation is "less" important than the one on - // the signature, as evidenced by how we treat it during projection. - // The safe thing to do here is to liberate it, though, which should - // have no worse effect than skipping the binder here. - let liberated_fn_ty = - self.infcx.replace_bound_vars_with_placeholders(obligation.predicate.rebind(self_ty)); - let output_ty = self - .infcx - .replace_bound_vars_with_placeholders(liberated_fn_ty.fn_sig(self.tcx()).output()); + let output_ty = self.infcx.replace_bound_vars_with_placeholders(sig.output()); let output_ty = normalize_with_depth_to( self, obligation.param_env, From 786ec7ccf1aacdd82ba7585618c335f8818b2a86 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 24 Nov 2022 23:36:26 +0100 Subject: [PATCH 06/10] Migrate source code elements style to CSS variables --- src/librustdoc/html/static/css/rustdoc.css | 7 +++++++ src/librustdoc/html/static/css/themes/ayu.css | 8 +++----- src/librustdoc/html/static/css/themes/dark.css | 10 ++-------- src/librustdoc/html/static/css/themes/light.css | 9 ++------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index d4e881ad832af..dad6a301f17ef 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1345,6 +1345,13 @@ a.test-arrow:hover { border-bottom: 1px solid var(--border-color); margin-bottom: 6px; } +#source-sidebar div.files > a:hover, details.dir-entry summary:hover, +#source-sidebar div.files > a:focus, details.dir-entry summary:focus { + background-color: var(--source-sidebar-background-hover); +} +#source-sidebar div.files > a.selected { + background-color: var(--source-sidebar-background-selected); +} #sidebar-toggle > button { font-size: inherit; font-weight: bold; diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index eb66377670c6b..de7db7d438c9f 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -84,6 +84,8 @@ Original by Dempfi (https://github.com/dempfi/ayu) --crate-search-div-hover-filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg) brightness(113%) contrast(76%); --crate-search-hover-border: #e0e0e0; + --source-sidebar-background-selected: #14191f; + --source-sidebar-background-hover: #14191f; } h1, h2, h3, h4 { @@ -208,12 +210,8 @@ pre.rust .kw-2, pre.rust .prelude-ty {} color: #fff; } #source-sidebar div.files > a:hover, details.dir-entry summary:hover, -#source-sidebar div.files > a:focus, details.dir-entry summary:focus { - background-color: #14191f; - color: #ffb44c; -} +#source-sidebar div.files > a:focus, details.dir-entry summary:focus, #source-sidebar div.files > a.selected { - background-color: #14191f; color: #ffb44c; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 44598a6b77866..d8929f3233864 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -79,6 +79,8 @@ --crate-search-div-hover-filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%); --crate-search-hover-border: #2196f3; + --source-sidebar-background-selected: #333; + --source-sidebar-background-hover: #444; } .content .item-info::before { color: #ccc; } @@ -105,14 +107,6 @@ details.rustdoc-toggle > summary::before { color: #888; } -#source-sidebar div.files > a:hover, details.dir-entry summary:hover, -#source-sidebar div.files > a:focus, details.dir-entry summary:focus { - background-color: #444; -} -#source-sidebar div.files > a.selected { - background-color: #333; -} - .scraped-example-list .scrape-help { border-color: #aaa; color: #eee; diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index f0db14fd59f53..ff6c68635338c 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -76,6 +76,8 @@ --crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%); --crate-search-hover-border: #717171; + --source-sidebar-background-selected: #fff; + --source-sidebar-background-hover: #e0e0e0; } .content .item-info::before { color: #ccc; } @@ -98,13 +100,6 @@ body.source .example-wrap pre.rust a { color: #888; } -#source-sidebar div.files > a:hover, details.dir-entry summary:hover, -#source-sidebar div.files > a:focus, details.dir-entry summary:focus { - background-color: #E0E0E0; -} -#source-sidebar div.files > a.selected { - background-color: #fff; -} .scraped-example-list .scrape-help { border-color: #555; color: #333; From 6fc52c6b8026ac71c455a553785989b0670103ef Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 24 Nov 2022 23:36:41 +0100 Subject: [PATCH 07/10] Extend GUI test to include more source code elements checks --- .../sidebar-source-code-display.goml | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml index abf8af77715c9..67f57405afc8f 100644 --- a/src/test/rustdoc-gui/sidebar-source-code-display.goml +++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml @@ -43,6 +43,7 @@ define-function: ( "#source-sidebar details[open] > .files a.selected", {"color": |color_hover|, "background-color": |background|}, )), + // Without hover or focus. ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle|})), // With focus. @@ -52,7 +53,8 @@ define-function: ( // With hover. ("move-cursor-to", "#sidebar-toggle > button"), ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle_hover|})), - // Without hover. + + // Without hover or focus. ("assert-css", ( "#source-sidebar details[open] > .files a:not(.selected)", {"color": |color|, "background-color": |background_toggle|}, @@ -70,7 +72,27 @@ define-function: ( "#source-sidebar details[open] > .files a:not(.selected)", {"color": |color_hover|, "background-color": |background_hover|}, )), - // Without hover. + + // Without hover or focus. + ("assert-css", ( + "#source-sidebar .dir-entry summary", + {"color": |color|, "background-color": |background_toggle|}, + )), + // With focus. + ("focus", "#source-sidebar .dir-entry summary"), + ("wait-for-css", ( + "#source-sidebar .dir-entry summary:focus", + {"color": |color_hover|, "background-color": |background_hover|}, + )), + ("focus", ".search-input"), + // With hover. + ("move-cursor-to", "#source-sidebar .dir-entry summary"), + ("assert-css", ( + "#source-sidebar .dir-entry summary:hover", + {"color": |color_hover|, "background-color": |background_hover|}, + )), + + // Without hover or focus. ("assert-css", ( "#source-sidebar details[open] > .folders > details > summary", {"color": |color|, "background-color": |background_toggle|}, From e6a4008d24cf91baf681014f301ff01b503f580a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 24 Nov 2022 23:39:49 +0100 Subject: [PATCH 08/10] Strenghten GUI test to include extra state in selector --- .../sidebar-source-code-display.goml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml index 67f57405afc8f..40ae4af81be45 100644 --- a/src/test/rustdoc-gui/sidebar-source-code-display.goml +++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml @@ -48,11 +48,17 @@ define-function: ( ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle|})), // With focus. ("focus", "#sidebar-toggle > button"), - ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle_hover|})), + ("assert-css", ( + "#sidebar-toggle > button:focus", + {"background-color": |background_toggle_hover|}, + )), ("focus", ".search-input"), // With hover. ("move-cursor-to", "#sidebar-toggle > button"), - ("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle_hover|})), + ("assert-css", ( + "#sidebar-toggle > button:hover", + {"background-color": |background_toggle_hover|}, + )), // Without hover or focus. ("assert-css", ( @@ -62,14 +68,14 @@ define-function: ( // With focus. ("focus", "#source-sidebar details[open] > .files a:not(.selected)"), ("wait-for-css", ( - "#source-sidebar details[open] > .files a:not(.selected)", + "#source-sidebar details[open] > .files a:not(.selected):focus", {"color": |color_hover|, "background-color": |background_hover|}, )), ("focus", ".search-input"), // With hover. ("move-cursor-to", "#source-sidebar details[open] > .files a:not(.selected)"), ("assert-css", ( - "#source-sidebar details[open] > .files a:not(.selected)", + "#source-sidebar details[open] > .files a:not(.selected):hover", {"color": |color_hover|, "background-color": |background_hover|}, )), @@ -100,14 +106,14 @@ define-function: ( // With focus. ("focus", "#source-sidebar details[open] > .folders > details > summary"), ("wait-for-css", ( - "#source-sidebar details[open] > .folders > details > summary", + "#source-sidebar details[open] > .folders > details > summary:focus", {"color": |color_hover|, "background-color": |background_hover|}, )), ("focus", ".search-input"), // With hover. ("move-cursor-to", "#source-sidebar details[open] > .folders > details > summary"), ("assert-css", ( - "#source-sidebar details[open] > .folders > details > summary", + "#source-sidebar details[open] > .folders > details > summary:hover", {"color": |color_hover|, "background-color": |background_hover|}, )), ], From fb3e724d7602675f147a9b80e70fb6bd6512738c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 27 Oct 2022 13:00:55 -0500 Subject: [PATCH 09/10] Don't set `is_preview` for clippy and rustfmt These have been shipped on stable for many years now and it would be very disruptive to ever remove them. Remove the `-preview` suffix from their dist components. --- src/bootstrap/dist.rs | 4 ---- src/bootstrap/download.rs | 2 ++ src/tools/build-manifest/src/versions.rs | 4 ++-- src/tools/bump-stage0/src/main.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index aacd2c7eab981..05e3321993782 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1153,7 +1153,6 @@ impl Step for Clippy { let mut tarball = Tarball::new(builder, "clippy", &target.triple); tarball.set_overlay(OverlayKind::Clippy); - tarball.is_preview(true); tarball.add_file(clippy, "bin", 0o755); tarball.add_file(cargoclippy, "bin", 0o755); tarball.add_legal_and_readme_to("share/doc/clippy"); @@ -1251,7 +1250,6 @@ impl Step for Rustfmt { .expect("cargo fmt expected to build - essential tool"); let mut tarball = Tarball::new(builder, "rustfmt", &target.triple); tarball.set_overlay(OverlayKind::Rustfmt); - tarball.is_preview(true); tarball.add_file(rustfmt, "bin", 0o755); tarball.add_file(cargofmt, "bin", 0o755); tarball.add_legal_and_readme_to("share/doc/rustfmt"); @@ -1512,8 +1510,6 @@ impl Step for Extended { format!("{}-{}", name, target.triple) } else if name == "rust-analyzer" { "rust-analyzer-preview".to_string() - } else if name == "clippy" { - "clippy-preview".to_string() } else if name == "rust-demangler" { "rust-demangler-preview".to_string() } else if name == "miri" { diff --git a/src/bootstrap/download.rs b/src/bootstrap/download.rs index d0f389df97344..430b3496d007c 100644 --- a/src/bootstrap/download.rs +++ b/src/bootstrap/download.rs @@ -326,6 +326,8 @@ impl Config { } let filename = format!("rustfmt-{version}-{build}.tar.xz", build = host.triple); + // cfg(bootstrap): will need to be changed from `rustfmt-preview` to `rustfmt` the next time you run `bump-stage0`. + // See self.download_component(DownloadSource::Dist, filename, "rustfmt-preview", &date, "stage0"); self.fix_bin_or_dylib(&bin_root.join("bin").join("rustfmt")); diff --git a/src/tools/build-manifest/src/versions.rs b/src/tools/build-manifest/src/versions.rs index dde9745afb785..66e6982d6b4d3 100644 --- a/src/tools/build-manifest/src/versions.rs +++ b/src/tools/build-manifest/src/versions.rs @@ -49,10 +49,10 @@ pkg_type! { Cargo = "cargo", HtmlDocs = "rust-docs", RustAnalysis = "rust-analysis", + Clippy = "clippy", + Rustfmt = "rustfmt", Rls = "rls"; preview = true, RustAnalyzer = "rust-analyzer"; preview = true, - Clippy = "clippy"; preview = true, - Rustfmt = "rustfmt"; preview = true, LlvmTools = "llvm-tools"; preview = true, Miri = "miri"; preview = true, JsonDocs = "rust-docs-json"; preview = true, diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs index aa346daf7e5f3..388203ee4637f 100644 --- a/src/tools/bump-stage0/src/main.rs +++ b/src/tools/bump-stage0/src/main.rs @@ -6,7 +6,7 @@ use std::convert::TryInto; const PATH: &str = "src/stage0.json"; const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo"]; -const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"]; +const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt"]; struct Tool { config: Config, From 6ed4f15940d94d290e23bb72df92c2fb73e8fbdc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 25 Nov 2022 08:47:59 +0100 Subject: [PATCH 10/10] RefCell::get_mut: fix typo and fix the same typo in a bunch of other places --- library/core/src/cell.rs | 2 +- src/tools/clippy/clippy_dev/src/setup/git_hook.rs | 2 +- src/tools/clippy/clippy_utils/src/hir_utils.rs | 2 +- src/tools/rust-analyzer/crates/flycheck/src/lib.rs | 2 +- src/tools/rust-analyzer/crates/hir-expand/src/lib.rs | 4 ++-- src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs | 2 +- .../rust-analyzer/crates/syntax/src/tests/sourcegen_ast.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index f2975d054572c..47cce2aa39b0c 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -1025,7 +1025,7 @@ impl RefCell { /// /// Since this method borrows `RefCell` mutably, it is statically guaranteed /// that no borrows to the underlying data exist. The dynamic checks inherent - /// in [`borrow_mut`] and most other methods of `RefCell` are therefor + /// in [`borrow_mut`] and most other methods of `RefCell` are therefore /// unnecessary. /// /// This method can only be called if `RefCell` can be mutably borrowed, diff --git a/src/tools/clippy/clippy_dev/src/setup/git_hook.rs b/src/tools/clippy/clippy_dev/src/setup/git_hook.rs index 1de5b1940bae1..c7c53bc69d0b8 100644 --- a/src/tools/clippy/clippy_dev/src/setup/git_hook.rs +++ b/src/tools/clippy/clippy_dev/src/setup/git_hook.rs @@ -6,7 +6,7 @@ use super::verify_inside_clippy_dir; /// Rusts setup uses `git rev-parse --git-common-dir` to get the root directory of the repo. /// I've decided against this for the sake of simplicity and to make sure that it doesn't install /// the hook if `clippy_dev` would be used in the rust tree. The hook also references this tool -/// for formatting and should therefor only be used in a normal clone of clippy +/// for formatting and should therefore only be used in a normal clone of clippy const REPO_GIT_DIR: &str = ".git"; const HOOK_SOURCE_FILE: &str = "util/etc/pre-commit.sh"; const HOOK_TARGET_FILE: &str = ".git/hooks/pre-commit"; diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index cf24ec8b67b90..abe10f3c81e51 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -113,7 +113,7 @@ impl HirEqInterExpr<'_, '_, '_> { } } - // eq_pat adds the HirIds to the locals map. We therefor call it last to make sure that + // eq_pat adds the HirIds to the locals map. We therefore call it last to make sure that // these only get added if the init and type is equal. both(&l.init, &r.init, |l, r| self.eq_expr(l, r)) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) diff --git a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs index 8a91d6066614f..ac086d4fe7433 100644 --- a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs +++ b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs @@ -362,7 +362,7 @@ impl FlycheckActor { /// A handle to a cargo process used for fly-checking. struct CargoHandle { /// The handle to the actual cargo process. As we cannot cancel directly from with - /// a read syscall dropping and therefor terminating the process is our best option. + /// a read syscall dropping and therefore terminating the process is our best option. child: JodChild, thread: jod_thread::JoinHandle>, receiver: Receiver, diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs index a5b499fe8d9d4..7352b003a491c 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs @@ -814,7 +814,7 @@ impl<'a> InFile<&'a SyntaxNode> { pub fn original_syntax_node(self, db: &dyn db::AstDatabase) -> Option> { // This kind of upmapping can only be achieved in attribute expanded files, - // as we don't have node inputs otherwise and therefor can't find an `N` node in the input + // as we don't have node inputs otherwise and therefore can't find an `N` node in the input if !self.file_id.is_macro() { return Some(self.map(Clone::clone)); } else if !self.file_id.is_attr_macro(db) { @@ -926,7 +926,7 @@ impl InFile { pub fn original_ast_node(self, db: &dyn db::AstDatabase) -> Option> { // This kind of upmapping can only be achieved in attribute expanded files, - // as we don't have node inputs otherwise and therefor can't find an `N` node in the input + // as we don't have node inputs otherwise and therefore can't find an `N` node in the input if !self.file_id.is_macro() { return Some(self); } else if !self.file_id.is_attr_macro(db) { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 4072ae585dbd9..c278ba2d7c5b3 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -157,7 +157,7 @@ config_data! { checkOnSave_noDefaultFeatures: Option = "null", /// Override the command rust-analyzer uses instead of `cargo check` for /// diagnostics on save. The command is required to output json and - /// should therefor include `--message-format=json` or a similar option. + /// should therefore include `--message-format=json` or a similar option. /// /// If you're changing this because you're using some tool wrapping /// Cargo, you might also want to change diff --git a/src/tools/rust-analyzer/crates/syntax/src/tests/sourcegen_ast.rs b/src/tools/rust-analyzer/crates/syntax/src/tests/sourcegen_ast.rs index 70b54843dbaab..712ef5f63b651 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/tests/sourcegen_ast.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/tests/sourcegen_ast.rs @@ -86,7 +86,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String { .traits .iter() .filter(|trait_name| { - // Loops have two expressions so this might collide, therefor manual impl it + // Loops have two expressions so this might collide, therefore manual impl it node.name != "ForExpr" && node.name != "WhileExpr" || trait_name.as_str() != "HasLoopBody" })