Skip to content

Rollup of 6 pull requests #143627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ impl<S: Stage> OnDuplicate<S> {
// them will be merged in another PR
#[allow(unused)]
pub(crate) enum AttributeOrder {
/// Duplicates after the first attribute will be an error.
/// Duplicates after the first attribute will be an error. I.e. only keep the lowest attribute.
///
/// Attributes are processed from bottom to top, so this raises an error on all the attributes
/// further above the lowest one:
/// ```
/// #[stable(since="1.0")] //~ WARNING duplicated attribute
/// #[stable(since="2.0")]
/// ```
///
/// This should be used where duplicates would be ignored, but carry extra
/// meaning that could cause confusion. For example, `#[stable(since="1.0")]
Expand All @@ -227,6 +234,13 @@ pub(crate) enum AttributeOrder {
/// Duplicates preceding the last instance of the attribute will be a
/// warning, with a note that this will be an error in the future.
///
/// Attributes are processed from bottom to top, so this raises a warning on all the attributes
/// below the higher one:
/// ```
/// #[path="foo.rs"]
/// #[path="bar.rs"] //~ WARNING duplicated attribute
/// ```
///
/// This is the same as `FutureWarnFollowing`, except the last attribute is
/// the one that is "used". Ideally these can eventually migrate to
/// `ErrorPreceding`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
StringPart::highlighted("multiple different versions".to_string()),
StringPart::normal(" of crate `".to_string()),
StringPart::highlighted(format!("{crate_name}")),
StringPart::normal("` in the dependency graph\n".to_string()),
StringPart::normal("` in the dependency graph".to_string()),
],
);
if points_at_type {
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@
#![feature(char_max_len)]
#![feature(clone_to_uninit)]
#![feature(coerce_unsized)]
#![feature(const_default)]
#![feature(const_eval_select)]
#![feature(const_heap)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]
#![feature(deprecated_suggestion)]
#![feature(deref_pure_trait)]
Expand Down
3 changes: 2 additions & 1 deletion library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,8 @@ impl_eq! { Cow<'a, str>, &'b str }
impl_eq! { Cow<'a, str>, String }

#[stable(feature = "rust1", since = "1.0.0")]
impl Default for String {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl const Default for String {
/// Creates an empty `String`.
#[inline]
fn default() -> String {
Expand Down
3 changes: 2 additions & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Vec<T> {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T> const Default for Vec<T> {
/// Creates an empty `Vec<T>`.
///
/// The vector will not allocate until elements are pushed onto it.
Expand Down
12 changes: 8 additions & 4 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ impl<T: Copy> Clone for Cell<T> {
}

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

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

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

#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
impl<T: Default> Default for SyncUnsafeCell<T> {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T: ~const Default> const Default for SyncUnsafeCell<T> {
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
fn default() -> SyncUnsafeCell<T> {
SyncUnsafeCell::new(Default::default())
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ use crate::ascii::Char as AsciiChar;
/// ```
#[rustc_diagnostic_item = "Default"]
#[stable(feature = "rust1", since = "1.0.0")]
#[const_trait]
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
pub trait Default: Sized {
/// Returns the "default value" for a type.
///
Expand Down Expand Up @@ -149,7 +151,8 @@ pub macro Default($item:item) {
macro_rules! default_impl {
($t:ty, $v:expr, $doc:tt) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for $t {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl const Default for $t {
#[inline(always)]
#[doc = $doc]
fn default() -> $t {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/iter/sources/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl<T> Clone for Empty<T> {
// not #[derive] because that adds a Default bound on T,
// which isn't necessary.
#[stable(feature = "iter_empty", since = "1.2.0")]
impl<T> Default for Empty<T> {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T> const Default for Empty<T> {
fn default() -> Empty<T> {
Empty(marker::PhantomData)
}
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,8 @@ impl<T: PointeeSized> Clone for PhantomData<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> Default for PhantomData<T> {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T: PointeeSized> const Default for PhantomData<T> {
fn default() -> Self {
Self
}
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,8 @@ where
impl<T> crate::clone::UseCloned for Option<T> where T: crate::clone::UseCloned {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T> const Default for Option<T> {
/// Returns [`None`][Option::None].
///
/// # Examples
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/ptr/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ impl hash::Hash for Alignment {

/// Returns [`Alignment::MIN`], which is valid for any type.
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
impl Default for Alignment {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl const Default for Alignment {
fn default() -> Alignment {
Alignment::MIN
}
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5158,15 +5158,17 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for &[T] {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T> const Default for &[T] {
/// Creates an empty slice.
fn default() -> Self {
&[]
}
}

#[stable(feature = "mut_slice_default", since = "1.5.0")]
impl<T> Default for &mut [T] {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl<T> const Default for &mut [T] {
/// Creates a mutable empty slice.
fn default() -> Self {
&mut []
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,8 @@ impl AsRef<[u8]> for str {
}

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

#[stable(feature = "default_mut_str", since = "1.28.0")]
impl Default for &mut str {
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
impl const Default for &mut str {
/// Creates an empty mutable str
#[inline]
fn default() -> Self {
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
- [m68k-unknown-none-elf](platform-support/m68k-unknown-none-elf.md)
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
- [mips64-unknown-linux-muslabi64](platform-support/mips64-unknown-linux-muslabi64.md)
- [mipsel-sony-psx](platform-support/mipsel-sony-psx.md)
- [mipsel-unknown-linux-gnu](platform-support/mipsel-unknown-linux-gnu.md)
- [mips\*-mti-none-elf](platform-support/mips-mti-none-elf.md)
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ target | std | host | notes
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
[`mips64-openwrt-linux-musl`](platform-support/mips64-openwrt-linux-musl.md) | ? | | MIPS64 for OpenWrt Linux musl 1.2.3
`mips64-unknown-linux-gnuabi64` | ✓ | ✓ | MIPS64 Linux, N64 ABI (kernel 4.4, glibc 2.23)
`mips64-unknown-linux-muslabi64` | ✓ | | MIPS64 Linux, N64 ABI, musl 1.2.3
[`mips64-unknown-linux-muslabi64`](platform-support/mips64-unknown-linux-muslabi64.md) | ✓ | | MIPS64 Linux, N64 ABI, musl 1.2.3
`mips64el-unknown-linux-gnuabi64` | ✓ | ✓ | MIPS64 (little endian) Linux, N64 ABI (kernel 4.4, glibc 2.23)
`mips64el-unknown-linux-muslabi64` | ✓ | | MIPS64 (little endian) Linux, N64 ABI, musl 1.2.3
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# mips64-unknown-linux-muslabi64

**Tier: 3**

Target for 64-bit big endian MIPS Linux programs using musl libc and the N64 ABI.

## Target maintainers

[@Gelbpunkt](https://github.com/Gelbpunkt)

## Requirements

Building the target itself requires a 64-bit big endian MIPS compiler that is
supported by `cc-rs`.

## Building the target

The target can be built by enabling it for a `rustc` build.

```toml
[build]
target = ["mips64-unknown-linux-muslabi64"]
```

Make sure your C compiler is included in `$PATH`, then add it to the
`bootstrap.toml`:

```toml
[target.mips64-unknown-linux-muslabi64]
cc = "mips64-linux-musl-gcc"
cxx = "mips64-linux-musl-g++"
ar = "mips64-linux-musl-ar"
linker = "mips64-linux-musl-gcc"
```

## Building Rust programs

Rust does not yet ship pre-compiled artifacts for this target. To compile for
this target, you will first need to build Rust with the target enabled (see
"Building the target" above).

## Cross-compilation

This target can be cross-compiled from any host.

## Testing

This target can be tested as normal with `x.py` on a 64-bit big endian MIPS
host or via QEMU emulation.
48 changes: 23 additions & 25 deletions src/doc/rustc/src/platform-support/wasm32-wasip1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,35 @@

The `wasm32-wasip1` target is a WebAssembly compilation target which
assumes that the [WASIp1] (aka "WASI preview1") set of "syscalls" are available
for use in the standard library. Historically this target in the Rust compiler
was one of the first for WebAssembly where Rust and C code are explicitly
intended to interoperate as well.

There's a bit of history to the target and current development which is also
worth explaining before going much further. Historically this target was
originally called `wasm32-wasi` in both rustc and Clang. This was first added
to Rust in 2019. In the intervening years leading up to 2024 the WASI standard
continued to be developed and was eventually "rebased" on top of the [Component
Model]. This was a large change to the WASI specification and was released as
0.2.0 ("WASIp2" colloquially) in January 2024. The previous target's name in
rustc, `wasm32-wasi`, was then renamed to `wasm32-wasip1`, to avoid
confusion with this new target to be added to rustc as `wasm32-wasip2`.
Some more context can be found in these MCPs:

* [Rename wasm32-wasi target to wasm32-wasip1](https://github.com/rust-lang/compiler-team/issues/607)
* [Smooth the renaming transition of wasm32-wasi](https://github.com/rust-lang/compiler-team/issues/695)

At this point the `wasm32-wasip1` target is intended for historical
compatibility with the first version of the WASI standard. As of now (January
2024) the 0.2.0 target of WASI ("WASIp2") is relatively new. The state of
WASI will likely change in few years after which point this documentation will
probably receive another update.

[WASI Preview1]: https://github.com/WebAssembly/WASI/tree/main/legacy/preview1
for use in the standard library. This target explicitly supports interop with
non-Rust code such as C and C++.

The [WASIp1] set of syscalls is standard insofar as it was written down once by
a set of folks and has not changed since then. Additionally the [WASIp1]
syscalls have been adapted and adopted into a number of runtimes and embeddings.
It is not standard in the sense that there are no formal semantics for each
syscall and APIs are no longer receiving any maintenance (e.g. no new APIs, no
new documentation, etc). After [WASIp1] was originally developed in 2019 the
WASI standard effort has since been "rebased" on top of the [Component Model].
This was a large change to the WASI specification and was released as 0.2.0
("WASIp2" colloquially) in January 2024. Current standardization efforts are
focused on the Component Model-based definition of WASI. At this point the
`wasm32-wasip1` Rust target is intended for historical compatibility with
[WASIp1] set of syscalls.

[WASIp1]: https://github.com/WebAssembly/WASI/tree/main/legacy/preview1
[Component Model]: https://github.com/webassembly/component-model

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

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

## Target maintainers

When this target was added to the compiler platform-specific documentation here
Expand Down
15 changes: 14 additions & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_ast::ast;
use rustc_attr_data_structures::{self as attrs, DeprecatedSince};
use rustc_hir::def::CtorKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{HeaderSafety, Safety};
use rustc_metadata::rendered_const;
use rustc_middle::{bug, ty};
use rustc_span::{Pos, kw, sym};
Expand Down Expand Up @@ -381,10 +382,22 @@ impl FromClean<clean::Union> for Union {

impl FromClean<rustc_hir::FnHeader> for FunctionHeader {
fn from_clean(header: &rustc_hir::FnHeader, renderer: &JsonRenderer<'_>) -> Self {
let is_unsafe = match header.safety {
HeaderSafety::SafeTargetFeatures => {
// The type system's internal implementation details consider
// safe functions with the `#[target_feature]` attribute to be analogous
// to unsafe functions: `header.is_unsafe()` returns `true` for them.
// For rustdoc, this isn't the right decision, so we explicitly return `false`.
// Context: https://github.com/rust-lang/rust/issues/142655
false
}
HeaderSafety::Normal(Safety::Safe) => false,
HeaderSafety::Normal(Safety::Unsafe) => true,
};
FunctionHeader {
is_async: header.is_async(),
is_const: header.is_const(),
is_unsafe: header.is_unsafe(),
is_unsafe,
abi: header.abi.into_json(renderer),
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/tools/clippy/clippy_utils/src/visitors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::msrvs::Msrv;
use crate::ty::needs_ordered_drop;
use crate::{get_enclosing_block, path_to_local_id};
use crate::qualify_min_const_fn::is_stable_const_fn;
use core::ops::ControlFlow;
use rustc_ast::visit::{VisitorResult, try_visit};
use rustc_hir::def::{CtorKind, DefKind, Res};
Expand Down Expand Up @@ -343,13 +345,13 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) ->
.cx
.qpath_res(p, hir_id)
.opt_def_id()
.is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {},
.is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {},
ExprKind::MethodCall(..)
if self
.cx
.typeck_results()
.type_dependent_def_id(e.hir_id)
.is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {},
.is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {},
ExprKind::Binary(_, lhs, rhs)
if self.cx.typeck_results().expr_ty(lhs).peel_refs().is_primitive_ty()
&& self.cx.typeck_results().expr_ty(rhs).peel_refs().is_primitive_ty() => {},
Expand Down
Loading
Loading