Skip to content

Commit acf2437

Browse files
committed
Auto merge of #147512 - Zalathar:rollup-p8kb5f7, r=Zalathar
Rollup of 12 pull requests Successful merges: - #146568 (Port the implemention of SIMD intrinsics from Miri to const-eval) - #147373 (give a better example why `std` modules named like primitives are needed) - #147419 (bootstrap: add `Builder::rustc_cmd` that includes the lib path) - #147420 (Add diagnostic items for `pub mod consts` of FP types) - #147457 (specialize slice::fill to use memset when possible) - #147467 (Fix double warnings on `#[no_mangle]`) - #147470 (Clarify how to remediate the panic_immediate_abort error) - #147480 (Do not invalidate CFG caches in CtfeLimit.) - #147481 (format: some small cleanup) - #147488 (refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`) - #147489 (Prefer to use repeat_n over repeat().take()) - #147506 (compiletest: Isolate public APIs and minimize public surface area) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd34871 + 76d4f37 commit acf2437

File tree

63 files changed

+1285
-1113
lines changed

Some content is hidden

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

63 files changed

+1285
-1113
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4805,7 +4805,6 @@ name = "rustdoc-gui-test"
48054805
version = "0.1.0"
48064806
dependencies = [
48074807
"build_helper",
4808-
"camino",
48094808
"compiletest",
48104809
"getopts",
48114810
"walkdir",

compiler/rustc_ast/src/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,11 @@ impl Token {
881881
}
882882

883883
pub fn is_qpath_start(&self) -> bool {
884-
self == &Lt || self == &Shl
884+
matches!(self.kind, Lt | Shl)
885885
}
886886

887887
pub fn is_path_start(&self) -> bool {
888-
self == &PathSep
888+
self.kind == PathSep
889889
|| self.is_qpath_start()
890890
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
891891
|| self.is_path_segment_keyword()

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::session_diagnostics::{
66
NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass, NullOnObjcSelector,
77
ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral,
88
};
9+
use crate::target_checking::Policy::AllowSilent;
910

1011
pub(crate) struct OptimizeParser;
1112

@@ -362,6 +363,8 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
362363
Allow(Target::Static),
363364
Allow(Target::Method(MethodKind::Inherent)),
364365
Allow(Target::Method(MethodKind::TraitImpl)),
366+
AllowSilent(Target::Const), // Handled in the `InvalidNoMangleItems` pass
367+
Error(Target::Closure),
365368
]);
366369
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
367370
}

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ impl AllowedTargets {
3131
pub(crate) fn is_allowed(&self, target: Target) -> AllowedResult {
3232
match self {
3333
AllowedTargets::AllowList(list) => {
34-
if list.contains(&Policy::Allow(target)) {
34+
if list.contains(&Policy::Allow(target))
35+
|| list.contains(&Policy::AllowSilent(target))
36+
{
3537
AllowedResult::Allowed
3638
} else if list.contains(&Policy::Warn(target)) {
3739
AllowedResult::Warn
@@ -40,7 +42,9 @@ impl AllowedTargets {
4042
}
4143
}
4244
AllowedTargets::AllowListWarnRest(list) => {
43-
if list.contains(&Policy::Allow(target)) {
45+
if list.contains(&Policy::Allow(target))
46+
|| list.contains(&Policy::AllowSilent(target))
47+
{
4448
AllowedResult::Allowed
4549
} else if list.contains(&Policy::Error(target)) {
4650
AllowedResult::Error
@@ -61,17 +65,26 @@ impl AllowedTargets {
6165
.iter()
6266
.filter_map(|target| match target {
6367
Policy::Allow(target) => Some(*target),
68+
Policy::AllowSilent(_) => None, // Not listed in possible targets
6469
Policy::Warn(_) => None,
6570
Policy::Error(_) => None,
6671
})
6772
.collect()
6873
}
6974
}
7075

76+
/// This policy determines what diagnostics should be emitted based on the `Target` of the attribute.
7177
#[derive(Debug, Eq, PartialEq)]
7278
pub(crate) enum Policy {
79+
/// A target that is allowed.
7380
Allow(Target),
81+
/// A target that is allowed and not listed in the possible targets.
82+
/// This is useful if the target is checked elsewhere.
83+
AllowSilent(Target),
84+
/// Emits a FCW on this target.
85+
/// This is useful if the target was previously allowed but should not be.
7486
Warn(Target),
87+
/// Emits an error on this target.
7588
Error(Target),
7689
}
7790

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn expand_preparsed_asm(
368368
if args.options.contains(ast::InlineAsmOptions::RAW) {
369369
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string().into()));
370370
let template_num_lines = 1 + template_str.matches('\n').count();
371-
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
371+
line_spans.extend(std::iter::repeat_n(template_sp, template_num_lines));
372372
continue;
373373
}
374374

@@ -523,7 +523,7 @@ fn expand_preparsed_asm(
523523

524524
if parser.line_spans.is_empty() {
525525
let template_num_lines = 1 + template_str.matches('\n').count();
526-
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
526+
line_spans.extend(std::iter::repeat_n(template_sp, template_num_lines));
527527
} else {
528528
line_spans.extend(
529529
parser

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,26 @@ struct MacroInput {
6969
/// Ok((fmtstr, parsed arguments))
7070
/// ```
7171
fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, MacroInput> {
72-
let mut args = FormatArguments::new();
73-
7472
let mut p = ecx.new_parser_from_tts(tts);
7573

76-
if p.token == token::Eof {
77-
return Err(ecx.dcx().create_err(errors::FormatRequiresString { span: sp }));
78-
}
79-
80-
let first_token = &p.token;
81-
82-
let fmtstr = if let token::Literal(lit) = first_token.kind
83-
&& matches!(lit.kind, token::Str | token::StrRaw(_))
84-
{
74+
// parse the format string
75+
let fmtstr = match p.token.kind {
76+
token::Eof => return Err(ecx.dcx().create_err(errors::FormatRequiresString { span: sp })),
8577
// This allows us to properly handle cases when the first comma
8678
// after the format string is mistakenly replaced with any operator,
8779
// which cause the expression parser to eat too much tokens.
88-
p.parse_literal_maybe_minus()?
89-
} else {
80+
token::Literal(token::Lit { kind: token::Str | token::StrRaw(_), .. }) => {
81+
p.parse_literal_maybe_minus()?
82+
}
9083
// Otherwise, we fall back to the expression parser.
91-
p.parse_expr()?
84+
_ => p.parse_expr()?,
9285
};
9386

94-
// Only allow implicit captures to be used when the argument is a direct literal
95-
// instead of a macro expanding to one.
96-
let is_direct_literal = matches!(fmtstr.kind, ExprKind::Lit(_));
97-
87+
// parse comma FormatArgument pairs
88+
let mut args = FormatArguments::new();
9889
let mut first = true;
99-
10090
while p.token != token::Eof {
91+
// parse a comma, or else report an error
10192
if !p.eat(exp!(Comma)) {
10293
if first {
10394
p.clear_expected_token_types();
@@ -120,9 +111,11 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
120111
}
121112
}
122113
first = false;
114+
// accept a trailing comma
123115
if p.token == token::Eof {
124116
break;
125-
} // accept trailing commas
117+
}
118+
// parse a FormatArgument
126119
match p.token.ident() {
127120
Some((ident, _)) if p.look_ahead(1, |t| *t == token::Eq) => {
128121
p.bump();
@@ -156,6 +149,10 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
156149
}
157150
}
158151
}
152+
153+
// Only allow implicit captures for direct literals
154+
let is_direct_literal = matches!(fmtstr.kind, ExprKind::Lit(_));
155+
159156
Ok(MacroInput { fmtstr, args, is_direct_literal })
160157
}
161158

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn data_id_for_static(
318318
let mut data = DataDescription::new();
319319
data.set_align(align);
320320
let data_gv = module.declare_data_in_data(data_id, &mut data);
321-
data.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect());
321+
data.define(std::iter::repeat_n(0, pointer_ty(tcx).bytes() as usize).collect());
322322
data.write_data_addr(0, data_gv, 0);
323323
match module.define_data(ref_data_id, &data) {
324324
// Every time the static is referenced there will be another definition of this global,

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,13 @@ impl<'ll> CodegenCx<'ll, '_> {
240240
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
241241
bug!("symbol `{}` is already defined", name);
242242
});
243-
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
244243
gv
245244
}
246-
_ => self.define_private_global(self.val_ty(cv)),
245+
_ => self.define_global("", self.val_ty(cv)).unwrap_or_else(|| {
246+
bug!("anonymous global symbol is already defined");
247+
}),
247248
};
249+
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
248250
llvm::set_initializer(gv, cv);
249251
set_global_alignment(self, gv, align);
250252
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
230230
}
231231
}
232232

233-
/// Declare a private global
234-
///
235-
/// Use this function when you intend to define a global without a name.
236-
pub(crate) fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
237-
unsafe { llvm::LLVMRustInsertPrivateGlobal(self.llmod(), ty) }
238-
}
239-
240233
/// Gets declared value by name.
241234
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
242235
debug!("get_declared_value(name={:?})", name);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,6 @@ unsafe extern "C" {
19551955
NameLen: size_t,
19561956
T: &'a Type,
19571957
) -> &'a Value;
1958-
pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
19591958
pub(crate) fn LLVMRustGetNamedValue(
19601959
M: &Module,
19611960
Name: *const c_char,

0 commit comments

Comments
 (0)