Skip to content

Commit 18b03c3

Browse files
committed
Auto merge of #143627 - matthiaskrgr:rollup-3elo6xo, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #134628 (Make `Default` const and add some `const Default` impls) - #143555 (Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.) - #143600 (Update intro blurb in `wasm32-wasip1` docs) - #143603 (Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast`) - #143620 (fix: Remove newline from multiple crate versions note) - #143622 (Add target maintainer information for mips64-unknown-linux-muslabi64) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 040e2f8 + 612e0a3 commit 18b03c3

36 files changed

+319
-189
lines changed

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ impl<S: Stage> OnDuplicate<S> {
217217
// them will be merged in another PR
218218
#[allow(unused)]
219219
pub(crate) enum AttributeOrder {
220-
/// Duplicates after the first attribute will be an error.
220+
/// Duplicates after the first attribute will be an error. I.e. only keep the lowest attribute.
221+
///
222+
/// Attributes are processed from bottom to top, so this raises an error on all the attributes
223+
/// further above the lowest one:
224+
/// ```
225+
/// #[stable(since="1.0")] //~ WARNING duplicated attribute
226+
/// #[stable(since="2.0")]
227+
/// ```
221228
///
222229
/// This should be used where duplicates would be ignored, but carry extra
223230
/// meaning that could cause confusion. For example, `#[stable(since="1.0")]
@@ -227,6 +234,13 @@ pub(crate) enum AttributeOrder {
227234
/// Duplicates preceding the last instance of the attribute will be a
228235
/// warning, with a note that this will be an error in the future.
229236
///
237+
/// Attributes are processed from bottom to top, so this raises a warning on all the attributes
238+
/// below the higher one:
239+
/// ```
240+
/// #[path="foo.rs"]
241+
/// #[path="bar.rs"] //~ WARNING duplicated attribute
242+
/// ```
243+
///
230244
/// This is the same as `FutureWarnFollowing`, except the last attribute is
231245
/// the one that is "used". Ideally these can eventually migrate to
232246
/// `ErrorPreceding`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19331933
StringPart::highlighted("multiple different versions".to_string()),
19341934
StringPart::normal(" of crate `".to_string()),
19351935
StringPart::highlighted(format!("{crate_name}")),
1936-
StringPart::normal("` in the dependency graph\n".to_string()),
1936+
StringPart::normal("` in the dependency graph".to_string()),
19371937
],
19381938
);
19391939
if points_at_type {

library/alloc/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@
107107
#![feature(char_max_len)]
108108
#![feature(clone_to_uninit)]
109109
#![feature(coerce_unsized)]
110+
#![feature(const_default)]
110111
#![feature(const_eval_select)]
111112
#![feature(const_heap)]
113+
#![feature(const_trait_impl)]
112114
#![feature(core_intrinsics)]
113115
#![feature(deprecated_suggestion)]
114116
#![feature(deref_pure_trait)]

library/alloc/src/string.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,8 @@ impl_eq! { Cow<'a, str>, &'b str }
26112611
impl_eq! { Cow<'a, str>, String }
26122612

26132613
#[stable(feature = "rust1", since = "1.0.0")]
2614-
impl Default for String {
2614+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2615+
impl const Default for String {
26152616
/// Creates an empty `String`.
26162617
#[inline]
26172618
fn default() -> String {

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
38953895
}
38963896

38973897
#[stable(feature = "rust1", since = "1.0.0")]
3898-
impl<T> Default for Vec<T> {
3898+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
3899+
impl<T> const Default for Vec<T> {
38993900
/// Creates an empty `Vec<T>`.
39003901
///
39013902
/// The vector will not allocate until elements are pushed onto it.

library/core/src/cell.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ impl<T: Copy> Clone for Cell<T> {
333333
}
334334

335335
#[stable(feature = "rust1", since = "1.0.0")]
336-
impl<T: Default> Default for Cell<T> {
336+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
337+
impl<T: ~const Default> const Default for Cell<T> {
337338
/// Creates a `Cell<T>`, with the `Default` value for T.
338339
#[inline]
339340
fn default() -> Cell<T> {
@@ -1323,7 +1324,8 @@ impl<T: Clone> Clone for RefCell<T> {
13231324
}
13241325

13251326
#[stable(feature = "rust1", since = "1.0.0")]
1326-
impl<T: Default> Default for RefCell<T> {
1327+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
1328+
impl<T: ~const Default> const Default for RefCell<T> {
13271329
/// Creates a `RefCell<T>`, with the `Default` value for T.
13281330
#[inline]
13291331
fn default() -> RefCell<T> {
@@ -2330,7 +2332,8 @@ impl<T: ?Sized> UnsafeCell<T> {
23302332
}
23312333

23322334
#[stable(feature = "unsafe_cell_default", since = "1.10.0")]
2333-
impl<T: Default> Default for UnsafeCell<T> {
2335+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2336+
impl<T: ~const Default> const Default for UnsafeCell<T> {
23342337
/// Creates an `UnsafeCell`, with the `Default` value for T.
23352338
fn default() -> UnsafeCell<T> {
23362339
UnsafeCell::new(Default::default())
@@ -2434,7 +2437,8 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
24342437
}
24352438

24362439
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2437-
impl<T: Default> Default for SyncUnsafeCell<T> {
2440+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2441+
impl<T: ~const Default> const Default for SyncUnsafeCell<T> {
24382442
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
24392443
fn default() -> SyncUnsafeCell<T> {
24402444
SyncUnsafeCell::new(Default::default())

library/core/src/default.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ use crate::ascii::Char as AsciiChar;
103103
/// ```
104104
#[rustc_diagnostic_item = "Default"]
105105
#[stable(feature = "rust1", since = "1.0.0")]
106+
#[const_trait]
107+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
106108
pub trait Default: Sized {
107109
/// Returns the "default value" for a type.
108110
///
@@ -149,7 +151,8 @@ pub macro Default($item:item) {
149151
macro_rules! default_impl {
150152
($t:ty, $v:expr, $doc:tt) => {
151153
#[stable(feature = "rust1", since = "1.0.0")]
152-
impl Default for $t {
154+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
155+
impl const Default for $t {
153156
#[inline(always)]
154157
#[doc = $doc]
155158
fn default() -> $t {

library/core/src/iter/sources/empty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl<T> Clone for Empty<T> {
8181
// not #[derive] because that adds a Default bound on T,
8282
// which isn't necessary.
8383
#[stable(feature = "iter_empty", since = "1.2.0")]
84-
impl<T> Default for Empty<T> {
84+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
85+
impl<T> const Default for Empty<T> {
8586
fn default() -> Empty<T> {
8687
Empty(marker::PhantomData)
8788
}

library/core/src/marker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,8 @@ impl<T: PointeeSized> Clone for PhantomData<T> {
858858
}
859859

860860
#[stable(feature = "rust1", since = "1.0.0")]
861-
impl<T: PointeeSized> Default for PhantomData<T> {
861+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
862+
impl<T: PointeeSized> const Default for PhantomData<T> {
862863
fn default() -> Self {
863864
Self
864865
}

library/core/src/option.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,8 @@ where
21112111
impl<T> crate::clone::UseCloned for Option<T> where T: crate::clone::UseCloned {}
21122112

21132113
#[stable(feature = "rust1", since = "1.0.0")]
2114-
impl<T> Default for Option<T> {
2114+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2115+
impl<T> const Default for Option<T> {
21152116
/// Returns [`None`][Option::None].
21162117
///
21172118
/// # Examples

library/core/src/ptr/alignment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ impl hash::Hash for Alignment {
230230

231231
/// Returns [`Alignment::MIN`], which is valid for any type.
232232
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
233-
impl Default for Alignment {
233+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
234+
impl const Default for Alignment {
234235
fn default() -> Alignment {
235236
Alignment::MIN
236237
}

library/core/src/slice/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,15 +5158,17 @@ where
51585158
}
51595159

51605160
#[stable(feature = "rust1", since = "1.0.0")]
5161-
impl<T> Default for &[T] {
5161+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
5162+
impl<T> const Default for &[T] {
51625163
/// Creates an empty slice.
51635164
fn default() -> Self {
51645165
&[]
51655166
}
51665167
}
51675168

51685169
#[stable(feature = "mut_slice_default", since = "1.5.0")]
5169-
impl<T> Default for &mut [T] {
5170+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
5171+
impl<T> const Default for &mut [T] {
51705172
/// Creates a mutable empty slice.
51715173
fn default() -> Self {
51725174
&mut []

library/core/src/str/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,8 @@ impl AsRef<[u8]> for str {
30723072
}
30733073

30743074
#[stable(feature = "rust1", since = "1.0.0")]
3075-
impl Default for &str {
3075+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
3076+
impl const Default for &str {
30763077
/// Creates an empty str
30773078
#[inline]
30783079
fn default() -> Self {
@@ -3081,7 +3082,8 @@ impl Default for &str {
30813082
}
30823083

30833084
#[stable(feature = "default_mut_str", since = "1.28.0")]
3084-
impl Default for &mut str {
3085+
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
3086+
impl const Default for &mut str {
30853087
/// Creates an empty mutable str
30863088
#[inline]
30873089
fn default() -> Self {

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
8484
- [m68k-unknown-none-elf](platform-support/m68k-unknown-none-elf.md)
8585
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
86+
- [mips64-unknown-linux-muslabi64](platform-support/mips64-unknown-linux-muslabi64.md)
8687
- [mipsel-sony-psx](platform-support/mipsel-sony-psx.md)
8788
- [mipsel-unknown-linux-gnu](platform-support/mipsel-unknown-linux-gnu.md)
8889
- [mips\*-mti-none-elf](platform-support/mips-mti-none-elf.md)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ target | std | host | notes
333333
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
334334
[`mips64-openwrt-linux-musl`](platform-support/mips64-openwrt-linux-musl.md) | ? | | MIPS64 for OpenWrt Linux musl 1.2.3
335335
`mips64-unknown-linux-gnuabi64` | ✓ | ✓ | MIPS64 Linux, N64 ABI (kernel 4.4, glibc 2.23)
336-
`mips64-unknown-linux-muslabi64` | ✓ | | MIPS64 Linux, N64 ABI, musl 1.2.3
336+
[`mips64-unknown-linux-muslabi64`](platform-support/mips64-unknown-linux-muslabi64.md) | ✓ | | MIPS64 Linux, N64 ABI, musl 1.2.3
337337
`mips64el-unknown-linux-gnuabi64` | ✓ | ✓ | MIPS64 (little endian) Linux, N64 ABI (kernel 4.4, glibc 2.23)
338338
`mips64el-unknown-linux-muslabi64` | ✓ | | MIPS64 (little endian) Linux, N64 ABI, musl 1.2.3
339339
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# mips64-unknown-linux-muslabi64
2+
3+
**Tier: 3**
4+
5+
Target for 64-bit big endian MIPS Linux programs using musl libc and the N64 ABI.
6+
7+
## Target maintainers
8+
9+
[@Gelbpunkt](https://github.com/Gelbpunkt)
10+
11+
## Requirements
12+
13+
Building the target itself requires a 64-bit big endian MIPS compiler that is
14+
supported by `cc-rs`.
15+
16+
## Building the target
17+
18+
The target can be built by enabling it for a `rustc` build.
19+
20+
```toml
21+
[build]
22+
target = ["mips64-unknown-linux-muslabi64"]
23+
```
24+
25+
Make sure your C compiler is included in `$PATH`, then add it to the
26+
`bootstrap.toml`:
27+
28+
```toml
29+
[target.mips64-unknown-linux-muslabi64]
30+
cc = "mips64-linux-musl-gcc"
31+
cxx = "mips64-linux-musl-g++"
32+
ar = "mips64-linux-musl-ar"
33+
linker = "mips64-linux-musl-gcc"
34+
```
35+
36+
## Building Rust programs
37+
38+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
39+
this target, you will first need to build Rust with the target enabled (see
40+
"Building the target" above).
41+
42+
## Cross-compilation
43+
44+
This target can be cross-compiled from any host.
45+
46+
## Testing
47+
48+
This target can be tested as normal with `x.py` on a 64-bit big endian MIPS
49+
host or via QEMU emulation.

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,35 @@
44

55
The `wasm32-wasip1` target is a WebAssembly compilation target which
66
assumes that the [WASIp1] (aka "WASI preview1") set of "syscalls" are available
7-
for use in the standard library. Historically this target in the Rust compiler
8-
was one of the first for WebAssembly where Rust and C code are explicitly
9-
intended to interoperate as well.
10-
11-
There's a bit of history to the target and current development which is also
12-
worth explaining before going much further. Historically this target was
13-
originally called `wasm32-wasi` in both rustc and Clang. This was first added
14-
to Rust in 2019. In the intervening years leading up to 2024 the WASI standard
15-
continued to be developed and was eventually "rebased" on top of the [Component
16-
Model]. This was a large change to the WASI specification and was released as
17-
0.2.0 ("WASIp2" colloquially) in January 2024. The previous target's name in
18-
rustc, `wasm32-wasi`, was then renamed to `wasm32-wasip1`, to avoid
19-
confusion with this new target to be added to rustc as `wasm32-wasip2`.
20-
Some more context can be found in these MCPs:
21-
22-
* [Rename wasm32-wasi target to wasm32-wasip1](https://github.com/rust-lang/compiler-team/issues/607)
23-
* [Smooth the renaming transition of wasm32-wasi](https://github.com/rust-lang/compiler-team/issues/695)
24-
25-
At this point the `wasm32-wasip1` target is intended for historical
26-
compatibility with the first version of the WASI standard. As of now (January
27-
2024) the 0.2.0 target of WASI ("WASIp2") is relatively new. The state of
28-
WASI will likely change in few years after which point this documentation will
29-
probably receive another update.
30-
31-
[WASI Preview1]: https://github.com/WebAssembly/WASI/tree/main/legacy/preview1
7+
for use in the standard library. This target explicitly supports interop with
8+
non-Rust code such as C and C++.
9+
10+
The [WASIp1] set of syscalls is standard insofar as it was written down once by
11+
a set of folks and has not changed since then. Additionally the [WASIp1]
12+
syscalls have been adapted and adopted into a number of runtimes and embeddings.
13+
It is not standard in the sense that there are no formal semantics for each
14+
syscall and APIs are no longer receiving any maintenance (e.g. no new APIs, no
15+
new documentation, etc). After [WASIp1] was originally developed in 2019 the
16+
WASI standard effort has since been "rebased" on top of the [Component Model].
17+
This was a large change to the WASI specification and was released as 0.2.0
18+
("WASIp2" colloquially) in January 2024. Current standardization efforts are
19+
focused on the Component Model-based definition of WASI. At this point the
20+
`wasm32-wasip1` Rust target is intended for historical compatibility with
21+
[WASIp1] set of syscalls.
22+
23+
[WASIp1]: https://github.com/WebAssembly/WASI/tree/main/legacy/preview1
3224
[Component Model]: https://github.com/webassembly/component-model
3325

3426
Today the `wasm32-wasip1` target will generate core WebAssembly modules
3527
which will import functions from the `wasi_snapshot_preview1` module for
3628
OS-related functionality (e.g. printing).
3729

30+
> **Note**: Prior to March 2024 this target was known as `wasm32-wasi` with some
31+
> historical context found in old MCPs:
32+
>
33+
> * [Rename wasm32-wasi target to wasm32-wasip1](https://github.com/rust-lang/compiler-team/issues/607)
34+
> * [Smooth the renaming transition of wasm32-wasi](https://github.com/rust-lang/compiler-team/issues/695)
35+
3836
## Target maintainers
3937

4038
When this target was added to the compiler platform-specific documentation here

src/librustdoc/json/conversions.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::ast;
77
use rustc_attr_data_structures::{self as attrs, DeprecatedSince};
88
use rustc_hir::def::CtorKind;
99
use rustc_hir::def_id::DefId;
10+
use rustc_hir::{HeaderSafety, Safety};
1011
use rustc_metadata::rendered_const;
1112
use rustc_middle::{bug, ty};
1213
use rustc_span::{Pos, kw, sym};
@@ -381,10 +382,22 @@ impl FromClean<clean::Union> for Union {
381382

382383
impl FromClean<rustc_hir::FnHeader> for FunctionHeader {
383384
fn from_clean(header: &rustc_hir::FnHeader, renderer: &JsonRenderer<'_>) -> Self {
385+
let is_unsafe = match header.safety {
386+
HeaderSafety::SafeTargetFeatures => {
387+
// The type system's internal implementation details consider
388+
// safe functions with the `#[target_feature]` attribute to be analogous
389+
// to unsafe functions: `header.is_unsafe()` returns `true` for them.
390+
// For rustdoc, this isn't the right decision, so we explicitly return `false`.
391+
// Context: https://github.com/rust-lang/rust/issues/142655
392+
false
393+
}
394+
HeaderSafety::Normal(Safety::Safe) => false,
395+
HeaderSafety::Normal(Safety::Unsafe) => true,
396+
};
384397
FunctionHeader {
385398
is_async: header.is_async(),
386399
is_const: header.is_const(),
387-
is_unsafe: header.is_unsafe(),
400+
is_unsafe,
388401
abi: header.abi.into_json(renderer),
389402
}
390403
}

src/tools/clippy/clippy_utils/src/visitors.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use crate::msrvs::Msrv;
12
use crate::ty::needs_ordered_drop;
23
use crate::{get_enclosing_block, path_to_local_id};
4+
use crate::qualify_min_const_fn::is_stable_const_fn;
35
use core::ops::ControlFlow;
46
use rustc_ast::visit::{VisitorResult, try_visit};
57
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -343,13 +345,13 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) ->
343345
.cx
344346
.qpath_res(p, hir_id)
345347
.opt_def_id()
346-
.is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {},
348+
.is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {},
347349
ExprKind::MethodCall(..)
348350
if self
349351
.cx
350352
.typeck_results()
351353
.type_dependent_def_id(e.hir_id)
352-
.is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {},
354+
.is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {},
353355
ExprKind::Binary(_, lhs, rhs)
354356
if self.cx.typeck_results().expr_ty(lhs).peel_refs().is_primitive_ty()
355357
&& self.cx.typeck_results().expr_ty(rhs).peel_refs().is_primitive_ty() => {},

0 commit comments

Comments
 (0)