Skip to content

Commit

Permalink
Auto merge of rust-lang#136918 - GuillaumeGomez:rollup-f6h21gg, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#134981 ( Explain that in paths generics can't be set on both the enum and the variant)
 - rust-lang#136698 (Replace i686-unknown-redox target with i586-unknown-redox)
 - rust-lang#136767 (improve host/cross target checking)
 - rust-lang#136829 ([rustdoc] Move line numbers into the `<code>` directly)
 - rust-lang#136875 (Rustc dev guide subtree update)
 - rust-lang#136900 (compiler: replace `ExternAbi::name` calls with formatters)
 - rust-lang#136913 (Put kobzol back on review rotation)
 - rust-lang#136915 (documentation fix: `f16` and `f128` are not double-precision)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 12, 2025
2 parents 021fb9c + 40f0499 commit 552a959
Show file tree
Hide file tree
Showing 69 changed files with 578 additions and 399 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ fn push_debuginfo_type_name<'tcx>(
output.push_str(sig.safety.prefix_str());

if sig.abi != rustc_abi::ExternAbi::Rust {
output.push_str("extern \"");
output.push_str(sig.abi.name());
output.push_str("\" ");
let _ = write!(output, "extern {} ", sig.abi);
}

output.push_str("fn(");
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ into_diag_arg_using_display!(
SplitDebuginfo,
ExitStatus,
ErrCode,
rustc_abi::ExternAbi,
);

impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ hir_analysis_cmse_entry_generic =
functions with the `"C-cmse-nonsecure-entry"` ABI cannot contain generics in their type
hir_analysis_cmse_inputs_stack_spill =
arguments for `"{$abi_name}"` function too large to pass via registers
arguments for `{$abi}` function too large to pass via registers
.label = {$plural ->
[false] this argument doesn't
*[true] these arguments don't
} fit in the available registers
.note = functions with the `"{$abi_name}"` ABI must pass all their arguments via the 4 32-bit available argument registers
.note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit available argument registers
hir_analysis_cmse_output_stack_spill =
return value of `"{$abi_name}"` function too large to pass via registers
return value of `{$abi}` function too large to pass via registers
.label = this type doesn't fit in the available registers
.note1 = functions with the `"{$abi_name}"` ABI must pass their result via the available return registers
.note1 = functions with the `{$abi}` ABI must pass their result via the available return registers
.note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
hir_analysis_coerce_pointee_no_field = `CoercePointee` can only be derived on `struct`s with at least one field
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,10 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
if !infer_replacements.is_empty() {
diag.multipart_suggestion(
format!(
"try replacing `_` with the type{} in the corresponding trait method signature",
rustc_errors::pluralize!(infer_replacements.len()),
),
"try replacing `_` with the type{} in the corresponding trait method \
signature",
rustc_errors::pluralize!(infer_replacements.len()),
),
infer_replacements,
Applicability::MachineApplicable,
);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Errors emitted by `rustc_hir_analysis`.
use rustc_abi::ExternAbi;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan,
Expand Down Expand Up @@ -1690,7 +1691,7 @@ pub(crate) struct CmseInputsStackSpill {
#[label]
pub span: Span,
pub plural: bool,
pub abi_name: &'static str,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
Expand All @@ -1701,7 +1702,7 @@ pub(crate) struct CmseOutputStackSpill {
#[primary_span]
#[label]
pub span: Span,
pub abi_name: &'static str,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub(crate) fn validate_cmse_abi<'tcx>(
abi: ExternAbi,
fn_sig: ty::PolyFnSig<'tcx>,
) {
let abi_name = abi.name();

match abi {
ExternAbi::CCmseNonSecureCall => {
let hir_node = tcx.hir_node(hir_id);
Expand Down Expand Up @@ -56,7 +54,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
.to(bare_fn_ty.decl.inputs[index].span)
.to(bare_fn_ty.decl.inputs.last().unwrap().span);
let plural = bare_fn_ty.param_names.len() - index != 1;
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name });
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
Expand All @@ -69,7 +67,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
Ok(true) => {}
Ok(false) => {
let span = bare_fn_ty.decl.output.span();
dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name });
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
Expand All @@ -92,7 +90,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
// ^^^^^^
let span = decl.inputs[index].span.to(decl.inputs.last().unwrap().span);
let plural = decl.inputs.len() - index != 1;
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name });
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
Expand All @@ -105,7 +103,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
Ok(true) => {}
Ok(false) => {
let span = decl.output.span();
dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name });
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
Expand Down
55 changes: 38 additions & 17 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_errors::{
Applicability, Diag, ErrorGuaranteed, MultiSpan, listify, pluralize, struct_span_code_err,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_middle::bug;
use rustc_middle::ty::fast_reject::{TreatParams, simplify_type};
Expand Down Expand Up @@ -1027,7 +1027,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&self,
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
args_visitors: impl Iterator<Item = &'a hir::GenericArg<'a>> + Clone,
err_extend: GenericsArgsErrExtend<'_>,
err_extend: GenericsArgsErrExtend<'a>,
) -> ErrorGuaranteed {
#[derive(PartialEq, Eq, Hash)]
enum ProhibitGenericsArg {
Expand All @@ -1047,23 +1047,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
};
});

let segments: Vec<_> = segments.collect();
let types_and_spans: Vec<_> = segments
.clone()
.iter()
.flat_map(|segment| {
if segment.args().args.is_empty() {
None
} else {
Some((
match segment.res {
hir::def::Res::PrimTy(ty) => {
Res::PrimTy(ty) => {
format!("{} `{}`", segment.res.descr(), ty.name())
}
hir::def::Res::Def(_, def_id)
Res::Def(_, def_id)
if let Some(name) = self.tcx().opt_item_name(def_id) =>
{
format!("{} `{name}`", segment.res.descr())
}
hir::def::Res::Err => "this type".to_string(),
Res::Err => "this type".to_string(),
_ => segment.res.descr().to_string(),
},
segment.ident.span,
Expand All @@ -1074,11 +1075,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let this_type = listify(&types_and_spans, |(t, _)| t.to_string())
.expect("expected one segment to deny");

let arg_spans: Vec<Span> = segments
.clone()
.flat_map(|segment| segment.args().args)
.map(|arg| arg.span())
.collect();
let arg_spans: Vec<Span> =
segments.iter().flat_map(|segment| segment.args().args).map(|arg| arg.span()).collect();

let mut kinds = Vec::with_capacity(4);
prohibit_args.iter().for_each(|arg| match arg {
Expand All @@ -1103,7 +1101,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
for (what, span) in types_and_spans {
err.span_label(span, format!("not allowed on {what}"));
}
generics_args_err_extend(self.tcx(), segments, &mut err, err_extend);
generics_args_err_extend(self.tcx(), segments.into_iter(), &mut err, err_extend);
err.emit()
}

Expand Down Expand Up @@ -1400,15 +1398,15 @@ pub enum GenericsArgsErrExtend<'tcx> {
},
SelfTyParam(Span),
Param(DefId),
DefVariant,
DefVariant(&'tcx [hir::PathSegment<'tcx>]),
None,
}

fn generics_args_err_extend<'a>(
tcx: TyCtxt<'_>,
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
err: &mut Diag<'_>,
err_extend: GenericsArgsErrExtend<'_>,
err_extend: GenericsArgsErrExtend<'a>,
) {
match err_extend {
GenericsArgsErrExtend::EnumVariant { qself, assoc_segment, adt_def } => {
Expand Down Expand Up @@ -1496,6 +1494,32 @@ fn generics_args_err_extend<'a>(
];
err.multipart_suggestion_verbose(msg, suggestion, Applicability::MaybeIncorrect);
}
GenericsArgsErrExtend::DefVariant(segments) => {
let args: Vec<Span> = segments
.iter()
.filter_map(|segment| match segment.res {
Res::Def(
DefKind::Ctor(CtorOf::Variant, _) | DefKind::Variant | DefKind::Enum,
_,
) => segment.args().span_ext().map(|s| s.with_lo(segment.ident.span.hi())),
_ => None,
})
.collect();
if args.len() > 1
&& let Some(span) = args.into_iter().last()
{
err.note(
"generic arguments are not allowed on both an enum and its variant's path \
segments simultaneously; they are only valid in one place or the other",
);
err.span_suggestion_verbose(
span,
"remove the generics arguments from one of the path segments",
String::new(),
Applicability::MaybeIncorrect,
);
}
}
GenericsArgsErrExtend::PrimTy(prim_ty) => {
let name = prim_ty.name_str();
for segment in segments {
Expand All @@ -1512,9 +1536,6 @@ fn generics_args_err_extend<'a>(
GenericsArgsErrExtend::OpaqueTy => {
err.note("`impl Trait` types can't have type parameters");
}
GenericsArgsErrExtend::DefVariant => {
err.note("enum variants can't have type parameters");
}
GenericsArgsErrExtend::Param(def_id) => {
let span = tcx.def_ident_span(def_id).unwrap();
let kind = tcx.def_descr(def_id);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
pub fn prohibit_generic_args<'a>(
&self,
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
err_extend: GenericsArgsErrExtend<'_>,
err_extend: GenericsArgsErrExtend<'a>,
) -> Result<(), ErrorGuaranteed> {
let args_visitors = segments.clone().flat_map(|segment| segment.args().args);
let mut result = Ok(());
Expand Down Expand Up @@ -1911,7 +1911,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
path.segments.iter().enumerate().filter_map(|(index, seg)| {
if !indices.contains(&index) { Some(seg) } else { None }
}),
GenericsArgsErrExtend::DefVariant,
GenericsArgsErrExtend::DefVariant(&path.segments),
);

let GenericPathSegment(def_id, index) = generic_segments.last().unwrap();
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let mut user_self_ty = None;
let mut is_alias_variant_ctor = false;
let mut err_extend = GenericsArgsErrExtend::None;
match res {
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) if let Some(self_ty) = self_ty => {
let adt_def = self_ty.normalized.ty_adt_def().unwrap();
user_self_ty =
Some(UserSelfTy { impl_def_id: adt_def.did(), self_ty: self_ty.raw });
is_alias_variant_ctor = true;
err_extend = GenericsArgsErrExtend::DefVariant(segments);
}
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
err_extend = GenericsArgsErrExtend::DefVariant(segments);
}
Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
let assoc_item = tcx.associated_item(def_id);
Expand Down Expand Up @@ -1095,7 +1100,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
segments.iter().enumerate().filter_map(|(index, seg)| {
if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None }
}),
GenericsArgsErrExtend::None,
err_extend,
);

if let Res::Local(hid) = res {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ pub(super) fn decorate_lint(
.decorate_lint(diag);
}
BuiltinLintDiag::MissingAbi(label_span, default_abi) => {
lints::MissingAbi { span: label_span, default_abi: default_abi.name() }
.decorate_lint(diag);
lints::MissingAbi { span: label_span, default_abi }.decorate_lint(diag);
}
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(rustc::untranslatable_diagnostic)]
use std::num::NonZero;

use rustc_abi::ExternAbi;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
Expand Down Expand Up @@ -2833,9 +2834,9 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
#[derive(LintDiagnostic)]
#[diag(lint_extern_without_abi)]
pub(crate) struct MissingAbi {
#[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")]
#[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")]
pub span: Span,
pub default_abi: &'static str,
pub default_abi: ExternAbi,
}

#[derive(LintDiagnostic)]
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir_transform/src/function_item_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
let unsafety = fn_sig.safety().prefix_str();
let abi = match fn_sig.abi() {
ExternAbi::Rust => String::from(""),
other_abi => {
let mut s = String::from("extern \"");
s.push_str(other_abi.name());
s.push_str("\" ");
s
}
other_abi => format!("extern {other_abi} "),
};
let ident = self.tcx.item_ident(fn_id);
let ty_params = fn_args.types().map(|ty| format!("{ty}"));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ supported_targets! {
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),

("aarch64-unknown-redox", aarch64_unknown_redox),
("i686-unknown-redox", i686_unknown_redox),
("i586-unknown-redox", i586_unknown_redox),
("x86_64-unknown-redox", x86_64_unknown_redox),

("i386-apple-ios", i386_apple_ios),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) fn target() -> Target {
base.stack_probes = StackProbeType::Call;

Target {
llvm_target: "i686-unknown-redox".into(),
llvm_target: "i586-unknown-redox".into(),
metadata: crate::spec::TargetMetadata {
description: None,
tier: None,
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/f128.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Constants for the `f128` double-precision floating point type.
//! Constants for the `f128` quadruple-precision floating point type.
//!
//! *[See also the `f128` primitive type](primitive@f128).*
//!
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/f16.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Constants for the `f16` double-precision floating point type.
//! Constants for the `f16` half-precision floating point type.
//!
//! *[See also the `f16` primitive type](primitive@f16).*
//!
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Step for Std {
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
// the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
if compiler.stage == 0 && compiler.host == builder.config.build {
if compiler.stage == 0 && builder.is_builder_target(&compiler.host) {
// We want to copy the host `bin` folder within the `rustlib` folder in the sysroot.
let src_sysroot_bin = builder
.rustc_snapshot_sysroot()
Expand Down Expand Up @@ -2310,7 +2310,8 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
// FIXME: to make things simpler for now, limit this to the host and target where we know
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
// cross-compiling. Expand this to other appropriate targets in the future.
if target != "x86_64-unknown-linux-gnu" || target != builder.config.build || !path.exists() {
if target != "x86_64-unknown-linux-gnu" || !builder.is_builder_target(&target) || !path.exists()
{
return;
}

Expand Down
Loading

0 comments on commit 552a959

Please sign in to comment.