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

+1-1
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

+3-4
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 src/libcore/macros/mod.rs

+1-3
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

+47
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

+5-5
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

-5
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

+20-1
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

+1-5
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

+1-1
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

+13-5
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,

src/librustc/session/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ use errors::emitter::{Emitter, EmitterWriter};
2121
use errors::emitter::HumanReadableErrorType;
2222
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2323
use syntax::edition::Edition;
24-
use syntax::feature_gate::{self, AttributeType};
24+
use syntax::feature_gate;
2525
use errors::json::JsonEmitter;
2626
use syntax::source_map;
2727
use syntax::sess::{ParseSess, ProcessCfgMod};
28-
use syntax::symbol::Symbol;
2928
use syntax_pos::{MultiSpan, Span};
3029

3130
use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
@@ -79,7 +78,6 @@ pub struct Session {
7978
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
8079
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
8180
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
82-
pub plugin_attributes: Lock<Vec<(Symbol, AttributeType)>>,
8381
pub crate_types: Once<Vec<config::CrateType>>,
8482
/// The `crate_disambiguator` is constructed out of all the `-C metadata`
8583
/// arguments passed to the compiler. Its value together with the crate-name
@@ -1039,12 +1037,11 @@ pub fn build_session_with_source_map(
10391037

10401038
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
10411039

1042-
let emitter = match diagnostics_output {
1043-
DiagnosticOutput::Default => default_emitter(&sopts, registry, &source_map, None),
1044-
DiagnosticOutput::Raw(write) => {
1045-
default_emitter(&sopts, registry, &source_map, Some(write))
1046-
}
1040+
let write_dest = match diagnostics_output {
1041+
DiagnosticOutput::Default => None,
1042+
DiagnosticOutput::Raw(write) => Some(write),
10471043
};
1044+
let emitter = default_emitter(&sopts, registry, &source_map, write_dest);
10481045

10491046
let diagnostic_handler = errors::Handler::with_emitter_and_flags(
10501047
emitter,
@@ -1166,7 +1163,6 @@ fn build_session_(
11661163
working_dir,
11671164
one_time_diagnostics: Default::default(),
11681165
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
1169-
plugin_attributes: Lock::new(Vec::new()),
11701166
crate_types: Once::new(),
11711167
crate_disambiguator: Once::new(),
11721168
features: Once::new(),

src/librustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ rustc_plugin = { path = "../librustc_plugin/deprecated" } # To get this in the s
2626
rustc_plugin_impl = { path = "../librustc_plugin" }
2727
rustc_save_analysis = { path = "../librustc_save_analysis" }
2828
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
29+
rustc_error_codes = { path = "../librustc_error_codes" }
2930
rustc_interface = { path = "../librustc_interface" }
3031
rustc_serialize = { path = "../libserialize", package = "serialize" }
3132
rustc_resolve = { path = "../librustc_resolve" }

src/librustc_driver/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc::ty::TyCtxt;
4040
use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
4141
use rustc_metadata::locator;
4242
use rustc_codegen_utils::codegen_backend::CodegenBackend;
43-
use errors::PResult;
43+
use errors::{PResult, registry::Registry};
4444
use rustc_interface::interface;
4545
use rustc_interface::util::get_codegen_sysroot;
4646
use rustc_data_structures::sync::SeqCst;
@@ -140,6 +140,10 @@ impl Callbacks for TimePassesCallbacks {
140140
}
141141
}
142142

143+
pub fn diagnostics_registry() -> Registry {
144+
Registry::new(&rustc_error_codes::DIAGNOSTICS)
145+
}
146+
143147
// Parse args and run the compiler. This is the primary entry point for rustc.
144148
// See comments on CompilerCalls below for details about the callbacks argument.
145149
// The FileLoader provides a way to load files from sources other than the file system.
@@ -182,13 +186,14 @@ pub fn run_compiler(
182186
lint_caps: Default::default(),
183187
register_lints: None,
184188
override_queries: None,
189+
registry: diagnostics_registry(),
185190
};
186191
callbacks.config(&mut config);
187192
config
188193
};
189194

190195
if let Some(ref code) = matches.opt_str("explain") {
191-
handle_explain(code, sopts.error_format);
196+
handle_explain(diagnostics_registry(), code, sopts.error_format);
192197
return Ok(());
193198
}
194199

@@ -261,6 +266,7 @@ pub fn run_compiler(
261266
lint_caps: Default::default(),
262267
register_lints: None,
263268
override_queries: None,
269+
registry: diagnostics_registry(),
264270
};
265271

266272
callbacks.config(&mut config);
@@ -510,15 +516,13 @@ fn stdout_isatty() -> bool {
510516
}
511517
}
512518

513-
fn handle_explain(code: &str,
514-
output: ErrorOutputType) {
515-
let descriptions = rustc_interface::util::diagnostics_registry();
519+
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
516520
let normalised = if code.starts_with("E") {
517521
code.to_string()
518522
} else {
519523
format!("E{0:0>4}", code)
520524
};
521-
match descriptions.find_description(&normalised) {
525+
match registry.find_description(&normalised) {
522526
Some(ref description) => {
523527
let mut is_in_code_block = false;
524528
let mut text = String::new();

src/librustc_error_codes/error_codes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// Error messages' format must follow the RFC 1567 available here:
88
// https://github.com/rust-lang/rfcs/pull/1567
99

10-
crate::register_diagnostics! {
11-
10+
register_diagnostics! {
1211
E0001: include_str!("./error_codes/E0001.md"),
1312
E0002: include_str!("./error_codes/E0002.md"),
1413
E0004: include_str!("./error_codes/E0004.md"),

src/librustc_error_codes/lib.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
//! This library is used to gather all error codes into one place. The goal
2-
//! being to make their maintenance easier.
1+
//! This library is used to gather all error codes into one place,
2+
//! the goal being to make their maintenance easier.
33
4-
#[macro_export]
54
macro_rules! register_diagnostics {
6-
($($ecode:ident: $message:expr,)*) => (
7-
$crate::register_diagnostics!{$($ecode:$message,)* ;}
8-
);
9-
105
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
116
pub static DIAGNOSTICS: &[(&str, &str)] = &[
127
$( (stringify!($ecode), $message), )*
138
];
149

1510
$(
16-
pub const $ecode: &str = $message;
11+
pub const $ecode: () = ();
1712
)*
1813
$(
1914
pub const $code: () = ();

src/librustc_interface/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ rustc_errors = { path = "../librustc_errors" }
3434
rustc_plugin = { path = "../librustc_plugin", package = "rustc_plugin_impl" }
3535
rustc_privacy = { path = "../librustc_privacy" }
3636
rustc_resolve = { path = "../librustc_resolve" }
37-
rustc_error_codes = { path = "../librustc_error_codes" }
3837
tempfile = "3.0.5"
3938
once_cell = "1"
4039

0 commit comments

Comments
 (0)