Skip to content

Commit ddd5e13

Browse files
committed
Auto merge of #149361 - Zalathar:rollup-ygtgbn5, r=Zalathar
Rollup of 19 pull requests Successful merges: - #148048 (Stabilize `maybe_uninit_write_slice`) - #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls) - #148765 (std: split up the `thread` module) - #149074 (Add Command::get_env_clear) - #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers) - #149131 (optimize `slice::Iter::next_chunk`) - #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead)) - #149239 (clarify float min/max behavios for NaNs and signed zeros) - #149243 (Fix typo and clarify bootstrap change tracker entry) - #149270 (implement `Iterator::{exactly_one, collect_array}`) - #149295 (Suggest _bytes versions of endian-converting methods) - #149301 (Motor OS: make decode_error_kind more comprehensive) - #149306 (bootstrap: Miri now handles jemalloc like everything else) - #149325 (rustdoc: add regression test for #140968) - #149332 (fix rustdoc search says “Consider searching for "null" instead.” #149324) - #149349 (Fix typo in comment.) - #149353 (Tidying up UI tests [3/N]) - #149355 (Document that `build.description` affects symbol mangling and crate IDs) - #149360 (Enable CI download for windows-gnullvm) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1be6b13 + 971bd20 commit ddd5e13

File tree

127 files changed

+2894
-2126
lines changed

Some content is hidden

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

127 files changed

+2894
-2126
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@
220220
# which is also used in places like debuginfo `DW_AT_producer`. This may be useful for
221221
# supplementary build information, like distro-specific package versions.
222222
#
223+
# IMPORTANT: Changing this value changes crate IDs and symbol name mangling, making
224+
# compiled artifacts incompatible. PGO profiles cannot be reused across different
225+
# descriptions, and incremental compilation caches are invalidated. Keep this value
226+
# consistent when reusing build artifacts.
227+
#
223228
# The Rust compiler will differentiate between versions of itself, including
224229
# based on this string, which means that if you wish to be compatible with
225230
# upstream Rust you need to set this to "". However, note that if you set this to "" but

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ impl MetadataLoader for DefaultMetadataLoader {
8686
format!("failed to parse aix dylib '{}': {}", path.display(), e)
8787
})?;
8888

89-
match archive.members().exactly_one() {
89+
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
90+
match Itertools::exactly_one(archive.members()) {
9091
Ok(lib) => {
9192
let lib = lib.map_err(|e| {
9293
format!("failed to parse aix dylib '{}': {}", path.display(), e)

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ enum MulAddType {
3636

3737
#[derive(Copy, Clone)]
3838
pub(crate) enum MinMax {
39-
/// The IEEE `Minimum` operation - see `f32::minimum` etc
39+
/// The IEEE-2019 `minimum` operation - see `f32::minimum` etc.
4040
/// In particular, `-0.0` is considered smaller than `+0.0` and
4141
/// if either input is NaN, the result is NaN.
4242
Minimum,
43-
/// The IEEE `MinNum` operation - see `f32::min` etc
43+
/// The IEEE-2008 `minNum` operation - see `f32::min` etc.
4444
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
45-
/// and is one argument is NaN, the other one is returned.
45+
/// and if one argument is NaN, the other one is returned.
4646
MinNum,
47-
/// The IEEE `Maximum` operation - see `f32::maximum` etc
47+
/// The IEEE-2019 `maximum` operation - see `f32::maximum` etc.
4848
/// In particular, `-0.0` is considered smaller than `+0.0` and
4949
/// if either input is NaN, the result is NaN.
5050
Maximum,
51-
/// The IEEE `MaxNum` operation - see `f32::max` etc
51+
/// The IEEE-2008 `maxNum` operation - see `f32::max` etc.
5252
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
53-
/// and is one argument is NaN, the other one is returned.
53+
/// and if one argument is NaN, the other one is returned.
5454
MaxNum,
5555
}
5656

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,9 +1586,10 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
15861586
map
15871587
});
15881588

1589-
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
1589+
pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
15901590
match sym {
15911591
sym::on_unimplemented | sym::do_not_recommend => true,
1592+
sym::on_const => features.diagnostic_on_const(),
15921593
_ => false,
15931594
}
15941595
}

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ declare_features! (
483483
(incomplete, deref_patterns, "1.79.0", Some(87121)),
484484
/// Allows deriving the From trait on single-field structs.
485485
(unstable, derive_from, "1.91.0", Some(144889)),
486+
/// Allows giving non-const impls custom diagnostic messages if attempted to be used as const
487+
(unstable, diagnostic_on_const, "CURRENT_RUSTC_VERSION", Some(143874)),
486488
/// Allows `#[doc(cfg(...))]`.
487489
(unstable, doc_cfg, "1.21.0", Some(43781)),
488490
/// Allows `#[doc(masked)]`.

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
802802
tcx.ensure_ok().type_of(def_id);
803803
tcx.ensure_ok().predicates_of(def_id);
804804
tcx.ensure_ok().associated_items(def_id);
805+
check_diagnostic_attrs(tcx, def_id);
805806
if of_trait {
806807
let impl_trait_header = tcx.impl_trait_header(def_id);
807808
res = res.and(
@@ -824,7 +825,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
824825
tcx.ensure_ok().predicates_of(def_id);
825826
tcx.ensure_ok().associated_items(def_id);
826827
let assoc_items = tcx.associated_items(def_id);
827-
check_on_unimplemented(tcx, def_id);
828+
check_diagnostic_attrs(tcx, def_id);
828829

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

1115-
pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1116+
pub(super) fn check_diagnostic_attrs(tcx: TyCtxt<'_>, def_id: LocalDefId) {
11161117
// an error would be reported if this fails.
11171118
let _ = OnUnimplementedDirective::of_item(tcx, def_id.to_def_id());
11181119
}

compiler/rustc_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ passes_deprecated_annotation_has_no_effect =
9696
passes_deprecated_attribute =
9797
deprecated attribute must be paired with either stable or unstable attribute
9898
99+
passes_diagnostic_diagnostic_on_const_only_for_trait_impls =
100+
`#[diagnostic::on_const]` can only be applied to trait impls
101+
99102
passes_diagnostic_diagnostic_on_unimplemented_only_for_traits =
100103
`#[diagnostic::on_unimplemented]` can only be applied to trait definitions
101104

compiler/rustc_passes/src/check_attr.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use rustc_hir::def::DefKind;
2323
use rustc_hir::def_id::LocalModDefId;
2424
use rustc_hir::intravisit::{self, Visitor};
2525
use rustc_hir::{
26-
self as hir, Attribute, CRATE_HIR_ID, CRATE_OWNER_ID, FnSig, ForeignItem, HirId, Item,
27-
ItemKind, MethodKind, PartialConstStability, Safety, Stability, StabilityLevel, Target,
26+
self as hir, Attribute, CRATE_HIR_ID, CRATE_OWNER_ID, Constness, FnSig, ForeignItem, HirId,
27+
Item, ItemKind, MethodKind, PartialConstStability, Safety, Stability, StabilityLevel, Target,
2828
TraitItem, find_attr,
2929
};
3030
use rustc_macros::LintDiagnostic;
@@ -55,6 +55,10 @@ use crate::{errors, fluent_generated as fluent};
5555
#[diag(passes_diagnostic_diagnostic_on_unimplemented_only_for_traits)]
5656
struct DiagnosticOnUnimplementedOnlyForTraits;
5757

58+
#[derive(LintDiagnostic)]
59+
#[diag(passes_diagnostic_diagnostic_on_const_only_for_trait_impls)]
60+
struct DiagnosticOnConstOnlyForTraitImpls;
61+
5862
fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
5963
match impl_item.kind {
6064
hir::ImplItemKind::Const(..) => Target::AssocConst,
@@ -294,6 +298,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
294298
[sym::diagnostic, sym::on_unimplemented, ..] => {
295299
self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
296300
}
301+
[sym::diagnostic, sym::on_const, ..] => {
302+
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
303+
}
297304
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
298305
[sym::doc, ..] => self.check_doc_attrs(
299306
attr,
@@ -517,6 +524,31 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
517524
}
518525
}
519526

527+
/// Checks if `#[diagnostic::on_const]` is applied to a trait impl
528+
fn check_diagnostic_on_const(
529+
&self,
530+
attr_span: Span,
531+
hir_id: HirId,
532+
target: Target,
533+
item: Option<ItemLike<'_>>,
534+
) {
535+
if matches!(target, Target::Impl { of_trait: true }) {
536+
match item.unwrap() {
537+
ItemLike::Item(it) => match it.expect_impl().constness {
538+
Constness::Const => {}
539+
Constness::NotConst => return,
540+
},
541+
ItemLike::ForeignItem => {}
542+
}
543+
}
544+
self.tcx.emit_node_span_lint(
545+
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
546+
hir_id,
547+
attr_span,
548+
DiagnosticOnConstOnlyForTraitImpls,
549+
);
550+
}
551+
520552
/// Checks if an `#[inline]` is applied to a function or a closure.
521553
fn check_inline(&self, hir_id: HirId, attr_span: Span, kind: &InlineAttr, target: Target) {
522554
match target {

compiler/rustc_resolve/src/macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
690690
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
691691
&& let [namespace, attribute, ..] = &*path.segments
692692
&& namespace.ident.name == sym::diagnostic
693-
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
693+
&& ![sym::on_unimplemented, sym::do_not_recommend, sym::on_const]
694+
.contains(&attribute.ident.name)
694695
{
695696
let typo_name = find_best_match_for_name(
696-
&[sym::on_unimplemented, sym::do_not_recommend],
697+
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const],
697698
attribute.ident.name,
698699
Some(5),
699700
);

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ symbols! {
878878
destructuring_assignment,
879879
diagnostic,
880880
diagnostic_namespace,
881+
diagnostic_on_const,
881882
dialect,
882883
direct,
883884
discriminant_kind,
@@ -1594,6 +1595,7 @@ symbols! {
15941595
old_name,
15951596
omit_gdb_pretty_printer_section,
15961597
on,
1598+
on_const,
15971599
on_unimplemented,
15981600
opaque,
15991601
opaque_module_name_placeholder: "<opaque>",

0 commit comments

Comments
 (0)