Skip to content

Commit 80d0d92

Browse files
committed
Auto merge of rust-lang#132171 - matthiaskrgr:rollup-tp75ge7, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#132114 (Use `Enabled{Lang,Lib}Feature` instead of n-tuples) - rust-lang#132163 (Update Fuchsia CI script for package serving) - rust-lang#132168 (Effects cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ae4c6b6 + 56463df commit 80d0d92

File tree

31 files changed

+163
-178
lines changed

31 files changed

+163
-178
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,9 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
623623
let stable_since = features
624624
.enabled_lang_features()
625625
.iter()
626-
.flat_map(|&(feature, _, since)| if feature == name { since } else { None })
627-
.next();
626+
.find(|feat| feat.gate_name == name)
627+
.map(|feat| feat.stable_since)
628+
.flatten();
628629
if let Some(since) = stable_since {
629630
err.stable_features.push(errors::StableFeature { name, since });
630631
} else {
@@ -642,16 +643,15 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
642643
}
643644

644645
fn check_incompatible_features(sess: &Session, features: &Features) {
645-
let enabled_features = features
646-
.enabled_lang_features()
647-
.iter()
648-
.copied()
649-
.map(|(name, span, _)| (name, span))
650-
.chain(features.enabled_lib_features().iter().copied());
646+
let enabled_lang_features =
647+
features.enabled_lang_features().iter().map(|feat| (feat.gate_name, feat.attr_sp));
648+
let enabled_lib_features =
649+
features.enabled_lib_features().iter().map(|feat| (feat.gate_name, feat.attr_sp));
650+
let enabled_features = enabled_lang_features.chain(enabled_lib_features);
651651

652652
for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES
653653
.iter()
654-
.filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
654+
.filter(|(f1, f2)| features.enabled(*f1) && features.enabled(*f2))
655655
{
656656
if let Some((f1_name, f1_span)) = enabled_features.clone().find(|(name, _)| name == f1) {
657657
if let Some((f2_name, f2_span)) = enabled_features.clone().find(|(name, _)| name == f2)
@@ -673,10 +673,11 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
673673
}
674674

675675
// Ban GCE with the new solver, because it does not implement GCE correctly.
676-
if let Some(&(_, gce_span, _)) = features
676+
if let Some(gce_span) = features
677677
.enabled_lang_features()
678678
.iter()
679-
.find(|&&(feat, _, _)| feat == sym::generic_const_exprs)
679+
.find(|feat| feat.gate_name == sym::generic_const_exprs)
680+
.map(|feat| feat.attr_sp)
680681
{
681682
sess.dcx().emit_err(errors::IncompatibleFeatures {
682683
spans: vec![gce_span],

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ impl DebugContext {
210210
type_names::push_generic_params(
211211
tcx,
212212
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
213-
enclosing_fn_def_id,
214213
&mut name,
215214
);
216215

compiler/rustc_codegen_gcc/src/callee.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
9898
// whether we are sharing generics or not. The important thing here is
9999
// that the visibility we apply to the declaration is the same one that
100100
// has been applied to the definition (wherever that definition may be).
101-
let is_generic =
102-
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
101+
let is_generic = instance.args.non_erasable_generics().next().is_some();
103102

104103
if is_generic {
105104
// This is a monomorphization. Its expected visibility depends

compiler/rustc_codegen_llvm/src/callee.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
9898
unsafe {
9999
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);
100100

101-
let is_generic =
102-
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
101+
let is_generic = instance.args.non_erasable_generics().next().is_some();
103102

104103
let is_hidden = if is_generic {
105104
// This is a monomorphization of a generic function.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
350350
type_names::push_generic_params(
351351
tcx,
352352
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
353-
enclosing_fn_def_id,
354353
&mut name,
355354
);
356355

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn exported_symbols_provider_local(
312312

313313
match *mono_item {
314314
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
315-
if args.non_erasable_generics(tcx, def).next().is_some() {
315+
if args.non_erasable_generics().next().is_some() {
316316
let symbol = ExportedSymbol::Generic(def, args);
317317
symbols.push((symbol, SymbolExportInfo {
318318
level: SymbolExportLevel::Rust,
@@ -321,27 +321,21 @@ fn exported_symbols_provider_local(
321321
}));
322322
}
323323
}
324-
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(def_id, Some(ty)), args }) => {
324+
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
325325
// A little sanity-check
326-
assert_eq!(
327-
args.non_erasable_generics(tcx, def_id).next(),
328-
Some(GenericArgKind::Type(ty))
329-
);
326+
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
330327
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportInfo {
331328
level: SymbolExportLevel::Rust,
332329
kind: SymbolExportKind::Text,
333330
used: false,
334331
}));
335332
}
336333
MonoItem::Fn(Instance {
337-
def: InstanceKind::AsyncDropGlueCtorShim(def_id, Some(ty)),
334+
def: InstanceKind::AsyncDropGlueCtorShim(_, Some(ty)),
338335
args,
339336
}) => {
340337
// A little sanity-check
341-
assert_eq!(
342-
args.non_erasable_generics(tcx, def_id).next(),
343-
Some(GenericArgKind::Type(ty))
344-
);
338+
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
345339
symbols.push((ExportedSymbol::AsyncDropGlueCtorShim(ty), SymbolExportInfo {
346340
level: SymbolExportLevel::Rust,
347341
kind: SymbolExportKind::Text,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ fn push_debuginfo_type_name<'tcx>(
110110
ty_and_layout,
111111
&|output, visited| {
112112
push_item_name(tcx, def.did(), true, output);
113-
push_generic_params_internal(tcx, args, def.did(), output, visited);
113+
push_generic_params_internal(tcx, args, output, visited);
114114
},
115115
output,
116116
visited,
117117
);
118118
} else {
119119
push_item_name(tcx, def.did(), qualified, output);
120-
push_generic_params_internal(tcx, args, def.did(), output, visited);
120+
push_generic_params_internal(tcx, args, output, visited);
121121
}
122122
}
123123
ty::Tuple(component_types) => {
@@ -251,13 +251,8 @@ fn push_debuginfo_type_name<'tcx>(
251251
let principal =
252252
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
253253
push_item_name(tcx, principal.def_id, qualified, output);
254-
let principal_has_generic_params = push_generic_params_internal(
255-
tcx,
256-
principal.args,
257-
principal.def_id,
258-
output,
259-
visited,
260-
);
254+
let principal_has_generic_params =
255+
push_generic_params_internal(tcx, principal.args, output, visited);
261256

262257
let projection_bounds: SmallVec<[_; 4]> = trait_data
263258
.projection_bounds()
@@ -538,13 +533,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
538533
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
539534
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
540535
visited.clear();
541-
push_generic_params_internal(
542-
tcx,
543-
trait_ref.args,
544-
trait_ref.def_id,
545-
&mut vtable_name,
546-
&mut visited,
547-
);
536+
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
548537
} else {
549538
vtable_name.push('_');
550539
}
@@ -647,12 +636,11 @@ fn push_unqualified_item_name(
647636
fn push_generic_params_internal<'tcx>(
648637
tcx: TyCtxt<'tcx>,
649638
args: GenericArgsRef<'tcx>,
650-
def_id: DefId,
651639
output: &mut String,
652640
visited: &mut FxHashSet<Ty<'tcx>>,
653641
) -> bool {
654642
assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
655-
let mut args = args.non_erasable_generics(tcx, def_id).peekable();
643+
let mut args = args.non_erasable_generics().peekable();
656644
if args.peek().is_none() {
657645
return false;
658646
}
@@ -736,12 +724,11 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
736724
pub fn push_generic_params<'tcx>(
737725
tcx: TyCtxt<'tcx>,
738726
args: GenericArgsRef<'tcx>,
739-
def_id: DefId,
740727
output: &mut String,
741728
) {
742729
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
743730
let mut visited = FxHashSet::default();
744-
push_generic_params_internal(tcx, args, def_id, output, &mut visited);
731+
push_generic_params_internal(tcx, args, output, &mut visited);
745732
}
746733

747734
fn push_closure_or_coroutine_name<'tcx>(
@@ -786,7 +773,7 @@ fn push_closure_or_coroutine_name<'tcx>(
786773
// FIXME(async_closures): This is probably not going to be correct w.r.t.
787774
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
788775
let args = args.truncate_to(tcx, generics);
789-
push_generic_params_internal(tcx, args, enclosing_fn_def_id, output, visited);
776+
push_generic_params_internal(tcx, args, output, visited);
790777
}
791778

792779
fn push_close_angle_bracket(cpp_like_debuginfo: bool, output: &mut String) {

compiler/rustc_expand/src/config.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_ast::{
1111
use rustc_attr as attr;
1212
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1313
use rustc_feature::{
14-
ACCEPTED_LANG_FEATURES, AttributeSafety, Features, REMOVED_LANG_FEATURES,
15-
UNSTABLE_LANG_FEATURES,
14+
ACCEPTED_LANG_FEATURES, AttributeSafety, EnabledLangFeature, EnabledLibFeature, Features,
15+
REMOVED_LANG_FEATURES, UNSTABLE_LANG_FEATURES,
1616
};
1717
use rustc_lint_defs::BuiltinLintDiag;
1818
use rustc_parse::validate_attr;
@@ -88,8 +88,11 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
8888

8989
// If the enabled feature is stable, record it.
9090
if let Some(f) = ACCEPTED_LANG_FEATURES.iter().find(|f| name == f.name) {
91-
let since = Some(Symbol::intern(f.since));
92-
features.set_enabled_lang_feature(name, mi.span(), since);
91+
features.set_enabled_lang_feature(EnabledLangFeature {
92+
gate_name: name,
93+
attr_sp: mi.span(),
94+
stable_since: Some(Symbol::intern(f.since)),
95+
});
9396
continue;
9497
}
9598

@@ -115,13 +118,19 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
115118
{
116119
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
117120
}
118-
features.set_enabled_lang_feature(name, mi.span(), None);
121+
122+
features.set_enabled_lang_feature(EnabledLangFeature {
123+
gate_name: name,
124+
attr_sp: mi.span(),
125+
stable_since: None,
126+
});
119127
continue;
120128
}
121129

122130
// Otherwise, the feature is unknown. Enable it as a lib feature.
123131
// It will be checked later whether the feature really exists.
124-
features.set_enabled_lib_feature(name, mi.span());
132+
features
133+
.set_enabled_lib_feature(EnabledLibFeature { gate_name: name, attr_sp: mi.span() });
125134

126135
// Similar to above, detect internal lib features to suppress
127136
// the ICE message that asks for a report.

compiler/rustc_feature/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ pub use builtin_attrs::{
135135
is_valid_for_get_attr,
136136
};
137137
pub use removed::REMOVED_LANG_FEATURES;
138-
pub use unstable::{Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES};
138+
pub use unstable::{
139+
EnabledLangFeature, EnabledLibFeature, Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES,
140+
};

compiler/rustc_feature/src/unstable.rs

+33-14
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,54 @@ macro_rules! status_to_enum {
3636
#[derive(Clone, Default, Debug)]
3737
pub struct Features {
3838
/// `#![feature]` attrs for language features, for error reporting.
39-
enabled_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
39+
enabled_lang_features: Vec<EnabledLangFeature>,
4040
/// `#![feature]` attrs for non-language (library) features.
41-
enabled_lib_features: Vec<(Symbol, Span)>,
41+
enabled_lib_features: Vec<EnabledLibFeature>,
4242
/// `enabled_lang_features` + `enabled_lib_features`.
4343
enabled_features: FxHashSet<Symbol>,
4444
}
4545

46+
/// Information about an enabled language feature.
47+
#[derive(Debug, Copy, Clone)]
48+
pub struct EnabledLangFeature {
49+
/// Name of the feature gate guarding the language feature.
50+
pub gate_name: Symbol,
51+
/// Span of the `#[feature(...)]` attribute.
52+
pub attr_sp: Span,
53+
/// If the lang feature is stable, the version number when it was stabilized.
54+
pub stable_since: Option<Symbol>,
55+
}
56+
57+
/// Information abhout an enabled library feature.
58+
#[derive(Debug, Copy, Clone)]
59+
pub struct EnabledLibFeature {
60+
pub gate_name: Symbol,
61+
pub attr_sp: Span,
62+
}
63+
4664
impl Features {
4765
/// `since` should be set for stable features that are nevertheless enabled with a `#[feature]`
4866
/// attribute, indicating since when they are stable.
49-
pub fn set_enabled_lang_feature(&mut self, name: Symbol, span: Span, since: Option<Symbol>) {
50-
self.enabled_lang_features.push((name, span, since));
51-
self.enabled_features.insert(name);
67+
pub fn set_enabled_lang_feature(&mut self, lang_feat: EnabledLangFeature) {
68+
self.enabled_lang_features.push(lang_feat);
69+
self.enabled_features.insert(lang_feat.gate_name);
5270
}
5371

54-
pub fn set_enabled_lib_feature(&mut self, name: Symbol, span: Span) {
55-
self.enabled_lib_features.push((name, span));
56-
self.enabled_features.insert(name);
72+
pub fn set_enabled_lib_feature(&mut self, lib_feat: EnabledLibFeature) {
73+
self.enabled_lib_features.push(lib_feat);
74+
self.enabled_features.insert(lib_feat.gate_name);
5775
}
5876

59-
/// Returns a list of triples with:
60-
/// - feature gate name
61-
/// - the span of the `#[feature]` attribute
62-
/// - (for already stable features) the version since which it is stable
63-
pub fn enabled_lang_features(&self) -> &Vec<(Symbol, Span, Option<Symbol>)> {
77+
/// Returns a list of [`EnabledLangFeature`] with info about:
78+
///
79+
/// - Feature gate name.
80+
/// - The span of the `#[feature]` attribute.
81+
/// - For stable language features, version info for when it was stabilized.
82+
pub fn enabled_lang_features(&self) -> &Vec<EnabledLangFeature> {
6483
&self.enabled_lang_features
6584
}
6685

67-
pub fn enabled_lib_features(&self) -> &Vec<(Symbol, Span)> {
86+
pub fn enabled_lib_features(&self) -> &Vec<EnabledLibFeature> {
6887
&self.enabled_lib_features
6988
}
7089

compiler/rustc_hir_analysis/src/bounds.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Bounds are restrictions applied to some types after they've been lowered from the HIR to the
22
//! [`rustc_middle::ty`] form.
33
4-
use rustc_data_structures::fx::FxIndexMap;
54
use rustc_hir::LangItem;
65
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
76
use rustc_span::Span;
@@ -25,7 +24,6 @@ use rustc_span::Span;
2524
#[derive(Default, PartialEq, Eq, Clone, Debug)]
2625
pub(crate) struct Bounds<'tcx> {
2726
clauses: Vec<(ty::Clause<'tcx>, Span)>,
28-
effects_min_tys: FxIndexMap<Ty<'tcx>, Span>,
2927
}
3028

3129
impl<'tcx> Bounds<'tcx> {
@@ -96,15 +94,7 @@ impl<'tcx> Bounds<'tcx> {
9694
}
9795
}
9896

99-
pub(crate) fn clauses(
100-
&self,
101-
// FIXME(effects): remove tcx
102-
_tcx: TyCtxt<'tcx>,
103-
) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
97+
pub(crate) fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
10498
self.clauses.iter().cloned()
10599
}
106-
107-
pub(crate) fn effects_min_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
108-
self.effects_min_tys.keys().copied()
109-
}
110100
}

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn associated_type_bounds<'tcx>(
6767
)
6868
});
6969

70-
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(bounds_from_parent));
70+
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent));
7171
debug!(
7272
"associated_type_bounds({}) = {:?}",
7373
tcx.def_path_str(assoc_item_def_id.to_def_id()),
@@ -339,7 +339,7 @@ fn opaque_type_bounds<'tcx>(
339339
}
340340
debug!(?bounds);
341341

342-
tcx.arena.alloc_from_iter(bounds.clauses(tcx))
342+
tcx.arena.alloc_from_iter(bounds.clauses())
343343
})
344344
}
345345

0 commit comments

Comments
 (0)