From d89fb1dee5bf47ae9bd9051b296da379e01f1755 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 18 Oct 2022 17:10:09 +0200 Subject: [PATCH 1/7] Stabilize proc_macro::Span::source_text Splits proc_macro::Span::source_text into a new feature gate and stabilizes it. --- library/proc_macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index f9c7d3e172c..8001fcff648 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -546,7 +546,7 @@ pub fn eq(&self, other: &Span) -> bool { /// Note: The observable result of a macro should only rely on the tokens and /// not on this source text. The result of this function is a best effort to /// be used for diagnostics only. - #[unstable(feature = "proc_macro_span", issue = "54725")] + #[stable(feature = "proc_macro_source_text", since = "CURRENT_RUSTC_VERSION")] pub fn source_text(&self) -> Option { self.0.source_text() } From a1d4ebe4961c107272f9764d1908227a3cd04092 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 19 Oct 2022 17:14:50 +0200 Subject: [PATCH 2/7] Fix regression in item-decl highlighting --- src/librustdoc/html/static/css/rustdoc.css | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 7b6f52b0acf..bc2d9403cca 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -229,44 +229,44 @@ h1 a, color: var(--main-color); } -span.enum, a.enum, -span.struct, a.struct, -span.union, a.union, -span.primitive, a.primitive, -span.type, a.type, -span.foreigntype, a.foreigntype { +.content span.enum, .content a.enum, +.content span.struct, .content a.struct, +.content span.union, .content a.union, +.content span.primitive, .content a.primitive, +.content span.type, .content a.type, +.content span.foreigntype, .content a.foreigntype { color: var(--type-link-color); } -span.trait, a.trait, -span.traitalias, a.traitalias { +.content span.trait, .content a.trait, +.content span.traitalias, .content a.traitalias { color: var(--trait-link-color); } -span.associatedtype, a.associatedtype, -span.constant, a.constant, -span.static, a.static { +.content span.associatedtype, .content a.associatedtype, +.content span.constant, .content a.constant, +.content span.static, .content a.static { color: var(--assoc-item-link-color); } -span.fn, a.fn, -.fnname, -span.method, a.method, -span.tymethod, a.tymethod { +.content span.fn, .content a.fn, +.content .fnname, +.content span.method, .content a.method, +.content span.tymethod, .content a.tymethod { color: var(--function-link-color); } -span.attr, a.attr, -span.derive, a.derive, -span.macro, a.macro { +.content span.attr, .content a.attr, +.content span.derive, .content a.derive, +.content span.macro, .content a.macro { color: var(--macro-link-color); } -span.mod, a.mod { +.content span.mod, .content a.mod { color: var(--mod-link-color); } -span.keyword, a.keyword { +.content span.keyword, .content a.keyword { color: var(--keyword-link-color); } From b4e06a74cacf79e43eed03df621a5d58d1d7ee9a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 19 Oct 2022 17:15:11 +0200 Subject: [PATCH 3/7] Add regression test for item-decl highlighting --- src/test/rustdoc-gui/item-decl-colors.goml | 74 ++++++++++++++++++++++ src/test/rustdoc-gui/sidebar.goml | 11 ++-- src/test/rustdoc-gui/src/test_docs/lib.rs | 18 ++++++ 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc-gui/item-decl-colors.goml diff --git a/src/test/rustdoc-gui/item-decl-colors.goml b/src/test/rustdoc-gui/item-decl-colors.goml new file mode 100644 index 00000000000..ce688287a74 --- /dev/null +++ b/src/test/rustdoc-gui/item-decl-colors.goml @@ -0,0 +1,74 @@ +// This test ensures that the color of the items in the type decl are working as expected. +define-function: ( + "check-colors", + ( + theme, + attr_color, + trait_color, + struct_color, + enum_color, + primitive_color, + constant_color, + fn_color, + assoc_type_color, + ), + [ + ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"), + ("show-text", true), + ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), + ("reload"), + ("assert-css", (".item-decl .code-attribute", {"color": |attr_color|}, ALL)), + ("assert-css", (".item-decl .trait", {"color": |trait_color|}, ALL)), + // We need to add `code` here because otherwise it would select the parent too. + ("assert-css", (".item-decl code .struct", {"color": |struct_color|}, ALL)), + ("assert-css", (".item-decl .enum", {"color": |enum_color|}, ALL)), + ("assert-css", (".item-decl .primitive", {"color": |primitive_color|}, ALL)), + ("goto", "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithoutGenerics.html"), + ("assert-css", (".item-decl .constant", {"color": |constant_color|}, ALL)), + ("assert-css", (".item-decl .fnname", {"color": |fn_color|}, ALL)), + ("assert-css", (".item-decl .associatedtype", {"color": |assoc_type_color|}, ALL)), + ], +) + +call-function: ( + "check-colors", + { + "theme": "ayu", + "attr_color": "rgb(153, 153, 153)", + "trait_color": "rgb(57, 175, 215)", + "struct_color": "rgb(255, 160, 165)", + "enum_color": "rgb(255, 160, 165)", + "primitive_color": "rgb(255, 160, 165)", + "constant_color": "rgb(57, 175, 215)", + "fn_color": "rgb(253, 214, 135)", + "assoc_type_color": "rgb(57, 175, 215)", + }, +) +call-function: ( + "check-colors", + { + "theme": "dark", + "attr_color": "rgb(153, 153, 153)", + "trait_color": "rgb(183, 140, 242)", + "struct_color": "rgb(45, 191, 184)", + "enum_color": "rgb(45, 191, 184)", + "primitive_color": "rgb(45, 191, 184)", + "constant_color": "rgb(210, 153, 29)", + "fn_color": "rgb(43, 171, 99)", + "assoc_type_color": "rgb(210, 153, 29)", + }, +) +call-function: ( + "check-colors", + { + "theme": "light", + "attr_color": "rgb(153, 153, 153)", + "trait_color": "rgb(110, 79, 201)", + "struct_color": "rgb(173, 55, 138)", + "enum_color": "rgb(173, 55, 138)", + "primitive_color": "rgb(173, 55, 138)", + "constant_color": "rgb(56, 115, 173)", + "fn_color": "rgb(173, 124, 55)", + "assoc_type_color": "rgb(56, 115, 173)", + }, +) diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml index 54193234af9..79a7f3349ab 100644 --- a/src/test/rustdoc-gui/sidebar.goml +++ b/src/test/rustdoc-gui/sidebar.goml @@ -19,11 +19,12 @@ assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Modules") assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Macros") assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Structs") assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Enums") -assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Traits") -assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Functions") -assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Type Definitions") -assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Unions") -assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Keywords") +assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Constants") +assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Traits") +assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions") +assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions") +assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions") +assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords") assert-text: ("#structs + .item-table .item-left > a", "Foo") click: "#structs + .item-table .item-left > a" diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index cc0efe7231a..77617e10beb 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -5,6 +5,7 @@ #![crate_name = "test_docs"] #![feature(rustdoc_internals)] #![feature(doc_cfg)] +#![feature(associated_type_defaults)] /*! Enable the feature some-feature to enjoy @@ -386,3 +387,20 @@ pub fn second_fn<'a>(&'a self) { pub unsafe fn unsafe_fn() {} pub fn safe_fn() {} + +#[repr(C)] +pub struct WithGenerics { + s: S, + t: T, + e: E, + p: P, +} + +pub const CONST: u8 = 0; + +pub trait TraitWithoutGenerics { + const C: u8 = CONST; + type T = SomeType; + + fn foo(); +} From 0dd329f687f2b3bb229d86f1df3341ea8976e565 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 19 Oct 2022 13:57:39 -0700 Subject: [PATCH 4/7] rustdoc: remove no-op CSS `nav.sub { font-size: 1rem }` This rule originated as a `font-size: 16px`, when body had `font-size: 13px` set in 4fd061c426902b0904c65e64a3780b21f9ab3afb. It remained even when body's font size was bumped up to 16px, 4d5f4ff5e9297dcad21612f9dd20ae4598b5b7e2, making the rule a no-op, and was carried forward when it was converted to 1rem in cc18120425a5c571a968d850c75cc935a8321136. --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 7b6f52b0acf..cc36513f47f 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -703,7 +703,6 @@ pre, .rustdoc.source .example-wrap { nav.sub { position: relative; - font-size: 1rem; flex-grow: 1; margin-bottom: 25px; } From 19bc8fb05ab083a315ee4285b4df7822e8bb1e24 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Wed, 19 Oct 2022 23:54:00 +0100 Subject: [PATCH 5/7] Remove extra spaces --- library/core/src/sync/atomic.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index cdc47e17938..edc68d6fae5 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -294,7 +294,7 @@ impl AtomicBool { /// ``` /// use std::sync::atomic::AtomicBool; /// - /// let atomic_true = AtomicBool::new(true); + /// let atomic_true = AtomicBool::new(true); /// let atomic_false = AtomicBool::new(false); /// ``` #[inline] @@ -1179,7 +1179,7 @@ pub const fn into_inner(self) -> *mut T { /// use std::sync::atomic::{AtomicPtr, Ordering}; /// /// let ptr = &mut 5; - /// let some_ptr = AtomicPtr::new(ptr); + /// let some_ptr = AtomicPtr::new(ptr); /// /// let value = some_ptr.load(Ordering::Relaxed); /// ``` @@ -1206,7 +1206,7 @@ pub fn load(&self, order: Ordering) -> *mut T { /// use std::sync::atomic::{AtomicPtr, Ordering}; /// /// let ptr = &mut 5; - /// let some_ptr = AtomicPtr::new(ptr); + /// let some_ptr = AtomicPtr::new(ptr); /// /// let other_ptr = &mut 10; /// @@ -1238,7 +1238,7 @@ pub fn store(&self, ptr: *mut T, order: Ordering) { /// use std::sync::atomic::{AtomicPtr, Ordering}; /// /// let ptr = &mut 5; - /// let some_ptr = AtomicPtr::new(ptr); + /// let some_ptr = AtomicPtr::new(ptr); /// /// let other_ptr = &mut 10; /// @@ -1290,9 +1290,9 @@ pub fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T { /// use std::sync::atomic::{AtomicPtr, Ordering}; /// /// let ptr = &mut 5; - /// let some_ptr = AtomicPtr::new(ptr); + /// let some_ptr = AtomicPtr::new(ptr); /// - /// let other_ptr = &mut 10; + /// let other_ptr = &mut 10; /// /// let value = some_ptr.compare_and_swap(ptr, other_ptr, Ordering::Relaxed); /// ``` @@ -1333,9 +1333,9 @@ pub fn compare_and_swap(&self, current: *mut T, new: *mut T, order: Ordering) -> /// use std::sync::atomic::{AtomicPtr, Ordering}; /// /// let ptr = &mut 5; - /// let some_ptr = AtomicPtr::new(ptr); + /// let some_ptr = AtomicPtr::new(ptr); /// - /// let other_ptr = &mut 10; + /// let other_ptr = &mut 10; /// /// let value = some_ptr.compare_exchange(ptr, other_ptr, /// Ordering::SeqCst, Ordering::Relaxed); From c5c9f748296854c522395d917bbfc819f74f3a8a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 19 Oct 2022 23:35:47 +0000 Subject: [PATCH 6/7] Erase regions before checking for default in uninitialized binding error --- .../src/diagnostics/conflict_errors.rs | 11 +++++- src/test/ui/borrowck/issue-103250.rs | 37 +++++++++++++++++++ src/test/ui/borrowck/issue-103250.stderr | 17 +++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/borrowck/issue-103250.rs create mode 100644 src/test/ui/borrowck/issue-103250.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2a8bd4d30ab..583bc2e281d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -492,10 +492,17 @@ fn suggest_assign_value( let Some(default_trait) = tcx.get_diagnostic_item(sym::Default) else { return false; }; + // Regions are already solved, so we must use a fresh InferCtxt, + // but the type has region variables, so erase those. tcx.infer_ctxt() .build() - .type_implements_trait(default_trait, ty, ty::List::empty(), param_env) - .may_apply() + .type_implements_trait( + default_trait, + tcx.erase_regions(ty), + ty::List::empty(), + param_env, + ) + .must_apply_modulo_regions() }; let assign_value = match ty.kind() { diff --git a/src/test/ui/borrowck/issue-103250.rs b/src/test/ui/borrowck/issue-103250.rs new file mode 100644 index 00000000000..46565f61ca9 --- /dev/null +++ b/src/test/ui/borrowck/issue-103250.rs @@ -0,0 +1,37 @@ +// edition:2021 + +type TranslateFn = Box String>; + +pub struct DeviceCluster { + devices: Vec, +} + +impl DeviceCluster { + pub async fn do_something(&mut self) -> Result> { + let mut last_error: Box; + + for device in &mut self.devices { + match device.do_something().await { + Ok(info) => { + return Ok(info); + } + Err(e) => {} + } + } + + Err(last_error) + //~^ ERROR used binding `last_error` isn't initialized + } +} + +pub struct Device { + translate_fn: Option, +} + +impl Device { + pub async fn do_something(&mut self) -> Result> { + Ok(String::from("")) + } +} + +fn main() {} diff --git a/src/test/ui/borrowck/issue-103250.stderr b/src/test/ui/borrowck/issue-103250.stderr new file mode 100644 index 00000000000..4a237835222 --- /dev/null +++ b/src/test/ui/borrowck/issue-103250.stderr @@ -0,0 +1,17 @@ +error[E0381]: used binding `last_error` isn't initialized + --> $DIR/issue-103250.rs:22:13 + | +LL | let mut last_error: Box; + | -------------- binding declared here but left uninitialized +... +LL | Err(last_error) + | ^^^^^^^^^^ `last_error` used here but it isn't initialized + | +help: consider assigning a value + | +LL | let mut last_error: Box = todo!(); + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0381`. From 205006660a4bd36b7cdf4b0938cfd50a4e785ca7 Mon Sep 17 00:00:00 2001 From: Andrew Pollack Date: Wed, 19 Oct 2022 19:02:55 +0000 Subject: [PATCH 7/7] Adjusting test to needs-unwind, with linking issue --- .../test-fn-signature-verification-for-explicit-return-type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs b/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs index 02fee1a00da..585874e273d 100644 --- a/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs +++ b/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs @@ -1,5 +1,5 @@ // run-pass -// ignore-fuchsia Test must be run out-of-process +// needs-unwind (#73509) #![feature(test)]