Skip to content

Commit 38081f2

Browse files
committed
Auto merge of #141716 - jhpratt:rollup-9bjrzfi, r=jhpratt
Rollup of 16 pull requests Successful merges: - #136429 (GCI: At their def site, actually wfcheck the where-clause & always eval free lifetime-generic constants) - #138139 (Emit warning while outputs is not exe and prints linkage info) - #141104 (Test(fs): Fix `test_eq_windows_file_type` for Windows 7) - #141477 (Path::with_extension: show that it adds an extension where one did no…) - #141533 (clean up old rintf leftovers) - #141612 (Call out possibility of invariant result in variance markers) - #141638 (Use `builtin_index` instead of hand-rolling it) - #141643 (ci: verify that codebuild jobs use ghcr.io) - #141675 (Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.) - #141680 (replace TraitRef link memory.md) - #141682 (interpret/allocation: Fixup type for `alloc_bytes`) - #141683 (Handle ed2021 precise capturing of unsafe binder) - #141684 (rustbook: Bump versions of `onig` and `onig_sys`) - #141687 (core: unstably expose atomic_compare_exchange so stdarch can use it) - #141690 (Add `rustc_diagnostic_item` to `sys::Mutex` methods) - #141702 (Add eholk to compiler reviewer rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5f025f3 + 4327a7c commit 38081f2

File tree

56 files changed

+322
-145
lines changed

Some content is hidden

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

56 files changed

+322
-145
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,9 +3417,9 @@ impl Item {
34173417
ItemKind::Fn(i) => Some(&i.generics),
34183418
ItemKind::TyAlias(i) => Some(&i.generics),
34193419
ItemKind::TraitAlias(_, generics, _)
3420-
| ItemKind::Enum(_, _, generics)
3421-
| ItemKind::Struct(_, _, generics)
3422-
| ItemKind::Union(_, _, generics) => Some(&generics),
3420+
| ItemKind::Enum(_, generics, _)
3421+
| ItemKind::Struct(_, generics, _)
3422+
| ItemKind::Union(_, generics, _) => Some(&generics),
34233423
ItemKind::Trait(i) => Some(&i.generics),
34243424
ItemKind::Impl(i) => Some(&i.generics),
34253425
}
@@ -3663,15 +3663,15 @@ pub enum ItemKind {
36633663
/// An enum definition (`enum`).
36643664
///
36653665
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
3666-
Enum(Ident, EnumDef, Generics),
3666+
Enum(Ident, Generics, EnumDef),
36673667
/// A struct definition (`struct`).
36683668
///
36693669
/// E.g., `struct Foo<A> { x: A }`.
3670-
Struct(Ident, VariantData, Generics),
3670+
Struct(Ident, Generics, VariantData),
36713671
/// A union definition (`union`).
36723672
///
36733673
/// E.g., `union Foo<A, B> { x: A, y: B }`.
3674-
Union(Ident, VariantData, Generics),
3674+
Union(Ident, Generics, VariantData),
36753675
/// A trait declaration (`trait`).
36763676
///
36773677
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
@@ -3688,10 +3688,8 @@ pub enum ItemKind {
36883688
///
36893689
/// E.g., `foo!(..)`.
36903690
MacCall(P<MacCall>),
3691-
36923691
/// A macro definition.
36933692
MacroDef(Ident, MacroDef),
3694-
36953693
/// A single delegation item (`reuse`).
36963694
///
36973695
/// E.g. `reuse <Type as Trait>::name { target_expr_template }`.
@@ -3767,9 +3765,9 @@ impl ItemKind {
37673765
Self::Fn(box Fn { generics, .. })
37683766
| Self::TyAlias(box TyAlias { generics, .. })
37693767
| Self::Const(box ConstItem { generics, .. })
3770-
| Self::Enum(_, _, generics)
3771-
| Self::Struct(_, _, generics)
3772-
| Self::Union(_, _, generics)
3768+
| Self::Enum(_, generics, _)
3769+
| Self::Struct(_, generics, _)
3770+
| Self::Union(_, generics, _)
37733771
| Self::Trait(box Trait { generics, .. })
37743772
| Self::TraitAlias(_, generics, _)
37753773
| Self::Impl(box Impl { generics, .. }) => Some(generics),

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,16 @@ macro_rules! common_visitor_and_walkers {
508508
)?
509509
$(<V as Visitor<$lt>>::Result::output())?
510510
}
511-
ItemKind::Enum(ident, enum_definition, generics) => {
511+
ItemKind::Enum(ident, generics, enum_definition) => {
512512
try_visit!(vis.visit_ident(ident));
513513
try_visit!(vis.visit_generics(generics));
514514
$(${ignore($mut)}
515515
enum_definition.variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
516516
)?
517517
$(${ignore($lt)}vis.visit_enum_def(enum_definition))?
518518
}
519-
ItemKind::Struct(ident, variant_data, generics)
520-
| ItemKind::Union(ident, variant_data, generics) => {
519+
ItemKind::Struct(ident, generics, variant_data)
520+
| ItemKind::Union(ident, generics, variant_data) => {
521521
try_visit!(vis.visit_ident(ident));
522522
try_visit!(vis.visit_generics(generics));
523523
vis.visit_variant_data(variant_data)

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
306306
);
307307
hir::ItemKind::TyAlias(ident, ty, generics)
308308
}
309-
ItemKind::Enum(ident, enum_definition, generics) => {
309+
ItemKind::Enum(ident, generics, enum_definition) => {
310310
let ident = self.lower_ident(*ident);
311311
let (generics, variants) = self.lower_generics(
312312
generics,
@@ -320,7 +320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
320320
);
321321
hir::ItemKind::Enum(ident, hir::EnumDef { variants }, generics)
322322
}
323-
ItemKind::Struct(ident, struct_def, generics) => {
323+
ItemKind::Struct(ident, generics, struct_def) => {
324324
let ident = self.lower_ident(*ident);
325325
let (generics, struct_def) = self.lower_generics(
326326
generics,
@@ -330,7 +330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
330330
);
331331
hir::ItemKind::Struct(ident, struct_def, generics)
332332
}
333-
ItemKind::Union(ident, vdata, generics) => {
333+
ItemKind::Union(ident, generics, vdata) => {
334334
let ident = self.lower_ident(*ident);
335335
let (generics, vdata) = self.lower_generics(
336336
generics,

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10101010
});
10111011
self.extern_mod_span = old_item;
10121012
}
1013-
ItemKind::Enum(_, def, _) => {
1013+
ItemKind::Enum(_, _, def) => {
10141014
for variant in &def.variants {
10151015
self.visibility_not_permitted(
10161016
&variant.vis,
@@ -1061,7 +1061,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10611061
}
10621062
visit::walk_item(self, item)
10631063
}
1064-
ItemKind::Struct(ident, vdata, generics) => match vdata {
1064+
ItemKind::Struct(ident, generics, vdata) => match vdata {
10651065
VariantData::Struct { fields, .. } => {
10661066
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
10671067
self.visit_generics(generics);
@@ -1070,7 +1070,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10701070
}
10711071
_ => visit::walk_item(self, item),
10721072
},
1073-
ItemKind::Union(ident, vdata, generics) => {
1073+
ItemKind::Union(ident, generics, vdata) => {
10741074
if vdata.fields().is_empty() {
10751075
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
10761076
}

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ impl<'a> State<'a> {
298298
*defaultness,
299299
);
300300
}
301-
ast::ItemKind::Enum(ident, enum_definition, params) => {
302-
self.print_enum_def(enum_definition, params, *ident, item.span, &item.vis);
301+
ast::ItemKind::Enum(ident, generics, enum_definition) => {
302+
self.print_enum_def(enum_definition, generics, *ident, item.span, &item.vis);
303303
}
304-
ast::ItemKind::Struct(ident, struct_def, generics) => {
304+
ast::ItemKind::Struct(ident, generics, struct_def) => {
305305
let (cb, ib) = self.head(visibility_qualified(&item.vis, "struct"));
306306
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
307307
}
308-
ast::ItemKind::Union(ident, struct_def, generics) => {
308+
ast::ItemKind::Union(ident, generics, struct_def) => {
309309
let (cb, ib) = self.head(visibility_qualified(&item.vis, "union"));
310310
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
311311
}

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub(crate) fn expand_deriving_clone(
3434
let is_simple;
3535
match item {
3636
Annotatable::Item(annitem) => match &annitem.kind {
37-
ItemKind::Struct(_, _, Generics { params, .. })
38-
| ItemKind::Enum(_, _, Generics { params, .. }) => {
37+
ItemKind::Struct(_, Generics { params, .. }, _)
38+
| ItemKind::Enum(_, Generics { params, .. }, _) => {
3939
let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
4040
let has_derive_copy = cx.resolver.has_derive_copy(container_id);
4141
if has_derive_copy

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn expand_deriving_partial_ord(
2121

2222
// Order in which to perform matching
2323
let discr_then_data = if let Annotatable::Item(item) = item
24-
&& let ItemKind::Enum(_, def, _) = &item.kind
24+
&& let ItemKind::Enum(_, _, def) = &item.kind
2525
{
2626
let dataful: Vec<bool> = def.variants.iter().map(|v| !v.data.fields().is_empty()).collect();
2727
match dataful.iter().filter(|&&b| b).count() {

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
3030
item.visit_with(&mut DetectNonGenericPointeeAttr { cx });
3131

3232
let (name_ident, generics) = if let Annotatable::Item(aitem) = item
33-
&& let ItemKind::Struct(ident, struct_data, g) = &aitem.kind
33+
&& let ItemKind::Struct(ident, g, struct_data) = &aitem.kind
3434
{
3535
if !matches!(
3636
struct_data,

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,23 +488,23 @@ impl<'a> TraitDef<'a> {
488488
);
489489

490490
let newitem = match &item.kind {
491-
ast::ItemKind::Struct(ident, struct_def, generics) => self.expand_struct_def(
491+
ast::ItemKind::Struct(ident, generics, struct_def) => self.expand_struct_def(
492492
cx,
493493
struct_def,
494494
*ident,
495495
generics,
496496
from_scratch,
497497
is_packed,
498498
),
499-
ast::ItemKind::Enum(ident, enum_def, generics) => {
499+
ast::ItemKind::Enum(ident, generics, enum_def) => {
500500
// We ignore `is_packed` here, because `repr(packed)`
501501
// enums cause an error later on.
502502
//
503503
// This can only cause further compilation errors
504504
// downstream in blatantly illegal code, so it is fine.
505505
self.expand_enum_def(cx, enum_def, *ident, generics, from_scratch)
506506
}
507-
ast::ItemKind::Union(ident, struct_def, generics) => {
507+
ast::ItemKind::Union(ident, generics, struct_def) => {
508508
if self.supports_unions {
509509
self.expand_struct_def(
510510
cx,

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6868
}
6969
}
7070

71+
fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
72+
let print_native_static_libs =
73+
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
74+
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
75+
if print_native_static_libs {
76+
if !has_staticlib {
77+
sess.dcx()
78+
.warn(format!("cannot output linkage information without staticlib crate-type"));
79+
sess.dcx()
80+
.note(format!("consider `--crate-type staticlib` to print linkage information"));
81+
} else if !sess.opts.output_types.should_link() {
82+
sess.dcx()
83+
.warn(format!("cannot output linkage information when --emit link is not passed"));
84+
}
85+
}
86+
}
87+
7188
/// Performs the linkage portion of the compilation phase. This will generate all
7289
/// of the requested outputs for this compilation session.
7390
pub fn link_binary(
@@ -180,6 +197,8 @@ pub fn link_binary(
180197
}
181198
}
182199

200+
check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);
201+
183202
// Remove the temporary object file and metadata if we aren't saving temps.
184203
sess.time("link_binary_remove_temps", || {
185204
// If the user requests that temporaries are saved, don't delete any.

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ pub fn parse_macro_name_and_helper_attrs(
14241424
/// See #73345 and #83125 for more details.
14251425
/// FIXME(#73933): Remove this eventually.
14261426
fn pretty_printing_compatibility_hack(item: &Item, psess: &ParseSess) {
1427-
if let ast::ItemKind::Enum(ident, enum_def, _) = &item.kind
1427+
if let ast::ItemKind::Enum(ident, _, enum_def) = &item.kind
14281428
&& ident.name == sym::ProceduralMasqueradeDummyType
14291429
&& let [variant] = &*enum_def.variants
14301430
&& variant.ident.name == sym::Input

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,9 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
298298
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
299299
}
300300
hir::ItemKind::Static(_, ty, ..) => {
301-
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
302-
}
303-
hir::ItemKind::Const(_, ty, ..) => {
304-
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
301+
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
305302
}
303+
hir::ItemKind::Const(_, ty, ..) => check_const_item(tcx, def_id, ty.span, item.span),
306304
hir::ItemKind::Struct(_, _, hir_generics) => {
307305
let res = check_type_defn(tcx, item, false);
308306
check_variances_for_type_defn(tcx, item, hir_generics);
@@ -366,7 +364,7 @@ fn check_foreign_item<'tcx>(
366364
check_item_fn(tcx, def_id, item.ident, item.span, sig.decl)
367365
}
368366
hir::ForeignItemKind::Static(ty, ..) => {
369-
check_item_type(tcx, def_id, ty.span, UnsizedHandling::AllowIfForeignTail)
367+
check_static_item(tcx, def_id, ty.span, UnsizedHandling::AllowIfForeignTail)
370368
}
371369
hir::ForeignItemKind::Type => Ok(()),
372370
}
@@ -1048,8 +1046,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
10481046
match ty.kind() {
10491047
ty::Adt(adt_def, ..) => adt_def.did().is_local(),
10501048
// Arrays and slices use the inner type's `ConstParamTy`.
1051-
ty::Array(ty, ..) => ty_is_local(*ty),
1052-
ty::Slice(ty) => ty_is_local(*ty),
1049+
ty::Array(ty, ..) | ty::Slice(ty) => ty_is_local(*ty),
10531050
// `&` references use the inner type's `ConstParamTy`.
10541051
// `&mut` are not supported.
10551052
ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(*ty),
@@ -1331,14 +1328,13 @@ enum UnsizedHandling {
13311328
AllowIfForeignTail,
13321329
}
13331330

1334-
fn check_item_type(
1331+
#[instrument(level = "debug", skip(tcx, ty_span, unsized_handling))]
1332+
fn check_static_item(
13351333
tcx: TyCtxt<'_>,
13361334
item_id: LocalDefId,
13371335
ty_span: Span,
13381336
unsized_handling: UnsizedHandling,
13391337
) -> Result<(), ErrorGuaranteed> {
1340-
debug!("check_item_type: {:?}", item_id);
1341-
13421338
enter_wf_checking_ctxt(tcx, ty_span, item_id, |wfcx| {
13431339
let ty = tcx.type_of(item_id).instantiate_identity();
13441340
let item_ty = wfcx.deeply_normalize(ty_span, Some(WellFormedLoc::Ty(item_id)), ty);
@@ -1388,6 +1384,34 @@ fn check_item_type(
13881384
})
13891385
}
13901386

1387+
fn check_const_item(
1388+
tcx: TyCtxt<'_>,
1389+
def_id: LocalDefId,
1390+
ty_span: Span,
1391+
item_span: Span,
1392+
) -> Result<(), ErrorGuaranteed> {
1393+
enter_wf_checking_ctxt(tcx, ty_span, def_id, |wfcx| {
1394+
let ty = tcx.type_of(def_id).instantiate_identity();
1395+
let ty = wfcx.deeply_normalize(ty_span, Some(WellFormedLoc::Ty(def_id)), ty);
1396+
1397+
wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(def_id)), ty.into());
1398+
wfcx.register_bound(
1399+
traits::ObligationCause::new(
1400+
ty_span,
1401+
wfcx.body_def_id,
1402+
ObligationCauseCode::SizedConstOrStatic,
1403+
),
1404+
wfcx.param_env,
1405+
ty,
1406+
tcx.require_lang_item(LangItem::Sized, None),
1407+
);
1408+
1409+
check_where_clauses(wfcx, item_span, def_id);
1410+
1411+
Ok(())
1412+
})
1413+
}
1414+
13911415
#[instrument(level = "debug", skip(tcx, hir_self_ty, hir_trait_ref))]
13921416
fn check_impl<'tcx>(
13931417
tcx: TyCtxt<'tcx>,

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
203203
tcx.ensure_ok().eval_static_initializer(item_def_id);
204204
check::maybe_check_static_with_link_section(tcx, item_def_id);
205205
}
206-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
206+
DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() => {
207+
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but
208+
// seems to be fine for now. Revisit this!
207209
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
208210
let cid = GlobalId { instance, promoted: None };
209211
let typing_env = ty::TypingEnv::fully_monomorphized();

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17931793
let element_ty = if !args.is_empty() {
17941794
let coerce_to = expected
17951795
.to_option(self)
1796-
.and_then(|uty| match *self.try_structurally_resolve_type(expr.span, uty).kind() {
1797-
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
1798-
_ => None,
1799-
})
1796+
.and_then(|uty| self.try_structurally_resolve_type(expr.span, uty).builtin_index())
18001797
.unwrap_or_else(|| self.next_ty_var(expr.span));
18011798
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
18021799
assert_eq!(self.diverges.get(), Diverges::Maybe);
@@ -1874,10 +1871,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18741871
}
18751872

18761873
let uty = match expected {
1877-
ExpectHasType(uty) => match *uty.kind() {
1878-
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
1879-
_ => None,
1880-
},
1874+
ExpectHasType(uty) => uty.builtin_index(),
18811875
_ => None,
18821876
};
18831877

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl Allocation {
512512
pub fn adjust_from_tcx<'tcx, Prov: Provenance, Bytes: AllocBytes>(
513513
&self,
514514
cx: &impl HasDataLayout,
515-
mut alloc_bytes: impl FnMut(&[u8], Align) -> InterpResult<'tcx, Bytes>,
515+
alloc_bytes: impl FnOnce(&[u8], Align) -> InterpResult<'tcx, Bytes>,
516516
mut adjust_ptr: impl FnMut(Pointer<CtfeProvenance>) -> InterpResult<'tcx, Pointer<Prov>>,
517517
) -> InterpResult<'tcx, Allocation<Prov, (), Bytes>> {
518518
// Copy the data.

0 commit comments

Comments
 (0)