Skip to content

Commit de4cba3

Browse files
committed
Auto merge of rust-lang#115665 - matthiaskrgr:rollup-azdjs2r, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#115345 (MCP661: Move wasm32-wasi-preview1-threads target to Tier 2) - rust-lang#115604 (rustdoc: Render private fields in tuple struct as `/* private fields */`) - rust-lang#115624 (Print the path of a return-position impl trait in trait when `return_type_notation` is enabled) - rust-lang#115629 (Don't suggest dereferencing to unsized type) - rust-lang#115634 (Use `newtype_index` for `IntVid` and `FloatVid`.) - rust-lang#115649 (diagnostics: add test case for trait bounds diagnostic) - rust-lang#115655 (rustdoc: remove unused ID `mainThemeStyle`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3d24970 + dfa6622 commit de4cba3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+246
-82
lines changed

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,13 @@ impl<'tcx> InferCtxt<'tcx> {
764764
.collect();
765765
vars.extend(
766766
(0..inner.int_unification_table().len())
767-
.map(|i| ty::IntVid { index: i as u32 })
767+
.map(|i| ty::IntVid::from_u32(i as u32))
768768
.filter(|&vid| inner.int_unification_table().probe_value(vid).is_none())
769769
.map(|v| Ty::new_int_var(self.tcx, v)),
770770
);
771771
vars.extend(
772772
(0..inner.float_unification_table().len())
773-
.map(|i| ty::FloatVid { index: i as u32 })
773+
.map(|i| ty::FloatVid::from_u32(i as u32))
774774
.filter(|&vid| inner.float_unification_table().probe_value(vid).is_none())
775775
.map(|v| Ty::new_float_var(self.tcx, v)),
776776
);

compiler/rustc_middle/src/ty/print/pretty.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,17 @@ pub trait PrettyPrinter<'tcx>:
11231123
}
11241124
}
11251125

1126+
if self.tcx().features().return_type_notation
1127+
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = self.tcx().opt_rpitit_info(def_id)
1128+
&& let ty::Alias(_, alias_ty) = self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
1129+
&& alias_ty.def_id == def_id
1130+
{
1131+
let num_args = self.tcx().generics_of(fn_def_id).count();
1132+
write!(self, " {{ ")?;
1133+
self = self.print_def_path(fn_def_id, &args[..num_args])?;
1134+
write!(self, "() }}")?;
1135+
}
1136+
11261137
Ok(self)
11271138
}
11281139

@@ -1239,21 +1250,18 @@ pub trait PrettyPrinter<'tcx>:
12391250
.generics_of(principal.def_id)
12401251
.own_args_no_defaults(cx.tcx(), principal.args);
12411252

1242-
let mut projections = predicates.projection_bounds();
1243-
1244-
let mut args = args.iter().cloned();
1245-
let arg0 = args.next();
1246-
let projection0 = projections.next();
1247-
if arg0.is_some() || projection0.is_some() {
1248-
let args = arg0.into_iter().chain(args);
1249-
let projections = projection0.into_iter().chain(projections);
1253+
let mut projections: Vec<_> = predicates.projection_bounds().collect();
1254+
projections.sort_by_cached_key(|proj| {
1255+
cx.tcx().item_name(proj.item_def_id()).to_string()
1256+
});
12501257

1258+
if !args.is_empty() || !projections.is_empty() {
12511259
p!(generic_delimiters(|mut cx| {
1252-
cx = cx.comma_sep(args)?;
1253-
if arg0.is_some() && projection0.is_some() {
1260+
cx = cx.comma_sep(args.iter().copied())?;
1261+
if !args.is_empty() && !projections.is_empty() {
12541262
write!(cx, ", ")?;
12551263
}
1256-
cx.comma_sep(projections)
1264+
cx.comma_sep(projections.iter().copied())
12571265
}));
12581266
}
12591267
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
838838
obligation.param_env,
839839
real_trait_pred_and_base_ty,
840840
);
841-
if self.predicate_may_hold(&obligation) {
841+
let sized_obligation = Obligation::new(
842+
self.tcx,
843+
obligation.cause.clone(),
844+
obligation.param_env,
845+
ty::TraitRef::from_lang_item(
846+
self.tcx,
847+
hir::LangItem::Sized,
848+
obligation.cause.span,
849+
[base_ty],
850+
),
851+
);
852+
if self.predicate_may_hold(&obligation)
853+
&& self.predicate_must_hold_modulo_regions(&sized_obligation)
854+
{
842855
let call_node = self.tcx.hir().get(*call_hir_id);
843856
let msg = "consider dereferencing here";
844857
let is_receiver = matches!(

compiler/rustc_type_ir/src/lib.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,16 @@ rustc_index::newtype_index! {
574574
pub struct TyVid {}
575575
}
576576

577-
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
578-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
579-
pub struct IntVid {
580-
pub index: u32,
577+
rustc_index::newtype_index! {
578+
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
579+
#[debug_format = "?{}i"]
580+
pub struct IntVid {}
581581
}
582582

583-
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
584-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
585-
pub struct FloatVid {
586-
pub index: u32,
583+
rustc_index::newtype_index! {
584+
/// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
585+
#[debug_format = "?{}f"]
586+
pub struct FloatVid {}
587587
}
588588

589589
/// A placeholder for a type that hasn't been inferred yet.
@@ -645,11 +645,11 @@ impl UnifyKey for IntVid {
645645
type Value = Option<IntVarValue>;
646646
#[inline] // make this function eligible for inlining - it is quite hot.
647647
fn index(&self) -> u32 {
648-
self.index
648+
self.as_u32()
649649
}
650650
#[inline]
651651
fn from_index(i: u32) -> IntVid {
652-
IntVid { index: i }
652+
IntVid::from_u32(i)
653653
}
654654
fn tag() -> &'static str {
655655
"IntVid"
@@ -662,11 +662,11 @@ impl UnifyKey for FloatVid {
662662
type Value = Option<FloatVarValue>;
663663
#[inline]
664664
fn index(&self) -> u32 {
665-
self.index
665+
self.as_u32()
666666
}
667667
#[inline]
668668
fn from_index(i: u32) -> FloatVid {
669-
FloatVid { index: i }
669+
FloatVid::from_u32(i)
670670
}
671671
fn tag() -> &'static str {
672672
"FloatVid"
@@ -770,18 +770,6 @@ impl fmt::Debug for FloatVarValue {
770770
}
771771
}
772772

773-
impl fmt::Debug for IntVid {
774-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
775-
write!(f, "?{}i", self.index)
776-
}
777-
}
778-
779-
impl fmt::Debug for FloatVid {
780-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
781-
write!(f, "?{}f", self.index)
782-
}
783-
}
784-
785773
impl fmt::Debug for Variance {
786774
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
787775
f.write_str(match *self {

src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
1010
git clone https://github.com/WebAssembly/wasi-libc
1111

1212
cd wasi-libc
13-
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
13+
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
1414
make -j$(nproc) \
1515
CC="$bin/clang" \
1616
NM="$bin/llvm-nm" \

src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
1010
git clone https://github.com/WebAssembly/wasi-libc
1111

1212
cd wasi-libc
13-
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
13+
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
1414
make -j$(nproc) \
1515
CC="$bin/clang" \
1616
NM="$bin/llvm-nm" \

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ target | std | notes
181181
`wasm32-unknown-emscripten` | ✓ | WebAssembly via Emscripten
182182
`wasm32-unknown-unknown` | ✓ | WebAssembly
183183
`wasm32-wasi` | ✓ | WebAssembly with WASI
184+
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads
184185
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
185186
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
186187
`x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia`
@@ -323,7 +324,6 @@ target | std | host | notes
323324
`thumbv7a-pc-windows-msvc` | ? | |
324325
`thumbv7a-uwp-windows-msvc` | ✓ | |
325326
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL
326-
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads
327327
[`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly
328328
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64
329329
[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS

src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `wasm32-wasi-preview1-threads`
22

3-
**Tier: 3**
3+
**Tier: 2**
44

55
The `wasm32-wasi-preview1-threads` target is a new and still (as of July 2023) an
66
experimental target. This target is an extension to `wasm32-wasi-preview1` target,
@@ -70,12 +70,6 @@ compile `wasm32-wasi-preview1-threads` binaries straight out of the box. You can
7070
reliably interoperate with C code in this mode (yet).
7171

7272

73-
This target is not a stable target. This means that there are not many engines
74-
which implement the `wasi-threads` feature and if they do they're likely behind a
75-
flag, for example:
76-
77-
* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`
78-
7973
Also note that at this time the `wasm32-wasi-preview1-threads` target assumes the
8074
presence of other merged wasm proposals such as (with their LLVM feature flags):
8175

@@ -94,6 +88,17 @@ The target intends to match the corresponding Clang target for its `"C"` ABI.
9488
> found it's recommended to open an issue either with rust-lang/rust or ideally
9589
> with LLVM itself.
9690
91+
## Platform requirements
92+
93+
The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implemetation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads).
94+
95+
This target is not a stable target. This means that there are a few engines
96+
which implement the `wasi-threads` feature and if they do they're likely behind a
97+
flag, for example:
98+
99+
* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`
100+
* [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) - needs to be built with WAMR_BUILD_LIB_WASI_THREADS=1
101+
97102
## Building the target
98103

99104
Users need to install or built wasi-sdk since release 20.0
@@ -110,12 +115,16 @@ After that users can build this by adding it to the `target` list in
110115

111116
## Building Rust programs
112117

113-
Since it is Tier 3, rust doesn't ship pre-compiled artifacts for this target.
118+
From Rust Nightly 1.71.1 (2023-08-03) on the artifacts are shipped pre-compiled:
119+
120+
```text
121+
rustup target add wasm32-wasi-preview1-threads --toolchain nightly
122+
```
123+
124+
Rust programs can be built for that target:
114125

115-
Specify `wasi-root` as explained in the previous section and then use the `build-std`
116-
nightly cargo feature to build the standard library:
117-
```shell
118-
cargo +nightly build --target=wasm32-wasi-preview1-threads -Zbuild-std
126+
```text
127+
rustc --target wasm32-wasi-preview1-threads your-code.rs
119128
```
120129

121130
## Cross-compilation

src/librustdoc/html/markdown.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,6 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
15741574
map.insert("crate-search-div".into(), 1);
15751575
// This is the list of IDs used in HTML generated in Rust (including the ones
15761576
// used in tera template files).
1577-
map.insert("mainThemeStyle".into(), 1);
15781577
map.insert("themeStyle".into(), 1);
15791578
map.insert("settings-menu".into(), 1);
15801579
map.insert("help-button".into(), 1);

src/librustdoc/html/render/print_item.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,12 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
13841384
s: &'a [clean::Item],
13851385
) -> impl fmt::Display + 'a + Captures<'cx> {
13861386
display_fn(|f| {
1387+
if s.iter()
1388+
.all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))))
1389+
{
1390+
return f.write_str("/* private fields */");
1391+
}
1392+
13871393
for (i, ty) in s.iter().enumerate() {
13881394
if i > 0 {
13891395
f.write_str(", ")?;
@@ -2069,21 +2075,31 @@ fn render_struct_fields(
20692075
}
20702076
Some(CtorKind::Fn) => {
20712077
w.write_str("(");
2072-
for (i, field) in fields.iter().enumerate() {
2073-
if i > 0 {
2074-
w.write_str(", ");
2075-
}
2076-
match *field.kind {
2077-
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
2078-
clean::StructFieldItem(ref ty) => {
2079-
write!(
2080-
w,
2081-
"{}{}",
2082-
visibility_print_with_space(field.visibility(tcx), field.item_id, cx),
2083-
ty.print(cx),
2084-
)
2078+
if fields.iter().all(|field| {
2079+
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
2080+
}) {
2081+
write!(w, "/* private fields */");
2082+
} else {
2083+
for (i, field) in fields.iter().enumerate() {
2084+
if i > 0 {
2085+
w.write_str(", ");
2086+
}
2087+
match *field.kind {
2088+
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
2089+
clean::StructFieldItem(ref ty) => {
2090+
write!(
2091+
w,
2092+
"{}{}",
2093+
visibility_print_with_space(
2094+
field.visibility(tcx),
2095+
field.item_id,
2096+
cx
2097+
),
2098+
ty.print(cx),
2099+
)
2100+
}
2101+
_ => unreachable!(),
20852102
}
2086-
_ => unreachable!(),
20872103
}
20882104
}
20892105
w.write_str(")");

src/librustdoc/html/templates/page.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
<link rel="stylesheet" {#+ #}
1616
href="{{static_root_path|safe}}{{files.normalize_css}}"> {# #}
1717
<link rel="stylesheet" {#+ #}
18-
href="{{static_root_path|safe}}{{files.rustdoc_css}}" {#+ #}
19-
id="mainThemeStyle"> {# #}
18+
href="{{static_root_path|safe}}{{files.rustdoc_css}}"> {# #}
2019
{% if !layout.default_settings.is_empty() %}
2120
<script id="default-settings" {#+ #}
2221
{%~ for (k, v) in layout.default_settings ~%}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
22

33
// @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \
4-
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
4+
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>('
55
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);

tests/rustdoc/const-generics/const-generics-docs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<const N: usize> Trait<N> for [u8; N] {}
3333
// @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \
3434
// 'pub struct Foo<const N: usize> where u8: Trait<N>'
3535
pub struct Foo<const N: usize> where u8: Trait<N>;
36-
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>(_)'
36+
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>('
3737
pub struct Bar<T, const N: usize>([T; N]);
3838

3939
// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl<const M: usize> Foo<M>where u8: Trait<M>'
@@ -92,7 +92,7 @@ macro_rules! define_me {
9292
}
9393

9494
// @has foo/struct.Foz.html '//pre[@class="rust item-decl"]' \
95-
// 'pub struct Foz<const N: usize>(_);'
95+
// 'pub struct Foz<const N: usize>(/* private fields */);'
9696
define_me!(Foz<N>);
9797

9898
trait Q {

tests/rustdoc/issue-88600.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct S;
88

99
// @has issue_88600/enum.FooEnum.html
1010
pub enum FooEnum {
11-
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)'
11+
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)'
1212
// @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0
1313
HiddenTupleItem(#[doc(hidden)] H),
14-
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)'
14+
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(/* private fields */)'
1515
// @count - '//*[@id="variant.MultipleHidden.field.0"]' 0
1616
// @count - '//*[@id="variant.MultipleHidden.field.1"]' 0
1717
MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test checks the diplay of "/* private fields */" sentence in tuple structs.
2+
#![crate_name = "foo"]
3+
4+
// @has 'foo/struct.A.html' '//*[@class="rust item-decl"]/code' 'pub struct A(pub u8, _);'
5+
pub struct A(pub u8, u8);
6+
// @has 'foo/struct.B.html' '//*[@class="rust item-decl"]/code' 'pub struct B(_, pub u8);'
7+
pub struct B(u8, pub u8);
8+
// @has 'foo/struct.C.html' '//*[@class="rust item-decl"]/code' 'pub struct C(_, pub u8, _);'
9+
pub struct C(u8, pub u8, u8);
10+
// @has 'foo/struct.D.html' '//*[@class="rust item-decl"]/code' 'pub struct D(pub u8, _, pub u8);'
11+
pub struct D(pub u8, u8, pub u8);
12+
// @has 'foo/struct.E.html' '//*[@class="rust item-decl"]/code' 'pub struct E(/* private fields */);'
13+
pub struct E(u8);
14+
// @has 'foo/struct.F.html' '//*[@class="rust item-decl"]/code' 'pub struct F(/* private fields */);'
15+
pub struct F(u8, u8);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(_)
1+
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(/* private fields */)
22
<span class="where">where
33
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<code>pub struct Alpha&lt;A&gt;(_)
1+
<code>pub struct Alpha&lt;A&gt;(/* private fields */)
22
<span class="where">where
33
A: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code>

0 commit comments

Comments
 (0)