Skip to content

Commit 9285d40

Browse files
committed
Auto merge of #65885 - Centril:rollup-y6b2qbf, r=Centril
Rollup of 6 pull requests Successful merges: - #64747 (Stabilize `Option::flatten`) - #65664 (`std::panic::Location` is a lang_item, add `core::intrinsics::caller_location` (RFC 2091 3/N)) - #65792 (rustc, rustc_passes: reduce deps on rustc_expand) - #65849 (librustc_lexer: Enhance documentation) - #65873 (doc: explain why it is unsafe to construct Vec<u8> from Vec<u16>) - #65880 (Gather together usefulness tests) Failed merges: r? @ghost
2 parents 95f437b + 606743e commit 9285d40

File tree

140 files changed

+698
-300
lines changed

Some content is hidden

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

140 files changed

+698
-300
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,6 @@ dependencies = [
31353135
"serialize",
31363136
"smallvec",
31373137
"syntax",
3138-
"syntax_expand",
31393138
"syntax_pos",
31403139
]
31413140

@@ -3451,7 +3450,6 @@ dependencies = [
34513450
"rustc_target",
34523451
"serialize",
34533452
"syntax",
3454-
"syntax_expand",
34553453
"syntax_pos",
34563454
"tempfile",
34573455
]
@@ -3707,7 +3705,6 @@ dependencies = [
37073705
"rustc_index",
37083706
"rustc_target",
37093707
"syntax",
3710-
"syntax_expand",
37113708
"syntax_pos",
37123709
]
37133710

src/liballoc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![feature(drain_filter)]
44
#![feature(exact_size_is_empty)]
55
#![feature(new_uninit)]
6-
#![feature(option_flattening)]
76
#![feature(pattern)]
87
#![feature(trusted_len)]
98
#![feature(try_reserve)]

src/liballoc/vec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ impl<T> Vec<T> {
411411
///
412412
/// Violating these may cause problems like corrupting the allocator's
413413
/// internal data structures. For example it is **not** safe
414-
/// to build a `Vec<u8>` from a pointer to a C `char` array and a `size_t`.
414+
/// to build a `Vec<u8>` from a pointer to a C `char` array with length `size_t`.
415+
/// It's also not safe to build one from a `Vec<u16>` and its length, because
416+
/// the allocator cares about the alignment, and these two types have different
417+
/// alignments. The buffer was allocated with alignment 2 (for `u16`), but after
418+
/// turning it into a `Vec<u8>` it'll be deallocated with alignment 1.
415419
///
416420
/// The ownership of `ptr` is effectively transferred to the
417421
/// `Vec<T>` which may then deallocate, reallocate or change the

src/libcore/intrinsics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ extern "rust-intrinsic" {
696696
/// This will statically either panic, or do nothing.
697697
pub fn panic_if_uninhabited<T>();
698698

699+
/// Gets a reference to a static `Location` indicating where it was called.
700+
#[cfg(not(bootstrap))]
701+
pub fn caller_location() -> &'static crate::panic::Location<'static>;
702+
699703
/// Creates a value initialized to zero.
700704
///
701705
/// `init` is unsafe because it returns a zeroed-out datum,

src/libcore/macros.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/// Panics the current thread.
22
///
33
/// For details, see `std::macros`.
4+
#[cfg(bootstrap)]
45
#[macro_export]
5-
#[allow_internal_unstable(core_panic)]
6+
#[allow_internal_unstable(core_panic, panic_internals)]
67
#[stable(feature = "core", since = "1.6.0")]
78
macro_rules! panic {
89
() => (
@@ -20,6 +21,38 @@ macro_rules! panic {
2021
});
2122
}
2223

24+
/// Panics the current thread.
25+
///
26+
/// For details, see `std::macros`.
27+
#[cfg(not(bootstrap))]
28+
#[macro_export]
29+
#[allow_internal_unstable(core_panic, panic_internals)]
30+
#[stable(feature = "core", since = "1.6.0")]
31+
macro_rules! panic {
32+
() => (
33+
$crate::panic!("explicit panic")
34+
);
35+
($msg:expr) => ({
36+
const LOC: &$crate::panic::Location<'_> = &$crate::panic::Location::internal_constructor(
37+
$crate::file!(),
38+
$crate::line!(),
39+
$crate::column!(),
40+
);
41+
$crate::panicking::panic($msg, LOC)
42+
});
43+
($msg:expr,) => (
44+
$crate::panic!($msg)
45+
);
46+
($fmt:expr, $($arg:tt)+) => ({
47+
const LOC: &$crate::panic::Location<'_> = &$crate::panic::Location::internal_constructor(
48+
$crate::file!(),
49+
$crate::line!(),
50+
$crate::column!(),
51+
);
52+
$crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+), LOC)
53+
});
54+
}
55+
2356
/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
2457
///
2558
/// On panic, this macro will print the values of the expressions with their

src/libcore/option.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,6 @@ impl<T> Option<Option<T>> {
15671567
/// # Examples
15681568
/// Basic usage:
15691569
/// ```
1570-
/// #![feature(option_flattening)]
15711570
/// let x: Option<Option<u32>> = Some(Some(6));
15721571
/// assert_eq!(Some(6), x.flatten());
15731572
///
@@ -1579,13 +1578,12 @@ impl<T> Option<Option<T>> {
15791578
/// ```
15801579
/// Flattening once only removes one level of nesting:
15811580
/// ```
1582-
/// #![feature(option_flattening)]
15831581
/// let x: Option<Option<Option<u32>>> = Some(Some(Some(6)));
15841582
/// assert_eq!(Some(Some(6)), x.flatten());
15851583
/// assert_eq!(Some(6), x.flatten().flatten());
15861584
/// ```
15871585
#[inline]
1588-
#[unstable(feature = "option_flattening", issue = "60258")]
1586+
#[stable(feature = "option_flattening", since = "1.40.0")]
15891587
pub fn flatten(self) -> Option<T> {
15901588
self.and_then(convert::identity)
15911589
}

src/libcore/panic.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::fmt;
3535
pub struct PanicInfo<'a> {
3636
payload: &'a (dyn Any + Send),
3737
message: Option<&'a fmt::Arguments<'a>>,
38-
location: Location<'a>,
38+
location: &'a Location<'a>,
3939
}
4040

4141
impl<'a> PanicInfo<'a> {
@@ -45,11 +45,16 @@ impl<'a> PanicInfo<'a> {
4545
issue = "0")]
4646
#[doc(hidden)]
4747
#[inline]
48-
pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>,
49-
location: Location<'a>)
50-
-> Self {
48+
pub fn internal_constructor(
49+
message: Option<&'a fmt::Arguments<'a>>,
50+
location: &'a Location<'a>,
51+
) -> Self {
5152
struct NoPayload;
52-
PanicInfo { payload: &NoPayload, location, message }
53+
PanicInfo {
54+
location,
55+
message,
56+
payload: &NoPayload,
57+
}
5358
}
5459

5560
#[doc(hidden)]
@@ -162,6 +167,7 @@ impl fmt::Display for PanicInfo<'_> {
162167
///
163168
/// panic!("Normal panic");
164169
/// ```
170+
#[cfg_attr(not(bootstrap), lang = "panic_location")]
165171
#[derive(Debug)]
166172
#[stable(feature = "panic_hooks", since = "1.10.0")]
167173
pub struct Location<'a> {
@@ -176,7 +182,7 @@ impl<'a> Location<'a> {
176182
and related macros",
177183
issue = "0")]
178184
#[doc(hidden)]
179-
pub fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self {
185+
pub const fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self {
180186
Location { file, line, col }
181187
}
182188

src/libcore/panicking.rs

+59-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use crate::fmt;
3030
use crate::panic::{Location, PanicInfo};
3131

32+
#[cfg(bootstrap)]
3233
#[cold]
3334
// never inline unless panic_immediate_abort to avoid code
3435
// bloat at the call sites as much as possible
@@ -49,6 +50,27 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
4950
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), &(file, line, col))
5051
}
5152

53+
#[cfg(not(bootstrap))]
54+
#[cold]
55+
// never inline unless panic_immediate_abort to avoid code
56+
// bloat at the call sites as much as possible
57+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
58+
#[lang = "panic"]
59+
pub fn panic(expr: &str, location: &Location<'_>) -> ! {
60+
if cfg!(feature = "panic_immediate_abort") {
61+
unsafe { super::intrinsics::abort() }
62+
}
63+
64+
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
65+
// reduce size overhead. The format_args! macro uses str's Display trait to
66+
// write expr, which calls Formatter::pad, which must accommodate string
67+
// truncation and padding (even though none is used here). Using
68+
// Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
69+
// output binary, saving up to a few kilobytes.
70+
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), location)
71+
}
72+
73+
#[cfg(bootstrap)]
5274
#[cold]
5375
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
5476
#[lang = "panic_bounds_check"]
@@ -62,6 +84,22 @@ fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
6284
len, index), file_line_col)
6385
}
6486

87+
#[cfg(not(bootstrap))]
88+
#[cold]
89+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
90+
#[lang = "panic_bounds_check"]
91+
fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
92+
if cfg!(feature = "panic_immediate_abort") {
93+
unsafe { super::intrinsics::abort() }
94+
}
95+
96+
panic_fmt(
97+
format_args!("index out of bounds: the len is {} but the index is {}", len, index),
98+
location
99+
)
100+
}
101+
102+
#[cfg(bootstrap)]
65103
#[cold]
66104
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
67105
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
@@ -77,9 +115,26 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
77115
}
78116

79117
let (file, line, col) = *file_line_col;
80-
let pi = PanicInfo::internal_constructor(
81-
Some(&fmt),
82-
Location::internal_constructor(file, line, col),
83-
);
118+
let location = Location::internal_constructor(file, line, col);
119+
let pi = PanicInfo::internal_constructor(Some(&fmt), &location);
120+
unsafe { panic_impl(&pi) }
121+
}
122+
123+
#[cfg(not(bootstrap))]
124+
#[cold]
125+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
126+
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
127+
pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
128+
if cfg!(feature = "panic_immediate_abort") {
129+
unsafe { super::intrinsics::abort() }
130+
}
131+
132+
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
133+
extern "Rust" {
134+
#[lang = "panic_impl"]
135+
fn panic_impl(pi: &PanicInfo<'_>) -> !;
136+
}
137+
138+
let pi = PanicInfo::internal_constructor(Some(&fmt), location);
84139
unsafe { panic_impl(&pi) }
85140
}

src/librustc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ rustc_index = { path = "../librustc_index" }
2929
errors = { path = "../librustc_errors", package = "rustc_errors" }
3030
rustc_serialize = { path = "../libserialize", package = "serialize" }
3131
syntax = { path = "../libsyntax" }
32-
syntax_expand = { path = "../libsyntax_expand" }
3332
syntax_pos = { path = "../libsyntax_pos" }
3433
backtrace = "0.3.3"
3534
parking_lot = "0.9"

src/librustc/hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::ty;
66
use crate::util::nodemap::DefIdMap;
77

88
use syntax::ast;
9-
use syntax_expand::base::MacroKind;
109
use syntax::ast::NodeId;
10+
use syntax_pos::hygiene::MacroKind;
1111
use syntax_pos::Span;
1212
use rustc_macros::HashStable;
1313

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use syntax::ast;
6464
use syntax::ptr::P as AstP;
6565
use syntax::ast::*;
6666
use syntax::errors;
67-
use syntax_expand::base::SpecialDerives;
67+
use syntax::expand::SpecialDerives;
6868
use syntax::print::pprust;
6969
use syntax::parse::token::{self, Nonterminal, Token};
7070
use syntax::tokenstream::{TokenStream, TokenTree};

src/librustc/hir/lowering/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use smallvec::SmallVec;
1818
use syntax::attr;
1919
use syntax::ast::*;
2020
use syntax::visit::{self, Visitor};
21-
use syntax_expand::base::SpecialDerives;
21+
use syntax::expand::SpecialDerives;
2222
use syntax::source_map::{respan, DesugaringKind, Spanned};
2323
use syntax::symbol::{kw, sym};
2424
use syntax_pos::Span;

src/librustc/hir/map/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use crate::hir::map::definitions::*;
22
use crate::hir::def_id::DefIndex;
33

44
use syntax::ast::*;
5-
use syntax_expand::hygiene::ExpnId;
65
use syntax::visit;
76
use syntax::symbol::{kw, sym};
87
use syntax::parse::token::{self, Token};
8+
use syntax_pos::hygiene::ExpnId;
99
use syntax_pos::Span;
1010

1111
/// Creates `DefId`s for nodes in the AST.

src/librustc/hir/map/definitions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::borrow::Borrow;
1717
use std::fmt::Write;
1818
use std::hash::Hash;
1919
use syntax::ast;
20-
use syntax_expand::hygiene::ExpnId;
21-
use syntax::symbol::{Symbol, sym};
20+
use syntax_pos::symbol::{Symbol, sym};
21+
use syntax_pos::hygiene::ExpnId;
2222
use syntax_pos::{Span, DUMMY_SP};
2323

2424
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_data_structures::svh::Svh;
2020
use rustc_index::vec::IndexVec;
2121
use syntax::ast::{self, Name, NodeId};
2222
use syntax::source_map::Spanned;
23-
use syntax_expand::base::MacroKind;
23+
use syntax_pos::hygiene::MacroKind;
2424
use syntax_pos::{Span, DUMMY_SP};
2525

2626
pub mod blocks;

src/librustc/ich/hcx.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use std::cell::RefCell;
1313

1414
use syntax::ast;
1515
use syntax::source_map::SourceMap;
16-
use syntax_expand::hygiene::SyntaxContext;
1716
use syntax::symbol::Symbol;
1817
use syntax::tokenstream::DelimSpan;
1918
use syntax_pos::{Span, DUMMY_SP};
20-
use syntax_pos::hygiene;
19+
use syntax_pos::hygiene::{self, SyntaxContext};
2120

2221
use rustc_data_structures::stable_hasher::{
2322
HashStable, StableHasher, ToStableHashKey,

src/librustc/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl_stable_hash_for!(enum ::syntax::ast::AsmDialect {
6060
Intel
6161
});
6262

63-
impl_stable_hash_for!(enum ::syntax_expand::base::MacroKind {
63+
impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind {
6464
Bang,
6565
Attr,
6666
Derive,

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use syntax::ast;
3939
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
4040
use syntax::early_buffered_lints::BufferedEarlyLintId;
4141
use syntax::edition::Edition;
42-
use syntax_expand::base::MacroKind;
4342
use syntax::symbol::{Symbol, sym};
43+
use syntax_pos::hygiene::MacroKind;
4444
use syntax_pos::Span;
4545

4646
pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore,

src/librustc/middle/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ language_item_table! {
370370
PanicFnLangItem, "panic", panic_fn, Target::Fn;
371371
PanicBoundsCheckFnLangItem, "panic_bounds_check", panic_bounds_check_fn, Target::Fn;
372372
PanicInfoLangItem, "panic_info", panic_info, Target::Struct;
373+
PanicLocationLangItem, "panic_location", panic_location, Target::Struct;
373374
PanicImplLangItem, "panic_impl", panic_impl, Target::Fn;
374375
// Libstd panic entry point. Necessary for const eval to be able to catch it
375376
BeginPanicFnLangItem, "begin_panic", begin_panic_fn, Target::Fn;

src/librustc/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ rustc_queries! {
466466
no_force
467467
desc { "extract field of const" }
468468
}
469+
470+
query const_caller_location(key: (syntax_pos::Symbol, u32, u32)) -> &'tcx ty::Const<'tcx> {
471+
eval_always
472+
no_force
473+
desc { "get a &core::panic::Location referring to a span" }
474+
}
469475
}
470476

471477
TypeChecking {

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use errors::emitter::HumanReadableErrorType;
2424
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2525
use syntax::ast::{self, NodeId};
2626
use syntax::edition::Edition;
27-
use syntax_expand::allocator::AllocatorKind;
27+
use syntax::expand::allocator::AllocatorKind;
2828
use syntax::feature_gate::{self, AttributeType};
2929
use syntax::json::JsonEmitter;
3030
use syntax::source_map;

0 commit comments

Comments
 (0)