Skip to content

Rollup of 16 pull requests #141716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c59b708
Emit warning while outputs is not exe and prints linkage info
xizheyin Mar 7, 2025
98bb597
Update compiler/rustc_codegen_ssa/src/back/link.rs
xizheyin May 2, 2025
72a9219
check all crate-type to find staticlib
xizheyin May 2, 2025
f66787a
Update compiler/rustc_codegen_ssa/src/back/link.rs
xizheyin May 2, 2025
a3bd12b
Path::with_extension: improve examples
tshepang May 24, 2025
248f4b2
reduce clutter... too many imports
tshepang May 24, 2025
396c5ca
clean up old rintf leftovers
RalfJung May 25, 2025
7aef56d
Call out possibility of invariant result
jhpratt May 26, 2025
a83f8d0
Always evaluate free lifetime-generic constants
fmease May 2, 2025
db21caf
Drive-by: Delete dead TyCtxtEnsureOk::const_eval_poly
fmease May 2, 2025
4c4a40f
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.
nnethercote May 27, 2025
bf52d1a
ci: verify that codebuild jobs use ghcr.io
marcoieni May 28, 2025
550aed8
Use `builin_index` instead of hand-rolling it
oli-obk May 26, 2025
0dd5722
Test(fs): Fix test_eq_windows_file_type for Windows 7
PaulDance May 16, 2025
9389daa
replace TraitRef link memory.md
davidjsonn May 28, 2025
bcebf58
interpret/allocation: make alloc fn be FnOnce
nia-e May 28, 2025
3a736e2
Handle e2021 precise capturing of unsafe binder
compiler-errors May 28, 2025
d88641f
rustbook: Bump versions of `onig` and `onig_sys`
petrochenkov May 28, 2025
2e99a88
Add diagnostic items to sys::Mutex
Patrick-6 May 28, 2025
149b5b2
Make pthread Mutex internals less public
Patrick-6 May 28, 2025
9f12748
GCI: Check where-clauses for well-formedness at the def site
fmease Feb 2, 2025
2593df8
core: unstably expose atomic_compare_exchange so stdarch can use it
RalfJung May 28, 2025
8237107
Add comments to diagnostic items
Patrick-6 May 28, 2025
9f2ee0f
Add eholk to compiler reviewer rotation
eholk May 28, 2025
d3c605a
Rollup merge of #136429 - fmease:gci-fix-def-site-checks, r=BoxyUwU
jhpratt May 29, 2025
394fde0
Rollup merge of #138139 - xizheyin:issue-137384, r=ChrisDenton
jhpratt May 29, 2025
d9ed867
Rollup merge of #141104 - PaulDance:fix-win7-test_eq_windows_file_typ…
jhpratt May 29, 2025
ffdd3b1
Rollup merge of #141477 - tshepang:patch-1, r=ChrisDenton
jhpratt May 29, 2025
6bf4224
Rollup merge of #141533 - RalfJung:rintf, r=bjorn3
jhpratt May 29, 2025
1c46b4a
Rollup merge of #141612 - jhpratt:phantom-docs, r=tgross35
jhpratt May 29, 2025
d3a6963
Rollup merge of #141638 - oli-obk:builtin-index, r=lcnr
jhpratt May 29, 2025
e96b112
Rollup merge of #141643 - marcoieni:codebuild-check, r=Kobzol
jhpratt May 29, 2025
0ac0285
Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
jhpratt May 29, 2025
bab9879
Rollup merge of #141680 - davidjsonn:master, r=oli-obk
jhpratt May 29, 2025
e987a99
Rollup merge of #141682 - nia-e:fixup-alloc, r=RalfJung
jhpratt May 29, 2025
dc22509
Rollup merge of #141683 - compiler-errors:unsafe-binder-capture, r=ol…
jhpratt May 29, 2025
643f9c2
Rollup merge of #141684 - petrochenkov:bumponig, r=ehuss
jhpratt May 29, 2025
f4dcb7f
Rollup merge of #141687 - RalfJung:atomic_compare_exchange, r=bjorn3
jhpratt May 29, 2025
e7ef07a
Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-se
jhpratt May 29, 2025
4327a7c
Rollup merge of #141702 - eholk:eholk-reviewers, r=aDotInTheVoid
jhpratt May 29, 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
20 changes: 9 additions & 11 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,9 +3417,9 @@ impl Item {
ItemKind::Fn(i) => Some(&i.generics),
ItemKind::TyAlias(i) => Some(&i.generics),
ItemKind::TraitAlias(_, generics, _)
| ItemKind::Enum(_, _, generics)
| ItemKind::Struct(_, _, generics)
| ItemKind::Union(_, _, generics) => Some(&generics),
| ItemKind::Enum(_, generics, _)
| ItemKind::Struct(_, generics, _)
| ItemKind::Union(_, generics, _) => Some(&generics),
ItemKind::Trait(i) => Some(&i.generics),
ItemKind::Impl(i) => Some(&i.generics),
}
Expand Down Expand Up @@ -3663,15 +3663,15 @@ pub enum ItemKind {
/// An enum definition (`enum`).
///
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
Enum(Ident, EnumDef, Generics),
Enum(Ident, Generics, EnumDef),
/// A struct definition (`struct`).
///
/// E.g., `struct Foo<A> { x: A }`.
Struct(Ident, VariantData, Generics),
Struct(Ident, Generics, VariantData),
/// A union definition (`union`).
///
/// E.g., `union Foo<A, B> { x: A, y: B }`.
Union(Ident, VariantData, Generics),
Union(Ident, Generics, VariantData),
/// A trait declaration (`trait`).
///
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
Expand All @@ -3688,10 +3688,8 @@ pub enum ItemKind {
///
/// E.g., `foo!(..)`.
MacCall(P<MacCall>),

/// A macro definition.
MacroDef(Ident, MacroDef),

/// A single delegation item (`reuse`).
///
/// E.g. `reuse <Type as Trait>::name { target_expr_template }`.
Expand Down Expand Up @@ -3767,9 +3765,9 @@ impl ItemKind {
Self::Fn(box Fn { generics, .. })
| Self::TyAlias(box TyAlias { generics, .. })
| Self::Const(box ConstItem { generics, .. })
| Self::Enum(_, _, generics)
| Self::Struct(_, _, generics)
| Self::Union(_, _, generics)
| Self::Enum(_, generics, _)
| Self::Struct(_, generics, _)
| Self::Union(_, generics, _)
| Self::Trait(box Trait { generics, .. })
| Self::TraitAlias(_, generics, _)
| Self::Impl(box Impl { generics, .. }) => Some(generics),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,16 @@ macro_rules! common_visitor_and_walkers {
)?
$(<V as Visitor<$lt>>::Result::output())?
}
ItemKind::Enum(ident, enum_definition, generics) => {
ItemKind::Enum(ident, generics, enum_definition) => {
try_visit!(vis.visit_ident(ident));
try_visit!(vis.visit_generics(generics));
$(${ignore($mut)}
enum_definition.variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
)?
$(${ignore($lt)}vis.visit_enum_def(enum_definition))?
}
ItemKind::Struct(ident, variant_data, generics)
| ItemKind::Union(ident, variant_data, generics) => {
ItemKind::Struct(ident, generics, variant_data)
| ItemKind::Union(ident, generics, variant_data) => {
try_visit!(vis.visit_ident(ident));
try_visit!(vis.visit_generics(generics));
vis.visit_variant_data(variant_data)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::TyAlias(ident, ty, generics)
}
ItemKind::Enum(ident, enum_definition, generics) => {
ItemKind::Enum(ident, generics, enum_definition) => {
let ident = self.lower_ident(*ident);
let (generics, variants) = self.lower_generics(
generics,
Expand All @@ -320,7 +320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::Enum(ident, hir::EnumDef { variants }, generics)
}
ItemKind::Struct(ident, struct_def, generics) => {
ItemKind::Struct(ident, generics, struct_def) => {
let ident = self.lower_ident(*ident);
let (generics, struct_def) = self.lower_generics(
generics,
Expand All @@ -330,7 +330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::Struct(ident, struct_def, generics)
}
ItemKind::Union(ident, vdata, generics) => {
ItemKind::Union(ident, generics, vdata) => {
let ident = self.lower_ident(*ident);
let (generics, vdata) = self.lower_generics(
generics,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
});
self.extern_mod_span = old_item;
}
ItemKind::Enum(_, def, _) => {
ItemKind::Enum(_, _, def) => {
for variant in &def.variants {
self.visibility_not_permitted(
&variant.vis,
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
visit::walk_item(self, item)
}
ItemKind::Struct(ident, vdata, generics) => match vdata {
ItemKind::Struct(ident, generics, vdata) => match vdata {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
Expand All @@ -1070,7 +1070,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
_ => visit::walk_item(self, item),
},
ItemKind::Union(ident, vdata, generics) => {
ItemKind::Union(ident, generics, vdata) => {
if vdata.fields().is_empty() {
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ impl<'a> State<'a> {
*defaultness,
);
}
ast::ItemKind::Enum(ident, enum_definition, params) => {
self.print_enum_def(enum_definition, params, *ident, item.span, &item.vis);
ast::ItemKind::Enum(ident, generics, enum_definition) => {
self.print_enum_def(enum_definition, generics, *ident, item.span, &item.vis);
}
ast::ItemKind::Struct(ident, struct_def, generics) => {
ast::ItemKind::Struct(ident, generics, struct_def) => {
let (cb, ib) = self.head(visibility_qualified(&item.vis, "struct"));
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
}
ast::ItemKind::Union(ident, struct_def, generics) => {
ast::ItemKind::Union(ident, generics, struct_def) => {
let (cb, ib) = self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub(crate) fn expand_deriving_clone(
let is_simple;
match item {
Annotatable::Item(annitem) => match &annitem.kind {
ItemKind::Struct(_, _, Generics { params, .. })
| ItemKind::Enum(_, _, Generics { params, .. }) => {
ItemKind::Struct(_, Generics { params, .. }, _)
| ItemKind::Enum(_, Generics { params, .. }, _) => {
let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
let has_derive_copy = cx.resolver.has_derive_copy(container_id);
if has_derive_copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn expand_deriving_partial_ord(

// Order in which to perform matching
let discr_then_data = if let Annotatable::Item(item) = item
&& let ItemKind::Enum(_, def, _) = &item.kind
&& let ItemKind::Enum(_, _, def) = &item.kind
{
let dataful: Vec<bool> = def.variants.iter().map(|v| !v.data.fields().is_empty()).collect();
match dataful.iter().filter(|&&b| b).count() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
item.visit_with(&mut DetectNonGenericPointeeAttr { cx });

let (name_ident, generics) = if let Annotatable::Item(aitem) = item
&& let ItemKind::Struct(ident, struct_data, g) = &aitem.kind
&& let ItemKind::Struct(ident, g, struct_data) = &aitem.kind
{
if !matches!(
struct_data,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,23 +488,23 @@ impl<'a> TraitDef<'a> {
);

let newitem = match &item.kind {
ast::ItemKind::Struct(ident, struct_def, generics) => self.expand_struct_def(
ast::ItemKind::Struct(ident, generics, struct_def) => self.expand_struct_def(
cx,
struct_def,
*ident,
generics,
from_scratch,
is_packed,
),
ast::ItemKind::Enum(ident, enum_def, generics) => {
ast::ItemKind::Enum(ident, generics, enum_def) => {
// We ignore `is_packed` here, because `repr(packed)`
// enums cause an error later on.
//
// This can only cause further compilation errors
// downstream in blatantly illegal code, so it is fine.
self.expand_enum_def(cx, enum_def, *ident, generics, from_scratch)
}
ast::ItemKind::Union(ident, struct_def, generics) => {
ast::ItemKind::Union(ident, generics, struct_def) => {
if self.supports_unions {
self.expand_struct_def(
cx,
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
}
}

fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
let print_native_static_libs =
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
if print_native_static_libs {
if !has_staticlib {
sess.dcx()
.warn(format!("cannot output linkage information without staticlib crate-type"));
sess.dcx()
.note(format!("consider `--crate-type staticlib` to print linkage information"));
} else if !sess.opts.output_types.should_link() {
sess.dcx()
.warn(format!("cannot output linkage information when --emit link is not passed"));
}
}
}

/// Performs the linkage portion of the compilation phase. This will generate all
/// of the requested outputs for this compilation session.
pub fn link_binary(
Expand Down Expand Up @@ -180,6 +197,8 @@ pub fn link_binary(
}
}

check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);

// Remove the temporary object file and metadata if we aren't saving temps.
sess.time("link_binary_remove_temps", || {
// If the user requests that temporaries are saved, don't delete any.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ pub fn parse_macro_name_and_helper_attrs(
/// See #73345 and #83125 for more details.
/// FIXME(#73933): Remove this eventually.
fn pretty_printing_compatibility_hack(item: &Item, psess: &ParseSess) {
if let ast::ItemKind::Enum(ident, enum_def, _) = &item.kind
if let ast::ItemKind::Enum(ident, _, enum_def) = &item.kind
&& ident.name == sym::ProceduralMasqueradeDummyType
&& let [variant] = &*enum_def.variants
&& variant.ident.name == sym::Input
Expand Down
44 changes: 34 additions & 10 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
}
hir::ItemKind::Static(_, ty, ..) => {
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
}
hir::ItemKind::Const(_, ty, ..) => {
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
}
hir::ItemKind::Const(_, ty, ..) => check_const_item(tcx, def_id, ty.span, item.span),
hir::ItemKind::Struct(_, _, hir_generics) => {
let res = check_type_defn(tcx, item, false);
check_variances_for_type_defn(tcx, item, hir_generics);
Expand Down Expand Up @@ -366,7 +364,7 @@ fn check_foreign_item<'tcx>(
check_item_fn(tcx, def_id, item.ident, item.span, sig.decl)
}
hir::ForeignItemKind::Static(ty, ..) => {
check_item_type(tcx, def_id, ty.span, UnsizedHandling::AllowIfForeignTail)
check_static_item(tcx, def_id, ty.span, UnsizedHandling::AllowIfForeignTail)
}
hir::ForeignItemKind::Type => Ok(()),
}
Expand Down Expand Up @@ -1048,8 +1046,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
match ty.kind() {
ty::Adt(adt_def, ..) => adt_def.did().is_local(),
// Arrays and slices use the inner type's `ConstParamTy`.
ty::Array(ty, ..) => ty_is_local(*ty),
ty::Slice(ty) => ty_is_local(*ty),
ty::Array(ty, ..) | ty::Slice(ty) => ty_is_local(*ty),
// `&` references use the inner type's `ConstParamTy`.
// `&mut` are not supported.
ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(*ty),
Expand Down Expand Up @@ -1331,14 +1328,13 @@ enum UnsizedHandling {
AllowIfForeignTail,
}

fn check_item_type(
#[instrument(level = "debug", skip(tcx, ty_span, unsized_handling))]
fn check_static_item(
tcx: TyCtxt<'_>,
item_id: LocalDefId,
ty_span: Span,
unsized_handling: UnsizedHandling,
) -> Result<(), ErrorGuaranteed> {
debug!("check_item_type: {:?}", item_id);

enter_wf_checking_ctxt(tcx, ty_span, item_id, |wfcx| {
let ty = tcx.type_of(item_id).instantiate_identity();
let item_ty = wfcx.deeply_normalize(ty_span, Some(WellFormedLoc::Ty(item_id)), ty);
Expand Down Expand Up @@ -1388,6 +1384,34 @@ fn check_item_type(
})
}

fn check_const_item(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
ty_span: Span,
item_span: Span,
) -> Result<(), ErrorGuaranteed> {
enter_wf_checking_ctxt(tcx, ty_span, def_id, |wfcx| {
let ty = tcx.type_of(def_id).instantiate_identity();
let ty = wfcx.deeply_normalize(ty_span, Some(WellFormedLoc::Ty(def_id)), ty);

wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(def_id)), ty.into());
wfcx.register_bound(
traits::ObligationCause::new(
ty_span,
wfcx.body_def_id,
ObligationCauseCode::SizedConstOrStatic,
),
wfcx.param_env,
ty,
tcx.require_lang_item(LangItem::Sized, None),
);

check_where_clauses(wfcx, item_span, def_id);

Ok(())
})
}

#[instrument(level = "debug", skip(tcx, hir_self_ty, hir_trait_ref))]
fn check_impl<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.ensure_ok().eval_static_initializer(item_def_id);
check::maybe_check_static_with_link_section(tcx, item_def_id);
}
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() => {
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but
// seems to be fine for now. Revisit this!
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
let cid = GlobalId { instance, promoted: None };
let typing_env = ty::TypingEnv::fully_monomorphized();
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,10 +1793,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_ty = if !args.is_empty() {
let coerce_to = expected
.to_option(self)
.and_then(|uty| match *self.try_structurally_resolve_type(expr.span, uty).kind() {
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
_ => None,
})
.and_then(|uty| self.try_structurally_resolve_type(expr.span, uty).builtin_index())
.unwrap_or_else(|| self.next_ty_var(expr.span));
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
assert_eq!(self.diverges.get(), Diverges::Maybe);
Expand Down Expand Up @@ -1874,10 +1871,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

let uty = match expected {
ExpectHasType(uty) => match *uty.kind() {
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
_ => None,
},
ExpectHasType(uty) => uty.builtin_index(),
_ => None,
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl Allocation {
pub fn adjust_from_tcx<'tcx, Prov: Provenance, Bytes: AllocBytes>(
&self,
cx: &impl HasDataLayout,
mut alloc_bytes: impl FnMut(&[u8], Align) -> InterpResult<'tcx, Bytes>,
alloc_bytes: impl FnOnce(&[u8], Align) -> InterpResult<'tcx, Bytes>,
mut adjust_ptr: impl FnMut(Pointer<CtfeProvenance>) -> InterpResult<'tcx, Pointer<Prov>>,
) -> InterpResult<'tcx, Allocation<Prov, (), Bytes>> {
// Copy the data.
Expand Down
Loading
Loading