Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5088b38
Stabilize maybe_uninit_write_slice
thaliaarchi Oct 22, 2025
b6a6f00
Add Command::get_env_clear
schneems Nov 19, 2025
1223f5c
Resolve to a concrete impl instead of using fuzzy search
oli-obk Nov 6, 2025
9a8dc7e
Replace uses of 'CHECK: br' and 'CHECK-NOT: br' with 'br {{.*}}'.
zachs18 Nov 21, 2025
238ef54
Add tidy check to forbid 'CHECK: br' and 'CHECK-NOT: br' in new codeg…
zachs18 Nov 21, 2025
b5164c0
Fix typo and clarify bootstrap change tracker entry
yotamofek Nov 23, 2025
8b87b25
intrinsics: clarify float min/max behavios for NaNs and signed zeros
RalfJung Nov 23, 2025
15290fa
add NaN examples to public min/max functions
RalfJung Nov 24, 2025
7f89192
num: Implement `uint_gather_scatter_bits` feature for unsigned integers
okaneco Nov 19, 2025
e1a805a
Motor OS: make decode_error_kind more comprehensive
lasiotus Nov 25, 2025
9352610
rustdoc: add regression test for #140968
lolbinarycat Nov 25, 2025
9218298
Add a diagnostic attribute for special casing const bound errors for …
oli-obk Nov 6, 2025
3a91d34
bootstrap: Miri now handles jemalloc like everything else
RalfJung Nov 25, 2025
be28e7f
Add 'stack-protector' tests for Linux/Win32/Win64.
cezarbbb Nov 4, 2025
9a48fb6
optimize slice::Iter::next_chunk
bend-n Nov 20, 2025
0a712d2
Rollup merge of #147115 - cezarbbb:stable_ssp, r=SparrowLii
Zalathar Nov 27, 2025
a32d310
Rollup merge of #148048 - thaliaarchi:stabilize-maybeuninit-write-sli…
Zalathar Nov 27, 2025
e4cd17c
Rollup merge of #148641 - oli-obk:push-olzwqxsmnxmz, r=jackh726
Zalathar Nov 27, 2025
45c136b
Rollup merge of #149074 - schneems:schneems/get_env_clear, r=Mark-Sim…
Zalathar Nov 27, 2025
e3ecd45
Rollup merge of #149097 - okaneco:gather_scatter_bits, r=Mark-Simulacrum
Zalathar Nov 27, 2025
a8007e6
Rollup merge of #149131 - bend-n:optimize_slice_iter_next_chunk, r=Ma…
Zalathar Nov 27, 2025
39a8f75
Rollup merge of #149190 - zachs18:chilly, r=Mark-Simulacrum
Zalathar Nov 27, 2025
df6f24c
Rollup merge of #149239 - RalfJung:float-intrinsics, r=tgross35
Zalathar Nov 27, 2025
5432029
Rollup merge of #149243 - yotamofek:pr/change_tracker_typo, r=Mark-Si…
Zalathar Nov 27, 2025
0dae3e0
Rollup merge of #149301 - moturus:main, r=Mark-Simulacrum
Zalathar Nov 27, 2025
a545fa3
Rollup merge of #149306 - RalfJung:bootstra-miri-jemalloc, r=Kobzol
Zalathar Nov 27, 2025
8d6e349
Rollup merge of #149325 - lolbinarycat:rustdoc-alias-sort-140968, r=G…
Zalathar Nov 27, 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
12 changes: 6 additions & 6 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ enum MulAddType {

#[derive(Copy, Clone)]
pub(crate) enum MinMax {
/// The IEEE `Minimum` operation - see `f32::minimum` etc
/// The IEEE-2019 `minimum` operation - see `f32::minimum` etc.
/// In particular, `-0.0` is considered smaller than `+0.0` and
/// if either input is NaN, the result is NaN.
Minimum,
/// The IEEE `MinNum` operation - see `f32::min` etc
/// The IEEE-2008 `minNum` operation - see `f32::min` etc.
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
/// and is one argument is NaN, the other one is returned.
/// and if one argument is NaN, the other one is returned.
MinNum,
/// The IEEE `Maximum` operation - see `f32::maximum` etc
/// The IEEE-2019 `maximum` operation - see `f32::maximum` etc.
/// In particular, `-0.0` is considered smaller than `+0.0` and
/// if either input is NaN, the result is NaN.
Maximum,
/// The IEEE `MaxNum` operation - see `f32::max` etc
/// The IEEE-2008 `maxNum` operation - see `f32::max` etc.
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
/// and is one argument is NaN, the other one is returned.
/// and if one argument is NaN, the other one is returned.
MaxNum,
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,9 +1586,10 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
map
});

pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
match sym {
sym::on_unimplemented | sym::do_not_recommend => true,
sym::on_const => features.diagnostic_on_const(),
_ => false,
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ declare_features! (
(incomplete, deref_patterns, "1.79.0", Some(87121)),
/// Allows deriving the From trait on single-field structs.
(unstable, derive_from, "1.91.0", Some(144889)),
/// Allows giving non-const impls custom diagnostic messages if attempted to be used as const
(unstable, diagnostic_on_const, "CURRENT_RUSTC_VERSION", Some(143874)),
/// Allows `#[doc(cfg(...))]`.
(unstable, doc_cfg, "1.21.0", Some(43781)),
/// Allows `#[doc(masked)]`.
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
tcx.ensure_ok().type_of(def_id);
tcx.ensure_ok().predicates_of(def_id);
tcx.ensure_ok().associated_items(def_id);
check_diagnostic_attrs(tcx, def_id);
if of_trait {
let impl_trait_header = tcx.impl_trait_header(def_id);
res = res.and(
Expand All @@ -824,7 +825,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
tcx.ensure_ok().predicates_of(def_id);
tcx.ensure_ok().associated_items(def_id);
let assoc_items = tcx.associated_items(def_id);
check_on_unimplemented(tcx, def_id);
check_diagnostic_attrs(tcx, def_id);

for &assoc_item in assoc_items.in_definition_order() {
match assoc_item.kind {
Expand Down Expand Up @@ -1112,7 +1113,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
})
}

pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, def_id: LocalDefId) {
pub(super) fn check_diagnostic_attrs(tcx: TyCtxt<'_>, def_id: LocalDefId) {
// an error would be reported if this fails.
let _ = OnUnimplementedDirective::of_item(tcx, def_id.to_def_id());
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ passes_deprecated_annotation_has_no_effect =
passes_deprecated_attribute =
deprecated attribute must be paired with either stable or unstable attribute

passes_diagnostic_diagnostic_on_const_only_for_trait_impls =
`#[diagnostic::on_const]` can only be applied to trait impls

passes_diagnostic_diagnostic_on_unimplemented_only_for_traits =
`#[diagnostic::on_unimplemented]` can only be applied to trait definitions

Expand Down
36 changes: 34 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{
self as hir, Attribute, CRATE_HIR_ID, CRATE_OWNER_ID, FnSig, ForeignItem, HirId, Item,
ItemKind, MethodKind, PartialConstStability, Safety, Stability, StabilityLevel, Target,
self as hir, Attribute, CRATE_HIR_ID, CRATE_OWNER_ID, Constness, FnSig, ForeignItem, HirId,
Item, ItemKind, MethodKind, PartialConstStability, Safety, Stability, StabilityLevel, Target,
TraitItem, find_attr,
};
use rustc_macros::LintDiagnostic;
Expand Down Expand Up @@ -55,6 +55,10 @@ use crate::{errors, fluent_generated as fluent};
#[diag(passes_diagnostic_diagnostic_on_unimplemented_only_for_traits)]
struct DiagnosticOnUnimplementedOnlyForTraits;

#[derive(LintDiagnostic)]
#[diag(passes_diagnostic_diagnostic_on_const_only_for_trait_impls)]
struct DiagnosticOnConstOnlyForTraitImpls;

fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst,
Expand Down Expand Up @@ -294,6 +298,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::diagnostic, sym::on_unimplemented, ..] => {
self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
}
[sym::diagnostic, sym::on_const, ..] => {
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
}
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
[sym::doc, ..] => self.check_doc_attrs(
attr,
Expand Down Expand Up @@ -517,6 +524,31 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks if `#[diagnostic::on_const]` is applied to a trait impl
fn check_diagnostic_on_const(
&self,
attr_span: Span,
hir_id: HirId,
target: Target,
item: Option<ItemLike<'_>>,
) {
if matches!(target, Target::Impl { of_trait: true }) {
match item.unwrap() {
ItemLike::Item(it) => match it.expect_impl().constness {
Constness::Const => {}
Constness::NotConst => return,
},
ItemLike::ForeignItem => {}
}
}
self.tcx.emit_node_span_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
DiagnosticOnConstOnlyForTraitImpls,
);
}

/// Checks if an `#[inline]` is applied to a function or a closure.
fn check_inline(&self, hir_id: HirId, attr_span: Span, kind: &InlineAttr, target: Target) {
match target {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
&& let [namespace, attribute, ..] = &*path.segments
&& namespace.ident.name == sym::diagnostic
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
&& ![sym::on_unimplemented, sym::do_not_recommend, sym::on_const]
.contains(&attribute.ident.name)
{
let typo_name = find_best_match_for_name(
&[sym::on_unimplemented, sym::do_not_recommend],
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const],
attribute.ident.name,
Some(5),
);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ symbols! {
destructuring_assignment,
diagnostic,
diagnostic_namespace,
diagnostic_on_const,
dialect,
direct,
discriminant_kind,
Expand Down Expand Up @@ -1594,6 +1595,7 @@ symbols! {
old_name,
omit_gdb_pretty_printer_section,
on,
on_const,
on_unimplemented,
opaque,
opaque_module_name_placeholder: "<opaque>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use super::{
};
use crate::error_reporting::TypeErrCtxt;
use crate::error_reporting::infer::TyCategory;
use crate::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
use crate::error_reporting::traits::report_dyn_incompatibility;
use crate::errors::{ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch, CoroClosureNotFn};
use crate::infer::{self, InferCtxt, InferCtxtExt as _};
Expand Down Expand Up @@ -587,7 +588,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}

ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
self.report_host_effect_error(bound_predicate.rebind(predicate), obligation.param_env, span)
self.report_host_effect_error(bound_predicate.rebind(predicate), &obligation, span)
}

ty::PredicateKind::Subtype(predicate) => {
Expand Down Expand Up @@ -808,20 +809,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn report_host_effect_error(
&self,
predicate: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
param_env: ty::ParamEnv<'tcx>,
main_obligation: &PredicateObligation<'tcx>,
span: Span,
) -> Diag<'a> {
// FIXME(const_trait_impl): We should recompute the predicate with `[const]`
// if it's `const`, and if it holds, explain that this bound only
// *conditionally* holds. If that fails, we should also do selection
// to drill this down to an impl or built-in source, so we can
// point at it and explain that while the trait *is* implemented,
// that implementation is not const.
// *conditionally* holds.
let trait_ref = predicate.map_bound(|predicate| ty::TraitPredicate {
trait_ref: predicate.trait_ref,
polarity: ty::PredicatePolarity::Positive,
});
let mut file = None;

let err_msg = self.get_standard_error_message(
trait_ref,
None,
Expand All @@ -832,18 +831,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
);
let mut diag = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
*diag.long_ty_path() = file;
if !self.predicate_may_hold(&Obligation::new(
let obligation = Obligation::new(
self.tcx,
ObligationCause::dummy(),
param_env,
main_obligation.param_env,
trait_ref,
)) {
);
if !self.predicate_may_hold(&obligation) {
diag.downgrade_to_delayed_bug();
}
for candidate in self.find_similar_impl_candidates(trait_ref) {
let CandidateSimilarity::Exact { .. } = candidate.similarity else { continue };
let impl_did = candidate.impl_def_id;
let trait_did = candidate.trait_ref.def_id;

if let Ok(Some(ImplSource::UserDefined(impl_data))) =
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref.skip_binder()))
{
let impl_did = impl_data.impl_def_id;
let trait_did = trait_ref.def_id();
let impl_span = self.tcx.def_span(impl_did);
let trait_name = self.tcx.item_name(trait_did);

Expand All @@ -865,6 +867,42 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
impl_span,
format!("trait `{trait_name}` is implemented but not `const`"),
);

let (condition_options, format_args) = self.on_unimplemented_components(
trait_ref,
main_obligation,
diag.long_ty_path(),
);

if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, impl_did)
{
let note = command.evaluate(
self.tcx,
predicate.skip_binder().trait_ref,
&condition_options,
&format_args,
);
let OnUnimplementedNote {
message,
label,
notes,
parent_label,
append_const_msg: _,
} = note;

if let Some(message) = message {
diag.primary_message(message);
}
if let Some(label) = label {
diag.span_label(impl_span, label);
}
for note in notes {
diag.note(note);
}
if let Some(parent_label) = parent_label {
diag.span_label(impl_span, parent_label);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit};
use rustc_errors::codes::*;
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{AttrArgs, Attribute};
use rustc_macros::LintDiagnostic;
Expand Down Expand Up @@ -103,7 +104,27 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if trait_pred.polarity() != ty::PredicatePolarity::Positive {
return OnUnimplementedNote::default();
}
let (condition_options, format_args) =
self.on_unimplemented_components(trait_pred, obligation, long_ty_path);
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, trait_pred.def_id())
{
command.evaluate(
self.tcx,
trait_pred.skip_binder().trait_ref,
&condition_options,
&format_args,
)
} else {
OnUnimplementedNote::default()
}
}

pub(crate) fn on_unimplemented_components(
&self,
trait_pred: ty::PolyTraitPredicate<'tcx>,
obligation: &PredicateObligation<'tcx>,
long_ty_path: &mut Option<PathBuf>,
) -> (ConditionOptions, FormatArgs<'tcx>) {
let (def_id, args) = self
.impl_similar_to(trait_pred, obligation)
.unwrap_or_else(|| (trait_pred.def_id(), trait_pred.skip_binder().trait_ref.args));
Expand Down Expand Up @@ -293,12 +314,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.collect();

let format_args = FormatArgs { this, trait_sugared, generic_args, item_context };

if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
command.evaluate(self.tcx, trait_pred.trait_ref, &condition_options, &format_args)
} else {
OnUnimplementedNote::default()
}
(condition_options, format_args)
}
}

Expand All @@ -325,7 +341,7 @@ pub struct OnUnimplementedDirective {
}

/// For the `#[rustc_on_unimplemented]` attribute
#[derive(Default)]
#[derive(Default, Debug)]
pub struct OnUnimplementedNote {
pub message: Option<String>,
pub label: Option<String>,
Expand Down Expand Up @@ -562,17 +578,21 @@ impl<'tcx> OnUnimplementedDirective {
}

pub fn of_item(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> Result<Option<Self>, ErrorGuaranteed> {
if !tcx.is_trait(item_def_id) {
let attr = if tcx.is_trait(item_def_id) {
sym::on_unimplemented
} else if let DefKind::Impl { of_trait: true } = tcx.def_kind(item_def_id) {
sym::on_const
} else {
// It could be a trait_alias (`trait MyTrait = SomeOtherTrait`)
// or an implementation (`impl MyTrait for Foo {}`)
//
// We don't support those.
return Ok(None);
}
};
if let Some(attr) = tcx.get_attr(item_def_id, sym::rustc_on_unimplemented) {
return Self::parse_attribute(attr, false, tcx, item_def_id);
} else {
tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, sym::on_unimplemented])
tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, attr])
.filter_map(|attr| Self::parse_attribute(attr, true, tcx, item_def_id).transpose())
.try_fold(None, |aggr: Option<Self>, directive| {
let directive = directive?;
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ dependencies = [

[[package]]
name = "moto-rt"
version = "0.15.0"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058a2807a30527bee4c30df7ababe971cdde94372d4dbd1ff145bb403381436c"
checksum = "0bf4bc387d3b3502cb92c09ec980cca909b94978e144c61da8319ecf4bc8d031"
dependencies = [
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand Down
Loading
Loading