Skip to content

Commit

Permalink
Auto merge of rust-lang#135279 - matthiaskrgr:rollup-ek2qere, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#135212 (Remove outdated information in the `unreachable_pub` lint description)
 - rust-lang#135225 (Explicitly build proc macro test with panic=unwind)
 - rust-lang#135242 (add missing provenance APIs on NonNull)
 - rust-lang#135247 (Add a list of symbols for stable standard library crates)
 - rust-lang#135269 (Remove some unnecessary `.into()` calls)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 9, 2025
2 parents b6b8361 + a1cadea commit ec12cd8
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ rm tests/ui/mir/mir_raw_fat_ptr.rs # same
rm tests/ui/consts/issue-33537.rs # same
rm tests/ui/consts/const-mut-refs-crate.rs # same
rm tests/ui/abi/large-byval-align.rs # exceeds implementation limit of Cranelift
rm tests/ui/invalid-compile-flags/crate-type-flag.rs # warning about proc-macros and panic=abort

# doesn't work due to the way the rustc test suite is invoked.
# should work when using ./x.py test the way it is intended
Expand Down
17 changes: 7 additions & 10 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_lint_defs::BuiltinLintDiag;
use rustc_parse::validate_attr;
use rustc_session::Session;
use rustc_session::parse::feature_err;
use rustc_span::{Span, Symbol, sym};
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
use thin_vec::ThinVec;
use tracing::instrument;

Expand Down Expand Up @@ -107,14 +107,11 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -

// If the enabled feature is unstable, record it.
if UNSTABLE_LANG_FEATURES.iter().find(|f| name == f.name).is_some() {
// When the ICE comes from core, alloc or std (approximation of the standard
// library), there's a chance that the person hitting the ICE may be using
// -Zbuild-std or similar with an untested target. The bug is probably in the
// standard library and not the compiler in that case, but that doesn't really
// matter - we want a bug report.
if features.internal(name)
&& ![sym::core, sym::alloc, sym::std].contains(&crate_name)
{
// When the ICE comes a standard library crate, there's a chance that the person
// hitting the ICE may be using -Zbuild-std or similar with an untested target.
// The bug is probably in the standard library and not the compiler in that case,
// but that doesn't really matter - we want a bug report.
if features.internal(name) && !STDLIB_STABLE_CRATES.contains(&crate_name) {
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
}

Expand All @@ -133,7 +130,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -

// Similar to above, detect internal lib features to suppress
// the ICE message that asks for a report.
if features.internal(name) && ![sym::core, sym::alloc, sym::std].contains(&crate_name) {
if features.internal(name) && !STDLIB_STABLE_CRATES.contains(&crate_name) {
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ fn check_type_defn<'tcx>(
} else {
// Evaluate the constant proactively, to emit an error if the constant has
// an unconditional error. We only do so if the const has no type params.
let _ = tcx.const_eval_poly(def_id.into());
let _ = tcx.const_eval_poly(def_id);
}
}
let field_id = field.did.expect_local();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_lint::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
use rustc_middle::span_bug;
use rustc_middle::ty::{self, Ty};
use rustc_session::lint::builtin::{RUST_2021_PRELUDE_COLLISIONS, RUST_2024_PRELUDE_COLLISIONS};
use rustc_span::{Ident, Span, kw, sym};
use rustc_span::{Ident, STDLIB_STABLE_CRATES, Span, kw, sym};
use rustc_trait_selection::infer::InferCtxtExt;
use tracing::debug;

Expand Down Expand Up @@ -76,7 +76,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// No need to lint if method came from std/core, as that will now be in the prelude
if matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) {
if STDLIB_STABLE_CRATES.contains(&self.tcx.crate_name(pick.item.def_id.krate)) {
return;
}

Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

// No need to lint if method came from std/core, as that will now be in the prelude
if matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) {
if STDLIB_STABLE_CRATES.contains(&self.tcx.crate_name(pick.item.def_id.krate)) {
return;
}

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,8 @@ declare_lint! {
/// `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the
/// intent that the item is only visible within its own crate.
///
/// This lint is "allow" by default because it will trigger for a large
/// amount of existing Rust code, and has some false-positives. Eventually it
/// is desired for this to become warn-by-default.
/// This lint is "allow" by default because it will trigger for a large amount of existing Rust code.
/// Eventually it is desired for this to become warn-by-default.
///
/// [`unnameable_types`]: #unnameable-types
pub UNREACHABLE_PUB,
Expand Down Expand Up @@ -1304,9 +1303,9 @@ impl UnreachablePub {
cx.effective_visibilities.effective_vis(def_id).map(|effective_vis| {
effective_vis.at_level(rustc_middle::middle::privacy::Level::Reachable)
})
&& let parent_parent = cx.tcx.parent_module_from_def_id(
cx.tcx.parent_module_from_def_id(def_id.into()).into(),
)
&& let parent_parent = cx
.tcx
.parent_module_from_def_id(cx.tcx.parent_module_from_def_id(def_id).into())
&& *restricted_did == parent_parent.to_local_def_id()
&& !restricted_did.to_def_id().is_crate_root()
{
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_parse/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2366,8 +2366,7 @@ fn string_to_tts_1() {
token::Ident(sym::i32, IdentIsRaw::No),
sp(8, 11),
),
])
.into(),
]),
),
TokenTree::Delimited(
DelimSpan::from_pair(sp(13, 14), sp(18, 19)),
Expand All @@ -2383,8 +2382,7 @@ fn string_to_tts_1() {
),
// `Alone` because the `;` is followed by whitespace.
TokenTree::token_alone(token::Semi, sp(16, 17)),
])
.into(),
]),
),
]);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod span_encoding;
pub use span_encoding::{DUMMY_SP, Span};

pub mod symbol;
pub use symbol::{Ident, MacroRulesNormalizedIdent, Symbol, kw, sym};
pub use symbol::{Ident, MacroRulesNormalizedIdent, STDLIB_STABLE_CRATES, Symbol, kw, sym};

mod analyze_source_file;
pub mod fatal_error;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,10 @@ symbols! {
}
}

/// Symbols for crates that are part of the stable standard library: `std`, `core`, `alloc`, and
/// `proc_macro`.
pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, sym::proc_macro];

#[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)]
pub struct Ident {
pub name: Symbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc_middle::ty::{
self, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast,
};
use rustc_middle::{bug, span_bug};
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, sym};
use rustc_span::{BytePos, DUMMY_SP, STDLIB_STABLE_CRATES, Span, Symbol, sym};
use tracing::{debug, instrument};

use super::on_unimplemented::{AppendConstMessage, OnUnimplementedNote};
Expand Down Expand Up @@ -520,7 +520,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
match obligation.cause.span.ctxt().outer_expn_data().macro_def_id {
Some(macro_def_id) => {
let crate_name = tcx.crate_name(macro_def_id.krate);
crate_name == sym::std || crate_name == sym::core
STDLIB_STABLE_CRATES.contains(&crate_name)
}
None => false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn is_const_evaluatable<'tcx>(
Err(
EvaluateConstErr::EvaluationFailure(e)
| EvaluateConstErr::InvalidConstParamTy(e),
) => Err(NotConstEvaluatable::Error(e.into())),
) => Err(NotConstEvaluatable::Error(e)),
Ok(_) => Ok(()),
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn is_const_evaluatable<'tcx>(
}
Err(
EvaluateConstErr::EvaluationFailure(e) | EvaluateConstErr::InvalidConstParamTy(e),
) => Err(NotConstEvaluatable::Error(e.into())),
) => Err(NotConstEvaluatable::Error(e)),
Ok(_) => Ok(()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// let x: Rc<&str> = Rc::new("Hello, world!");
/// {
/// let s = String::from("Oh, no!");
/// let mut y: Rc<&str> = x.clone().into();
/// let mut y: Rc<&str> = x.clone();
/// unsafe {
/// // this is Undefined Behavior, because x's inner type
/// // is &'long str, not &'short str
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// let x: Arc<&str> = Arc::new("Hello, world!");
/// {
/// let s = String::from("Oh, no!");
/// let mut y: Arc<&str> = x.clone().into();
/// let mut y: Arc<&str> = x.clone();
/// unsafe {
/// // this is Undefined Behavior, because x's inner type
/// // is &'long str, not &'short str
Expand Down
48 changes: 45 additions & 3 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ impl<T: ?Sized> !Send for NonNull<T> {}
impl<T: ?Sized> !Sync for NonNull<T> {}

impl<T: Sized> NonNull<T> {
/// Creates a pointer with the given address and no [provenance][crate::ptr#provenance].
///
/// For more details, see the equivalent method on a raw pointer, [`ptr::without_provenance_mut`].
///
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
#[unstable(feature = "nonnull_provenance", issue = "135243")]
pub const fn without_provenance(addr: NonZero<usize>) -> Self {
// SAFETY: we know `addr` is non-zero.
unsafe {
let ptr = crate::ptr::without_provenance_mut(addr.get());
NonNull::new_unchecked(ptr)
}
}

/// Creates a new `NonNull` that is dangling, but well-aligned.
///
/// This is useful for initializing types which lazily allocate, like
Expand Down Expand Up @@ -116,6 +130,21 @@ impl<T: Sized> NonNull<T> {
}
}

/// Converts an address back to a mutable pointer, picking up some previously 'exposed'
/// [provenance][crate::ptr#provenance].
///
/// For more details, see the equivalent method on a raw pointer, [`ptr::with_exposed_provenance_mut`].
///
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
#[unstable(feature = "nonnull_provenance", issue = "135243")]
pub fn with_exposed_provenance(addr: NonZero<usize>) -> Self {
// SAFETY: we know `addr` is non-zero.
unsafe {
let ptr = crate::ptr::with_exposed_provenance_mut(addr.get());
NonNull::new_unchecked(ptr)
}
}

/// Returns a shared references to the value. In contrast to [`as_ref`], this does not require
/// that the value has to be initialized.
///
Expand Down Expand Up @@ -282,7 +311,7 @@ impl<T: ?Sized> NonNull<T> {

/// Gets the "address" portion of the pointer.
///
/// For more details see the equivalent method on a raw pointer, [`pointer::addr`].
/// For more details, see the equivalent method on a raw pointer, [`pointer::addr`].
///
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
#[must_use]
Expand All @@ -294,10 +323,23 @@ impl<T: ?Sized> NonNull<T> {
unsafe { NonZero::new_unchecked(self.as_ptr().addr()) }
}

/// Exposes the ["provenance"][crate::ptr#provenance] part of the pointer for future use in
/// [`with_exposed_provenance`][NonNull::with_exposed_provenance] and returns the "address" portion.
///
/// For more details, see the equivalent method on a raw pointer, [`pointer::expose_provenance`].
///
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
#[unstable(feature = "nonnull_provenance", issue = "135243")]
pub fn expose_provenance(self) -> NonZero<usize> {
// SAFETY: The pointer is guaranteed by the type to be non-null,
// meaning that the address will be non-zero.
unsafe { NonZero::new_unchecked(self.as_ptr().expose_provenance()) }
}

/// Creates a new pointer with the given address and the [provenance][crate::ptr#provenance] of
/// `self`.
///
/// For more details see the equivalent method on a raw pointer, [`pointer::with_addr`].
/// For more details, see the equivalent method on a raw pointer, [`pointer::with_addr`].
///
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
#[must_use]
Expand All @@ -311,7 +353,7 @@ impl<T: ?Sized> NonNull<T> {
/// Creates a new pointer by mapping `self`'s address to a new one, preserving the
/// [provenance][crate::ptr#provenance] of `self`.
///
/// For more details see the equivalent method on a raw pointer, [`pointer::map_addr`].
/// For more details, see the equivalent method on a raw pointer, [`pointer::map_addr`].
///
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl Builder {

let id = ThreadId::new();
let my_thread = match name {
Some(name) => Thread::new(id, name.into()),
Some(name) => Thread::new(id, name),
None => Thread::new_unnamed(id),
};

Expand Down
1 change: 1 addition & 0 deletions tests/ui/invalid-compile-flags/crate-type-flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
//@[bin] check-pass

//@[proc_dash_macro] ignore-wasm (proc-macro is not supported)
//@[proc_dash_macro] needs-unwind (panic=abort causes warning to be emitted)
//@[proc_dash_macro] compile-flags: --crate-type=proc-macro
//@[proc_dash_macro] check-pass

Expand Down

0 comments on commit ec12cd8

Please sign in to comment.