From 2484a182399918eab2e25b3532936eebf09d9bb5 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 24 Oct 2022 17:25:30 +0200 Subject: [PATCH 01/15] Add `compile_fail` to `let_underscore_drop` example --- compiler/rustc_lint/src/let_underscore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index 78f355ec3d0..b51c1679f9f 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -11,7 +11,7 @@ declare_lint! { /// scope. /// /// ### Example - /// ``` + /// ```compile_fail /// struct SomeStruct; /// impl Drop for SomeStruct { /// fn drop(&mut self) { From 3ff010bdbc0b138e8761cedcec4d6174b2e7ab61 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 24 Oct 2022 17:30:29 +0200 Subject: [PATCH 02/15] Update compiler/rustc_lint/src/let_underscore.rs --- compiler/rustc_lint/src/let_underscore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index b51c1679f9f..c59f56756c6 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -11,7 +11,7 @@ declare_lint! { /// scope. /// /// ### Example - /// ```compile_fail + /// ```rust,compile_fail /// struct SomeStruct; /// impl Drop for SomeStruct { /// fn drop(&mut self) { From 6b5f2753f75d5f9f10eee9252a1346a72f1c9ee2 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 24 Oct 2022 18:00:41 +0200 Subject: [PATCH 03/15] Update let_underscore.rs --- compiler/rustc_lint/src/let_underscore.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index c59f56756c6..11ceb4e22ae 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -11,7 +11,7 @@ declare_lint! { /// scope. /// /// ### Example - /// ```rust,compile_fail + /// ``` /// struct SomeStruct; /// impl Drop for SomeStruct { /// fn drop(&mut self) { @@ -56,7 +56,7 @@ declare_lint! { /// of at end of scope, which is typically incorrect. /// /// ### Example - /// ```compile_fail + /// ```rust,compile_fail /// use std::sync::{Arc, Mutex}; /// use std::thread; /// let data = Arc::new(Mutex::new(0)); From 6279d092c32bc60be2eeb91210f1d875e28b6b72 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 24 Oct 2022 15:56:01 +0000 Subject: [PATCH 04/15] Make `pointer::byte_offset_from` more generic --- library/core/src/ptr/const_ptr.rs | 2 +- library/core/src/ptr/mut_ptr.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 67e59460d74..7a8b1a9a65b 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -684,7 +684,7 @@ impl *const T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize { + pub const unsafe fn byte_offset_from(self, origin: *const U) -> isize { // SAFETY: the caller must uphold the safety contract for `offset_from`. unsafe { self.cast::().offset_from(origin.cast::()) } } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 0bb2566fd4c..40c2e97a669 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -861,7 +861,7 @@ impl *mut T { #[unstable(feature = "pointer_byte_offsets", issue = "96283")] #[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize { + pub const unsafe fn byte_offset_from(self, origin: *const U) -> isize { // SAFETY: the caller must uphold the safety contract for `offset_from`. unsafe { self.cast::().offset_from(origin.cast::()) } } From 8ecbb7e39a2bbd082fbac4b05eb715bda2c91fce Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 24 Oct 2022 21:25:30 +0200 Subject: [PATCH 05/15] fix the lint as requested --- src/tools/lint-docs/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs index 857feb77325..3842a649c6f 100644 --- a/src/tools/lint-docs/src/lib.rs +++ b/src/tools/lint-docs/src/lib.rs @@ -37,10 +37,8 @@ impl Lint { } fn is_ignored(&self) -> bool { - self.doc - .iter() - .filter(|line| line.starts_with("```rust")) - .all(|line| line.contains(",ignore")) + let blocks: Vec<_> = self.doc.iter().filter(|line| line.starts_with("```rust")).collect(); + !blocks.is_empty() && blocks.iter().all(|line| line.contains(",ignore")) } /// Checks the doc style of the lint. From 30b522365bf3a2be8248c1572054e5988db0e1fd Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 25 Oct 2022 00:59:32 +0200 Subject: [PATCH 06/15] Fix failing examples --- compiler/rustc_lint/src/let_underscore.rs | 2 +- .../rustc_lint/src/opaque_hidden_inferred_bound.rs | 14 +++++++++----- compiler/rustc_lint_defs/src/builtin.rs | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index 11ceb4e22ae..e1177c10414 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -11,7 +11,7 @@ declare_lint! { /// scope. /// /// ### Example - /// ``` + /// ```rust /// struct SomeStruct; /// impl Drop for SomeStruct { /// fn drop(&mut self) { diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 7f6f4a0abb4..ccc53707f7c 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -26,19 +26,23 @@ declare_lint! { /// /// ### Example /// - /// ``` + /// ```rust + /// trait Duh {} + /// + /// impl Duh for i32 {} + /// /// trait Trait { - /// type Assoc: Send; + /// type Assoc: Duh; /// } /// /// struct Struct; /// - /// impl Trait for Struct { - /// type Assoc = i32; + /// impl Trait for F { + /// type Assoc = F; /// } /// /// fn test() -> impl Trait { - /// Struct + /// 42 /// } /// ``` /// diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 61ee467f595..1fc2c454864 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -605,7 +605,7 @@ declare_lint! { /// /// ### Example /// - /// ``` + /// ```rust /// #[warn(unused_tuple_struct_fields)] /// struct S(i32, i32, i32); /// let s = S(1, 2, 3); @@ -1154,7 +1154,7 @@ declare_lint! { /// /// ### Example /// - /// ```compile_fail + /// ```rust,compile_fail /// #[repr(packed)] /// pub struct Foo { /// field1: u64, @@ -2615,7 +2615,7 @@ declare_lint! { /// /// ### Example /// - /// ```compile_fail + /// ```rust,compile_fail /// # #![allow(unused)] /// enum E { /// A, @@ -3986,7 +3986,7 @@ declare_lint! { /// /// ### Example /// - /// ``` + /// ```rust /// #![allow(test_unstable_lint)] /// ``` /// From 5fd561dea24d137734195d8d2dc82fe179553b2d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 14 Nov 2022 13:38:53 +0100 Subject: [PATCH 07/15] avoid memory leak in mpsc test --- library/std/src/sync/mpsc/tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/sync/mpsc/tests.rs b/library/std/src/sync/mpsc/tests.rs index 82c52eb4fef..1e52a4a705c 100644 --- a/library/std/src/sync/mpsc/tests.rs +++ b/library/std/src/sync/mpsc/tests.rs @@ -713,10 +713,11 @@ fn issue_39364() { let t = thread::spawn(move || { thread::sleep(Duration::from_millis(300)); let _ = tx.clone(); - crate::mem::forget(tx); + // Don't drop; hand back to caller. + tx }); let _ = rx.recv_timeout(Duration::from_millis(500)); - t.join().unwrap(); + let _tx = t.join().unwrap(); // delay dropping until end of test let _ = rx.recv_timeout(Duration::from_millis(500)); } From 55746a44795c763715d96ae184044fe2d409bee5 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Mon, 14 Nov 2022 23:52:41 +0530 Subject: [PATCH 08/15] Fix test/ui/issues/issue-30490.rs Since the empty main is used for `not(unix)`, all the targets that will use this empty main will also need `allow(unused_imports)`. Originally part of https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh --- src/test/ui/issues/issue-30490.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/issues/issue-30490.rs b/src/test/ui/issues/issue-30490.rs index 68d9c4de4d1..4f0eeac8f71 100644 --- a/src/test/ui/issues/issue-30490.rs +++ b/src/test/ui/issues/issue-30490.rs @@ -10,7 +10,7 @@ // This test checks to avoid that regression. #![cfg_attr(unix, feature(rustc_private))] -#![cfg_attr(windows, allow(unused_imports))] +#![cfg_attr(not(unix), allow(unused_imports))] #[cfg(unix)] extern crate libc; From 8b346754eda9e9cddeeb50b1103d461cf3196843 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 14 Nov 2022 14:11:30 -0700 Subject: [PATCH 09/15] rustdoc: remove no-op CSS `.popover { font-size: 1rem }` This rule was added in cc4f804829ae because the help popover inherited the font-size from the help button "?" icon. It doesn't inherit this any more, because it was moved from being nested inside the link to sharing a wrapper DIV with it. --- src/librustdoc/html/static/css/rustdoc.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 3f295b96dc5..b83bb405dc2 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -920,7 +920,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ } .popover { - font-size: 1rem; position: absolute; right: 0; z-index: 2; @@ -928,7 +927,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ margin-top: 7px; border-radius: 3px; border: 1px solid var(--border-color); - font-size: 1rem; --popover-arrow-offset: 11px; } From bd84709298a096fb9518e1f14ee58d3a5bd21ae2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 14 Nov 2022 14:34:46 -0700 Subject: [PATCH 10/15] rustdoc: add test case for font size in help popover --- src/test/rustdoc-gui/help-page.goml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/rustdoc-gui/help-page.goml b/src/test/rustdoc-gui/help-page.goml index 521e14748af..392f17bfd47 100644 --- a/src/test/rustdoc-gui/help-page.goml +++ b/src/test/rustdoc-gui/help-page.goml @@ -3,6 +3,7 @@ goto: "file://" + |DOC_PATH| + "/help.html" size: (1000, 1000) // Try desktop size first. wait-for: "#help" assert-css: ("#help", {"display": "block"}) +assert-css: ("#help dd", {"font-size": "16px"}) click: "#help-button > a" assert-css: ("#help", {"display": "block"}) compare-elements-property: (".sub", "#help", ["offsetWidth"]) @@ -18,6 +19,7 @@ size: (1000, 1000) // Only supported on desktop. assert-false: "#help" click: "#help-button > a" assert-css: ("#help", {"display": "block"}) +assert-css: ("#help dd", {"font-size": "16px"}) click: "#help-button > a" assert-css: ("#help", {"display": "none"}) compare-elements-property-false: (".sub", "#help", ["offsetWidth"]) From 70ad2f53449995eb632eb9ef8f7740b34afb46b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 13 Nov 2022 05:12:44 +0100 Subject: [PATCH 11/15] respect visibility & stability of inherent associated types --- .../rustc_hir_analysis/src/astconv/mod.rs | 83 ++++++++++--------- .../assoc-inherent-private.rs | 23 +++++ .../assoc-inherent-private.stderr | 21 +++++ .../assoc-inherent-unstable.rs | 6 ++ .../assoc-inherent-unstable.stderr | 11 +++ .../auxiliary/assoc-inherent-unstable.rs | 11 +++ src/test/ui/traits/item-privacy.stderr | 5 +- 7 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 src/test/ui/associated-inherent-types/assoc-inherent-private.rs create mode 100644 src/test/ui/associated-inherent-types/assoc-inherent-private.stderr create mode 100644 src/test/ui/associated-inherent-types/assoc-inherent-unstable.rs create mode 100644 src/test/ui/associated-inherent-types/assoc-inherent-unstable.stderr create mode 100644 src/test/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 4518cf30acd..7a2d98dbe75 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1917,17 +1917,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } // see if we can satisfy using an inherent associated type - for impl_ in tcx.inherent_impls(adt_def.did()) { - let assoc_ty = tcx.associated_items(impl_).find_by_name_and_kind( - tcx, - assoc_ident, - ty::AssocKind::Type, - *impl_, - ); - if let Some(assoc_ty) = assoc_ty { - let ty = tcx.type_of(assoc_ty.def_id); - return Ok((ty, DefKind::AssocTy, assoc_ty.def_id)); - } + for &impl_ in tcx.inherent_impls(adt_def.did()) { + let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, impl_) else { + continue; + }; + // FIXME(inherent_associated_types): This does not substitute parameters. + let ty = tcx.type_of(assoc_ty_did); + return Ok((ty, DefKind::AssocTy, assoc_ty_did)); } } @@ -2014,37 +2010,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }; let trait_did = bound.def_id(); - let (assoc_ident, def_scope) = - tcx.adjust_ident_and_get_scope(assoc_ident, trait_did, hir_ref_id); - - // We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead - // of calling `filter_by_name_and_kind`. - let item = tcx.associated_items(trait_did).in_definition_order().find(|i| { - i.kind.namespace() == Namespace::TypeNS - && i.ident(tcx).normalize_to_macros_2_0() == assoc_ident - }); - // Assume that if it's not matched, there must be a const defined with the same name - // but it was used in a type position. - let Some(item) = item else { + let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did) else { + // Assume that if it's not matched, there must be a const defined with the same name + // but it was used in a type position. let msg = format!("found associated const `{assoc_ident}` when type was expected"); let guar = tcx.sess.struct_span_err(span, &msg).emit(); return Err(guar); }; - let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, assoc_segment, bound); + let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound); let ty = self.normalize_ty(span, ty); - let kind = DefKind::AssocTy; - if !item.visibility(tcx).is_accessible_from(def_scope, tcx) { - let kind = kind.descr(item.def_id); - let msg = format!("{} `{}` is private", kind, assoc_ident); - tcx.sess - .struct_span_err(span, &msg) - .span_label(span, &format!("private {}", kind)) - .emit(); - } - tcx.check_stability(item.def_id, Some(hir_ref_id), span, None); - if let Some(variant_def_id) = variant_resolution { tcx.struct_span_lint_hir( AMBIGUOUS_ASSOCIATED_ITEMS, @@ -2063,7 +2039,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }; could_refer_to(DefKind::Variant, variant_def_id, ""); - could_refer_to(kind, item.def_id, " also"); + could_refer_to(DefKind::AssocTy, assoc_ty_did, " also"); lint.span_suggestion( span, @@ -2076,7 +2052,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }, ); } - Ok((ty, kind, item.def_id)) + Ok((ty, DefKind::AssocTy, assoc_ty_did)) + } + + fn lookup_assoc_ty( + &self, + ident: Ident, + block: hir::HirId, + span: Span, + scope: DefId, + ) -> Option { + let tcx = self.tcx(); + let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, block); + + // We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead + // of calling `find_by_name_and_kind`. + let item = tcx.associated_items(scope).in_definition_order().find(|i| { + i.kind.namespace() == Namespace::TypeNS + && i.ident(tcx).normalize_to_macros_2_0() == ident + })?; + + let kind = DefKind::AssocTy; + if !item.visibility(tcx).is_accessible_from(def_scope, tcx) { + let kind = kind.descr(item.def_id); + let msg = format!("{kind} `{ident}` is private"); + let def_span = self.tcx().def_span(item.def_id); + tcx.sess + .struct_span_err_with_code(span, &msg, rustc_errors::error_code!(E0624)) + .span_label(span, &format!("private {kind}")) + .span_label(def_span, &format!("{kind} defined here")) + .emit(); + } + tcx.check_stability(item.def_id, Some(block), span, None); + + Some(item.def_id) } fn qpath_to_ty( diff --git a/src/test/ui/associated-inherent-types/assoc-inherent-private.rs b/src/test/ui/associated-inherent-types/assoc-inherent-private.rs new file mode 100644 index 00000000000..53158195443 --- /dev/null +++ b/src/test/ui/associated-inherent-types/assoc-inherent-private.rs @@ -0,0 +1,23 @@ +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +mod m { + pub struct T; + impl T { + type P = (); + } +} +type U = m::T::P; //~ ERROR associated type `P` is private + +mod n { + pub mod n { + pub struct T; + impl T { + pub(super) type P = bool; + } + } + type U = n::T::P; +} +type V = n::n::T::P; //~ ERROR associated type `P` is private + +fn main() {} diff --git a/src/test/ui/associated-inherent-types/assoc-inherent-private.stderr b/src/test/ui/associated-inherent-types/assoc-inherent-private.stderr new file mode 100644 index 00000000000..d67b45dae3f --- /dev/null +++ b/src/test/ui/associated-inherent-types/assoc-inherent-private.stderr @@ -0,0 +1,21 @@ +error[E0624]: associated type `P` is private + --> $DIR/assoc-inherent-private.rs:10:10 + | +LL | type P = (); + | ------ associated type defined here +... +LL | type U = m::T::P; + | ^^^^^^^ private associated type + +error[E0624]: associated type `P` is private + --> $DIR/assoc-inherent-private.rs:21:10 + | +LL | pub(super) type P = bool; + | ----------------- associated type defined here +... +LL | type V = n::n::T::P; + | ^^^^^^^^^^ private associated type + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0624`. diff --git a/src/test/ui/associated-inherent-types/assoc-inherent-unstable.rs b/src/test/ui/associated-inherent-types/assoc-inherent-unstable.rs new file mode 100644 index 00000000000..34b4e47bf46 --- /dev/null +++ b/src/test/ui/associated-inherent-types/assoc-inherent-unstable.rs @@ -0,0 +1,6 @@ +// aux-crate:aux=assoc-inherent-unstable.rs +// edition: 2021 + +type Data = aux::Owner::Data; //~ ERROR use of unstable library feature 'data' + +fn main() {} diff --git a/src/test/ui/associated-inherent-types/assoc-inherent-unstable.stderr b/src/test/ui/associated-inherent-types/assoc-inherent-unstable.stderr new file mode 100644 index 00000000000..c0be8bfd79b --- /dev/null +++ b/src/test/ui/associated-inherent-types/assoc-inherent-unstable.stderr @@ -0,0 +1,11 @@ +error[E0658]: use of unstable library feature 'data' + --> $DIR/assoc-inherent-unstable.rs:4:13 + | +LL | type Data = aux::Owner::Data; + | ^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(data)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs b/src/test/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs new file mode 100644 index 00000000000..6b71ffc97b5 --- /dev/null +++ b/src/test/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs @@ -0,0 +1,11 @@ +#![feature(staged_api)] +#![feature(inherent_associated_types)] +#![stable(feature = "main", since = "1.0.0")] + +#[stable(feature = "main", since = "1.0.0")] +pub struct Owner; + +impl Owner { + #[unstable(feature = "data", issue = "none")] + pub type Data = (); +} diff --git a/src/test/ui/traits/item-privacy.stderr b/src/test/ui/traits/item-privacy.stderr index 7f78b37ba84..f137a298a7f 100644 --- a/src/test/ui/traits/item-privacy.stderr +++ b/src/test/ui/traits/item-privacy.stderr @@ -162,9 +162,12 @@ error[E0223]: ambiguous associated type LL | let _: S::C; | ^^^^ help: use fully-qualified syntax: `::C` -error: associated type `A` is private +error[E0624]: associated type `A` is private --> $DIR/item-privacy.rs:119:12 | +LL | type A = u8; + | ------ associated type defined here +... LL | let _: T::A; | ^^^^ private associated type From 155a5535a68c959f511278dc6c21c06cbafca2f8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 14 Nov 2022 15:27:04 -0700 Subject: [PATCH 12/15] rustdoc: remove no-op CSS `.main-header { justify-content }` This rule was added in 152e8889052adaaa6c12652486292be34059713c to push the out-of-band content to the right while allowing it to line wrap when it got too big. The idea was that the justification rule would fill the space between the `

` element and the `
` element. A later commit, 3cb03cb34247383ffb67a017ae70134741e8c4da, flattened the in-band element into the `

`, copying the `flex-grow` rule. This means the `

` element now grows to fill the space, so there's no need to justify-content any more. This commit also adds a test case for this. --- src/librustdoc/html/static/css/rustdoc.css | 1 - .../rustdoc-gui/type-declation-overflow.goml | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 3f295b96dc5..114959d7377 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -159,7 +159,6 @@ h1.fqn { .main-heading { display: flex; flex-wrap: wrap; - justify-content: space-between; padding-bottom: 6px; margin-bottom: 15px; } diff --git a/src/test/rustdoc-gui/type-declation-overflow.goml b/src/test/rustdoc-gui/type-declation-overflow.goml index dcffe956c21..c014eb52e71 100644 --- a/src/test/rustdoc-gui/type-declation-overflow.goml +++ b/src/test/rustdoc-gui/type-declation-overflow.goml @@ -41,3 +41,20 @@ goto: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLon store-property: (scrollWidth, ".mobile-topbar h2", "scrollWidth") assert-property: (".mobile-topbar h2", {"clientWidth": |scrollWidth|}) assert-css: (".mobile-topbar h2", {"overflow-x": "hidden"}) + +// Check wrapping for top main-heading h1 and out-of-band. +// On desktop, they wrap when too big. +size: (1100, 800) +goto: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html" +compare-elements-position-false: (".main-heading h1", ".main-heading .out-of-band", ("y")) +goto: "file://" + |DOC_PATH| + "/lib2/index.html" +compare-elements-position: (".main-heading h1", ".main-heading .out-of-band", ("y")) +// make sure there is a gap between them +compare-elements-position-near-false: (".main-heading h1", ".main-heading .out-of-band", {"x": 550}) + +// On mobile, they always wrap. +size: (600, 600) +goto: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html" +compare-elements-position-false: (".main-heading h1", ".main-heading .out-of-band", ("y")) +goto: "file://" + |DOC_PATH| + "/lib2/index.html" +compare-elements-position-false: (".main-heading h1", ".main-heading .out-of-band", ("y")) From 9857de218f10cfbe750d4c8165d960ae0da63cf4 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 9 Nov 2022 22:40:51 +0900 Subject: [PATCH 13/15] shift no characters when using raw string literals remove `find_skips` remove unnecessary variables --- compiler/rustc_parse_format/src/lib.rs | 174 +++++++++--------- src/test/ui/fmt/format-raw-string-error.rs | 3 + .../ui/fmt/format-raw-string-error.stderr | 10 + src/test/ui/fmt/issue-104142.rs | 6 + src/test/ui/fmt/issue-104142.stderr | 10 + 5 files changed, 115 insertions(+), 88 deletions(-) create mode 100644 src/test/ui/fmt/format-raw-string-error.rs create mode 100644 src/test/ui/fmt/format-raw-string-error.stderr create mode 100644 src/test/ui/fmt/issue-104142.rs create mode 100644 src/test/ui/fmt/issue-104142.stderr diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index 54bf4d1d6b7..0113eb4e3d1 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -818,96 +818,94 @@ fn find_skips_from_snippet( _ => return (vec![], false), }; - fn find_skips(snippet: &str, is_raw: bool) -> Vec { - let mut s = snippet.char_indices(); - let mut skips = vec![]; - while let Some((pos, c)) = s.next() { - match (c, s.clone().next()) { - // skip whitespace and empty lines ending in '\\' - ('\\', Some((next_pos, '\n'))) if !is_raw => { - skips.push(pos); - skips.push(next_pos); - let _ = s.next(); - - while let Some((pos, c)) = s.clone().next() { - if matches!(c, ' ' | '\n' | '\t') { - skips.push(pos); - let _ = s.next(); - } else { - break; - } - } - } - ('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => { - skips.push(next_pos); - let _ = s.next(); - } - ('\\', Some((_, 'x'))) if !is_raw => { - for _ in 0..3 { - // consume `\xAB` literal - if let Some((pos, _)) = s.next() { - skips.push(pos); - } else { - break; - } - } - } - ('\\', Some((_, 'u'))) if !is_raw => { - if let Some((pos, _)) = s.next() { - skips.push(pos); - } - if let Some((next_pos, next_c)) = s.next() { - if next_c == '{' { - // consume up to 6 hexanumeric chars - let digits_len = - s.clone().take(6).take_while(|(_, c)| c.is_digit(16)).count(); - - let len_utf8 = s - .as_str() - .get(..digits_len) - .and_then(|digits| u32::from_str_radix(digits, 16).ok()) - .and_then(char::from_u32) - .map_or(1, char::len_utf8); - - // Skip the digits, for chars that encode to more than 1 utf-8 byte - // exclude as many digits as it is greater than 1 byte - // - // So for a 3 byte character, exclude 2 digits - let required_skips = - digits_len.saturating_sub(len_utf8.saturating_sub(1)); - - // skip '{' and '}' also - for pos in (next_pos..).take(required_skips + 2) { - skips.push(pos) - } - - s.nth(digits_len); - } else if next_c.is_digit(16) { - skips.push(next_pos); - // We suggest adding `{` and `}` when appropriate, accept it here as if - // it were correct - let mut i = 0; // consume up to 6 hexanumeric chars - while let (Some((next_pos, c)), _) = (s.next(), i < 6) { - if c.is_digit(16) { - skips.push(next_pos); - } else { - break; - } - i += 1; - } - } - } - } - _ => {} - } - } - skips + if str_style.is_some() { + return (vec![], true); } - let r_start = str_style.map_or(0, |r| r + 1); - let r_end = str_style.unwrap_or(0); - let s = &snippet[r_start + 1..snippet.len() - r_end - 1]; - (find_skips(s, str_style.is_some()), true) + let snippet = &snippet[1..snippet.len() - 1]; + + let mut s = snippet.char_indices(); + let mut skips = vec![]; + while let Some((pos, c)) = s.next() { + match (c, s.clone().next()) { + // skip whitespace and empty lines ending in '\\' + ('\\', Some((next_pos, '\n'))) => { + skips.push(pos); + skips.push(next_pos); + let _ = s.next(); + + while let Some((pos, c)) = s.clone().next() { + if matches!(c, ' ' | '\n' | '\t') { + skips.push(pos); + let _ = s.next(); + } else { + break; + } + } + } + ('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => { + skips.push(next_pos); + let _ = s.next(); + } + ('\\', Some((_, 'x'))) => { + for _ in 0..3 { + // consume `\xAB` literal + if let Some((pos, _)) = s.next() { + skips.push(pos); + } else { + break; + } + } + } + ('\\', Some((_, 'u'))) => { + if let Some((pos, _)) = s.next() { + skips.push(pos); + } + if let Some((next_pos, next_c)) = s.next() { + if next_c == '{' { + // consume up to 6 hexanumeric chars + let digits_len = + s.clone().take(6).take_while(|(_, c)| c.is_digit(16)).count(); + + let len_utf8 = s + .as_str() + .get(..digits_len) + .and_then(|digits| u32::from_str_radix(digits, 16).ok()) + .and_then(char::from_u32) + .map_or(1, char::len_utf8); + + // Skip the digits, for chars that encode to more than 1 utf-8 byte + // exclude as many digits as it is greater than 1 byte + // + // So for a 3 byte character, exclude 2 digits + let required_skips = digits_len.saturating_sub(len_utf8.saturating_sub(1)); + + // skip '{' and '}' also + for pos in (next_pos..).take(required_skips + 2) { + skips.push(pos) + } + + s.nth(digits_len); + } else if next_c.is_digit(16) { + skips.push(next_pos); + // We suggest adding `{` and `}` when appropriate, accept it here as if + // it were correct + let mut i = 0; // consume up to 6 hexanumeric chars + while let (Some((next_pos, c)), _) = (s.next(), i < 6) { + if c.is_digit(16) { + skips.push(next_pos); + } else { + break; + } + i += 1; + } + } + } + } + _ => {} + } + } + (skips, true) } #[cfg(test)] diff --git a/src/test/ui/fmt/format-raw-string-error.rs b/src/test/ui/fmt/format-raw-string-error.rs new file mode 100644 index 00000000000..9f0bc01a749 --- /dev/null +++ b/src/test/ui/fmt/format-raw-string-error.rs @@ -0,0 +1,3 @@ +fn main() { + println!(r#"\'\'\'\'\'\'\'\'\'\'\'\'\'\'}"#); //~ ERROR invalid format string: unmatched `}` found +} diff --git a/src/test/ui/fmt/format-raw-string-error.stderr b/src/test/ui/fmt/format-raw-string-error.stderr new file mode 100644 index 00000000000..8d61950d8c2 --- /dev/null +++ b/src/test/ui/fmt/format-raw-string-error.stderr @@ -0,0 +1,10 @@ +error: invalid format string: unmatched `}` found + --> $DIR/format-raw-string-error.rs:2:45 + | +LL | println!(r#"\'\'\'\'\'\'\'\'\'\'\'\'\'\'}"#); + | ^ unmatched `}` in format string + | + = note: if you intended to print `}`, you can escape it using `}}` + +error: aborting due to previous error + diff --git a/src/test/ui/fmt/issue-104142.rs b/src/test/ui/fmt/issue-104142.rs new file mode 100644 index 00000000000..8d7283a7197 --- /dev/null +++ b/src/test/ui/fmt/issue-104142.rs @@ -0,0 +1,6 @@ +fn main() { + println!( + r#" + \"\'}、"# //~ ERROR invalid format string: unmatched `}` found + ); +} diff --git a/src/test/ui/fmt/issue-104142.stderr b/src/test/ui/fmt/issue-104142.stderr new file mode 100644 index 00000000000..d41644faa28 --- /dev/null +++ b/src/test/ui/fmt/issue-104142.stderr @@ -0,0 +1,10 @@ +error: invalid format string: unmatched `}` found + --> $DIR/issue-104142.rs:4:9 + | +LL | \"\'}、"# + | ^ unmatched `}` in format string + | + = note: if you intended to print `}`, you can escape it using `}}` + +error: aborting due to previous error + From 6211faa7e75c769396b82ec890fab2549d27b204 Mon Sep 17 00:00:00 2001 From: Andrew Pollack Date: Tue, 15 Nov 2022 16:44:08 +0000 Subject: [PATCH 14/15] Fuchsia test suite script fix --- src/doc/rustc/src/platform-support/fuchsia.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/doc/rustc/src/platform-support/fuchsia.md b/src/doc/rustc/src/platform-support/fuchsia.md index 62cad19d0ec..5de29b35e6b 100644 --- a/src/doc/rustc/src/platform-support/fuchsia.md +++ b/src/doc/rustc/src/platform-support/fuchsia.md @@ -675,12 +675,18 @@ run the tests on our emulator. To run the full `src/test/ui` test suite: test src/test/ui \ --target x86_64-fuchsia \ --run=always --jobs 1 \ - --test-args --target-rustcflags -L \ - --test-args --target-rustcflags ${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \ - --test-args --target-rustcflags -L \ - --test-args --target-rustcflags ${SDK_PATH}/arch/{x64|arm64}/lib \ - --test-args --target-rustcflags -Cpanic=abort \ - --test-args --target-rustcflags -Zpanic_abort_tests \ + --test-args --target-rustcflags \ + --test-args -L \ + --test-args --target-rustcflags \ + --test-args ${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \ + --test-args --target-rustcflags \ + --test-args -L \ + --test-args --target-rustcflags \ + --test-args ${SDK_PATH}/arch/{x64|arm64}/lib \ + --test-args --target-rustcflags \ + --test-args -Cpanic=abort \ + --test-args --target-rustcflags \ + --test-args -Zpanic_abort_tests \ --test-args --remote-test-client \ --test-args src/ci/docker/scripts/fuchsia-test-runner.py \ ) From e6e29a813472f11da65b06e635a52795028d3bd1 Mon Sep 17 00:00:00 2001 From: Stewart Russell Date: Tue, 15 Nov 2022 21:19:47 -0500 Subject: [PATCH 15/15] Update PROBLEMATIC_CONSTS in style.rs added 3735932941, since 3735927486 was already present. --- src/tools/tidy/src/style.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 541380cebde..e3a094caf91 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -60,7 +60,7 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[ // Intentionally written in decimal rather than hex const PROBLEMATIC_CONSTS: &[u32] = &[ 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037, - 3735927486, 4027431614, 4276992702, + 3735927486, 3735932941, 4027431614, 4276992702, ]; /// Parser states for `line_is_url`.