Skip to content

Commit 2636cb4

Browse files
committed
Auto merge of #148818 - Zalathar:rollup-4vujcg0, r=Zalathar
Rollup of 13 pull requests Successful merges: - #148694 (std: support `RwLock` and thread parking on TEEOS) - #148712 (Port `cfg_select!` to the new attribute parsing system) - #148760 (rustc_target: hide TargetOptions::vendor) - #148771 (IAT: Reinstate early bailout) - #148775 (Fix a typo in the documentation for the strict_shr function) - #148779 (Implement DynSend and DynSync for std::panic::Location.) - #148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`) - #148783 (add test for assoc type norm wf check) - #148785 (Replace `master` branch references with `main`) - #148791 (fix "is_closure_like" doc comment) - #148792 (Prefer to use file.stable_id over file.name from source map) - #148805 (rustc-dev-guide subtree update) - #148807 (Document (and test) a problem with `Clone`/`Copy` deriving.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9312cd6 + 224ff38 commit 2636cb4

File tree

66 files changed

+927
-627
lines changed

Some content is hidden

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

66 files changed

+927
-627
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use rustc_ast::token::Token;
2+
use rustc_ast::tokenstream::TokenStream;
3+
use rustc_ast::{AttrStyle, NodeId, token};
4+
use rustc_feature::{AttributeTemplate, Features};
5+
use rustc_hir::AttrPath;
6+
use rustc_hir::attrs::CfgEntry;
7+
use rustc_parse::exp;
8+
use rustc_parse::parser::Parser;
9+
use rustc_session::Session;
10+
use rustc_span::{ErrorGuaranteed, Ident, Span};
11+
12+
use crate::parser::MetaItemOrLitParser;
13+
use crate::{AttributeParser, ParsedDescription, ShouldEmit, parse_cfg_entry};
14+
15+
pub enum CfgSelectPredicate {
16+
Cfg(CfgEntry),
17+
Wildcard(Token),
18+
}
19+
20+
#[derive(Default)]
21+
pub struct CfgSelectBranches {
22+
/// All the conditional branches.
23+
pub reachable: Vec<(CfgEntry, TokenStream, Span)>,
24+
/// The first wildcard `_ => { ... }` branch.
25+
pub wildcard: Option<(Token, TokenStream, Span)>,
26+
/// All branches after the first wildcard, including further wildcards.
27+
/// These branches are kept for formatting.
28+
pub unreachable: Vec<(CfgSelectPredicate, TokenStream, Span)>,
29+
}
30+
31+
pub fn parse_cfg_select(
32+
p: &mut Parser<'_>,
33+
sess: &Session,
34+
features: Option<&Features>,
35+
lint_node_id: NodeId,
36+
) -> Result<CfgSelectBranches, ErrorGuaranteed> {
37+
let mut branches = CfgSelectBranches::default();
38+
39+
while p.token != token::Eof {
40+
if p.eat_keyword(exp!(Underscore)) {
41+
let underscore = p.prev_token;
42+
p.expect(exp!(FatArrow)).map_err(|e| e.emit())?;
43+
44+
let tts = p.parse_delimited_token_tree().map_err(|e| e.emit())?;
45+
let span = underscore.span.to(p.token.span);
46+
47+
match branches.wildcard {
48+
None => branches.wildcard = Some((underscore, tts, span)),
49+
Some(_) => {
50+
branches.unreachable.push((CfgSelectPredicate::Wildcard(underscore), tts, span))
51+
}
52+
}
53+
} else {
54+
let meta = MetaItemOrLitParser::parse_single(p, ShouldEmit::ErrorsAndLints)
55+
.map_err(|diag| diag.emit())?;
56+
let cfg_span = meta.span();
57+
let cfg = AttributeParser::parse_single_args(
58+
sess,
59+
cfg_span,
60+
cfg_span,
61+
AttrStyle::Inner,
62+
AttrPath {
63+
segments: vec![Ident::from_str("cfg_select")].into_boxed_slice(),
64+
span: cfg_span,
65+
},
66+
ParsedDescription::Macro,
67+
cfg_span,
68+
lint_node_id,
69+
features,
70+
ShouldEmit::ErrorsAndLints,
71+
&meta,
72+
parse_cfg_entry,
73+
&AttributeTemplate::default(),
74+
)?;
75+
76+
p.expect(exp!(FatArrow)).map_err(|e| e.emit())?;
77+
78+
let tts = p.parse_delimited_token_tree().map_err(|e| e.emit())?;
79+
let span = cfg_span.to(p.token.span);
80+
81+
match branches.wildcard {
82+
None => branches.reachable.push((cfg, tts, span)),
83+
Some(_) => branches.unreachable.push((CfgSelectPredicate::Cfg(cfg), tts, span)),
84+
}
85+
}
86+
}
87+
88+
Ok(branches)
89+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(crate) mod allow_unstable;
3333
pub(crate) mod body;
3434
pub(crate) mod cfg;
3535
pub(crate) mod cfg_old;
36+
pub(crate) mod cfg_select;
3637
pub(crate) mod codegen_attrs;
3738
pub(crate) mod confusables;
3839
pub(crate) mod crate_level;

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub use attributes::cfg::{
106106
CFG_TEMPLATE, EvalConfigResult, eval_config_entry, parse_cfg, parse_cfg_attr, parse_cfg_entry,
107107
};
108108
pub use attributes::cfg_old::*;
109+
pub use attributes::cfg_select::*;
109110
pub use attributes::util::{is_builtin_attr, is_doc_alias_attrs_contain_symbol, parse_version};
110111
pub use context::{Early, Late, OmitDoc, ShouldEmit};
111112
pub use interface::AttributeParser;
Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
use rustc_ast::tokenstream::TokenStream;
22
use rustc_attr_parsing as attr;
3+
use rustc_attr_parsing::{
4+
CfgSelectBranches, CfgSelectPredicate, EvalConfigResult, ShouldEmit, parse_cfg_select,
5+
};
36
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
4-
use rustc_parse::parser::cfg_select::{CfgSelectBranches, CfgSelectPredicate, parse_cfg_select};
57
use rustc_span::{Ident, Span, sym};
68

79
use crate::errors::{CfgSelectNoMatches, CfgSelectUnreachable};
810

911
/// Selects the first arm whose predicate evaluates to true.
1012
fn select_arm(ecx: &ExtCtxt<'_>, branches: CfgSelectBranches) -> Option<(TokenStream, Span)> {
1113
for (cfg, tt, arm_span) in branches.reachable {
12-
if attr::cfg_matches(
13-
&cfg,
14+
if let EvalConfigResult::True = attr::eval_config_entry(
1415
&ecx.sess,
16+
&cfg,
1517
ecx.current_expansion.lint_node_id,
16-
Some(ecx.ecfg.features),
18+
ShouldEmit::ErrorsAndLints,
1719
) {
1820
return Some((tt, arm_span));
1921
}
@@ -27,37 +29,41 @@ pub(super) fn expand_cfg_select<'cx>(
2729
sp: Span,
2830
tts: TokenStream,
2931
) -> MacroExpanderResult<'cx> {
30-
ExpandResult::Ready(match parse_cfg_select(&mut ecx.new_parser_from_tts(tts)) {
31-
Ok(branches) => {
32-
if let Some((underscore, _, _)) = branches.wildcard {
33-
// Warn for every unreachable predicate. We store the fully parsed branch for rustfmt.
34-
for (predicate, _, _) in &branches.unreachable {
35-
let span = match predicate {
36-
CfgSelectPredicate::Wildcard(underscore) => underscore.span,
37-
CfgSelectPredicate::Cfg(cfg) => cfg.span(),
38-
};
39-
let err = CfgSelectUnreachable { span, wildcard_span: underscore.span };
40-
ecx.dcx().emit_warn(err);
32+
ExpandResult::Ready(
33+
match parse_cfg_select(
34+
&mut ecx.new_parser_from_tts(tts),
35+
ecx.sess,
36+
Some(ecx.ecfg.features),
37+
ecx.current_expansion.lint_node_id,
38+
) {
39+
Ok(branches) => {
40+
if let Some((underscore, _, _)) = branches.wildcard {
41+
// Warn for every unreachable predicate. We store the fully parsed branch for rustfmt.
42+
for (predicate, _, _) in &branches.unreachable {
43+
let span = match predicate {
44+
CfgSelectPredicate::Wildcard(underscore) => underscore.span,
45+
CfgSelectPredicate::Cfg(cfg) => cfg.span(),
46+
};
47+
let err = CfgSelectUnreachable { span, wildcard_span: underscore.span };
48+
ecx.dcx().emit_warn(err);
49+
}
4150
}
42-
}
4351

44-
if let Some((tts, arm_span)) = select_arm(ecx, branches) {
45-
return ExpandResult::from_tts(
46-
ecx,
47-
tts,
48-
sp,
49-
arm_span,
50-
Ident::with_dummy_span(sym::cfg_select),
51-
);
52-
} else {
53-
// Emit a compiler error when none of the predicates matched.
54-
let guar = ecx.dcx().emit_err(CfgSelectNoMatches { span: sp });
55-
DummyResult::any(sp, guar)
52+
if let Some((tts, arm_span)) = select_arm(ecx, branches) {
53+
return ExpandResult::from_tts(
54+
ecx,
55+
tts,
56+
sp,
57+
arm_span,
58+
Ident::with_dummy_span(sym::cfg_select),
59+
);
60+
} else {
61+
// Emit a compiler error when none of the predicates matched.
62+
let guar = ecx.dcx().emit_err(CfgSelectNoMatches { span: sp });
63+
DummyResult::any(sp, guar)
64+
}
5665
}
57-
}
58-
Err(err) => {
59-
let guar = err.emit();
60-
DummyResult::any(sp, guar)
61-
}
62-
})
66+
Err(guar) => DummyResult::any(sp, guar),
67+
},
68+
)
6369
}

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ pub(crate) fn codegen_call_with_unwind_action(
916916
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
917917
let param = AbiParam::new(ty);
918918
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() {
919-
match (&tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) {
920-
(Arch::X86_64, _) | (Arch::AArch64, "apple") => match (ty, is_signed) {
919+
match (&tcx.sess.target.arch, tcx.sess.target.is_like_darwin) {
920+
(Arch::X86_64, _) | (Arch::AArch64, true) => match (ty, is_signed) {
921921
(types::I8 | types::I16, true) => param.sext(),
922922
(types::I8 | types::I16, false) => param.uext(),
923923
_ => param,

compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::prelude::*;
55

66
pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
77
let (value, arg_ty) =
8-
if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64 {
8+
if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
99
(
1010
fx.bcx.ins().bitcast(types::I16, MemFlags::new(), value),
1111
lib_call_arg_param(fx.tcx, types::I16, false),
@@ -22,8 +22,7 @@ fn f16_to_f64(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
2222
}
2323

2424
pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
25-
let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64
26-
{
25+
let ret_ty = if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
2726
types::I16
2827
} else {
2928
types::F16
@@ -38,8 +37,7 @@ pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value
3837
}
3938

4039
fn f64_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
41-
let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64
42-
{
40+
let ret_ty = if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
4341
types::I16
4442
} else {
4543
types::F16

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ fn self_contained_components(
18191819
LinkSelfContainedDefault::InferredForMusl => sess.crt_static(Some(crate_type)),
18201820
LinkSelfContainedDefault::InferredForMingw => {
18211821
sess.host == sess.target
1822-
&& sess.target.vendor != "uwp"
1822+
&& sess.target.abi != "uwp"
18231823
&& detect_self_contained_mingw(sess, linker)
18241824
}
18251825
}

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn get_linker<'a>(
8383
// To comply with the Windows App Certification Kit,
8484
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
8585
let t = &sess.target;
86-
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == "uwp" {
86+
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.abi == "uwp" {
8787
if let Some(ref tool) = msvc_tool {
8888
let original_path = tool.path();
8989
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
@@ -134,7 +134,7 @@ pub(crate) fn get_linker<'a>(
134134

135135
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
136136
// to the linker args construction.
137-
assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp");
137+
assert!(cmd.get_args().is_empty() || sess.target.abi == "uwp");
138138
match flavor {
139139
LinkerFlavor::Unix(Cc::No) if sess.target.os == "l4re" => {
140140
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn asm_const_to_str<'tcx>(
171171
}
172172

173173
pub fn is_mingw_gnu_toolchain(target: &Target) -> bool {
174-
target.vendor == "pc" && target.os == "windows" && target.env == "gnu" && target.abi.is_empty()
174+
target.os == "windows" && target.env == "gnu" && target.abi.is_empty()
175175
}
176176

177177
pub fn i686_decorated_name(

compiler/rustc_data_structures/src/marker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ impl !DynSend for std::env::VarsOs {}
5353

5454
macro_rules! already_send {
5555
($([$ty: ty])*) => {
56-
$(unsafe impl DynSend for $ty where $ty: Send {})*
56+
$(unsafe impl DynSend for $ty where Self: Send {})*
5757
};
5858
}
5959

6060
// These structures are already `Send`.
6161
already_send!(
62-
[std::backtrace::Backtrace][std::io::Stdout][std::io::Stderr][std::io::Error][std::fs::File]
62+
[std::backtrace::Backtrace][std::io::Stdout][std::io::Stderr][std::io::Error][std::fs::File][std::panic::Location<'_>]
6363
[rustc_arena::DroplessArena][jobserver_crate::Client][jobserver_crate::HelperThread]
6464
[crate::memmap::Mmap][crate::profiling::SelfProfiler][crate::owned_slice::OwnedSlice]
6565
);
@@ -127,14 +127,14 @@ impl !DynSync for std::env::VarsOs {}
127127

128128
macro_rules! already_sync {
129129
($([$ty: ty])*) => {
130-
$(unsafe impl DynSync for $ty where $ty: Sync {})*
130+
$(unsafe impl DynSync for $ty where Self: Sync {})*
131131
};
132132
}
133133

134134
// These structures are already `Sync`.
135135
already_sync!(
136136
[std::sync::atomic::AtomicBool][std::sync::atomic::AtomicUsize][std::sync::atomic::AtomicU8]
137-
[std::sync::atomic::AtomicU32][std::backtrace::Backtrace][std::io::Error][std::fs::File]
137+
[std::sync::atomic::AtomicU32][std::backtrace::Backtrace][std::io::Error][std::fs::File][std::panic::Location<'_>]
138138
[jobserver_crate::Client][jobserver_crate::HelperThread][crate::memmap::Mmap]
139139
[crate::profiling::SelfProfiler][crate::owned_slice::OwnedSlice]
140140
);

0 commit comments

Comments
 (0)