Skip to content

Commit 432abd8

Browse files
committed
Auto merge of #102061 - notriddle:rollup-kwu9vp8, r=notriddle
Rollup of 12 pull requests Successful merges: - #100250 (Manually cleanup token stream when macro expansion aborts.) - #101014 (Fix -Zmeta-stats ICE by giving `FileEncoder` file read permissions) - #101958 (Improve error for when query is unsupported by crate) - #101976 (MirPhase: clarify that linting is not a semantic change) - #102001 (Use LLVM C-API to build atomic cmpxchg and fence) - #102008 (Add GUI test for notable traits element position) - #102013 (Simplify rpitit handling on lower_fn_decl) - #102021 (some post-valtree cleanup) - #102027 (rustdoc: remove `docblock` class from `item-decl`) - #102034 (rustdoc: remove no-op CSS `h1-6 { border-bottom-color }`) - #102038 (Make the `normalize-overflow` rustdoc test actually do something) - #102053 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cd8cc91 + 25f5483 commit 432abd8

File tree

131 files changed

+1984
-1016
lines changed

Some content is hidden

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

131 files changed

+1984
-1016
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+15-45
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,10 @@ enum FnDeclKind {
324324
}
325325

326326
impl FnDeclKind {
327-
fn impl_trait_return_allowed(&self, tcx: TyCtxt<'_>) -> bool {
327+
fn impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
328328
match self {
329329
FnDeclKind::Fn | FnDeclKind::Inherent => true,
330330
FnDeclKind::Impl if tcx.features().return_position_impl_trait_in_trait => true,
331-
_ => false,
332-
}
333-
}
334-
335-
fn impl_trait_in_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
336-
match self {
337331
FnDeclKind::Trait if tcx.features().return_position_impl_trait_in_trait => true,
338332
_ => false,
339333
}
@@ -1698,9 +1692,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16981692
}));
16991693

17001694
let output = if let Some((ret_id, span)) = make_ret_async {
1701-
match kind {
1702-
FnDeclKind::Trait => {
1703-
if !kind.impl_trait_in_trait_allowed(self.tcx) {
1695+
if !kind.impl_trait_allowed(self.tcx) {
1696+
match kind {
1697+
FnDeclKind::Trait | FnDeclKind::Impl => {
17041698
self.tcx
17051699
.sess
17061700
.create_feature_err(
@@ -1709,51 +1703,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17091703
)
17101704
.emit();
17111705
}
1712-
self.lower_async_fn_ret_ty(
1713-
&decl.output,
1714-
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
1715-
ret_id,
1716-
true,
1717-
)
1718-
}
1719-
_ => {
1720-
if !kind.impl_trait_return_allowed(self.tcx) {
1721-
if kind == FnDeclKind::Impl {
1722-
self.tcx
1723-
.sess
1724-
.create_feature_err(
1725-
TraitFnAsync { fn_span, span },
1726-
sym::return_position_impl_trait_in_trait,
1727-
)
1728-
.emit();
1729-
} else {
1730-
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
1731-
}
1706+
_ => {
1707+
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
17321708
}
1733-
self.lower_async_fn_ret_ty(
1734-
&decl.output,
1735-
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
1736-
ret_id,
1737-
false,
1738-
)
17391709
}
17401710
}
1711+
1712+
self.lower_async_fn_ret_ty(
1713+
&decl.output,
1714+
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
1715+
ret_id,
1716+
matches!(kind, FnDeclKind::Trait),
1717+
)
17411718
} else {
17421719
match decl.output {
17431720
FnRetTy::Ty(ref ty) => {
17441721
let mut context = match fn_node_id {
1745-
Some(fn_node_id) if kind.impl_trait_return_allowed(self.tcx) => {
1746-
let fn_def_id = self.local_def_id(fn_node_id);
1747-
ImplTraitContext::ReturnPositionOpaqueTy {
1748-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1749-
in_trait: false,
1750-
}
1751-
}
1752-
Some(fn_node_id) if kind.impl_trait_in_trait_allowed(self.tcx) => {
1722+
Some(fn_node_id) if kind.impl_trait_allowed(self.tcx) => {
17531723
let fn_def_id = self.local_def_id(fn_node_id);
17541724
ImplTraitContext::ReturnPositionOpaqueTy {
17551725
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1756-
in_trait: true,
1726+
in_trait: matches!(kind, FnDeclKind::Trait),
17571727
}
17581728
}
17591729
_ => ImplTraitContext::Disallowed(match kind {

compiler/rustc_builtin_macros/src/cfg_eval.rs

+36-28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::visit::Visitor;
77
use rustc_ast::NodeId;
88
use rustc_ast::{mut_visit, visit};
99
use rustc_ast::{Attribute, HasAttrs, HasTokens};
10+
use rustc_errors::PResult;
1011
use rustc_expand::base::{Annotatable, ExtCtxt};
1112
use rustc_expand::config::StripUnconfigured;
1213
use rustc_expand::configure;
@@ -144,33 +145,34 @@ impl CfgEval<'_, '_> {
144145
// the location of `#[cfg]` and `#[cfg_attr]` in the token stream. The tokenization
145146
// process is lossless, so this process is invisible to proc-macros.
146147

147-
let parse_annotatable_with: fn(&mut Parser<'_>) -> _ = match annotatable {
148-
Annotatable::Item(_) => {
149-
|parser| Annotatable::Item(parser.parse_item(ForceCollect::Yes).unwrap().unwrap())
150-
}
151-
Annotatable::TraitItem(_) => |parser| {
152-
Annotatable::TraitItem(
153-
parser.parse_trait_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
154-
)
155-
},
156-
Annotatable::ImplItem(_) => |parser| {
157-
Annotatable::ImplItem(
158-
parser.parse_impl_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
159-
)
160-
},
161-
Annotatable::ForeignItem(_) => |parser| {
162-
Annotatable::ForeignItem(
163-
parser.parse_foreign_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
164-
)
165-
},
166-
Annotatable::Stmt(_) => |parser| {
167-
Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes).unwrap().unwrap()))
168-
},
169-
Annotatable::Expr(_) => {
170-
|parser| Annotatable::Expr(parser.parse_expr_force_collect().unwrap())
171-
}
172-
_ => unreachable!(),
173-
};
148+
let parse_annotatable_with: for<'a> fn(&mut Parser<'a>) -> PResult<'a, _> =
149+
match annotatable {
150+
Annotatable::Item(_) => {
151+
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
152+
}
153+
Annotatable::TraitItem(_) => |parser| {
154+
Ok(Annotatable::TraitItem(
155+
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
156+
))
157+
},
158+
Annotatable::ImplItem(_) => |parser| {
159+
Ok(Annotatable::ImplItem(
160+
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
161+
))
162+
},
163+
Annotatable::ForeignItem(_) => |parser| {
164+
Ok(Annotatable::ForeignItem(
165+
parser.parse_foreign_item(ForceCollect::Yes)?.unwrap().unwrap(),
166+
))
167+
},
168+
Annotatable::Stmt(_) => |parser| {
169+
Ok(Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes)?.unwrap())))
170+
},
171+
Annotatable::Expr(_) => {
172+
|parser| Ok(Annotatable::Expr(parser.parse_expr_force_collect()?))
173+
}
174+
_ => unreachable!(),
175+
};
174176

175177
// 'Flatten' all nonterminals (i.e. `TokenKind::Interpolated`)
176178
// to `None`-delimited groups containing the corresponding tokens. This
@@ -193,7 +195,13 @@ impl CfgEval<'_, '_> {
193195
let mut parser =
194196
rustc_parse::stream_to_parser(&self.cfg.sess.parse_sess, orig_tokens, None);
195197
parser.capture_cfg = true;
196-
annotatable = parse_annotatable_with(&mut parser);
198+
match parse_annotatable_with(&mut parser) {
199+
Ok(a) => annotatable = a,
200+
Err(mut err) => {
201+
err.emit();
202+
return Some(annotatable);
203+
}
204+
}
197205

198206
// Now that we have our re-parsed `AttrTokenStream`, recursively configuring
199207
// our attribute target will correctly the tokens as well.

compiler/rustc_codegen_llvm/src/builder.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::attributes;
22
use crate::common::Funclet;
33
use crate::context::CodegenCx;
4-
use crate::llvm::{self, BasicBlock, False};
5-
use crate::llvm::{AtomicOrdering, AtomicRmwBinOp, SynchronizationScope};
4+
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock};
65
use crate::type_::Type;
76
use crate::type_of::LayoutLlvmExt;
87
use crate::value::Value;
98
use cstr::cstr;
109
use libc::{c_char, c_uint};
11-
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind};
10+
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
1211
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1312
use rustc_codegen_ssa::mir::place::PlaceRef;
1413
use rustc_codegen_ssa::traits::*;
@@ -1042,15 +1041,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10421041
) -> &'ll Value {
10431042
let weak = if weak { llvm::True } else { llvm::False };
10441043
unsafe {
1045-
llvm::LLVMRustBuildAtomicCmpXchg(
1044+
let value = llvm::LLVMBuildAtomicCmpXchg(
10461045
self.llbuilder,
10471046
dst,
10481047
cmp,
10491048
src,
10501049
AtomicOrdering::from_generic(order),
10511050
AtomicOrdering::from_generic(failure_order),
1052-
weak,
1053-
)
1051+
llvm::False, // SingleThreaded
1052+
);
1053+
llvm::LLVMSetWeak(value, weak);
1054+
value
10541055
}
10551056
}
10561057
fn atomic_rmw(
@@ -1067,21 +1068,26 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10671068
dst,
10681069
src,
10691070
AtomicOrdering::from_generic(order),
1070-
False,
1071+
llvm::False, // SingleThreaded
10711072
)
10721073
}
10731074
}
10741075

10751076
fn atomic_fence(
10761077
&mut self,
10771078
order: rustc_codegen_ssa::common::AtomicOrdering,
1078-
scope: rustc_codegen_ssa::common::SynchronizationScope,
1079+
scope: SynchronizationScope,
10791080
) {
1081+
let single_threaded = match scope {
1082+
SynchronizationScope::SingleThread => llvm::True,
1083+
SynchronizationScope::CrossThread => llvm::False,
1084+
};
10801085
unsafe {
1081-
llvm::LLVMRustBuildAtomicFence(
1086+
llvm::LLVMBuildFence(
10821087
self.llbuilder,
10831088
AtomicOrdering::from_generic(order),
1084-
SynchronizationScope::from_generic(scope),
1089+
single_threaded,
1090+
UNNAMED,
10851091
);
10861092
}
10871093
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+9-27
Original file line numberDiff line numberDiff line change
@@ -400,27 +400,6 @@ impl AtomicOrdering {
400400
}
401401
}
402402

403-
/// LLVMRustSynchronizationScope
404-
#[derive(Copy, Clone)]
405-
#[repr(C)]
406-
pub enum SynchronizationScope {
407-
SingleThread,
408-
CrossThread,
409-
}
410-
411-
impl SynchronizationScope {
412-
pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
413-
match sc {
414-
rustc_codegen_ssa::common::SynchronizationScope::SingleThread => {
415-
SynchronizationScope::SingleThread
416-
}
417-
rustc_codegen_ssa::common::SynchronizationScope::CrossThread => {
418-
SynchronizationScope::CrossThread
419-
}
420-
}
421-
}
422-
}
423-
424403
/// LLVMRustFileType
425404
#[derive(Copy, Clone)]
426405
#[repr(C)]
@@ -1782,16 +1761,18 @@ extern "C" {
17821761
Order: AtomicOrdering,
17831762
) -> &'a Value;
17841763

1785-
pub fn LLVMRustBuildAtomicCmpXchg<'a>(
1764+
pub fn LLVMBuildAtomicCmpXchg<'a>(
17861765
B: &Builder<'a>,
17871766
LHS: &'a Value,
17881767
CMP: &'a Value,
17891768
RHS: &'a Value,
17901769
Order: AtomicOrdering,
17911770
FailureOrder: AtomicOrdering,
1792-
Weak: Bool,
1771+
SingleThreaded: Bool,
17931772
) -> &'a Value;
17941773

1774+
pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
1775+
17951776
pub fn LLVMBuildAtomicRMW<'a>(
17961777
B: &Builder<'a>,
17971778
Op: AtomicRmwBinOp,
@@ -1801,11 +1782,12 @@ extern "C" {
18011782
SingleThreaded: Bool,
18021783
) -> &'a Value;
18031784

1804-
pub fn LLVMRustBuildAtomicFence(
1805-
B: &Builder<'_>,
1785+
pub fn LLVMBuildFence<'a>(
1786+
B: &Builder<'a>,
18061787
Order: AtomicOrdering,
1807-
Scope: SynchronizationScope,
1808-
);
1788+
SingleThreaded: Bool,
1789+
Name: *const c_char,
1790+
) -> &'a Value;
18091791

18101792
/// Writes a module to the specified path. Returns 0 on success.
18111793
pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;

compiler/rustc_const_eval/src/const_eval/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
100100
tcx: TyCtxt<'tcx>,
101101
param_env: ty::ParamEnv<'tcx>,
102102
val: mir::ConstantKind<'tcx>,
103-
) -> InterpResult<'tcx, mir::DestructuredMirConstant<'tcx>> {
103+
) -> InterpResult<'tcx, mir::DestructuredConstant<'tcx>> {
104104
trace!("destructure_mir_constant: {:?}", val);
105105
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
106-
let op = ecx.mir_const_to_op(&val, None)?;
106+
let op = ecx.const_to_op(&val, None)?;
107107

108108
// We go to `usize` as we cannot allocate anything bigger anyway.
109109
let (field_count, variant, down) = match val.ty().kind() {
@@ -129,7 +129,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
129129
.collect::<InterpResult<'tcx, Vec<_>>>()?;
130130
let fields = tcx.arena.alloc_from_iter(fields_iter);
131131

132-
Ok(mir::DestructuredMirConstant { variant, fields })
132+
Ok(mir::DestructuredConstant { variant, fields })
133133
}
134134

135135
#[instrument(skip(tcx), level = "debug")]
@@ -139,7 +139,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
139139
val: mir::ConstantKind<'tcx>,
140140
) -> mir::ConstantKind<'tcx> {
141141
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
142-
let op = ecx.mir_const_to_op(&val, None).unwrap();
142+
let op = ecx.const_to_op(&val, None).unwrap();
143143
let mplace = ecx.deref_operand(&op).unwrap();
144144
if let Some(alloc_id) = mplace.ptr.provenance {
145145
assert_eq!(

compiler/rustc_const_eval/src/interpret/eval_context.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
683683
self.stack_mut().push(frame);
684684

685685
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
686-
for const_ in &body.required_consts {
687-
let span = const_.span;
688-
let const_ =
689-
self.subst_from_current_frame_and_normalize_erasing_regions(const_.literal)?;
690-
self.mir_const_to_op(&const_, None).map_err(|err| {
686+
for ct in &body.required_consts {
687+
let span = ct.span;
688+
let ct = self.subst_from_current_frame_and_normalize_erasing_regions(ct.literal)?;
689+
self.const_to_op(&ct, None).map_err(|err| {
691690
// If there was an error, set the span of the current frame to this constant.
692691
// Avoiding doing this when evaluation succeeds.
693692
self.frame_mut().loc = Err(span);

0 commit comments

Comments
 (0)