From 0b5000776083365b71fe78a3379f87a75cf9fb8a Mon Sep 17 00:00:00 2001 From: Infra <1011X@users.noreply.github.com> Date: Fri, 8 Jul 2022 01:29:35 -0400 Subject: [PATCH 1/8] improve print styles this change removes some interactive elements in `@media print` form. more specifically, it removes the source links, the expand/collapse toggle buttons, and the `#copy-path` button. it also adjusts some spacing and removes the `.top-doc` description completely if it's currently collapsed. --- src/librustdoc/html/static/css/rustdoc.css | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b3dc60d880bbf..a37cb6f6fe09e 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2056,9 +2056,19 @@ in storage.js plus the media query with (min-width: 701px) } @media print { - nav.sub, .content .out-of-band { + nav.sidebar, nav.sub, .content .out-of-band, a.srclink, #copy-path, + details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before, + details.rustdoc-toggle.top-doc > summary { display: none; } + + .docblock { + margin-left: 0; + } + + main { + padding-left: 15px; + } } @media (max-width: 464px) { From 933cbd40692709e810a5c2a3c4caf50345c9d394 Mon Sep 17 00:00:00 2001 From: Infra <1011X@users.noreply.github.com> Date: Fri, 8 Jul 2022 01:54:55 -0400 Subject: [PATCH 2/8] try to fix tidy issues --- src/librustdoc/html/static/css/rustdoc.css | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index a37cb6f6fe09e..c145942c84304 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2057,18 +2057,18 @@ in storage.js plus the media query with (min-width: 701px) @media print { nav.sidebar, nav.sub, .content .out-of-band, a.srclink, #copy-path, - details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before, - details.rustdoc-toggle.top-doc > summary { + details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before, + details.rustdoc-toggle.top-doc > summary { display: none; } - - .docblock { - margin-left: 0; - } - - main { - padding-left: 15px; - } + + .docblock { + margin-left: 0; + } + + main { + padding-left: 15px; + } } @media (max-width: 464px) { From aa7bcaa8c33be862c9802d64979c3202decd554b Mon Sep 17 00:00:00 2001 From: Infra <1011X@users.noreply.github.com> Date: Fri, 8 Jul 2022 12:44:16 -0400 Subject: [PATCH 3/8] set all padding for main element in print --- src/librustdoc/html/static/css/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index c145942c84304..294b0a1e9c92f 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2067,7 +2067,7 @@ in storage.js plus the media query with (min-width: 701px) } main { - padding-left: 15px; + padding: 10px; } } From 0201f2f5912e002f988d192037a2d5822b8f39b2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume.gomez@huawei.com> Date: Sat, 9 Jul 2022 15:54:14 +0200 Subject: [PATCH 4/8] Fix display of search result crate filter dropdown --- src/librustdoc/html/static/css/rustdoc.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b3dc60d880bbf..7185106b2d0d7 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -924,7 +924,6 @@ table, #crate-search { min-width: 115px; margin-top: 5px; - margin-left: 0.25em; padding-left: 0.3125em; padding-right: 23px; border: 1px solid; @@ -941,6 +940,8 @@ table, background-size: 20px; background-position: calc(100% - 1px) 56%; background-image: /* AUTOREPLACE: */url("down-arrow.svg"); + max-width: 100%; + text-overflow: ellipsis; } .search-container { margin-top: 4px; From 9d5e6e2fc3709d5491af7e199a4d18c11170cffd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume.gomez@huawei.com> Date: Sat, 9 Jul 2022 15:54:36 +0200 Subject: [PATCH 5/8] Add GUI test for search result crate filter dropdown --- .../rustdoc-gui/search-result-display.goml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/rustdoc-gui/search-result-display.goml b/src/test/rustdoc-gui/search-result-display.goml index ff792eced703a..b31905a126a0e 100644 --- a/src/test/rustdoc-gui/search-result-display.goml +++ b/src/test/rustdoc-gui/search-result-display.goml @@ -10,3 +10,31 @@ size: (600, 100) // As counter-intuitive as it may seem, in this width, the width is "100%", which is why // when computed it's larger. assert-css: (".search-results div.desc", {"width": "570px"}) + +// Check that the crate filter `<select>` is correctly handled when it goes to next line. +// To do so we need to update the length of one of its `<option>`. +size: (900, 900) + +// First we check the current width and position. +assert-css: ("#crate-search", {"width": "222px"}) +compare-elements-position-near: ( + "#crate-search", + "#search-settings .search-results-title", + {"y": 5}, +) + +// Then we update the text of one of the `<option>`. +text: ( + "#crate-search option", + "sdjfaksdjfaksjdbfkadsbfkjsadbfkdsbkfbsadkjfbkdsabfkadsfkjdsafa", +) + +// Then we compare again. +assert-css: ("#crate-search", {"width": "640px"}) +compare-elements-position-near-false: ( + "#crate-search", + "#search-settings .search-results-title", + {"y": 5}, +) +// And we check that the `<select>` isn't bigger than its container. +assert-css: ("#search", {"width": "640px"}) From bda83e6543fa89fd64efafdfb93924fede792850 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda <takoyaki0316@gmail.com> Date: Sun, 10 Jul 2022 03:18:56 +0900 Subject: [PATCH 6/8] avoid some `&str` to `String` conversions --- compiler/rustc_borrowck/src/diagnostics/mod.rs | 8 ++++---- compiler/rustc_middle/src/mir/mod.rs | 8 +++----- compiler/rustc_mir_transform/src/check_packed_ref.rs | 4 +--- compiler/rustc_resolve/src/diagnostics.rs | 5 +---- compiler/rustc_resolve/src/late/diagnostics.rs | 6 ++---- compiler/rustc_span/src/hygiene.rs | 3 +-- .../rustc_trait_selection/src/traits/specialize/mod.rs | 2 +- compiler/rustc_typeck/src/check/_match.rs | 2 +- compiler/rustc_typeck/src/check/demand.rs | 4 ++-- compiler/rustc_typeck/src/check/op.rs | 4 ++-- compiler/rustc_typeck/src/hir_wf_check.rs | 2 +- compiler/rustc_typeck/src/lib.rs | 5 ++--- .../src/structured_errors/wrong_number_of_generic_args.rs | 4 ++-- 13 files changed, 23 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 6fea6941085ce..d296a1a0ac61b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -597,16 +597,16 @@ impl UseSpans<'_> { } /// Describe the span associated with a use of a place. - pub(super) fn describe(&self) -> String { + pub(super) fn describe(&self) -> &str { match *self { UseSpans::ClosureUse { generator_kind, .. } => { if generator_kind.is_some() { - " in generator".to_string() + " in generator" } else { - " in closure".to_string() + " in closure" } } - _ => String::new(), + _ => "", } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index e7d7317456c74..fa3d05e2f81a5 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1929,12 +1929,10 @@ impl BorrowKind { } } - pub fn describe_mutability(&self) -> String { + pub fn describe_mutability(&self) -> &str { match *self { - BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => { - "immutable".to_string() - } - BorrowKind::Mut { .. } => "mutable".to_string(), + BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => "immutable", + BorrowKind::Mut { .. } => "mutable", } } } diff --git a/compiler/rustc_mir_transform/src/check_packed_ref.rs b/compiler/rustc_mir_transform/src/check_packed_ref.rs index 4bf66cd4c9f2e..2eb38941f1a50 100644 --- a/compiler/rustc_mir_transform/src/check_packed_ref.rs +++ b/compiler/rustc_mir_transform/src/check_packed_ref.rs @@ -39,13 +39,11 @@ fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) { let message = if tcx.generics_of(def_id).own_requires_monomorphization() { "`#[derive]` can't be used on a `#[repr(packed)]` struct with \ type or const parameters (error E0133)" - .to_string() } else { "`#[derive]` can't be used on a `#[repr(packed)]` struct that \ does not derive Copy (error E0133)" - .to_string() }; - lint.build(&message).emit(); + lint.build(message).emit(); }); } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 0f58206eee9f3..072a52079e340 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -928,10 +928,7 @@ impl<'a> Resolver<'a> { "generic parameters with a default cannot use \ forward declared identifiers" ); - err.span_label( - span, - "defaulted generic parameters cannot be forward declared".to_string(), - ); + err.span_label(span, "defaulted generic parameters cannot be forward declared"); err } ResolutionError::ParamInTyOfConstParam(name) => { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 03cb1cfcfc9ef..677d7036b2f1b 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -349,10 +349,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { err.code(rustc_errors::error_code!(E0424)); err.span_label(span, match source { - PathSource::Pat => "`self` value is a keyword and may not be bound to variables or shadowed" - .to_string(), - _ => "`self` value is a keyword only available in methods with a `self` parameter" - .to_string(), + PathSource::Pat => "`self` value is a keyword and may not be bound to variables or shadowed", + _ => "`self` value is a keyword only available in methods with a `self` parameter", }); if let Some((fn_kind, span)) = &self.diagnostic_metadata.current_function { // The current function has a `self' parameter, but we were unable to resolve diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 955db72157c6a..3df4dfb74b319 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -629,8 +629,7 @@ pub fn debug_hygiene_data(verbose: bool) -> String { if verbose { format!("{:#?}", data) } else { - let mut s = String::from(""); - s.push_str("Expansions:"); + let mut s = String::from("Expansions:"); let mut debug_expn_data = |(id, expn_data): (&ExpnId, &ExpnData)| { s.push_str(&format!( "\n{:?}: parent: {:?}, call_site_ctxt: {:?}, def_site_ctxt: {:?}, kind: {:?}", diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index a80354897d618..13848d378909d 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -406,7 +406,7 @@ fn report_conflicting_impls( let mut err = err.build(&msg); match tcx.span_of_impl(overlap.with_impl) { Ok(span) => { - err.span_label(span, "first implementation here".to_string()); + err.span_label(span, "first implementation here"); err.span_label( impl_span, diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index deaadf0e5c84a..79e402b542a60 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -263,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if let ExprKind::Block(block, _) = &then_expr.kind && let Some(expr) = &block.expr { - err.span_label(expr.span, "found here".to_string()); + err.span_label(expr.span, "found here"); } err.note("`if` expressions without `else` evaluate to `()`"); err.help("consider adding an `else` block that evaluates to the expected type"); diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 53ca027bb57f5..eb7e52c5ed376 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -317,9 +317,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .tcx .is_diagnostic_item(sym::Result, expected_adt.did()) { - vec!["Ok(())".to_string()] + vec!["Ok(())"] } else if self.tcx.is_diagnostic_item(sym::Option, expected_adt.did()) { - vec!["None".to_string(), "Some(())".to_string()] + vec!["None", "Some(())"] } else { return; }; diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 42893789957f4..0887c27ea360c 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -565,9 +565,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .is_ok() { let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() { - ("( /* arguments */ )".to_string(), Applicability::HasPlaceholders) + ("( /* arguments */ )", Applicability::HasPlaceholders) } else { - ("()".to_string(), Applicability::MaybeIncorrect) + ("()", Applicability::MaybeIncorrect) }; err.span_suggestion_verbose( diff --git a/compiler/rustc_typeck/src/hir_wf_check.rs b/compiler/rustc_typeck/src/hir_wf_check.rs index 4392b9aada978..5117dc49fb531 100644 --- a/compiler/rustc_typeck/src/hir_wf_check.rs +++ b/compiler/rustc_typeck/src/hir_wf_check.rs @@ -86,7 +86,7 @@ fn diagnostic_hir_wf_check<'tcx>( let errors = fulfill.select_all_or_error(&infcx); if !errors.is_empty() { - tracing::debug!("Wf-check got errors for {:?}: {:?}", ty, errors); + debug!("Wf-check got errors for {:?}: {:?}", ty, errors); for error in errors { if error.obligation.predicate == self.predicate { // Save the cause from the greatest depth - this corresponds diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 08c194ec0b605..dd712fd7ed71d 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -252,7 +252,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { let mut diag = struct_span_err!(tcx.sess, generics_param_span.unwrap_or(main_span), E0131, "{}", msg); if let Some(generics_param_span) = generics_param_span { - let label = "`main` cannot have generic parameters".to_string(); + let label = "`main` cannot have generic parameters"; diag.span_label(generics_param_span, label); } diag.emit(); @@ -307,8 +307,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span); if !return_ty.bound_vars().is_empty() { let msg = "`main` function return type is not allowed to have generic \ - parameters" - .to_owned(); + parameters"; struct_span_err!(tcx.sess, return_ty_span, E0131, "{}", msg).emit(); error = true; } diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index 72a32dade4eef..265a57c392944 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -126,8 +126,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn kind(&self) -> String { - if self.missing_lifetimes() { "lifetime".to_string() } else { "generic".to_string() } + fn kind(&self) -> &str { + if self.missing_lifetimes() { "lifetime" } else { "generic" } } fn num_provided_args(&self) -> usize { From ed542df9bc798bbdfe4d18308b9a6528bebf0461 Mon Sep 17 00:00:00 2001 From: Smitty <me@smitop.com> Date: Sat, 9 Jul 2022 18:52:37 -0400 Subject: [PATCH 7/8] Fix binary name in help message for test binaries --- library/test/src/cli.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 000f5fa3f5860..f981b9c495476 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -196,6 +196,7 @@ Test Attributes: pub fn parse_opts(args: &[String]) -> Option<OptRes> { // Parse matches. let opts = optgroups(); + let binary = args.get(0).map(|c| &**c).unwrap_or("..."); let args = args.get(1..).unwrap_or(args); let matches = match opts.parse(args) { Ok(m) => m, @@ -205,7 +206,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> { // Check if help was requested. if matches.opt_present("h") { // Show help and do nothing more. - usage(&args[0], &opts); + usage(binary, &opts); return None; } From e9292b76525aaaaf3ad96b1231defdffc309fa03 Mon Sep 17 00:00:00 2001 From: Maybe Waffle <waffle.lapkin@gmail.com> Date: Sun, 10 Jul 2022 13:17:33 +0400 Subject: [PATCH 8/8] fill new tracking issue for `feature(strict_provenance_atomic_ptr)` --- library/core/src/sync/atomic.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index b32dcfefacda8..3780d330547b7 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -1487,7 +1487,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_ptr_add(&self, val: usize, order: Ordering) -> *mut T { self.fetch_byte_add(val.wrapping_mul(core::mem::size_of::<T>()), order) } @@ -1531,7 +1531,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_ptr_sub(&self, val: usize, order: Ordering) -> *mut T { self.fetch_byte_sub(val.wrapping_mul(core::mem::size_of::<T>()), order) } @@ -1566,7 +1566,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_byte_add(&self, val: usize, order: Ordering) -> *mut T { #[cfg(not(bootstrap))] // SAFETY: data races are prevented by atomic intrinsics. @@ -1609,7 +1609,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_byte_sub(&self, val: usize, order: Ordering) -> *mut T { #[cfg(not(bootstrap))] // SAFETY: data races are prevented by atomic intrinsics. @@ -1667,7 +1667,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_or(&self, val: usize, order: Ordering) -> *mut T { #[cfg(not(bootstrap))] // SAFETY: data races are prevented by atomic intrinsics. @@ -1724,7 +1724,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_and(&self, val: usize, order: Ordering) -> *mut T { #[cfg(not(bootstrap))] // SAFETY: data races are prevented by atomic intrinsics. @@ -1779,7 +1779,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[cfg(target_has_atomic = "ptr")] - #[unstable(feature = "strict_provenance_atomic_ptr", issue = "95228")] + #[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")] pub fn fetch_xor(&self, val: usize, order: Ordering) -> *mut T { #[cfg(not(bootstrap))] // SAFETY: data races are prevented by atomic intrinsics.