From 328f81713cc80861fb79c629e4887de1a8b7bf05 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 12 Oct 2022 12:57:16 +0200 Subject: [PATCH 1/9] Make `CStr::from_ptr` `const`. --- library/core/src/ffi/c_str.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 55e58c4e0baa5..ae15be793414e 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -240,7 +240,9 @@ impl CStr { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] - pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { + #[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")] + #[rustc_allow_const_fn_unstable(const_eval_select)] + pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { // SAFETY: The caller has provided a pointer that points to a valid C // string with a NUL terminator of size less than `isize::MAX`, whose // content remain valid and doesn't change for the lifetime of the @@ -252,13 +254,29 @@ impl CStr { // // The cast from c_char to u8 is ok because a c_char is always one byte. unsafe { - extern "C" { - /// Provided by libc or compiler_builtins. - fn strlen(s: *const c_char) -> usize; + const fn strlen_ct(s: *const c_char) -> usize { + let mut len = 0; + + // SAFETY: Outer caller has provided a pointer to a valid C string. + while unsafe { *s.add(len) } != 0 { + len += 1; + } + + len } - let len = strlen(ptr); - let ptr = ptr as *const u8; - CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1)) + + fn strlen_rt(s: *const c_char) -> usize { + extern "C" { + /// Provided by libc or compiler_builtins. + fn strlen(s: *const c_char) -> usize; + } + + // SAFETY: Outer caller has provided a pointer to a valid C string. + unsafe { strlen(s) } + } + + let len = intrinsics::const_eval_select((ptr,), strlen_ct, strlen_rt); + Self::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr.cast(), len + 1)) } } From 36dbb07dafe59c4d1491c2fbff6971d653f2ff77 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 12 Oct 2022 13:12:27 +0200 Subject: [PATCH 2/9] Update docs for `CStr::from_ptr`. --- library/core/src/ffi/c_str.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index ae15be793414e..9f7c960d88feb 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -221,9 +221,7 @@ impl CStr { /// # Examples /// /// ```ignore (extern-declaration) - /// # fn main() { - /// use std::ffi::CStr; - /// use std::os::raw::c_char; + /// use std::ffi::{c_char, CStr}; /// /// extern "C" { /// fn my_string() -> *const c_char; @@ -233,7 +231,18 @@ impl CStr { /// let slice = CStr::from_ptr(my_string()); /// println!("string returned: {}", slice.to_str().unwrap()); /// } - /// # } + /// ``` + /// + /// ``` + /// #![feature(const_cstr_methods)] + /// + /// use std::ffi::{c_char, CStr}; + /// + /// const HELLO_PTR: *const c_char = { + /// const BYTES: &[u8] = b"Hello, world!\0"; + /// BYTES.as_ptr().cast() + /// }; + /// const HELLO: &CStr = unsafe { CStr::from_ptr(HELLO_PTR) }; /// ``` /// /// [valid]: core::ptr#safety From 4accf838f6d847c0c93f4c25540446dad0309519 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 22 Oct 2022 03:09:49 +0000 Subject: [PATCH 3/9] Note scope of TAIT more accurately --- .../rustc_error_messages/locales/en-US/hir_analysis.ftl | 2 +- compiler/rustc_hir_analysis/src/collect/type_of.rs | 6 ++++++ compiler/rustc_hir_analysis/src/errors.rs | 1 + src/test/ui/generic-associated-types/issue-87258_a.stderr | 2 +- src/test/ui/lint/inline-trait-and-foreign-items.stderr | 2 +- src/test/ui/lint/no-coverage.stderr | 2 +- src/test/ui/save-analysis/issue-68621.stderr | 2 +- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl index 357c6900a70e5..a5bbd1f7fc24b 100644 --- a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl +++ b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl @@ -93,7 +93,7 @@ hir_analysis_expected_default_return_type = expected `()` because of default ret hir_analysis_expected_return_type = expected `{$expected}` because of return type hir_analysis_unconstrained_opaque_type = unconstrained opaque type - .note = `{$name}` must be used in combination with a concrete type within the same module + .note = `{$name}` must be used in combination with a concrete type within the same {$what} hir_analysis_missing_type_params = the type {$parameterCount -> diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 32f359a815819..05ada7879224a 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -693,6 +693,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T tcx.sess.emit_err(UnconstrainedOpaqueType { span: tcx.def_span(def_id), name: tcx.item_name(tcx.local_parent(def_id).to_def_id()), + what: match tcx.hir().get(scope) { + _ if scope == hir::CRATE_HIR_ID => "module", + Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module", + Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => "impl", + _ => "item", + }, }); return tcx.ty_error(); }; diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index aaebbe6398a13..5b41a64dcd8e7 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -143,6 +143,7 @@ pub struct UnconstrainedOpaqueType { #[primary_span] pub span: Span, pub name: Symbol, + pub what: &'static str, } pub struct MissingTypeParams { diff --git a/src/test/ui/generic-associated-types/issue-87258_a.stderr b/src/test/ui/generic-associated-types/issue-87258_a.stderr index fa0748a280b60..eae9bd9b16f2d 100644 --- a/src/test/ui/generic-associated-types/issue-87258_a.stderr +++ b/src/test/ui/generic-associated-types/issue-87258_a.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | type FooFuture<'a> = impl Trait1; | ^^^^^^^^^^^ | - = note: `FooFuture` must be used in combination with a concrete type within the same module + = note: `FooFuture` must be used in combination with a concrete type within the same impl error: aborting due to previous error diff --git a/src/test/ui/lint/inline-trait-and-foreign-items.stderr b/src/test/ui/lint/inline-trait-and-foreign-items.stderr index 27399746bed6f..2f1fb4c46c08b 100644 --- a/src/test/ui/lint/inline-trait-and-foreign-items.stderr +++ b/src/test/ui/lint/inline-trait-and-foreign-items.stderr @@ -67,7 +67,7 @@ error: unconstrained opaque type LL | type U = impl Trait; | ^^^^^^^^^^ | - = note: `U` must be used in combination with a concrete type within the same module + = note: `U` must be used in combination with a concrete type within the same impl error: aborting due to 6 previous errors; 2 warnings emitted diff --git a/src/test/ui/lint/no-coverage.stderr b/src/test/ui/lint/no-coverage.stderr index 8452ccc7a03cb..404efbeac1e13 100644 --- a/src/test/ui/lint/no-coverage.stderr +++ b/src/test/ui/lint/no-coverage.stderr @@ -94,7 +94,7 @@ error: unconstrained opaque type LL | type U = impl Trait; | ^^^^^^^^^^ | - = note: `U` must be used in combination with a concrete type within the same module + = note: `U` must be used in combination with a concrete type within the same impl error: aborting due to 7 previous errors; 6 warnings emitted diff --git a/src/test/ui/save-analysis/issue-68621.stderr b/src/test/ui/save-analysis/issue-68621.stderr index 4a4bf9a6996bc..4452ee7915baa 100644 --- a/src/test/ui/save-analysis/issue-68621.stderr +++ b/src/test/ui/save-analysis/issue-68621.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | type Future = impl Trait; | ^^^^^^^^^^ | - = note: `Future` must be used in combination with a concrete type within the same module + = note: `Future` must be used in combination with a concrete type within the same impl error: aborting due to previous error From 509d8ad454ee48d6b8f24728755d8ed9ec9628c8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 27 Oct 2022 13:36:27 -0700 Subject: [PATCH 4/9] rustdoc: remove redundant `div.search-container` This wrapper DIV was originally added in 89e1fb322321c05497caa01372ceb7d5b57fa680, when it allowed the search bar's size to be calculated without using `calc()`. This `width` hack can be removed using flexbox. --- src/librustdoc/html/static/css/rustdoc.css | 19 +++++------- src/librustdoc/html/static/js/main.js | 2 +- src/librustdoc/html/templates/page.html | 34 ++++++++++------------ 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 934334e0c88bd..65f6a79d58921 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -679,13 +679,16 @@ nav.sub { display: flex; align-items: center; } -nav.sub form { +.search-form { + position: relative; + display: flex; + height: 34px; flex-grow: 1; } .source nav.sub { margin: 0 0 15px 0; } -.source nav.sub form { +.source .search-form { margin-left: 32px; } @@ -776,11 +779,6 @@ table, padding-right: 1.25rem; } -.search-container { - position: relative; - display: flex; - height: 34px; -} .search-results-title { margin-top: 0; white-space: nowrap; @@ -856,15 +854,12 @@ so that we can apply CSS-filters to change the arrow color in themes */ -webkit-appearance: textfield for search inputs. That causes rounded corners and no border on iOS Safari. */ -webkit-appearance: none; - /* Override Normalize.css: we have margins and do - not want to overflow */ - box-sizing: border-box !important; outline: none; border: 1px solid var(--border-color); border-radius: 2px; padding: 8px; font-size: 1rem; - width: 100%; + flex-grow: 1; background-color: var(--button-background-color); color: var(--search-color); } @@ -1951,7 +1946,7 @@ in storage.js flex-direction: column; } - nav.sub form { + .search-form { align-self: stretch; } diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 0b816eace64b1..33480fa41cf07 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -932,7 +932,7 @@ function loadCss(cssFileName) { * Hide all the popover menus. */ window.hidePopoverMenus = function() { - onEachLazy(document.querySelectorAll(".search-container .popover"), elem => { + onEachLazy(document.querySelectorAll(".search-form .popover"), elem => { elem.style.display = "none"; }); }; diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index ee8938ea6030c..c323869168789 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -115,24 +115,22 @@

{#- -#} {#- -#} {%- endif -%}
{#- -#} -
{#- -#} - {#- This empty span is a hacky fix for Safari - See #93184 -#} - {#- -#} -
{#- -#} - ? {#- -#} -
{#- -#} -
{#- -#} - {#- -#} - Change settings {#- -#} - {#- -#} -
{#- -#} + {#- This empty span is a hacky fix for Safari - See #93184 -#} + {#- -#} +
{#- -#} + ? {#- -#} +
{#- -#} +
{#- -#} + {#- -#} + Change settings {#- -#} + {#- -#}
{#- -#} {#- -#} {#- -#} From 92b314ba30c396fab7e4ffeabf3ebf3f6101516a Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Fri, 21 Oct 2022 18:37:35 +0800 Subject: [PATCH 5/9] add test for issue 98634 --- src/test/ui/async-await/issue-98634.rs | 50 ++++++++++++++++++ src/test/ui/async-await/issue-98634.stderr | 60 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/test/ui/async-await/issue-98634.rs create mode 100644 src/test/ui/async-await/issue-98634.stderr diff --git a/src/test/ui/async-await/issue-98634.rs b/src/test/ui/async-await/issue-98634.rs new file mode 100644 index 0000000000000..b0d38687f01c4 --- /dev/null +++ b/src/test/ui/async-await/issue-98634.rs @@ -0,0 +1,50 @@ +// edition: 2021 + +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll, Waker}, +}; + +pub struct StructAsync Pin>>> { + pub callback: F, +} + +impl Future for StructAsync +where + F: Fn() -> Pin>>, +{ + type Output = (); + + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { + Poll::Pending + } +} + +async fn callback() {} + +struct Runtime; + +fn waker() -> &'static Waker { + todo!() +} + +impl Runtime { + #[track_caller] + pub fn block_on(&self, mut future: F) -> F::Output { + loop { + unsafe { + Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker())); + } + } + } +} + +fn main() { + Runtime.block_on(async { + StructAsync { callback }.await; + //~^ ERROR expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + //~| ERROR expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + //~| ERROR expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + }); +} diff --git a/src/test/ui/async-await/issue-98634.stderr b/src/test/ui/async-await/issue-98634.stderr new file mode 100644 index 0000000000000..5160e48d88afd --- /dev/null +++ b/src/test/ui/async-await/issue-98634.stderr @@ -0,0 +1,60 @@ +error[E0271]: expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + --> $DIR/issue-98634.rs:45:23 + | +LL | StructAsync { callback }.await; + | ^^^^^^^^ expected struct `Pin`, found opaque type + | +note: while checking the return type of the `async fn` + --> $DIR/issue-98634.rs:24:21 + | +LL | async fn callback() {} + | ^ checked the `Output` of this `async fn`, found opaque type + = note: expected struct `Pin + 'static)>>` + found opaque type `impl Future` +note: required by a bound in `StructAsync` + --> $DIR/issue-98634.rs:9:35 + | +LL | pub struct StructAsync Pin>>> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` + +error[E0271]: expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + --> $DIR/issue-98634.rs:45:9 + | +LL | StructAsync { callback }.await; + | ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type + | +note: while checking the return type of the `async fn` + --> $DIR/issue-98634.rs:24:21 + | +LL | async fn callback() {} + | ^ checked the `Output` of this `async fn`, found opaque type + = note: expected struct `Pin + 'static)>>` + found opaque type `impl Future` +note: required by a bound in `StructAsync` + --> $DIR/issue-98634.rs:9:35 + | +LL | pub struct StructAsync Pin>>> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` + +error[E0271]: expected `fn() -> impl Future {callback}` to be a fn item that returns `Pin + 'static)>>`, but it returns `impl Future` + --> $DIR/issue-98634.rs:45:33 + | +LL | StructAsync { callback }.await; + | ^^^^^^ expected struct `Pin`, found opaque type + | +note: while checking the return type of the `async fn` + --> $DIR/issue-98634.rs:24:21 + | +LL | async fn callback() {} + | ^ checked the `Output` of this `async fn`, found opaque type + = note: expected struct `Pin + 'static)>>` + found opaque type `impl Future` +note: required by a bound in `StructAsync` + --> $DIR/issue-98634.rs:9:35 + | +LL | pub struct StructAsync Pin>>> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0271`. From 064ad83cc3555fc2ca747cffaf0445365acb866c Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 28 Oct 2022 01:43:37 +0100 Subject: [PATCH 6/9] rustdoc-json-types: Improve ItemSummary::path docs --- src/rustdoc-json-types/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 7379b04ad1677..4bc91fc4030e2 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -51,6 +51,11 @@ pub struct ItemSummary { pub crate_id: u32, /// The list of path components for the fully qualified path of this item (e.g. /// `["std", "io", "lazy", "Lazy"]` for `std::io::lazy::Lazy`). + /// + /// Note that items can appear in multiple paths, and the one chosen is implementation + /// defined. Currenty, this is the full path to where the item was defined. Eg + /// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is + /// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change. pub path: Vec, /// Whether this item is a struct, trait, macro, etc. pub kind: ItemKind, From b3f9277a17e455d51b1c8c88f56e224e37b4159c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 28 Oct 2022 14:17:34 +0200 Subject: [PATCH 7/9] Remove unneeded attribute. --- library/core/src/ffi/c_str.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 9f7c960d88feb..8923f548adf72 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -250,7 +250,6 @@ impl CStr { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")] - #[rustc_allow_const_fn_unstable(const_eval_select)] pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { // SAFETY: The caller has provided a pointer that points to a valid C // string with a NUL terminator of size less than `isize::MAX`, whose From 6bc5fddc00d3589a1b4a7b9bf74be74fcbf1ee35 Mon Sep 17 00:00:00 2001 From: xxchan Date: Fri, 28 Oct 2022 22:58:19 +0200 Subject: [PATCH 8/9] Add a test for TAIT used with impl/dyn Trait inside RPIT --- .../ui/type-alias-impl-trait/issue-101750.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/issue-101750.rs diff --git a/src/test/ui/type-alias-impl-trait/issue-101750.rs b/src/test/ui/type-alias-impl-trait/issue-101750.rs new file mode 100644 index 0000000000000..f564f4fa702cb --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-101750.rs @@ -0,0 +1,37 @@ +#![feature(type_alias_impl_trait)] + +// check-pass + +trait Trait {} + +type TAIT = impl Trait; + +struct Concrete; +impl Trait for Concrete {} + +fn tait() -> TAIT { + Concrete +} + +trait OuterTrait { + type Item; +} +struct Dummy { + t: T, +} +impl OuterTrait for Dummy { + type Item = T; +} + +fn tait_and_impl_trait() -> impl OuterTrait { + Dummy { + t: (tait(), Concrete), + } +} + +fn tait_and_dyn_trait() -> impl OuterTrait)> { + let b: Box = Box::new(Concrete); + Dummy { t: (tait(), b) } +} + +fn main() {} From 298253af98db70ce5dd0294698dfb89cb3bd09ab Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 27 Oct 2022 16:14:48 -0500 Subject: [PATCH 9/9] Specialize ToString for Symbol --- compiler/rustc_span/src/symbol.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 3fe79370c374d..7f16da52b4439 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1901,6 +1901,13 @@ impl fmt::Display for Symbol { } } +// takes advantage of `str::to_string` specialization +impl ToString for Symbol { + fn to_string(&self) -> String { + self.as_str().to_string() + } +} + impl Encodable for Symbol { default fn encode(&self, s: &mut S) { s.emit_str(self.as_str());