Skip to content

Commit 5eddb80

Browse files
committed
Auto merge of #152951 - jhpratt:rollup-NcY8xiT, r=jhpratt
Rollup of 14 pull requests Successful merges: - #150468 (rustc_target: callconv: powerpc64: Use the ABI set in target options instead of guessing) - #151628 (Fix ICE in const eval of packed SIMD types with non-power-of-two element counts) - #151871 (don't use env with infer vars) - #152591 (Simplify internals of `{Rc,Arc}::default`) - #152657 (std: move `exit` out of PAL) - #152865 (Fixed ByteStr not padding within its Display trait when no specific alignment is mentioned) - #152908 (Enable rust.remap-debuginfo in the dist profile) - #152705 (Test(lib/win/proc): Skip `raw_attributes` doctest under Win7) - #152767 (fix typo in `carryless_mul` macro invocation) - #152837 (fix(codegen): Use `body_codegen_attrs` For Caller In `adjust_target_feature_sig`) - #152871 (Fix warnings in rs{begin,end}.rs files) - #152921 (Add build.rustdoc option to bootstrap config) - #152933 (Start migration for `LintDiagnostic` items by adding API and migrating `LinkerOutput` lint) - #152937 (remove unneeded reboxing)
2 parents d8b2222 + c240758 commit 5eddb80

File tree

43 files changed

+511
-167
lines changed

Some content is hidden

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

43 files changed

+511
-167
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@
302302
# If you set this, you likely want to set `cargo` as well.
303303
#build.rustc = "/path/to/rustc"
304304

305+
# Use this rustdoc binary as the stage0 snapshot rustdoc.
306+
# If unspecified, then the binary "rustdoc" (with platform-specific extension, e.g. ".exe")
307+
# in the same directory as "rustc" will be used.
308+
#build.rustdoc = "/path/to/rustdoc"
309+
305310
# Instead of downloading the src/stage0 version of rustfmt specified,
306311
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
307312
#build.rustfmt = "/path/to/rustfmt"

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,9 +4211,7 @@ impl ForeignItemKind {
42114211
impl From<ForeignItemKind> for ItemKind {
42124212
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
42134213
match foreign_item_kind {
4214-
ForeignItemKind::Static(box static_foreign_item) => {
4215-
ItemKind::Static(Box::new(static_foreign_item))
4216-
}
4214+
ForeignItemKind::Static(static_foreign_item) => ItemKind::Static(static_foreign_item),
42174215
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
42184216
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
42194217
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
@@ -4226,7 +4224,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
42264224

42274225
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
42284226
Ok(match item_kind {
4229-
ItemKind::Static(box static_item) => ForeignItemKind::Static(Box::new(static_item)),
4227+
ItemKind::Static(static_item) => ForeignItemKind::Static(static_item),
42304228
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
42314229
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
42324230
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ use rustc_attr_parsing::eval_config_entry;
1818
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1919
use rustc_data_structures::memmap::Mmap;
2020
use rustc_data_structures::temp_dir::MaybeTempDir;
21-
use rustc_errors::{DiagCtxtHandle, LintDiagnostic};
21+
use rustc_errors::DiagCtxtHandle;
2222
use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize};
2323
use rustc_hir::attrs::NativeLibKind;
2424
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
25-
use rustc_macros::LintDiagnostic;
25+
use rustc_macros::Diagnostic;
2626
use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file};
2727
use rustc_metadata::{
2828
EncodedMetadata, NativeLibSearchFallback, find_native_static_library,
2929
walk_native_lib_search_dirs,
3030
};
3131
use rustc_middle::bug;
32-
use rustc_middle::lint::lint_level;
32+
use rustc_middle::lint::diag_lint_level;
3333
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
3434
use rustc_middle::middle::dependency_format::Linkage;
3535
use rustc_middle::middle::exported_symbols::SymbolExportKind;
@@ -662,7 +662,7 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
662662
}
663663
}
664664

665-
#[derive(LintDiagnostic)]
665+
#[derive(Diagnostic)]
666666
#[diag("{$inner}")]
667667
/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
668668
/// end up with inconsistent languages within the same diagnostic.
@@ -938,9 +938,7 @@ fn link_natively(
938938

939939
let level = codegen_results.crate_info.lint_levels.linker_messages;
940940
let lint = |msg| {
941-
lint_level(sess, LINKER_MESSAGES, level, None, |diag| {
942-
LinkerOutput { inner: msg }.decorate_lint(diag)
943-
})
941+
diag_lint_level(sess, LINKER_MESSAGES, level, None, LinkerOutput { inner: msg });
944942
};
945943

946944
if !prog.stderr.is_empty() {

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use either::Either;
22
use rustc_abi::{BackendRepr, Endian};
33
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::{Float, Round};
5-
use rustc_data_structures::assert_matches;
65
use rustc_middle::mir::interpret::{InterpErrorKind, Pointer, UndefinedBehaviorInfo};
76
use rustc_middle::ty::{FloatTy, ScalarInt, SimdAlign};
87
use rustc_middle::{bug, err_ub_format, mir, span_bug, throw_unsup_format, ty};
@@ -838,7 +837,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
838837
vector_layout: TyAndLayout<'tcx>,
839838
alignment: SimdAlign,
840839
) -> InterpResult<'tcx> {
841-
assert_matches!(vector_layout.backend_repr, BackendRepr::SimdVector { .. });
840+
// Packed SIMD types with non-power-of-two element counts use BackendRepr::Memory
841+
// instead of BackendRepr::SimdVector. We need to handle both cases.
842+
// FIXME: remove the BackendRepr::Memory case when SIMD vectors are always passed as BackendRepr::SimdVector.
843+
assert!(vector_layout.ty.is_simd(), "check_simd_ptr_alignment called on non-SIMD type");
844+
match vector_layout.backend_repr {
845+
BackendRepr::SimdVector { .. } | BackendRepr::Memory { .. } => {}
846+
_ => {
847+
span_bug!(
848+
self.cur_span(),
849+
"SIMD type has unexpected backend_repr: {:?}",
850+
vector_layout.backend_repr
851+
);
852+
}
853+
}
842854

843855
let align = match alignment {
844856
ty::SimdAlign::Unaligned => {

compiler/rustc_error_messages/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,18 @@ impl MultiSpan {
109109
MultiSpan { primary_spans: vec, span_labels: vec![] }
110110
}
111111

112+
pub fn push_primary_span(&mut self, primary_span: Span) {
113+
self.primary_spans.push(primary_span);
114+
}
115+
112116
pub fn push_span_label(&mut self, span: Span, label: impl Into<DiagMessage>) {
113117
self.span_labels.push((span, label.into()));
114118
}
115119

120+
pub fn push_span_diag(&mut self, span: Span, diag: DiagMessage) {
121+
self.span_labels.push((span, diag));
122+
}
123+
116124
/// Selects the first primary span (if any).
117125
pub fn primary_span(&self) -> Option<Span> {
118126
self.primary_spans.first().cloned()
@@ -179,6 +187,11 @@ impl MultiSpan {
179187
span_labels
180188
}
181189

190+
/// Returns the span labels as contained by `MultiSpan`.
191+
pub fn span_labels_raw(&self) -> &[(Span, DiagMessage)] {
192+
&self.span_labels
193+
}
194+
182195
/// Returns `true` if any of the span labels is displayable.
183196
pub fn has_span_labels(&self) -> bool {
184197
self.span_labels.iter().any(|(sp, _)| !sp.is_dummy())

compiler/rustc_middle/src/lint.rs

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::sorted_map::SortedMap;
5-
use rustc_errors::{Diag, MultiSpan};
5+
use rustc_errors::{Diag, Diagnostic, MultiSpan};
66
use rustc_hir::{HirId, ItemLocalId};
77
use rustc_lint_defs::EditionFcw;
88
use rustc_macros::{Decodable, Encodable, HashStable};
@@ -482,3 +482,205 @@ pub fn lint_level(
482482
}
483483
lint_level_impl(sess, lint, level, span, Box::new(decorate))
484484
}
485+
486+
/// The innermost function for emitting lints implementing the [`trait@Diagnostic`] trait.
487+
///
488+
/// If you are looking to implement a lint, look for higher level functions,
489+
/// for example:
490+
///
491+
/// - [`TyCtxt::emit_node_span_lint`]
492+
/// - [`TyCtxt::node_span_lint`]
493+
/// - [`TyCtxt::emit_node_lint`]
494+
/// - [`TyCtxt::node_lint`]
495+
/// - `LintContext::opt_span_lint`
496+
///
497+
/// This function will replace `lint_level` once all `LintDiagnostic` items have been migrated to
498+
/// `Diagnostic`.
499+
#[track_caller]
500+
pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
501+
sess: &'a Session,
502+
lint: &'static Lint,
503+
level: LevelAndSource,
504+
span: Option<MultiSpan>,
505+
decorate: D,
506+
) {
507+
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
508+
// the "real" work.
509+
#[track_caller]
510+
fn diag_lint_level_impl<'a>(
511+
sess: &'a Session,
512+
lint: &'static Lint,
513+
level: LevelAndSource,
514+
span: Option<MultiSpan>,
515+
decorate: Box<
516+
dyn FnOnce(rustc_errors::DiagCtxtHandle<'a>, rustc_errors::Level) -> Diag<'a, ()> + 'a,
517+
>,
518+
) {
519+
let LevelAndSource { level, lint_id, src } = level;
520+
521+
// Check for future incompatibility lints and issue a stronger warning.
522+
let future_incompatible = lint.future_incompatible;
523+
524+
let has_future_breakage = future_incompatible.map_or(
525+
// Default allow lints trigger too often for testing.
526+
sess.opts.unstable_opts.future_incompat_test && lint.default_level != Level::Allow,
527+
|incompat| incompat.report_in_deps,
528+
);
529+
530+
// Convert lint level to error level.
531+
let err_level = match level {
532+
Level::Allow => {
533+
if has_future_breakage {
534+
rustc_errors::Level::Allow
535+
} else {
536+
return;
537+
}
538+
}
539+
Level::Expect => {
540+
// This case is special as we actually allow the lint itself in this context, but
541+
// we can't return early like in the case for `Level::Allow` because we still
542+
// need the lint diagnostic to be emitted to `rustc_error::DiagCtxtInner`.
543+
//
544+
// We can also not mark the lint expectation as fulfilled here right away, as it
545+
// can still be cancelled in the decorate function. All of this means that we simply
546+
// create a `Diag` and continue as we would for warnings.
547+
rustc_errors::Level::Expect
548+
}
549+
Level::ForceWarn => rustc_errors::Level::ForceWarning,
550+
Level::Warn => rustc_errors::Level::Warning,
551+
Level::Deny | Level::Forbid => rustc_errors::Level::Error,
552+
};
553+
// Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),
554+
// so we need to make sure when we do call `decorate` that the diagnostic is eventually
555+
// emitted or we'll get a `must_produce_diag` ICE.
556+
//
557+
// When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors:
558+
// 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)`
559+
// or `Error`, then the diagnostic will be emitted regardless of CLI options.
560+
// 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by
561+
// `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic
562+
// will be emitted if `can_emit_warnings` is true.
563+
let skip = err_level == rustc_errors::Level::Warning && !sess.dcx().can_emit_warnings();
564+
565+
let disable_suggestions = if let Some(ref span) = span
566+
// If this code originates in a foreign macro, aka something that this crate
567+
// did not itself author, then it's likely that there's nothing this crate
568+
// can do about it. We probably want to skip the lint entirely.
569+
&& span.primary_spans().iter().any(|s| s.in_external_macro(sess.source_map()))
570+
{
571+
true
572+
} else {
573+
false
574+
};
575+
576+
let mut err: Diag<'_, ()> = if !skip {
577+
decorate(sess.dcx(), err_level)
578+
} else {
579+
Diag::new(sess.dcx(), err_level, "")
580+
};
581+
if let Some(span) = span
582+
&& err.span.primary_span().is_none()
583+
{
584+
// We can't use `err.span()` because it overwrites the labels, so we need to do it manually.
585+
for primary in span.primary_spans() {
586+
err.span.push_primary_span(*primary);
587+
}
588+
for (label_span, label) in span.span_labels_raw() {
589+
err.span.push_span_diag(*label_span, label.clone());
590+
}
591+
}
592+
if let Some(lint_id) = lint_id {
593+
err.lint_id(lint_id);
594+
}
595+
596+
if disable_suggestions {
597+
// Any suggestions made here are likely to be incorrect, so anything we
598+
// emit shouldn't be automatically fixed by rustfix.
599+
err.disable_suggestions();
600+
601+
// If this is a future incompatible that is not an edition fixing lint
602+
// it'll become a hard error, so we have to emit *something*. Also,
603+
// if this lint occurs in the expansion of a macro from an external crate,
604+
// allow individual lints to opt-out from being reported.
605+
let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
606+
607+
if !incompatible && !lint.report_in_external_macro {
608+
err.cancel();
609+
610+
// Don't continue further, since we don't want to have
611+
// `diag_span_note_once` called for a diagnostic that isn't emitted.
612+
return;
613+
}
614+
}
615+
616+
err.is_lint(lint.name_lower(), has_future_breakage);
617+
// Lint diagnostics that are covered by the expect level will not be emitted outside
618+
// the compiler. It is therefore not necessary to add any information for the user.
619+
// This will therefore directly call the decorate function which will in turn emit
620+
// the diagnostic.
621+
if let Level::Expect = level {
622+
err.emit();
623+
return;
624+
}
625+
626+
if let Some(future_incompatible) = future_incompatible {
627+
let explanation = match future_incompatible.reason {
628+
FutureIncompatibilityReason::FutureReleaseError(_) => {
629+
"this was previously accepted by the compiler but is being phased out; \
630+
it will become a hard error in a future release!"
631+
.to_owned()
632+
}
633+
FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => {
634+
"this will change its meaning in a future release!".to_owned()
635+
}
636+
FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => {
637+
let current_edition = sess.edition();
638+
format!(
639+
"this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
640+
)
641+
}
642+
FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw {
643+
edition, ..
644+
}) => {
645+
format!("this changes meaning in Rust {edition}")
646+
}
647+
FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw {
648+
edition,
649+
..
650+
}) => {
651+
format!(
652+
"this was previously accepted by the compiler but is being phased out; \
653+
it will become a hard error in Rust {edition} and in a future release in all editions!"
654+
)
655+
}
656+
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(
657+
EditionFcw { edition, .. },
658+
) => {
659+
format!(
660+
"this changes meaning in Rust {edition} and in a future release in all editions!"
661+
)
662+
}
663+
FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(),
664+
FutureIncompatibilityReason::Unreachable => unreachable!(),
665+
};
666+
667+
if future_incompatible.explain_reason {
668+
err.warn(explanation);
669+
}
670+
671+
let citation =
672+
format!("for more information, see {}", future_incompatible.reason.reference());
673+
err.note(citation);
674+
}
675+
676+
explain_lint_level_source(sess, lint, level, src, &mut err);
677+
err.emit();
678+
}
679+
diag_lint_level_impl(
680+
sess,
681+
lint,
682+
level,
683+
span,
684+
Box::new(move |dcx, level| decorate.into_diag(dcx, level)),
685+
);
686+
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,8 @@ impl<'tcx> TyCtxt<'tcx> {
13311331
caller: DefId,
13321332
) -> Option<ty::Binder<'tcx, ty::FnSig<'tcx>>> {
13331333
let fun_features = &self.codegen_fn_attrs(fun_def).target_features;
1334-
let callee_features = &self.codegen_fn_attrs(caller).target_features;
1335-
if self.is_target_feature_call_safe(&fun_features, &callee_features) {
1334+
let caller_features = &self.body_codegen_attrs(caller).target_features;
1335+
if self.is_target_feature_call_safe(&fun_features, &caller_features) {
13361336
return Some(fun_sig.map_bound(|sig| ty::FnSig { safety: hir::Safety::Safe, ..sig }));
13371337
}
13381338
None

compiler/rustc_target/src/callconv/powerpc64.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use rustc_abi::{Endian, HasDataLayout, TyAbiInterface};
66

77
use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform};
8-
use crate::spec::{Env, HasTargetSpec, Os};
8+
use crate::spec::{Abi, HasTargetSpec, Os};
99

1010
#[derive(Debug, Clone, Copy, PartialEq)]
1111
enum ABI {
@@ -106,8 +106,10 @@ where
106106
Ty: TyAbiInterface<'a, C> + Copy,
107107
C: HasDataLayout + HasTargetSpec,
108108
{
109-
let abi = if cx.target_spec().env == Env::Musl || cx.target_spec().os == Os::FreeBsd {
109+
let abi = if cx.target_spec().options.abi == Abi::ElfV2 {
110110
ELFv2
111+
} else if cx.target_spec().options.abi == Abi::ElfV1 {
112+
ELFv1
111113
} else if cx.target_spec().os == Os::Aix {
112114
AIX
113115
} else {

0 commit comments

Comments
 (0)