Skip to content

Commit ec12cd8

Browse files
committed
Auto merge of rust-lang#135279 - matthiaskrgr:rollup-ek2qere, r=matthiaskrgr
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
2 parents b6b8361 + a1cadea commit ec12cd8

File tree

15 files changed

+76
-36
lines changed

15 files changed

+76
-36
lines changed

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ rm tests/ui/mir/mir_raw_fat_ptr.rs # same
123123
rm tests/ui/consts/issue-33537.rs # same
124124
rm tests/ui/consts/const-mut-refs-crate.rs # same
125125
rm tests/ui/abi/large-byval-align.rs # exceeds implementation limit of Cranelift
126-
rm tests/ui/invalid-compile-flags/crate-type-flag.rs # warning about proc-macros and panic=abort
127126

128127
# doesn't work due to the way the rustc test suite is invoked.
129128
# should work when using ./x.py test the way it is intended

compiler/rustc_expand/src/config.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_lint_defs::BuiltinLintDiag;
1818
use rustc_parse::validate_attr;
1919
use rustc_session::Session;
2020
use rustc_session::parse::feature_err;
21-
use rustc_span::{Span, Symbol, sym};
21+
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
2222
use thin_vec::ThinVec;
2323
use tracing::instrument;
2424

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

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

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

134131
// Similar to above, detect internal lib features to suppress
135132
// the ICE message that asks for a report.
136-
if features.internal(name) && ![sym::core, sym::alloc, sym::std].contains(&crate_name) {
133+
if features.internal(name) && !STDLIB_STABLE_CRATES.contains(&crate_name) {
137134
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
138135
}
139136
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ fn check_type_defn<'tcx>(
11201120
} else {
11211121
// Evaluate the constant proactively, to emit an error if the constant has
11221122
// an unconditional error. We only do so if the const has no type params.
1123-
let _ = tcx.const_eval_poly(def_id.into());
1123+
let _ = tcx.const_eval_poly(def_id);
11241124
}
11251125
}
11261126
let field_id = field.did.expect_local();

compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_lint::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
88
use rustc_middle::span_bug;
99
use rustc_middle::ty::{self, Ty};
1010
use rustc_session::lint::builtin::{RUST_2021_PRELUDE_COLLISIONS, RUST_2024_PRELUDE_COLLISIONS};
11-
use rustc_span::{Ident, Span, kw, sym};
11+
use rustc_span::{Ident, STDLIB_STABLE_CRATES, Span, kw, sym};
1212
use rustc_trait_selection::infer::InferCtxtExt;
1313
use tracing::debug;
1414

@@ -76,7 +76,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7676
};
7777

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

@@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
252252
}
253253

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

compiler/rustc_lint/src/builtin.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,8 @@ declare_lint! {
12711271
/// `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the
12721272
/// intent that the item is only visible within its own crate.
12731273
///
1274-
/// This lint is "allow" by default because it will trigger for a large
1275-
/// amount of existing Rust code, and has some false-positives. Eventually it
1276-
/// is desired for this to become warn-by-default.
1274+
/// This lint is "allow" by default because it will trigger for a large amount of existing Rust code.
1275+
/// Eventually it is desired for this to become warn-by-default.
12771276
///
12781277
/// [`unnameable_types`]: #unnameable-types
12791278
pub UNREACHABLE_PUB,
@@ -1304,9 +1303,9 @@ impl UnreachablePub {
13041303
cx.effective_visibilities.effective_vis(def_id).map(|effective_vis| {
13051304
effective_vis.at_level(rustc_middle::middle::privacy::Level::Reachable)
13061305
})
1307-
&& let parent_parent = cx.tcx.parent_module_from_def_id(
1308-
cx.tcx.parent_module_from_def_id(def_id.into()).into(),
1309-
)
1306+
&& let parent_parent = cx
1307+
.tcx
1308+
.parent_module_from_def_id(cx.tcx.parent_module_from_def_id(def_id).into())
13101309
&& *restricted_did == parent_parent.to_local_def_id()
13111310
&& !restricted_did.to_def_id().is_crate_root()
13121311
{

compiler/rustc_parse/src/parser/tests.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2366,8 +2366,7 @@ fn string_to_tts_1() {
23662366
token::Ident(sym::i32, IdentIsRaw::No),
23672367
sp(8, 11),
23682368
),
2369-
])
2370-
.into(),
2369+
]),
23712370
),
23722371
TokenTree::Delimited(
23732372
DelimSpan::from_pair(sp(13, 14), sp(18, 19)),
@@ -2383,8 +2382,7 @@ fn string_to_tts_1() {
23832382
),
23842383
// `Alone` because the `;` is followed by whitespace.
23852384
TokenTree::token_alone(token::Semi, sp(16, 17)),
2386-
])
2387-
.into(),
2385+
]),
23882386
),
23892387
]);
23902388

compiler/rustc_span/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mod span_encoding;
6767
pub use span_encoding::{DUMMY_SP, Span};
6868

6969
pub mod symbol;
70-
pub use symbol::{Ident, MacroRulesNormalizedIdent, Symbol, kw, sym};
70+
pub use symbol::{Ident, MacroRulesNormalizedIdent, STDLIB_STABLE_CRATES, Symbol, kw, sym};
7171

7272
mod analyze_source_file;
7373
pub mod fatal_error;

compiler/rustc_span/src/symbol.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,10 @@ symbols! {
22402240
}
22412241
}
22422242

2243+
/// Symbols for crates that are part of the stable standard library: `std`, `core`, `alloc`, and
2244+
/// `proc_macro`.
2245+
pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, sym::proc_macro];
2246+
22432247
#[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)]
22442248
pub struct Ident {
22452249
pub name: Symbol,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::ty::{
2727
self, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast,
2828
};
2929
use rustc_middle::{bug, span_bug};
30-
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, sym};
30+
use rustc_span::{BytePos, DUMMY_SP, STDLIB_STABLE_CRATES, Span, Symbol, sym};
3131
use tracing::{debug, instrument};
3232

3333
use super::on_unimplemented::{AppendConstMessage, OnUnimplementedNote};
@@ -520,7 +520,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
520520
match obligation.cause.span.ctxt().outer_expn_data().macro_def_id {
521521
Some(macro_def_id) => {
522522
let crate_name = tcx.crate_name(macro_def_id.krate);
523-
crate_name == sym::std || crate_name == sym::core
523+
STDLIB_STABLE_CRATES.contains(&crate_name)
524524
}
525525
None => false,
526526
};

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn is_const_evaluatable<'tcx>(
7979
Err(
8080
EvaluateConstErr::EvaluationFailure(e)
8181
| EvaluateConstErr::InvalidConstParamTy(e),
82-
) => Err(NotConstEvaluatable::Error(e.into())),
82+
) => Err(NotConstEvaluatable::Error(e)),
8383
Ok(_) => Ok(()),
8484
}
8585
}
@@ -140,7 +140,7 @@ pub fn is_const_evaluatable<'tcx>(
140140
}
141141
Err(
142142
EvaluateConstErr::EvaluationFailure(e) | EvaluateConstErr::InvalidConstParamTy(e),
143-
) => Err(NotConstEvaluatable::Error(e.into())),
143+
) => Err(NotConstEvaluatable::Error(e)),
144144
Ok(_) => Ok(()),
145145
}
146146
}

library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
17891789
/// let x: Rc<&str> = Rc::new("Hello, world!");
17901790
/// {
17911791
/// let s = String::from("Oh, no!");
1792-
/// let mut y: Rc<&str> = x.clone().into();
1792+
/// let mut y: Rc<&str> = x.clone();
17931793
/// unsafe {
17941794
/// // this is Undefined Behavior, because x's inner type
17951795
/// // is &'long str, not &'short str

library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
24682468
/// let x: Arc<&str> = Arc::new("Hello, world!");
24692469
/// {
24702470
/// let s = String::from("Oh, no!");
2471-
/// let mut y: Arc<&str> = x.clone().into();
2471+
/// let mut y: Arc<&str> = x.clone();
24722472
/// unsafe {
24732473
/// // this is Undefined Behavior, because x's inner type
24742474
/// // is &'long str, not &'short str

library/core/src/ptr/non_null.rs

+45-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ impl<T: ?Sized> !Send for NonNull<T> {}
8585
impl<T: ?Sized> !Sync for NonNull<T> {}
8686

8787
impl<T: Sized> NonNull<T> {
88+
/// Creates a pointer with the given address and no [provenance][crate::ptr#provenance].
89+
///
90+
/// For more details, see the equivalent method on a raw pointer, [`ptr::without_provenance_mut`].
91+
///
92+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
93+
#[unstable(feature = "nonnull_provenance", issue = "135243")]
94+
pub const fn without_provenance(addr: NonZero<usize>) -> Self {
95+
// SAFETY: we know `addr` is non-zero.
96+
unsafe {
97+
let ptr = crate::ptr::without_provenance_mut(addr.get());
98+
NonNull::new_unchecked(ptr)
99+
}
100+
}
101+
88102
/// Creates a new `NonNull` that is dangling, but well-aligned.
89103
///
90104
/// This is useful for initializing types which lazily allocate, like
@@ -116,6 +130,21 @@ impl<T: Sized> NonNull<T> {
116130
}
117131
}
118132

133+
/// Converts an address back to a mutable pointer, picking up some previously 'exposed'
134+
/// [provenance][crate::ptr#provenance].
135+
///
136+
/// For more details, see the equivalent method on a raw pointer, [`ptr::with_exposed_provenance_mut`].
137+
///
138+
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
139+
#[unstable(feature = "nonnull_provenance", issue = "135243")]
140+
pub fn with_exposed_provenance(addr: NonZero<usize>) -> Self {
141+
// SAFETY: we know `addr` is non-zero.
142+
unsafe {
143+
let ptr = crate::ptr::with_exposed_provenance_mut(addr.get());
144+
NonNull::new_unchecked(ptr)
145+
}
146+
}
147+
119148
/// Returns a shared references to the value. In contrast to [`as_ref`], this does not require
120149
/// that the value has to be initialized.
121150
///
@@ -282,7 +311,7 @@ impl<T: ?Sized> NonNull<T> {
282311

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

326+
/// Exposes the ["provenance"][crate::ptr#provenance] part of the pointer for future use in
327+
/// [`with_exposed_provenance`][NonNull::with_exposed_provenance] and returns the "address" portion.
328+
///
329+
/// For more details, see the equivalent method on a raw pointer, [`pointer::expose_provenance`].
330+
///
331+
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
332+
#[unstable(feature = "nonnull_provenance", issue = "135243")]
333+
pub fn expose_provenance(self) -> NonZero<usize> {
334+
// SAFETY: The pointer is guaranteed by the type to be non-null,
335+
// meaning that the address will be non-zero.
336+
unsafe { NonZero::new_unchecked(self.as_ptr().expose_provenance()) }
337+
}
338+
297339
/// Creates a new pointer with the given address and the [provenance][crate::ptr#provenance] of
298340
/// `self`.
299341
///
300-
/// For more details see the equivalent method on a raw pointer, [`pointer::with_addr`].
342+
/// For more details, see the equivalent method on a raw pointer, [`pointer::with_addr`].
301343
///
302344
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
303345
#[must_use]
@@ -311,7 +353,7 @@ impl<T: ?Sized> NonNull<T> {
311353
/// Creates a new pointer by mapping `self`'s address to a new one, preserving the
312354
/// [provenance][crate::ptr#provenance] of `self`.
313355
///
314-
/// For more details see the equivalent method on a raw pointer, [`pointer::map_addr`].
356+
/// For more details, see the equivalent method on a raw pointer, [`pointer::map_addr`].
315357
///
316358
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
317359
#[must_use]

library/std/src/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl Builder {
502502

503503
let id = ThreadId::new();
504504
let my_thread = match name {
505-
Some(name) => Thread::new(id, name.into()),
505+
Some(name) => Thread::new(id, name),
506506
None => Thread::new_unnamed(id),
507507
};
508508

tests/ui/invalid-compile-flags/crate-type-flag.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
//@[bin] check-pass
3131

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

0 commit comments

Comments
 (0)