Skip to content

Commit fc272e8

Browse files
celinvaltedinski
authored andcommitted
Merge rustc into rmc - 2021 week 45 (rust-lang#634)
Conflicts: .github/workflows/ci.yml src/librustdoc/lib.rs Resolution: . Keep deleted ci.yml . Manually merge import changes deleted: src/tools/dashboard/configs/books/The Unstable Book/Library Features/format_args_capture/28.props
1 parent 718b876 commit fc272e8

File tree

226 files changed

+9544
-1559
lines changed

Some content is hidden

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

226 files changed

+9544
-1559
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 7 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![feature(rustc_attrs)]
2020
#![cfg_attr(test, feature(test))]
2121

22-
use rustc_data_structures::sync;
2322
use smallvec::SmallVec;
2423

2524
use std::alloc::Layout;
@@ -517,130 +516,12 @@ impl DroplessArena {
517516
}
518517
}
519518

520-
/// Calls the destructor for an object when dropped.
521-
struct DropType {
522-
drop_fn: unsafe fn(*mut u8),
523-
obj: *mut u8,
524-
}
525-
526-
// SAFETY: we require `T: Send` before type-erasing into `DropType`.
527-
#[cfg(parallel_compiler)]
528-
unsafe impl sync::Send for DropType {}
529-
530-
impl DropType {
531-
#[inline]
532-
unsafe fn new<T: sync::Send>(obj: *mut T) -> Self {
533-
unsafe fn drop_for_type<T>(to_drop: *mut u8) {
534-
std::ptr::drop_in_place(to_drop as *mut T)
535-
}
536-
537-
DropType { drop_fn: drop_for_type::<T>, obj: obj as *mut u8 }
538-
}
539-
}
540-
541-
impl Drop for DropType {
542-
fn drop(&mut self) {
543-
unsafe { (self.drop_fn)(self.obj) }
544-
}
545-
}
546-
547-
/// An arena which can be used to allocate any type.
548-
///
549-
/// # Safety
550-
///
551-
/// Allocating in this arena is unsafe since the type system
552-
/// doesn't know which types it contains. In order to
553-
/// allocate safely, you must store a `PhantomData<T>`
554-
/// alongside this arena for each type `T` you allocate.
555-
#[derive(Default)]
556-
pub struct DropArena {
557-
/// A list of destructors to run when the arena drops.
558-
/// Ordered so `destructors` gets dropped before the arena
559-
/// since its destructor can reference memory in the arena.
560-
destructors: RefCell<Vec<DropType>>,
561-
arena: DroplessArena,
562-
}
563-
564-
impl DropArena {
565-
#[inline]
566-
pub unsafe fn alloc<T>(&self, object: T) -> &mut T
567-
where
568-
T: sync::Send,
569-
{
570-
let mem = self.arena.alloc_raw(Layout::new::<T>()) as *mut T;
571-
// Write into uninitialized memory.
572-
ptr::write(mem, object);
573-
let result = &mut *mem;
574-
// Record the destructor after doing the allocation as that may panic
575-
// and would cause `object`'s destructor to run twice if it was recorded before.
576-
self.destructors.borrow_mut().push(DropType::new(result));
577-
result
578-
}
579-
580-
#[inline]
581-
pub unsafe fn alloc_from_iter<T, I>(&self, iter: I) -> &mut [T]
582-
where
583-
T: sync::Send,
584-
I: IntoIterator<Item = T>,
585-
{
586-
let mut vec: SmallVec<[_; 8]> = iter.into_iter().collect();
587-
if vec.is_empty() {
588-
return &mut [];
589-
}
590-
let len = vec.len();
591-
592-
let start_ptr = self.arena.alloc_raw(Layout::array::<T>(len).unwrap()) as *mut T;
593-
594-
let mut destructors = self.destructors.borrow_mut();
595-
// Reserve space for the destructors so we can't panic while adding them.
596-
destructors.reserve(len);
597-
598-
// Move the content to the arena by copying it and then forgetting
599-
// the content of the SmallVec.
600-
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
601-
mem::forget(vec.drain(..));
602-
603-
// Record the destructors after doing the allocation as that may panic
604-
// and would cause `object`'s destructor to run twice if it was recorded before.
605-
for i in 0..len {
606-
destructors.push(DropType::new(start_ptr.add(i)));
607-
}
608-
609-
slice::from_raw_parts_mut(start_ptr, len)
610-
}
611-
}
612-
613-
pub macro arena_for_type {
614-
([][$ty:ty]) => {
615-
$crate::TypedArena<$ty>
616-
},
617-
([few $(, $attrs:ident)*][$ty:ty]) => {
618-
::std::marker::PhantomData<$ty>
619-
},
620-
([$ignore:ident $(, $attrs:ident)*]$args:tt) => {
621-
$crate::arena_for_type!([$($attrs),*]$args)
622-
},
623-
}
624-
625-
pub macro which_arena_for_type {
626-
([][$arena:expr]) => {
627-
::std::option::Option::Some($arena)
628-
},
629-
([few$(, $attrs:ident)*][$arena:expr]) => {
630-
::std::option::Option::None
631-
},
632-
([$ignore:ident$(, $attrs:ident)*]$args:tt) => {
633-
$crate::which_arena_for_type!([$($attrs),*]$args)
634-
},
635-
}
636-
637519
#[rustc_macro_transparency = "semitransparent"]
638520
pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
639521
#[derive(Default)]
640522
pub struct Arena<$tcx> {
641523
pub dropless: $crate::DroplessArena,
642-
drop: $crate::DropArena,
643-
$($name: $crate::arena_for_type!($a[$ty]),)*
524+
$($name: $crate::TypedArena<$ty>,)*
644525
}
645526

646527
pub trait ArenaAllocatable<'tcx, T = Self>: Sized {
@@ -670,13 +551,9 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
670551
#[inline]
671552
fn allocate_on<'a>(self, arena: &'a Arena<$tcx>) -> &'a mut Self {
672553
if !::std::mem::needs_drop::<Self>() {
673-
return arena.dropless.alloc(self);
674-
}
675-
match $crate::which_arena_for_type!($a[&arena.$name]) {
676-
::std::option::Option::<&$crate::TypedArena<Self>>::Some(ty_arena) => {
677-
ty_arena.alloc(self)
678-
}
679-
::std::option::Option::None => unsafe { arena.drop.alloc(self) },
554+
arena.dropless.alloc(self)
555+
} else {
556+
arena.$name.alloc(self)
680557
}
681558
}
682559

@@ -686,13 +563,9 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
686563
iter: impl ::std::iter::IntoIterator<Item = Self>,
687564
) -> &'a mut [Self] {
688565
if !::std::mem::needs_drop::<Self>() {
689-
return arena.dropless.alloc_from_iter(iter);
690-
}
691-
match $crate::which_arena_for_type!($a[&arena.$name]) {
692-
::std::option::Option::<&$crate::TypedArena<Self>>::Some(ty_arena) => {
693-
ty_arena.alloc_from_iter(iter)
694-
}
695-
::std::option::Option::None => unsafe { arena.drop.alloc_from_iter(iter) },
566+
arena.dropless.alloc_from_iter(iter)
567+
} else {
568+
arena.$name.alloc_from_iter(iter)
696569
}
697570
}
698571
}

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ pub struct InlineAsm {
20582058
pub template: Vec<InlineAsmTemplatePiece>,
20592059
pub template_strs: Box<[(Symbol, Option<Symbol>, Span)]>,
20602060
pub operands: Vec<(InlineAsmOperand, Span)>,
2061-
pub clobber_abi: Option<(Symbol, Span)>,
2061+
pub clobber_abis: Vec<(Symbol, Span)>,
20622062
pub options: InlineAsmOptions,
20632063
pub line_spans: Vec<Span>,
20642064
}
@@ -2715,7 +2715,7 @@ pub enum ItemKind {
27152715
/// E.g., `extern {}` or `extern "C" {}`.
27162716
ForeignMod(ForeignMod),
27172717
/// Module-level inline assembly (from `global_asm!()`).
2718-
GlobalAsm(InlineAsm),
2718+
GlobalAsm(Box<InlineAsm>),
27192719
/// A type alias (`type`).
27202720
///
27212721
/// E.g., `type Foo = Bar<u8>;`.

compiler/rustc_ast/src/util/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
169169
if let Some(mut idx) = token_text.find('\n') {
170170
code_to_the_left = false;
171171
while let Some(next_newline) = &token_text[idx + 1..].find('\n') {
172-
idx = idx + 1 + next_newline;
172+
idx += 1 + next_newline;
173173
comments.push(Comment {
174174
style: CommentStyle::BlankLine,
175175
lines: vec![],

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::LoweringContext;
22

33
use rustc_ast::*;
44
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_data_structures::stable_set::FxHashSet;
56
use rustc_errors::struct_span_err;
67
use rustc_hir as hir;
78
use rustc_session::parse::feature_err;
@@ -49,22 +50,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4950
.emit();
5051
}
5152

52-
let mut clobber_abi = None;
53+
let mut clobber_abis = FxHashMap::default();
5354
if let Some(asm_arch) = asm_arch {
54-
if let Some((abi_name, abi_span)) = asm.clobber_abi {
55-
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.sess.target, abi_name) {
56-
Ok(abi) => clobber_abi = Some((abi, abi_span)),
55+
for (abi_name, abi_span) in &asm.clobber_abis {
56+
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.sess.target, *abi_name) {
57+
Ok(abi) => {
58+
// If the abi was already in the list, emit an error
59+
match clobber_abis.get(&abi) {
60+
Some((prev_name, prev_sp)) => {
61+
let mut err = self.sess.struct_span_err(
62+
*abi_span,
63+
&format!("`{}` ABI specified multiple times", prev_name),
64+
);
65+
err.span_label(*prev_sp, "previously specified here");
66+
67+
// Multiple different abi names may actually be the same ABI
68+
// If the specified ABIs are not the same name, alert the user that they resolve to the same ABI
69+
let source_map = self.sess.source_map();
70+
if source_map.span_to_snippet(*prev_sp)
71+
!= source_map.span_to_snippet(*abi_span)
72+
{
73+
err.note("these ABIs are equivalent on the current target");
74+
}
75+
76+
err.emit();
77+
}
78+
None => {
79+
clobber_abis.insert(abi, (abi_name, *abi_span));
80+
}
81+
}
82+
}
5783
Err(&[]) => {
5884
self.sess
5985
.struct_span_err(
60-
abi_span,
86+
*abi_span,
6187
"`clobber_abi` is not supported on this target",
6288
)
6389
.emit();
6490
}
6591
Err(supported_abis) => {
6692
let mut err =
67-
self.sess.struct_span_err(abi_span, "invalid ABI for `clobber_abi`");
93+
self.sess.struct_span_err(*abi_span, "invalid ABI for `clobber_abi`");
6894
let mut abis = format!("`{}`", supported_abis[0]);
6995
for m in &supported_abis[1..] {
7096
let _ = write!(abis, ", `{}`", m);
@@ -348,8 +374,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
348374

349375
// If a clobber_abi is specified, add the necessary clobbers to the
350376
// operands list.
351-
if let Some((abi, abi_span)) = clobber_abi {
377+
let mut clobbered = FxHashSet::default();
378+
for (abi, (_, abi_span)) in clobber_abis {
352379
for &clobber in abi.clobbered_regs() {
380+
// Don't emit a clobber for a register already clobbered
381+
if clobbered.contains(&clobber) {
382+
continue;
383+
}
384+
353385
let mut output_used = false;
354386
clobber.overlapping_regs(|reg| {
355387
if used_output_regs.contains_key(&reg) {
@@ -366,6 +398,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
366398
},
367399
self.lower_span(abi_span),
368400
));
401+
clobbered.insert(clobber);
369402
}
370403
}
371404
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId};
44
use rustc_ast::{PatKind, RangeEnd, VariantData};
55
use rustc_errors::struct_span_err;
6-
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
6+
use rustc_feature::{AttributeGate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
77
use rustc_feature::{Features, GateIssue};
88
use rustc_session::parse::{feature_err, feature_err_issue};
99
use rustc_session::Session;
@@ -301,11 +301,14 @@ impl<'a> PostExpansionVisitor<'a> {
301301

302302
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
303303
fn visit_attribute(&mut self, attr: &ast::Attribute) {
304-
let attr_info =
305-
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
304+
let attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
306305
// Check feature gates for built-in attributes.
307-
if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
308-
gate_feature_fn!(self, has_feature, attr.span, name, descr);
306+
if let Some(BuiltinAttribute {
307+
gate: AttributeGate::Gated(_, name, descr, has_feature),
308+
..
309+
}) = attr_info
310+
{
311+
gate_feature_fn!(self, has_feature, attr.span, *name, descr);
309312
}
310313
// Check unstable flavors of the `#[doc]` attribute.
311314
if attr.has_name(sym::doc) {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,8 @@ impl<'a> State<'a> {
22352235

22362236
let mut args = vec![AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template))];
22372237
args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
2238-
if let Some((abi, _)) = asm.clobber_abi {
2239-
args.push(AsmArg::ClobberAbi(abi));
2238+
for (abi, _) in &asm.clobber_abis {
2239+
args.push(AsmArg::ClobberAbi(*abi));
22402240
}
22412241
if !asm.options.is_empty() {
22422242
args.push(AsmArg::Options(asm.options));

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(bool_to_option)]
44
#![feature(box_patterns)]
55
#![feature(crate_visibility_modifier)]
6-
#![feature(format_args_capture)]
6+
#![cfg_attr(bootstrap, feature(format_args_capture))]
77
#![feature(in_band_lifetimes)]
88
#![feature(iter_zip)]
99
#![feature(let_else)]

0 commit comments

Comments
 (0)