Skip to content

Commit 6de3a73

Browse files
committed
Auto merge of #141753 - matthiaskrgr:rollup-bw4j2u0, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #133823 (Use `cfg_attr_trace` in AST with a placeholder attribute for accurate suggestion) - #141004 (Report text_direction_codepoint_in_literal when parsing) - #141407 (Refactor the two-phase check for impls and impl items) - #141430 (remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`) - #141507 (atomic_load intrinsic: use const generic parameter for ordering) - #141538 (implement `va_arg` for x86_64 systemv) - #141669 (float: Replace some approximate assertions with exact) - #141747 (rustdoc: display doc(cfg(false)) properly) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1c0849d + 71529f5 commit 6de3a73

File tree

76 files changed

+2060
-1322
lines changed

Some content is hidden

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

76 files changed

+2060
-1322
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@ dependencies = [
21712171
name = "lint-docs"
21722172
version = "0.1.0"
21732173
dependencies = [
2174+
"rustc-literal-escaper",
21742175
"serde_json",
21752176
"tempfile",
21762177
"walkdir",

compiler/rustc_ast/src/ast.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_data_structures::tagged_ptr::Tag;
3232
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3333
pub use rustc_span::AttrId;
3434
use rustc_span::source_map::{Spanned, respan};
35-
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
35+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
3636
use thin_vec::{ThinVec, thin_vec};
3737

3838
pub use crate::format::*;
@@ -1526,6 +1526,19 @@ impl Expr {
15261526
| ExprKind::Struct(_)
15271527
)
15281528
}
1529+
1530+
/// Creates a dummy `P<Expr>`.
1531+
///
1532+
/// Should only be used when it will be replaced afterwards or as a return value when an error was encountered.
1533+
pub fn dummy() -> P<Expr> {
1534+
P(Expr {
1535+
id: DUMMY_NODE_ID,
1536+
kind: ExprKind::Dummy,
1537+
span: DUMMY_SP,
1538+
attrs: ThinVec::new(),
1539+
tokens: None,
1540+
})
1541+
}
15291542
}
15301543

15311544
#[derive(Clone, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl HasAttrs for Stmt {
304304
}
305305

306306
/// A newtype around an AST node that implements the traits above if the node implements them.
307+
#[repr(transparent)]
307308
pub struct AstNodeWrapper<Wrapped, Tag> {
308309
pub wrapped: Wrapped,
309310
pub tag: PhantomData<Tag>,
@@ -313,6 +314,11 @@ impl<Wrapped, Tag> AstNodeWrapper<Wrapped, Tag> {
313314
pub fn new(wrapped: Wrapped, _tag: Tag) -> AstNodeWrapper<Wrapped, Tag> {
314315
AstNodeWrapper { wrapped, tag: Default::default() }
315316
}
317+
318+
pub fn from_mut(wrapped: &mut Wrapped, _tag: Tag) -> &mut AstNodeWrapper<Wrapped, Tag> {
319+
// SAFETY: `AstNodeWrapper` is `repr(transparent)` w.r.t `Wrapped`
320+
unsafe { &mut *<*mut Wrapped>::cast(wrapped) }
321+
}
316322
}
317323

318324
impl<Wrapped: HasNodeId, Tag> HasNodeId for AstNodeWrapper<Wrapped, Tag> {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,6 @@ pub trait MutVisitor: Sized {
368368

369369
super::common_visitor_and_walkers!((mut) MutVisitor);
370370

371-
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
372-
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
373-
/// method.
374-
pub fn visit_clobber<T: DummyAstNode>(t: &mut T, f: impl FnOnce(T) -> T) {
375-
let old_t = std::mem::replace(t, T::dummy());
376-
*t = f(old_t);
377-
}
378-
379371
#[inline]
380372
fn visit_vec<T, F>(elems: &mut Vec<T>, mut visit_elem: F)
381373
where
@@ -1417,101 +1409,6 @@ fn walk_capture_by<T: MutVisitor>(vis: &mut T, capture_by: &mut CaptureBy) {
14171409
}
14181410
}
14191411

1420-
/// Some value for the AST node that is valid but possibly meaningless. Similar
1421-
/// to `Default` but not intended for wide use. The value will never be used
1422-
/// meaningfully, it exists just to support unwinding in `visit_clobber` in the
1423-
/// case where its closure panics.
1424-
pub trait DummyAstNode {
1425-
fn dummy() -> Self;
1426-
}
1427-
1428-
impl<T> DummyAstNode for Option<T> {
1429-
fn dummy() -> Self {
1430-
Default::default()
1431-
}
1432-
}
1433-
1434-
impl<T: DummyAstNode + 'static> DummyAstNode for P<T> {
1435-
fn dummy() -> Self {
1436-
P(DummyAstNode::dummy())
1437-
}
1438-
}
1439-
1440-
impl DummyAstNode for Item {
1441-
fn dummy() -> Self {
1442-
Item {
1443-
attrs: Default::default(),
1444-
id: DUMMY_NODE_ID,
1445-
span: Default::default(),
1446-
vis: Visibility {
1447-
kind: VisibilityKind::Public,
1448-
span: Default::default(),
1449-
tokens: Default::default(),
1450-
},
1451-
kind: ItemKind::ExternCrate(None, Ident::dummy()),
1452-
tokens: Default::default(),
1453-
}
1454-
}
1455-
}
1456-
1457-
impl DummyAstNode for Expr {
1458-
fn dummy() -> Self {
1459-
Expr {
1460-
id: DUMMY_NODE_ID,
1461-
kind: ExprKind::Dummy,
1462-
span: Default::default(),
1463-
attrs: Default::default(),
1464-
tokens: Default::default(),
1465-
}
1466-
}
1467-
}
1468-
1469-
impl DummyAstNode for Ty {
1470-
fn dummy() -> Self {
1471-
Ty {
1472-
id: DUMMY_NODE_ID,
1473-
kind: TyKind::Dummy,
1474-
span: Default::default(),
1475-
tokens: Default::default(),
1476-
}
1477-
}
1478-
}
1479-
1480-
impl DummyAstNode for Pat {
1481-
fn dummy() -> Self {
1482-
Pat {
1483-
id: DUMMY_NODE_ID,
1484-
kind: PatKind::Wild,
1485-
span: Default::default(),
1486-
tokens: Default::default(),
1487-
}
1488-
}
1489-
}
1490-
1491-
impl DummyAstNode for Stmt {
1492-
fn dummy() -> Self {
1493-
Stmt { id: DUMMY_NODE_ID, kind: StmtKind::Empty, span: Default::default() }
1494-
}
1495-
}
1496-
1497-
impl DummyAstNode for Crate {
1498-
fn dummy() -> Self {
1499-
Crate {
1500-
attrs: Default::default(),
1501-
items: Default::default(),
1502-
spans: Default::default(),
1503-
id: DUMMY_NODE_ID,
1504-
is_placeholder: Default::default(),
1505-
}
1506-
}
1507-
}
1508-
1509-
impl<N: DummyAstNode, T: DummyAstNode> DummyAstNode for crate::ast_traits::AstNodeWrapper<N, T> {
1510-
fn dummy() -> Self {
1511-
crate::ast_traits::AstNodeWrapper::new(N::dummy(), T::dummy())
1512-
}
1513-
}
1514-
15151412
#[derive(Debug)]
15161413
pub enum FnKind<'a> {
15171414
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
870870
// FIXME use a compiler fence once Cranelift supports it
871871
fx.bcx.ins().fence();
872872
}
873-
_ if intrinsic.as_str().starts_with("atomic_load") => {
873+
sym::atomic_load => {
874874
intrinsic_args!(fx, args => (ptr); intrinsic);
875875
let ptr = ptr.load_scalar(fx);
876876

877877
let ty = generic_args.type_at(0);
878+
let _ord = generic_args.const_at(1).to_value(); // FIXME: forward this to cranelift once they support that
878879
match ty.kind() {
879880
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
880881
// FIXME implement 128bit atomics

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
1212
use rustc_apfloat::{Float, Round, Status, ieee};
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_codegen_ssa::common::{
15-
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
15+
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
1616
};
1717
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1818
use rustc_codegen_ssa::mir::place::PlaceRef;
@@ -26,7 +26,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2626
use rustc_middle::ty::layout::{
2727
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
2828
};
29-
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
29+
use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::callconv::FnAbi;
@@ -75,7 +75,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
7575

7676
let load_ordering = match order {
7777
// TODO(antoyo): does this make sense?
78-
AtomicOrdering::AcquireRelease | AtomicOrdering::Release => AtomicOrdering::Acquire,
78+
AtomicOrdering::AcqRel | AtomicOrdering::Release => AtomicOrdering::Acquire,
7979
_ => order,
8080
};
8181
let previous_value =
@@ -2474,8 +2474,8 @@ impl ToGccOrdering for AtomicOrdering {
24742474
AtomicOrdering::Relaxed => __ATOMIC_RELAXED, // TODO(antoyo): check if that's the same.
24752475
AtomicOrdering::Acquire => __ATOMIC_ACQUIRE,
24762476
AtomicOrdering::Release => __ATOMIC_RELEASE,
2477-
AtomicOrdering::AcquireRelease => __ATOMIC_ACQ_REL,
2478-
AtomicOrdering::SequentiallyConsistent => __ATOMIC_SEQ_CST,
2477+
AtomicOrdering::AcqRel => __ATOMIC_ACQ_REL,
2478+
AtomicOrdering::SeqCst => __ATOMIC_SEQ_CST,
24792479
};
24802480
ordering as i32
24812481
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
612612
&mut self,
613613
ty: &'ll Type,
614614
ptr: &'ll Value,
615-
order: rustc_codegen_ssa::common::AtomicOrdering,
615+
order: rustc_middle::ty::AtomicOrdering,
616616
size: Size,
617617
) -> &'ll Value {
618618
unsafe {
@@ -851,7 +851,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
851851
&mut self,
852852
val: &'ll Value,
853853
ptr: &'ll Value,
854-
order: rustc_codegen_ssa::common::AtomicOrdering,
854+
order: rustc_middle::ty::AtomicOrdering,
855855
size: Size,
856856
) {
857857
debug!("Store {:?} -> {:?}", val, ptr);
@@ -1307,8 +1307,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13071307
dst: &'ll Value,
13081308
cmp: &'ll Value,
13091309
src: &'ll Value,
1310-
order: rustc_codegen_ssa::common::AtomicOrdering,
1311-
failure_order: rustc_codegen_ssa::common::AtomicOrdering,
1310+
order: rustc_middle::ty::AtomicOrdering,
1311+
failure_order: rustc_middle::ty::AtomicOrdering,
13121312
weak: bool,
13131313
) -> (&'ll Value, &'ll Value) {
13141314
let weak = if weak { llvm::True } else { llvm::False };
@@ -1334,7 +1334,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13341334
op: rustc_codegen_ssa::common::AtomicRmwBinOp,
13351335
dst: &'ll Value,
13361336
mut src: &'ll Value,
1337-
order: rustc_codegen_ssa::common::AtomicOrdering,
1337+
order: rustc_middle::ty::AtomicOrdering,
13381338
) -> &'ll Value {
13391339
// The only RMW operation that LLVM supports on pointers is compare-exchange.
13401340
let requires_cast_to_int = self.val_ty(src) == self.type_ptr()
@@ -1360,7 +1360,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13601360

13611361
fn atomic_fence(
13621362
&mut self,
1363-
order: rustc_codegen_ssa::common::AtomicOrdering,
1363+
order: rustc_middle::ty::AtomicOrdering,
13641364
scope: SynchronizationScope,
13651365
) {
13661366
let single_threaded = match scope {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ pub(crate) enum AtomicOrdering {
426426
}
427427

428428
impl AtomicOrdering {
429-
pub(crate) fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
430-
use rustc_codegen_ssa::common::AtomicOrdering as Common;
429+
pub(crate) fn from_generic(ao: rustc_middle::ty::AtomicOrdering) -> Self {
430+
use rustc_middle::ty::AtomicOrdering as Common;
431431
match ao {
432432
Common::Relaxed => Self::Monotonic,
433433
Common::Acquire => Self::Acquire,
434434
Common::Release => Self::Release,
435-
Common::AcquireRelease => Self::AcquireRelease,
436-
Common::SequentiallyConsistent => Self::SequentiallyConsistent,
435+
Common::AcqRel => Self::AcquireRelease,
436+
Common::SeqCst => Self::SequentiallyConsistent,
437437
}
438438
}
439439
}

0 commit comments

Comments
 (0)