Skip to content

Commit 33b530e

Browse files
committed
Auto merge of rust-lang#103714 - matthiaskrgr:rollup-kajt3i8, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#102961 (Make `CStr::from_ptr` `const`.) - rust-lang#103342 (Add test for issue 98634) - rust-lang#103383 (Note scope of TAIT more accurately) - rust-lang#103656 (Specialize ToString for Symbol) - rust-lang#103663 (rustdoc: remove redundant CSS/DOM `div.search-container`) - rust-lang#103664 (rustdoc-json-types: Improve ItemSummary::path docs) - rust-lang#103704 (Add a test for TAIT used with impl/dyn Trait inside RPIT) Failed merges: - rust-lang#103618 (Rename some `OwnerId` fields.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 607878d + cc8040e commit 33b530e

File tree

16 files changed

+232
-47
lines changed

16 files changed

+232
-47
lines changed

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ hir_analysis_expected_default_return_type = expected `()` because of default ret
9393
hir_analysis_expected_return_type = expected `{$expected}` because of return type
9494
9595
hir_analysis_unconstrained_opaque_type = unconstrained opaque type
96-
.note = `{$name}` must be used in combination with a concrete type within the same module
96+
.note = `{$name}` must be used in combination with a concrete type within the same {$what}
9797
9898
hir_analysis_missing_type_params =
9999
the type {$parameterCount ->

compiler/rustc_hir_analysis/src/collect/type_of.rs

+6
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
701701
tcx.sess.emit_err(UnconstrainedOpaqueType {
702702
span: tcx.def_span(def_id),
703703
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
704+
what: match tcx.hir().get(scope) {
705+
_ if scope == hir::CRATE_HIR_ID => "module",
706+
Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module",
707+
Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => "impl",
708+
_ => "item",
709+
},
704710
});
705711
return tcx.ty_error();
706712
};

compiler/rustc_hir_analysis/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct UnconstrainedOpaqueType {
143143
#[primary_span]
144144
pub span: Span,
145145
pub name: Symbol,
146+
pub what: &'static str,
146147
}
147148

148149
pub struct MissingTypeParams {

compiler/rustc_span/src/symbol.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,13 @@ impl fmt::Display for Symbol {
19011901
}
19021902
}
19031903

1904+
// takes advantage of `str::to_string` specialization
1905+
impl ToString for Symbol {
1906+
fn to_string(&self) -> String {
1907+
self.as_str().to_string()
1908+
}
1909+
}
1910+
19041911
impl<S: Encoder> Encodable<S> for Symbol {
19051912
default fn encode(&self, s: &mut S) {
19061913
s.emit_str(self.as_str());

library/core/src/ffi/c_str.rs

+37-11
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ impl CStr {
221221
/// # Examples
222222
///
223223
/// ```ignore (extern-declaration)
224-
/// # fn main() {
225-
/// use std::ffi::CStr;
226-
/// use std::os::raw::c_char;
224+
/// use std::ffi::{c_char, CStr};
227225
///
228226
/// extern "C" {
229227
/// fn my_string() -> *const c_char;
@@ -233,14 +231,26 @@ impl CStr {
233231
/// let slice = CStr::from_ptr(my_string());
234232
/// println!("string returned: {}", slice.to_str().unwrap());
235233
/// }
236-
/// # }
234+
/// ```
235+
///
236+
/// ```
237+
/// #![feature(const_cstr_methods)]
238+
///
239+
/// use std::ffi::{c_char, CStr};
240+
///
241+
/// const HELLO_PTR: *const c_char = {
242+
/// const BYTES: &[u8] = b"Hello, world!\0";
243+
/// BYTES.as_ptr().cast()
244+
/// };
245+
/// const HELLO: &CStr = unsafe { CStr::from_ptr(HELLO_PTR) };
237246
/// ```
238247
///
239248
/// [valid]: core::ptr#safety
240249
#[inline]
241250
#[must_use]
242251
#[stable(feature = "rust1", since = "1.0.0")]
243-
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
252+
#[rustc_const_unstable(feature = "const_cstr_methods", issue = "101719")]
253+
pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
244254
// SAFETY: The caller has provided a pointer that points to a valid C
245255
// string with a NUL terminator of size less than `isize::MAX`, whose
246256
// content remain valid and doesn't change for the lifetime of the
@@ -252,13 +262,29 @@ impl CStr {
252262
//
253263
// The cast from c_char to u8 is ok because a c_char is always one byte.
254264
unsafe {
255-
extern "C" {
256-
/// Provided by libc or compiler_builtins.
257-
fn strlen(s: *const c_char) -> usize;
265+
const fn strlen_ct(s: *const c_char) -> usize {
266+
let mut len = 0;
267+
268+
// SAFETY: Outer caller has provided a pointer to a valid C string.
269+
while unsafe { *s.add(len) } != 0 {
270+
len += 1;
271+
}
272+
273+
len
258274
}
259-
let len = strlen(ptr);
260-
let ptr = ptr as *const u8;
261-
CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1))
275+
276+
fn strlen_rt(s: *const c_char) -> usize {
277+
extern "C" {
278+
/// Provided by libc or compiler_builtins.
279+
fn strlen(s: *const c_char) -> usize;
280+
}
281+
282+
// SAFETY: Outer caller has provided a pointer to a valid C string.
283+
unsafe { strlen(s) }
284+
}
285+
286+
let len = intrinsics::const_eval_select((ptr,), strlen_ct, strlen_rt);
287+
Self::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr.cast(), len + 1))
262288
}
263289
}
264290

src/librustdoc/html/static/css/rustdoc.css

+7-12
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,16 @@ nav.sub {
683683
display: flex;
684684
align-items: center;
685685
}
686-
nav.sub form {
686+
.search-form {
687+
position: relative;
688+
display: flex;
689+
height: 34px;
687690
flex-grow: 1;
688691
}
689692
.source nav.sub {
690693
margin: 0 0 15px 0;
691694
}
692-
.source nav.sub form {
695+
.source .search-form {
693696
margin-left: 32px;
694697
}
695698

@@ -780,11 +783,6 @@ table,
780783
padding-right: 1.25rem;
781784
}
782785

783-
.search-container {
784-
position: relative;
785-
display: flex;
786-
height: 34px;
787-
}
788786
.search-results-title {
789787
margin-top: 0;
790788
white-space: nowrap;
@@ -860,15 +858,12 @@ so that we can apply CSS-filters to change the arrow color in themes */
860858
-webkit-appearance: textfield for search inputs. That
861859
causes rounded corners and no border on iOS Safari. */
862860
-webkit-appearance: none;
863-
/* Override Normalize.css: we have margins and do
864-
not want to overflow */
865-
box-sizing: border-box !important;
866861
outline: none;
867862
border: 1px solid var(--border-color);
868863
border-radius: 2px;
869864
padding: 8px;
870865
font-size: 1rem;
871-
width: 100%;
866+
flex-grow: 1;
872867
background-color: var(--button-background-color);
873868
color: var(--search-color);
874869
}
@@ -1957,7 +1952,7 @@ in storage.js
19571952
flex-direction: column;
19581953
}
19591954

1960-
nav.sub form {
1955+
.search-form {
19611956
align-self: stretch;
19621957
}
19631958

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ function loadCss(cssFileName) {
932932
* Hide all the popover menus.
933933
*/
934934
window.hidePopoverMenus = function() {
935-
onEachLazy(document.querySelectorAll(".search-container .popover"), elem => {
935+
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
936936
elem.style.display = "none";
937937
});
938938
};

src/librustdoc/html/templates/page.html

+16-18
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,22 @@ <h2></h2> {#- -#}
115115
</a> {#- -#}
116116
{%- endif -%}
117117
<form class="search-form"> {#- -#}
118-
<div class="search-container"> {#- -#}
119-
<span></span> {#- This empty span is a hacky fix for Safari - See #93184 -#}
120-
<input {# -#}
121-
class="search-input" {# -#}
122-
name="search" {# -#}
123-
autocomplete="off" {# -#}
124-
spellcheck="false" {# -#}
125-
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
126-
type="search"> {#- -#}
127-
<div id="help-button" title="help" tabindex="-1"> {#- -#}
128-
<a href="{{page.root_path|safe}}help.html">?</a> {#- -#}
129-
</div> {#- -#}
130-
<div id="settings-menu" tabindex="-1"> {#- -#}
131-
<a href="{{page.root_path|safe}}settings.html" title="settings"> {#- -#}
132-
<img width="22" height="22" alt="Change settings" {# -#}
133-
src="{{static_root_path|safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
134-
</a> {#- -#}
135-
</div> {#- -#}
118+
<span></span> {#- This empty span is a hacky fix for Safari - See #93184 -#}
119+
<input {# -#}
120+
class="search-input" {# -#}
121+
name="search" {# -#}
122+
autocomplete="off" {# -#}
123+
spellcheck="false" {# -#}
124+
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
125+
type="search"> {#- -#}
126+
<div id="help-button" title="help" tabindex="-1"> {#- -#}
127+
<a href="{{page.root_path|safe}}help.html">?</a> {#- -#}
128+
</div> {#- -#}
129+
<div id="settings-menu" tabindex="-1"> {#- -#}
130+
<a href="{{page.root_path|safe}}settings.html" title="settings"> {#- -#}
131+
<img width="22" height="22" alt="Change settings" {# -#}
132+
src="{{static_root_path|safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
133+
</a> {#- -#}
136134
</div> {#- -#}
137135
</form> {#- -#}
138136
</nav> {#- -#}

src/rustdoc-json-types/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pub struct ItemSummary {
5151
pub crate_id: u32,
5252
/// The list of path components for the fully qualified path of this item (e.g.
5353
/// `["std", "io", "lazy", "Lazy"]` for `std::io::lazy::Lazy`).
54+
///
55+
/// Note that items can appear in multiple paths, and the one chosen is implementation
56+
/// defined. Currenty, this is the full path to where the item was defined. Eg
57+
/// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is
58+
/// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change.
5459
pub path: Vec<String>,
5560
/// Whether this item is a struct, trait, macro, etc.
5661
pub kind: ItemKind,
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// edition: 2021
2+
3+
use std::{
4+
future::Future,
5+
pin::Pin,
6+
task::{Context, Poll, Waker},
7+
};
8+
9+
pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
10+
pub callback: F,
11+
}
12+
13+
impl<F> Future for StructAsync<F>
14+
where
15+
F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
16+
{
17+
type Output = ();
18+
19+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
20+
Poll::Pending
21+
}
22+
}
23+
24+
async fn callback() {}
25+
26+
struct Runtime;
27+
28+
fn waker() -> &'static Waker {
29+
todo!()
30+
}
31+
32+
impl Runtime {
33+
#[track_caller]
34+
pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
35+
loop {
36+
unsafe {
37+
Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker()));
38+
}
39+
}
40+
}
41+
}
42+
43+
fn main() {
44+
Runtime.block_on(async {
45+
StructAsync { callback }.await;
46+
//~^ ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
47+
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
48+
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
49+
});
50+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
2+
--> $DIR/issue-98634.rs:45:23
3+
|
4+
LL | StructAsync { callback }.await;
5+
| ^^^^^^^^ expected struct `Pin`, found opaque type
6+
|
7+
note: while checking the return type of the `async fn`
8+
--> $DIR/issue-98634.rs:24:21
9+
|
10+
LL | async fn callback() {}
11+
| ^ checked the `Output` of this `async fn`, found opaque type
12+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
13+
found opaque type `impl Future<Output = ()>`
14+
note: required by a bound in `StructAsync`
15+
--> $DIR/issue-98634.rs:9:35
16+
|
17+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
19+
20+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
21+
--> $DIR/issue-98634.rs:45:9
22+
|
23+
LL | StructAsync { callback }.await;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
25+
|
26+
note: while checking the return type of the `async fn`
27+
--> $DIR/issue-98634.rs:24:21
28+
|
29+
LL | async fn callback() {}
30+
| ^ checked the `Output` of this `async fn`, found opaque type
31+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
32+
found opaque type `impl Future<Output = ()>`
33+
note: required by a bound in `StructAsync`
34+
--> $DIR/issue-98634.rs:9:35
35+
|
36+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
38+
39+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
40+
--> $DIR/issue-98634.rs:45:33
41+
|
42+
LL | StructAsync { callback }.await;
43+
| ^^^^^^ expected struct `Pin`, found opaque type
44+
|
45+
note: while checking the return type of the `async fn`
46+
--> $DIR/issue-98634.rs:24:21
47+
|
48+
LL | async fn callback() {}
49+
| ^ checked the `Output` of this `async fn`, found opaque type
50+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
51+
found opaque type `impl Future<Output = ()>`
52+
note: required by a bound in `StructAsync`
53+
--> $DIR/issue-98634.rs:9:35
54+
|
55+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0271`.

src/test/ui/generic-associated-types/issue-87258_a.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: unconstrained opaque type
44
LL | type FooFuture<'a> = impl Trait1;
55
| ^^^^^^^^^^^
66
|
7-
= note: `FooFuture` must be used in combination with a concrete type within the same module
7+
= note: `FooFuture` must be used in combination with a concrete type within the same impl
88

99
error: aborting due to previous error
1010

src/test/ui/lint/inline-trait-and-foreign-items.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ error: unconstrained opaque type
6767
LL | type U = impl Trait;
6868
| ^^^^^^^^^^
6969
|
70-
= note: `U` must be used in combination with a concrete type within the same module
70+
= note: `U` must be used in combination with a concrete type within the same impl
7171

7272
error: aborting due to 6 previous errors; 2 warnings emitted
7373

src/test/ui/lint/no-coverage.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ error: unconstrained opaque type
9494
LL | type U = impl Trait;
9595
| ^^^^^^^^^^
9696
|
97-
= note: `U` must be used in combination with a concrete type within the same module
97+
= note: `U` must be used in combination with a concrete type within the same impl
9898

9999
error: aborting due to 7 previous errors; 6 warnings emitted
100100

src/test/ui/save-analysis/issue-68621.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: unconstrained opaque type
44
LL | type Future = impl Trait;
55
| ^^^^^^^^^^
66
|
7-
= note: `Future` must be used in combination with a concrete type within the same module
7+
= note: `Future` must be used in combination with a concrete type within the same impl
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)