Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07d41a7
Correctly handle `--no-run` rustdoc test option
GuillaumeGomez Jul 13, 2025
796c4ef
Correctly handle `should_panic` doctest attribute
GuillaumeGomez Jul 7, 2025
11b7070
Add regression test for #143009
GuillaumeGomez Jul 4, 2025
21a4d9d
Update std doctests
GuillaumeGomez Jul 7, 2025
5f2ae4f
Add regression test for #143858
GuillaumeGomez Jul 13, 2025
b001ba6
Add FIXME comments to use `test::ERROR_EXIT_CODE` once public and fix…
GuillaumeGomez Aug 1, 2025
030b664
Use libtest `ERROR_EXIT_CODE` constant
GuillaumeGomez Oct 4, 2025
560d450
Correctly handle `should_panic` on targets not supporting it
GuillaumeGomez Oct 5, 2025
a11fe5d
Add diagnostic items for `pub mod consts` of FP types
samueltardieu Oct 6, 2025
b70e20a
Correctly handle `-C panic=abort` in doctests
GuillaumeGomez Oct 7, 2025
594f9c6
Clarify how to remediate the panic_immediate_abort error
ia0 Oct 8, 2025
6060bcc
Improve error messages for failing `should_panic` doctests
GuillaumeGomez Oct 8, 2025
973ddd8
Do not invalidate CFG caches in CtfeLimit.
cjgillot Oct 8, 2025
d4ecd71
format: some small cleanup
hkBst Oct 8, 2025
730221e
Fix double error for `#[no_mangle]` on closures
JonathanBrouwer Oct 8, 2025
c050bfb
Fix double error for `#[no_mangle]` on consts
JonathanBrouwer Oct 8, 2025
28c8cf6
Rollup merge of #143900 - GuillaumeGomez:fix-no-run, r=fmease
chenyukang Oct 9, 2025
632e546
Rollup merge of #147420 - samueltardieu:diag-items/consts-mod, r=joboet
chenyukang Oct 9, 2025
54aab31
Rollup merge of #147467 - JonathanBrouwer:double_warnings, r=Jonathan…
chenyukang Oct 9, 2025
8b701ae
Rollup merge of #147470 - ia0:immediate-abort, r=Mark-Simulacrum
chenyukang Oct 9, 2025
fbda090
Rollup merge of #147480 - cjgillot:invalidate-ctfelimit, r=tmiasko
chenyukang Oct 9, 2025
4617330
Rollup merge of #147481 - hkBst:format-1, r=jackh726
chenyukang Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,11 @@ impl Token {
}

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

pub fn is_path_start(&self) -> bool {
self == &PathSep
self.kind == PathSep
|| self.is_qpath_start()
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
|| self.is_path_segment_keyword()
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::session_diagnostics::{
NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass, NullOnObjcSelector,
ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral,
};
use crate::target_checking::Policy::AllowSilent;

pub(crate) struct OptimizeParser;

Expand Down Expand Up @@ -362,6 +363,8 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
Allow(Target::Static),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
AllowSilent(Target::Const), // Handled in the `InvalidNoMangleItems` pass
Error(Target::Closure),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
}
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_attr_parsing/src/target_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl AllowedTargets {
pub(crate) fn is_allowed(&self, target: Target) -> AllowedResult {
match self {
AllowedTargets::AllowList(list) => {
if list.contains(&Policy::Allow(target)) {
if list.contains(&Policy::Allow(target))
|| list.contains(&Policy::AllowSilent(target))
{
AllowedResult::Allowed
} else if list.contains(&Policy::Warn(target)) {
AllowedResult::Warn
Expand All @@ -40,7 +42,9 @@ impl AllowedTargets {
}
}
AllowedTargets::AllowListWarnRest(list) => {
if list.contains(&Policy::Allow(target)) {
if list.contains(&Policy::Allow(target))
|| list.contains(&Policy::AllowSilent(target))
{
AllowedResult::Allowed
} else if list.contains(&Policy::Error(target)) {
AllowedResult::Error
Expand All @@ -61,17 +65,26 @@ impl AllowedTargets {
.iter()
.filter_map(|target| match target {
Policy::Allow(target) => Some(*target),
Policy::AllowSilent(_) => None, // Not listed in possible targets
Policy::Warn(_) => None,
Policy::Error(_) => None,
})
.collect()
}
}

/// This policy determines what diagnostics should be emitted based on the `Target` of the attribute.
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum Policy {
/// A target that is allowed.
Allow(Target),
/// A target that is allowed and not listed in the possible targets.
/// This is useful if the target is checked elsewhere.
AllowSilent(Target),
/// Emits a FCW on this target.
/// This is useful if the target was previously allowed but should not be.
Warn(Target),
/// Emits an error on this target.
Error(Target),
}

Expand Down
37 changes: 17 additions & 20 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,26 @@ struct MacroInput {
/// Ok((fmtstr, parsed arguments))
/// ```
fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, MacroInput> {
let mut args = FormatArguments::new();

let mut p = ecx.new_parser_from_tts(tts);

if p.token == token::Eof {
return Err(ecx.dcx().create_err(errors::FormatRequiresString { span: sp }));
}

let first_token = &p.token;

let fmtstr = if let token::Literal(lit) = first_token.kind
&& matches!(lit.kind, token::Str | token::StrRaw(_))
{
// parse the format string
let fmtstr = match p.token.kind {
token::Eof => return Err(ecx.dcx().create_err(errors::FormatRequiresString { span: sp })),
// This allows us to properly handle cases when the first comma
// after the format string is mistakenly replaced with any operator,
// which cause the expression parser to eat too much tokens.
p.parse_literal_maybe_minus()?
} else {
token::Literal(token::Lit { kind: token::Str | token::StrRaw(_), .. }) => {
p.parse_literal_maybe_minus()?
}
// Otherwise, we fall back to the expression parser.
p.parse_expr()?
_ => p.parse_expr()?,
};

// Only allow implicit captures to be used when the argument is a direct literal
// instead of a macro expanding to one.
let is_direct_literal = matches!(fmtstr.kind, ExprKind::Lit(_));

// parse comma FormatArgument pairs
let mut args = FormatArguments::new();
let mut first = true;

while p.token != token::Eof {
// parse a comma, or else report an error
if !p.eat(exp!(Comma)) {
if first {
p.clear_expected_token_types();
Expand All @@ -120,9 +111,11 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
}
}
first = false;
// accept a trailing comma
if p.token == token::Eof {
break;
} // accept trailing commas
}
// parse a FormatArgument
match p.token.ident() {
Some((ident, _)) if p.look_ahead(1, |t| *t == token::Eq) => {
p.bump();
Expand Down Expand Up @@ -156,6 +149,10 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
}
}
}

// Only allow implicit captures for direct literals
let is_direct_literal = matches!(fmtstr.kind, ExprKind::Lit(_));

Ok(MacroInput { fmtstr, args, is_direct_literal })
}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple time
codegen_ssa_no_field = no field `{$name}`
codegen_ssa_no_mangle_nameless = `#[no_mangle]` cannot be used on {$definition} as it has no name
codegen_ssa_no_module_named =
no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use rustc_span::{Ident, Span, sym};
use rustc_target::spec::SanitizerSet;

use crate::errors;
use crate::errors::NoMangleNameless;
use crate::target_features::{
check_target_feature_trait_unsafe, check_tied_features, from_target_feature_attr,
};
Expand Down Expand Up @@ -182,14 +181,10 @@ fn process_builtin_attrs(
if tcx.opt_item_name(did.to_def_id()).is_some() {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
} else {
tcx.dcx().emit_err(NoMangleNameless {
span: *attr_span,
definition: format!(
"{} {}",
tcx.def_descr_article(did.to_def_id()),
tcx.def_descr(did.to_def_id())
),
});
tcx.dcx().span_delayed_bug(
*attr_span,
"no_mangle should be on a named function",
);
}
}
AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,14 +1284,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
}
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_no_mangle_nameless)]
pub(crate) struct NoMangleNameless {
#[primary_span]
pub span: Span,
pub definition: String,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_feature_not_valid)]
pub(crate) struct FeatureNotValid<'a> {
Expand Down
17 changes: 5 additions & 12 deletions compiler/rustc_mir_transform/src/ctfe_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl<'tcx> crate::MirPass<'tcx> for CtfeLimit {
}
})
.collect();

let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
for index in indices {
insert_counter(
body.basic_blocks_mut()
.get_mut(index)
.expect("basic_blocks index {index} should exist"),
);
let bbdata = &mut basic_blocks[index];
let source_info = bbdata.terminator().source_info;
bbdata.statements.push(Statement::new(source_info, StatementKind::ConstEvalCounter));
}
}

Expand All @@ -53,10 +53,3 @@ fn has_back_edge(
// Check if any of the dominators of the node are also the node's successor.
node_data.terminator().successors().any(|succ| doms.dominates(succ, node))
}

fn insert_counter(basic_block_data: &mut BasicBlockData<'_>) {
basic_block_data.statements.push(Statement::new(
basic_block_data.terminator().source_info,
StatementKind::ConstEvalCounter,
));
}
4 changes: 4 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,12 @@ symbols! {
external_doc,
f,
f16,
f16_consts_mod,
f16_epsilon,
f16_nan,
f16c_target_feature,
f32,
f32_consts_mod,
f32_epsilon,
f32_legacy_const_digits,
f32_legacy_const_epsilon,
Expand All @@ -1002,6 +1004,7 @@ symbols! {
f32_legacy_const_radix,
f32_nan,
f64,
f64_consts_mod,
f64_epsilon,
f64_legacy_const_digits,
f64_legacy_const_epsilon,
Expand All @@ -1019,6 +1022,7 @@ symbols! {
f64_legacy_const_radix,
f64_nan,
f128,
f128_consts_mod,
f128_epsilon,
f128_nan,
fabsf16,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{intrinsics, mem};

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

Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{intrinsics, mem};

/// Basic mathematical constants.
#[unstable(feature = "f16", issue = "116909")]
#[rustc_diagnostic_item = "f16_consts_mod"]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.

Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "f32_consts_mod"]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.

Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub const NEG_INFINITY: f64 = f64::NEG_INFINITY;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "f64_consts_mod"]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.

Expand Down
3 changes: 2 additions & 1 deletion library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ use crate::panic::{Location, PanicInfo};
compile_error!(
"panic_immediate_abort is now a real panic strategy! \
Enable it with `panic = \"immediate-abort\"` in Cargo.toml, \
or with the compiler flags `-Zunstable-options -Cpanic=immediate-abort`"
or with the compiler flags `-Zunstable-options -Cpanic=immediate-abort`. \
In both cases, you still need to build core, e.g. with `-Zbuild-std`"
);

// First we define the two main entry points that all panics go through.
Expand Down
16 changes: 12 additions & 4 deletions library/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ use crate::fmt::{self, Write};
/// the `Debug` output means `Report` is an ideal starting place for formatting errors returned
/// from `main`.
///
/// ```should_panic
/// ```
/// #![feature(error_reporter)]
/// use std::error::Report;
/// # use std::error::Error;
Expand Down Expand Up @@ -154,10 +154,14 @@ use crate::fmt::{self, Write};
/// # Err(SuperError { source: SuperErrorSideKick })
/// # }
///
/// fn main() -> Result<(), Report<SuperError>> {
/// fn run() -> Result<(), Report<SuperError>> {
/// get_super_error()?;
/// Ok(())
/// }
///
/// fn main() {
/// assert!(run().is_err());
/// }
/// ```
///
/// This example produces the following output:
Expand All @@ -170,7 +174,7 @@ use crate::fmt::{self, Write};
/// output format. If you want to make sure your `Report`s are pretty printed and include backtrace
/// you will need to manually convert and enable those flags.
///
/// ```should_panic
/// ```
/// #![feature(error_reporter)]
/// use std::error::Report;
/// # use std::error::Error;
Expand Down Expand Up @@ -201,12 +205,16 @@ use crate::fmt::{self, Write};
/// # Err(SuperError { source: SuperErrorSideKick })
/// # }
///
/// fn main() -> Result<(), Report<SuperError>> {
/// fn run() -> Result<(), Report<SuperError>> {
/// get_super_error()
/// .map_err(Report::from)
/// .map_err(|r| r.pretty(true).show_backtrace(true))?;
/// Ok(())
/// }
///
/// fn main() {
/// assert!(run().is_err());
/// }
/// ```
///
/// This example produces the following output:
Expand Down
Loading
Loading