Skip to content

Commit c62665e

Browse files
committed
Auto merge of #107328 - matthiaskrgr:rollup-lfqwo0o, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #106904 (Preserve split DWARF files when building archives.) - #106971 (Handle diagnostics customization on the fluent side (for one specific diagnostic)) - #106978 (Migrate mir_build's borrow conflicts) - #107150 (`ty::tls` cleanups) - #107168 (Use a type-alias-impl-trait in `ObligationForest`) - #107189 (Encode info for Adt in a single place.) - #107322 (Custom mir: Add support for some remaining, easy to support constructs) - #107323 (Disable ConstGoto opt in cleanup blocks) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3e97763 + 4ed8cfc commit c62665e

File tree

36 files changed

+641
-611
lines changed

36 files changed

+641
-611
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

-12
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,6 @@ fn check_opaque_type_parameter_valid(
367367
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
368368
let arg_is_param = match arg.unpack() {
369369
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
370-
GenericArgKind::Lifetime(lt) if lt.is_static() => {
371-
tcx.sess
372-
.struct_span_err(span, "non-defining opaque type use in defining scope")
373-
.span_label(
374-
tcx.def_span(opaque_generics.param_at(i, tcx).def_id),
375-
"cannot use static lifetime; use a bound lifetime \
376-
instead or remove the lifetime parameter from the \
377-
opaque type",
378-
)
379-
.emit();
380-
return false;
381-
}
382370
GenericArgKind::Lifetime(lt) => {
383371
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
384372
}

compiler/rustc_codegen_ssa/src/back/link.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,6 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> (bool, bool) {
13011301
return (false, false);
13021302
}
13031303

1304-
// If we're only producing artifacts that are archives, no need to preserve
1305-
// the objects as they're losslessly contained inside the archives.
1306-
if sess.crate_types().iter().all(|&x| x.is_archive()) {
1307-
return (false, false);
1308-
}
1309-
13101304
match (sess.split_debuginfo(), sess.opts.unstable_opts.split_dwarf_kind) {
13111305
// If there is no split debuginfo then do not preserve objects.
13121306
(SplitDebuginfo::Off, _) => (false, false),

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ pub enum ProcessResult<O, E> {
139139
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
140140
struct ObligationTreeId(usize);
141141

142-
type ObligationTreeIdGenerator =
143-
std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> ObligationTreeId>;
142+
type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;
144143

145144
pub struct ObligationForest<O: ForestObligation> {
146145
/// The list of obligations. In between calls to [Self::process_obligations],

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@ borrowck_cannot_move_when_borrowed =
123123
124124
borrowck_opaque_type_non_generic_param =
125125
expected generic {$kind} parameter, found `{$ty}`
126-
.label = this generic parameter must be used with a generic {$kind} parameter
126+
.label = {STREQ($ty, "'static") ->
127+
[true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
128+
*[other] this generic parameter must be used with a generic {$kind} parameter
129+
}

compiler/rustc_error_messages/locales/en-US/infer.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ infer_region_explanation = {$pref_kind ->
147147
}{$desc_kind ->
148148
*[should_not_happen] [{$desc_kind}]
149149
[restatic] the static lifetime
150-
[reempty] the empty lifetime
151-
[reemptyuni] the empty lifetime in universe {$desc_arg}
152150
[revar] lifetime {$desc_arg}
153151
154152
[as_defined] the lifetime `{$desc_arg}` as defined here

compiler/rustc_error_messages/locales/en-US/mir_build.ftl

+12-4
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,18 @@ mir_build_borrow_of_moved_value = borrow of moved value
299299
.suggestion = borrow this binding in the pattern to avoid moving the value
300300
301301
mir_build_multiple_mut_borrows = cannot borrow value as mutable more than once at a time
302-
.label = first mutable borrow, by `{$name}`, occurs here
303-
.mutable_borrow = another mutable borrow, by `{$name_mut}`, occurs here
304-
.immutable_borrow = also borrowed as immutable, by `{$name_immut}`, here
305-
.moved = also moved into `{$name_moved}` here
302+
303+
mir_build_already_borrowed = cannot borrow value as mutable because it is also borrowed as immutable
304+
305+
mir_build_already_mut_borrowed = cannot borrow value as immutable because it is also borrowed as mutable
306+
307+
mir_build_moved_while_borrowed = cannot move out of value because it is borrowed
308+
309+
mir_build_mutable_borrow = value is mutably borrowed by `{$name}` here
310+
311+
mir_build_borrow = value is borrowed by `{$name}` here
312+
313+
mir_build_moved = value is moved into `{$name}` here
306314
307315
mir_build_union_pattern = cannot use unions in constant patterns
308316

compiler/rustc_error_messages/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ pub fn fluent_bundle(
182182
trace!(?locale);
183183
let mut bundle = new_bundle(vec![locale]);
184184

185+
// Add convenience functions available to ftl authors.
186+
register_functions(&mut bundle);
187+
185188
// Fluent diagnostics can insert directionality isolation markers around interpolated variables
186189
// indicating that there may be a shift from right-to-left to left-to-right text (or
187190
// vice-versa). These are disabled because they are sometimes visible in the error output, but
@@ -244,6 +247,15 @@ pub fn fluent_bundle(
244247
Ok(Some(bundle))
245248
}
246249

250+
fn register_functions(bundle: &mut FluentBundle) {
251+
bundle
252+
.add_function("STREQ", |positional, _named| match positional {
253+
[FluentValue::String(a), FluentValue::String(b)] => format!("{}", (a == b)).into(),
254+
_ => FluentValue::Error,
255+
})
256+
.expect("Failed to add a function to the bundle.");
257+
}
258+
247259
/// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily
248260
/// evaluated fluent bundle.
249261
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
@@ -256,6 +268,9 @@ pub fn fallback_fluent_bundle(
256268
) -> LazyFallbackBundle {
257269
Lrc::new(Lazy::new(move || {
258270
let mut fallback_bundle = new_bundle(vec![langid!("en-US")]);
271+
272+
register_functions(&mut fallback_bundle);
273+
259274
// See comment in `fluent_bundle`.
260275
fallback_bundle.set_use_isolating(with_directionality_markers);
261276

compiler/rustc_metadata/src/rmeta/encoder.rs

+45-113
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use rustc_span::symbol::{sym, Symbol};
3838
use rustc_span::{
3939
self, DebuggerVisualizerFile, ExternalSource, FileName, SourceFile, Span, SyntaxContext,
4040
};
41-
use rustc_target::abi::VariantIdx;
4241
use std::borrow::Borrow;
4342
use std::collections::hash_map::Entry;
4443
use std::hash::Hash;
@@ -1189,8 +1188,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11891188
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
11901189
}
11911190
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
1192-
let params_in_repr = self.tcx.params_in_repr(def_id);
1193-
record!(self.tables.params_in_repr[def_id] <- params_in_repr);
1191+
self.encode_info_for_adt(def_id);
11941192
}
11951193
if should_encode_trait_impl_trait_tys(tcx, def_id)
11961194
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
@@ -1213,46 +1211,53 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12131211
}
12141212
}
12151213

1216-
fn encode_enum_variant_info(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx) {
1214+
#[instrument(level = "trace", skip(self))]
1215+
fn encode_info_for_adt(&mut self, def_id: DefId) {
12171216
let tcx = self.tcx;
1218-
let variant = &def.variant(index);
1219-
let def_id = variant.def_id;
1220-
debug!("EncodeContext::encode_enum_variant_info({:?})", def_id);
1221-
1222-
let data = VariantData {
1223-
discr: variant.discr,
1224-
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1225-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1226-
};
1217+
let adt_def = tcx.adt_def(def_id);
1218+
record!(self.tables.repr_options[def_id] <- adt_def.repr());
12271219

1228-
record!(self.tables.variant_data[def_id] <- data);
1229-
self.tables.constness.set(def_id.index, hir::Constness::Const);
1230-
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
1231-
assert!(f.did.is_local());
1232-
f.did.index
1233-
}));
1234-
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
1235-
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
1236-
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id));
1220+
let params_in_repr = self.tcx.params_in_repr(def_id);
1221+
record!(self.tables.params_in_repr[def_id] <- params_in_repr);
1222+
1223+
if adt_def.is_enum() {
1224+
record_array!(self.tables.children[def_id] <- iter::from_generator(||
1225+
for variant in tcx.adt_def(def_id).variants() {
1226+
yield variant.def_id.index;
1227+
// Encode constructors which take a separate slot in value namespace.
1228+
if let Some(ctor_def_id) = variant.ctor_def_id() {
1229+
yield ctor_def_id.index;
1230+
}
1231+
}
1232+
));
1233+
} else {
1234+
// For non-enum, there is only one variant, and its def_id is the adt's.
1235+
debug_assert_eq!(adt_def.variants().len(), 1);
1236+
debug_assert_eq!(adt_def.non_enum_variant().def_id, def_id);
1237+
// Therefore, the loop over variants will encode its fields as the adt's children.
12371238
}
1238-
}
12391239

1240-
fn encode_enum_variant_ctor(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx) {
1241-
let variant = &def.variant(index);
1242-
let Some((ctor_kind, def_id)) = variant.ctor else { return };
1243-
debug!("EncodeContext::encode_enum_variant_ctor({:?})", def_id);
1240+
for variant in adt_def.variants().iter() {
1241+
let data = VariantData {
1242+
discr: variant.discr,
1243+
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1244+
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1245+
};
1246+
record!(self.tables.variant_data[variant.def_id] <- data);
12441247

1245-
// FIXME(eddyb) encode only the `CtorKind` for constructors.
1246-
let data = VariantData {
1247-
discr: variant.discr,
1248-
ctor: Some((ctor_kind, def_id.index)),
1249-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1250-
};
1248+
self.tables.constness.set(variant.def_id.index, hir::Constness::Const);
1249+
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| {
1250+
assert!(f.did.is_local());
1251+
f.did.index
1252+
}));
12511253

1252-
record!(self.tables.variant_data[def_id] <- data);
1253-
self.tables.constness.set(def_id.index, hir::Constness::Const);
1254-
if ctor_kind == CtorKind::Fn {
1255-
record!(self.tables.fn_sig[def_id] <- self.tcx.fn_sig(def_id));
1254+
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
1255+
self.tables.constness.set(ctor_def_id.index, hir::Constness::Const);
1256+
let fn_sig = tcx.fn_sig(ctor_def_id);
1257+
record!(self.tables.fn_sig[ctor_def_id] <- fn_sig);
1258+
// FIXME only encode signature for ctor_def_id
1259+
record!(self.tables.fn_sig[variant.def_id] <- fn_sig);
1260+
}
12561261
}
12571262
}
12581263

@@ -1305,25 +1310,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13051310
}
13061311
}
13071312

1308-
fn encode_struct_ctor(&mut self, adt_def: ty::AdtDef<'tcx>) {
1309-
let variant = adt_def.non_enum_variant();
1310-
let Some((ctor_kind, def_id)) = variant.ctor else { return };
1311-
debug!("EncodeContext::encode_struct_ctor({:?})", def_id);
1312-
1313-
let data = VariantData {
1314-
discr: variant.discr,
1315-
ctor: Some((ctor_kind, def_id.index)),
1316-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1317-
};
1318-
1319-
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1320-
record!(self.tables.variant_data[def_id] <- data);
1321-
self.tables.constness.set(def_id.index, hir::Constness::Const);
1322-
if ctor_kind == CtorKind::Fn {
1323-
record!(self.tables.fn_sig[def_id] <- self.tcx.fn_sig(def_id));
1324-
}
1325-
}
1326-
13271313
fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
13281314
debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
13291315
let bounds = self.tcx.explicit_item_bounds(def_id);
@@ -1532,33 +1518,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15321518
self.tables.is_type_alias_impl_trait.set_nullable(def_id.index, true);
15331519
}
15341520
}
1535-
hir::ItemKind::Enum(..) => {
1536-
let adt_def = self.tcx.adt_def(def_id);
1537-
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1538-
}
1539-
hir::ItemKind::Struct(..) => {
1540-
let adt_def = self.tcx.adt_def(def_id);
1541-
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1542-
self.tables.constness.set(def_id.index, hir::Constness::Const);
1543-
1544-
let variant = adt_def.non_enum_variant();
1545-
record!(self.tables.variant_data[def_id] <- VariantData {
1546-
discr: variant.discr,
1547-
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1548-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1549-
});
1550-
}
1551-
hir::ItemKind::Union(..) => {
1552-
let adt_def = self.tcx.adt_def(def_id);
1553-
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1554-
1555-
let variant = adt_def.non_enum_variant();
1556-
record!(self.tables.variant_data[def_id] <- VariantData {
1557-
discr: variant.discr,
1558-
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1559-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1560-
});
1561-
}
15621521
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
15631522
self.tables.impl_defaultness.set(def_id.index, *defaultness);
15641523
self.tables.constness.set(def_id.index, *constness);
@@ -1597,31 +1556,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15971556
}
15981557
hir::ItemKind::Static(..)
15991558
| hir::ItemKind::Const(..)
1559+
| hir::ItemKind::Enum(..)
1560+
| hir::ItemKind::Struct(..)
1561+
| hir::ItemKind::Union(..)
16001562
| hir::ItemKind::ForeignMod { .. }
16011563
| hir::ItemKind::GlobalAsm(..)
16021564
| hir::ItemKind::TyAlias(..) => {}
16031565
};
16041566
// FIXME(eddyb) there should be a nicer way to do this.
16051567
match item.kind {
1606-
hir::ItemKind::Enum(..) => {
1607-
record_array!(self.tables.children[def_id] <- iter::from_generator(||
1608-
for variant in tcx.adt_def(def_id).variants() {
1609-
yield variant.def_id.index;
1610-
// Encode constructors which take a separate slot in value namespace.
1611-
if let Some(ctor_def_id) = variant.ctor_def_id() {
1612-
yield ctor_def_id.index;
1613-
}
1614-
}
1615-
))
1616-
}
1617-
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
1618-
record_array!(self.tables.children[def_id] <-
1619-
self.tcx.adt_def(def_id).non_enum_variant().fields.iter().map(|f| {
1620-
assert!(f.did.is_local());
1621-
f.did.index
1622-
})
1623-
)
1624-
}
16251568
hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
16261569
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
16271570
record_array!(self.tables.children[def_id] <-
@@ -1649,17 +1592,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16491592
// so it's easier to do that here then to wait until we would encounter
16501593
// normally in the visitor walk.
16511594
match item.kind {
1652-
hir::ItemKind::Enum(..) => {
1653-
let def = self.tcx.adt_def(item.owner_id.to_def_id());
1654-
for (i, _) in def.variants().iter_enumerated() {
1655-
self.encode_enum_variant_info(def, i);
1656-
self.encode_enum_variant_ctor(def, i);
1657-
}
1658-
}
1659-
hir::ItemKind::Struct(..) => {
1660-
let def = self.tcx.adt_def(item.owner_id.to_def_id());
1661-
self.encode_struct_ctor(def);
1662-
}
16631595
hir::ItemKind::Impl { .. } => {
16641596
for &trait_item_def_id in
16651597
self.tcx.associated_item_def_ids(item.owner_id.to_def_id()).iter()

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#![feature(min_specialization)]
4444
#![feature(trusted_len)]
4545
#![feature(type_alias_impl_trait)]
46+
#![feature(strict_provenance)]
4647
#![feature(associated_type_bounds)]
4748
#![feature(rustc_attrs)]
4849
#![feature(control_flow_enum)]

0 commit comments

Comments
 (0)