Skip to content

Commit 111cf48

Browse files
committed
Auto merge of #147492 - matthiaskrgr:rollup-m0nudm2, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #143900 ([rustdoc] Correctly handle `should_panic` doctest attribute and fix `--no-run` test flag on the 2024 edition) - #147420 (Add diagnostic items for `pub mod consts` of FP types) - #147467 (Fix double warnings on `#[no_mangle]`) - #147476 (Add a test for the cold attribute) - #147480 (Do not invalidate CFG caches in CtfeLimit.) - #147481 (format: some small cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b6f0945 + f41bcbc commit 111cf48

File tree

31 files changed

+462
-92
lines changed

31 files changed

+462
-92
lines changed

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/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_ssa/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple time
223223
224224
codegen_ssa_no_field = no field `{$name}`
225225
226-
codegen_ssa_no_mangle_nameless = `#[no_mangle]` cannot be used on {$definition} as it has no name
227-
228226
codegen_ssa_no_module_named =
229227
no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
230228

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_span::{Ident, Span, sym};
1919
use rustc_target::spec::SanitizerSet;
2020

2121
use crate::errors;
22-
use crate::errors::NoMangleNameless;
2322
use crate::target_features::{
2423
check_target_feature_trait_unsafe, check_tied_features, from_target_feature_attr,
2524
};
@@ -182,14 +181,10 @@ fn process_builtin_attrs(
182181
if tcx.opt_item_name(did.to_def_id()).is_some() {
183182
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
184183
} else {
185-
tcx.dcx().emit_err(NoMangleNameless {
186-
span: *attr_span,
187-
definition: format!(
188-
"{} {}",
189-
tcx.def_descr_article(did.to_def_id()),
190-
tcx.def_descr(did.to_def_id())
191-
),
192-
});
184+
tcx.dcx().span_delayed_bug(
185+
*attr_span,
186+
"no_mangle should be on a named function",
187+
);
193188
}
194189
}
195190
AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,14 +1284,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
12841284
}
12851285
}
12861286

1287-
#[derive(Diagnostic)]
1288-
#[diag(codegen_ssa_no_mangle_nameless)]
1289-
pub(crate) struct NoMangleNameless {
1290-
#[primary_span]
1291-
pub span: Span,
1292-
pub definition: String,
1293-
}
1294-
12951287
#[derive(Diagnostic)]
12961288
#[diag(codegen_ssa_feature_not_valid)]
12971289
pub(crate) struct FeatureNotValid<'a> {

compiler/rustc_mir_transform/src/ctfe_limit.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ impl<'tcx> crate::MirPass<'tcx> for CtfeLimit {
2828
}
2929
})
3030
.collect();
31+
32+
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
3133
for index in indices {
32-
insert_counter(
33-
body.basic_blocks_mut()
34-
.get_mut(index)
35-
.expect("basic_blocks index {index} should exist"),
36-
);
34+
let bbdata = &mut basic_blocks[index];
35+
let source_info = bbdata.terminator().source_info;
36+
bbdata.statements.push(Statement::new(source_info, StatementKind::ConstEvalCounter));
3737
}
3838
}
3939

@@ -53,10 +53,3 @@ fn has_back_edge(
5353
// Check if any of the dominators of the node are also the node's successor.
5454
node_data.terminator().successors().any(|succ| doms.dominates(succ, node))
5555
}
56-
57-
fn insert_counter(basic_block_data: &mut BasicBlockData<'_>) {
58-
basic_block_data.statements.push(Statement::new(
59-
basic_block_data.terminator().source_info,
60-
StatementKind::ConstEvalCounter,
61-
));
62-
}

compiler/rustc_span/src/symbol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,10 +981,12 @@ symbols! {
981981
external_doc,
982982
f,
983983
f16,
984+
f16_consts_mod,
984985
f16_epsilon,
985986
f16_nan,
986987
f16c_target_feature,
987988
f32,
989+
f32_consts_mod,
988990
f32_epsilon,
989991
f32_legacy_const_digits,
990992
f32_legacy_const_epsilon,
@@ -1002,6 +1004,7 @@ symbols! {
10021004
f32_legacy_const_radix,
10031005
f32_nan,
10041006
f64,
1007+
f64_consts_mod,
10051008
f64_epsilon,
10061009
f64_legacy_const_digits,
10071010
f64_legacy_const_epsilon,
@@ -1019,6 +1022,7 @@ symbols! {
10191022
f64_legacy_const_radix,
10201023
f64_nan,
10211024
f128,
1025+
f128_consts_mod,
10221026
f128_epsilon,
10231027
f128_nan,
10241028
fabsf16,

library/core/src/num/f128.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{intrinsics, mem};
1818

1919
/// Basic mathematical constants.
2020
#[unstable(feature = "f128", issue = "116909")]
21+
#[rustc_diagnostic_item = "f128_consts_mod"]
2122
pub mod consts {
2223
// FIXME: replace with mathematical constants from cmath.
2324

0 commit comments

Comments
 (0)