Skip to content

Commit 8831d76

Browse files
committed
Auto merge of #66485 - JohnTitor:rollup-vbwhg6r, r=JohnTitor
Rollup of 11 pull requests Successful merges: - #65739 (Improve documentation of `Vec::split_off(...)`) - #66271 (syntax: Keep string literals in ABIs and `asm!` more precisely) - #66344 (rustc_plugin: Remove `Registry::register_attribute`) - #66381 (find_deprecation: deprecation attr may be ill-formed meta.) - #66395 (Centralize panic macro documentation) - #66456 (Move `DIAGNOSTICS` usage to `rustc_driver`) - #66465 (add missing 'static lifetime in docs) - #66466 (miri panic_unwind: fix hack for SEH platforms) - #66469 (Use "field is never read" instead of "field is never used") - #66471 (Add test for issue 63116) - #66477 (Clarify transmute_copy documentation example) Failed merges: r? @ghost
2 parents 2cdc289 + f65cb87 commit 8831d76

Some content is hidden

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

63 files changed

+472
-461
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3522,6 +3522,7 @@ dependencies = [
35223522
"rustc",
35233523
"rustc_codegen_utils",
35243524
"rustc_data_structures",
3525+
"rustc_error_codes",
35253526
"rustc_errors",
35263527
"rustc_interface",
35273528
"rustc_lint",
@@ -3595,7 +3596,6 @@ dependencies = [
35953596
"rustc_codegen_ssa",
35963597
"rustc_codegen_utils",
35973598
"rustc_data_structures",
3598-
"rustc_error_codes",
35993599
"rustc_errors",
36003600
"rustc_incremental",
36013601
"rustc_lint",

src/liballoc/vec.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,9 @@ impl<T> Vec<T> {
13331333

13341334
/// Splits the collection into two at the given index.
13351335
///
1336-
/// Returns a newly allocated `Self`. `self` contains elements `[0, at)`,
1337-
/// and the returned `Self` contains elements `[at, len)`.
1338-
///
1339-
/// Note that the capacity of `self` does not change.
1336+
/// Returns a newly allocated vector containing the elements in the range
1337+
/// `[at, len)`. After the call, the original vector will be left containing
1338+
/// the elements `[0, at)` with its previous capacity unchanged.
13401339
///
13411340
/// # Panics
13421341
///

src/libcore/macros.rs renamed to src/libcore/macros/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/// Panics the current thread.
2-
///
3-
/// For details, see `std::macros`.
1+
#[doc(include = "panic.md")]
42
#[macro_export]
53
#[allow_internal_unstable(core_panic,
64
// FIXME(anp, eddyb) `core_intrinsics` is used here to allow calling

src/libcore/macros/panic.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Panics the current thread.
2+
3+
This allows a program to terminate immediately and provide feedback
4+
to the caller of the program. `panic!` should be used when a program reaches
5+
an unrecoverable state.
6+
7+
This macro is the perfect way to assert conditions in example code and in
8+
tests. `panic!` is closely tied with the `unwrap` method of both [`Option`]
9+
and [`Result`][runwrap] enums. Both implementations call `panic!` when they are set
10+
to None or Err variants.
11+
12+
This macro is used to inject panic into a Rust thread, causing the thread to
13+
panic entirely. Each thread's panic can be reaped as the `Box<Any>` type,
14+
and the single-argument form of the `panic!` macro will be the value which
15+
is transmitted.
16+
17+
[`Result`] enum is often a better solution for recovering from errors than
18+
using the `panic!` macro. This macro should be used to avoid proceeding using
19+
incorrect values, such as from external sources. Detailed information about
20+
error handling is found in the [book].
21+
22+
The multi-argument form of this macro panics with a string and has the
23+
[`format!`] syntax for building a string.
24+
25+
See also the macro [`compile_error!`], for raising errors during compilation.
26+
27+
[runwrap]: ../std/result/enum.Result.html#method.unwrap
28+
[`Option`]: ../std/option/enum.Option.html#method.unwrap
29+
[`Result`]: ../std/result/enum.Result.html
30+
[`format!`]: ../std/macro.format.html
31+
[`compile_error!`]: ../std/macro.compile_error.html
32+
[book]: ../book/ch09-00-error-handling.html
33+
34+
# Current implementation
35+
36+
If the main thread panics it will terminate all your threads and end your
37+
program with code `101`.
38+
39+
# Examples
40+
41+
```should_panic
42+
# #![allow(unreachable_code)]
43+
panic!();
44+
panic!("this is a terrible mistake!");
45+
panic!(4); // panic with the value of 4 to be collected elsewhere
46+
panic!("this is a {} {message}", "fancy", message = "message");
47+
```

src/libcore/mem/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,20 +744,20 @@ pub fn drop<T>(_x: T) { }
744744
/// bar: u8,
745745
/// }
746746
///
747-
/// let foo_slice = [10u8];
747+
/// let foo_array = [10u8];
748748
///
749749
/// unsafe {
750-
/// // Copy the data from 'foo_slice' and treat it as a 'Foo'
751-
/// let mut foo_struct: Foo = mem::transmute_copy(&foo_slice);
750+
/// // Copy the data from 'foo_array' and treat it as a 'Foo'
751+
/// let mut foo_struct: Foo = mem::transmute_copy(&foo_array);
752752
/// assert_eq!(foo_struct.bar, 10);
753753
///
754754
/// // Modify the copied data
755755
/// foo_struct.bar = 20;
756756
/// assert_eq!(foo_struct.bar, 20);
757757
/// }
758758
///
759-
/// // The contents of 'foo_slice' should not have changed
760-
/// assert_eq!(foo_slice, [10]);
759+
/// // The contents of 'foo_array' should not have changed
760+
/// assert_eq!(foo_array, [10]);
761761
/// ```
762762
#[inline]
763763
#[stable(feature = "rust1", since = "1.0.0")]

src/libpanic_unwind/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ cfg_if::cfg_if! {
3939
if #[cfg(miri)] {
4040
#[path = "miri.rs"]
4141
mod imp;
42-
// On MSVC we need the SEH lang items as well...
43-
// This should match the conditions of the `seh.rs` import below.
44-
#[cfg(all(target_env = "msvc", not(target_arch = "aarch64")))]
45-
#[allow(unused)]
46-
mod seh;
4742
} else if #[cfg(target_os = "emscripten")] {
4843
#[path = "emcc.rs"]
4944
mod imp;

src/libpanic_unwind/miri.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(nonstandard_style)]
2+
13
use core::any::Any;
24
use alloc::boxed::Box;
35

@@ -13,11 +15,28 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
1315
Box::from_raw(ptr)
1416
}
1517

16-
1718
// This is required by the compiler to exist (e.g., it's a lang item),
1819
// but is never used by Miri. Therefore, we just use a stub here
1920
#[lang = "eh_personality"]
2021
#[cfg(not(test))]
2122
fn rust_eh_personality() {
2223
unsafe { core::intrinsics::abort() }
2324
}
25+
26+
// The rest is required on *some* targets to exist (specifically, MSVC targets that use SEH).
27+
// We just add it on all targets. Copied from `seh.rs`.
28+
#[repr(C)]
29+
pub struct _TypeDescriptor {
30+
pub pVFTable: *const u8,
31+
pub spare: *mut u8,
32+
pub name: [u8; 11],
33+
}
34+
35+
const TYPE_NAME: [u8; 11] = *b"rust_panic\0";
36+
37+
#[cfg_attr(not(test), lang = "eh_catch_typeinfo")]
38+
static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor {
39+
pVFTable: core::ptr::null(),
40+
spare: core::ptr::null_mut(),
41+
name: TYPE_NAME,
42+
};

src/librustc/hir/def.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub enum NonMacroAttrKind {
4242
DeriveHelper,
4343
/// Single-segment custom attribute registered with `#[register_attr]`.
4444
Registered,
45-
/// Single-segment custom attribute registered by a legacy plugin (`register_attribute`).
46-
LegacyPluginHelper,
4745
}
4846

4947
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
@@ -330,7 +328,6 @@ impl NonMacroAttrKind {
330328
NonMacroAttrKind::Tool => "tool attribute",
331329
NonMacroAttrKind::DeriveHelper => "derive helper attribute",
332330
NonMacroAttrKind::Registered => "explicitly registered attribute",
333-
NonMacroAttrKind::LegacyPluginHelper => "legacy plugin helper attribute",
334331
}
335332
}
336333

@@ -345,8 +342,7 @@ impl NonMacroAttrKind {
345342
pub fn is_used(self) -> bool {
346343
match self {
347344
NonMacroAttrKind::Tool | NonMacroAttrKind::DeriveHelper => true,
348-
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered |
349-
NonMacroAttrKind::LegacyPluginHelper => false,
345+
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
350346
}
351347
}
352348
}

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ impl<'a> LoweringContext<'a> {
12191219
ImplTraitContext::disallowed(),
12201220
),
12211221
unsafety: f.unsafety,
1222-
abi: this.lower_abi(f.abi),
1222+
abi: this.lower_extern(f.ext),
12231223
decl: this.lower_fn_decl(&f.decl, None, false, None),
12241224
param_names: this.lower_fn_params_to_names(&f.decl),
12251225
}))

src/librustc/hir/lowering/item.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl LoweringContext<'_> {
735735

736736
fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod {
737737
hir::ForeignMod {
738-
abi: self.lower_abi(fm.abi),
738+
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
739739
items: fm.items
740740
.iter()
741741
.map(|x| self.lower_foreign_item(x))
@@ -1283,18 +1283,26 @@ impl LoweringContext<'_> {
12831283
unsafety: h.unsafety,
12841284
asyncness: self.lower_asyncness(h.asyncness.node),
12851285
constness: h.constness.node,
1286-
abi: self.lower_abi(h.abi),
1286+
abi: self.lower_extern(h.ext),
12871287
}
12881288
}
12891289

1290-
pub(super) fn lower_abi(&mut self, abi: Abi) -> abi::Abi {
1291-
abi::lookup(&abi.symbol.as_str()).unwrap_or_else(|| {
1290+
pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi {
1291+
abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or_else(|| {
12921292
self.error_on_invalid_abi(abi);
12931293
abi::Abi::Rust
12941294
})
12951295
}
12961296

1297-
fn error_on_invalid_abi(&self, abi: Abi) {
1297+
pub(super) fn lower_extern(&mut self, ext: Extern) -> abi::Abi {
1298+
match ext {
1299+
Extern::None => abi::Abi::Rust,
1300+
Extern::Implicit => abi::Abi::C,
1301+
Extern::Explicit(abi) => self.lower_abi(abi),
1302+
}
1303+
}
1304+
1305+
fn error_on_invalid_abi(&self, abi: StrLit) {
12981306
struct_span_err!(
12991307
self.sess,
13001308
abi.span,

0 commit comments

Comments
 (0)