Skip to content

Commit 19b78cc

Browse files
authored
Rollup merge of #159899 - LorrensP-2158466:generic_args_terms, r=khyperia
`GenericArgs::types` triage + possible fixes cc [#t-types/call-for-participation > `args.types()` triage and fixes](https://rust-lang.zulipchat.com/#narrow/channel/618216-t-types.2Fcall-for-participation/topic/.60args.2Etypes.28.29.60.20triage.20and.20fixes/with/612733487)
2 parents 0bc8229 + 715bd31 commit 19b78cc

19 files changed

Lines changed: 47 additions & 37 deletions

File tree

‎compiler/rustc_borrowck/src/type_check/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18501850

18511851
assert_eq!(tcx.trait_impl_of_assoc(def_id), None);
18521852
self.prove_clauses(
1853-
args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())),
1853+
args.terms().map(|t| ty::ClauseKind::WellFormed(t.into())),
18541854
locations,
18551855
ConstraintCategory::Boring,
18561856
);

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
14321432
ty: Ty<'tcx>,
14331433
) -> SmallVec<Option<&'ll DIType>> {
14341434
if let ty::Adt(def, args) = *ty.kind() {
1435+
// FIXME: also do consts?
14351436
if args.types().next().is_some() {
14361437
let generics = cx.tcx.generics_of(def.did());
14371438
let names = get_parameter_names(cx, generics);

‎compiler/rustc_codegen_llvm/src/debuginfo/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
289289
generics: &ty::Generics,
290290
args: GenericArgsRef<'tcx>,
291291
) -> &'ll DIArray {
292-
if args.types().next().is_none() {
292+
if args.terms().next().is_none() {
293293
return create_DIArray(DIB(cx), &[]);
294294
}
295295

@@ -298,6 +298,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
298298
let names = get_parameter_names(cx, generics);
299299
iter::zip(args, names)
300300
.filter_map(|(kind, name)| {
301+
// FIXME: debug info for consts (using `createTemplateValueParameter`?)
301302
kind.as_type().map(|ty| {
302303
let actual_type = cx.tcx.normalize_erasing_regions(
303304
cx.typing_env(),

‎compiler/rustc_middle/src/ty/generic_args.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ impl<'tcx> GenericArgs<'tcx> {
518518
self.iter().filter_map(|k| k.as_const())
519519
}
520520

521+
#[inline]
522+
pub fn terms(&self) -> impl DoubleEndedIterator<Item = ty::Term<'tcx>> {
523+
self.iter().filter_map(|k| k.as_term())
524+
}
525+
521526
/// Returns generic arguments that are not lifetimes.
522527
#[inline]
523528
pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> {

‎compiler/rustc_middle/src/ty/print/pretty.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,9 +2305,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23052305
// `Foo<...>`.
23062306
if let Some(arg) = args.types().next() {
23072307
if let ty::Adt(_, arg_args) = arg.kind() {
2308-
if arg_args.consts().next().is_none()
2309-
&& arg_args.types().next().is_none()
2310-
{
2308+
if arg_args.terms().next().is_none() {
23112309
// Single param type with no type or const parameters:
23122310
// `Foo<Bar<'a>>`.
23132311
true

‎compiler/rustc_mir_transform/src/function_item_references.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
164164
other_abi => format!("extern {other_abi} "),
165165
};
166166
let ident = self.tcx.item_ident(fn_id);
167-
let ty_params = fn_args.types().map(|ty| format!("{ty}"));
168-
let const_params = fn_args.consts().map(|c| format!("{c}"));
169-
let params = ty_params.chain(const_params).join(", ");
167+
let params = fn_args.terms().map(|term| format!("{term}")).join(", ");
170168
let num_args = fn_sig.inputs().map_bound(|inputs| inputs.len()).skip_binder();
171169
let variadic = if fn_sig.c_variadic() { ", ..." } else { "" };
172170
let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" };

‎compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl<'tcx> InferSourceKind<'tcx> {
678678
|| matches!(
679679
ty.kind(),
680680
ty::Adt(_, args)
681-
if args.types().count() == 0 && args.consts().count() == 0
681+
if args.terms().next().is_none()
682682
)
683683
{
684684
// `ty` is either `_`, a primitive type like `u32` or a type with no type or

‎compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
182182
/// share an inference variable into a single diagnostic.
183183
pub(super) fn ambiguity_term(&self, predicate: ty::Predicate<'tcx>) -> Option<ty::Term<'tcx>> {
184184
match predicate.kind().skip_binder() {
185-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => data
186-
.trait_ref
187-
.args
188-
.iter()
189-
.filter_map(ty::GenericArg::as_term)
190-
.find(|term| term.has_non_region_infer()),
185+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
186+
data.trait_ref.args.terms().find(|term| term.has_non_region_infer())
187+
}
191188
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => data
192189
.projection_term
193190
.args
194-
.iter()
195-
.filter_map(ty::GenericArg::as_term)
191+
.terms()
196192
.chain([data.term])
197193
.find(|term| term.has_non_region_infer()),
198194
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => Some(term),

‎compiler/rustc_trait_selection/src/traits/auto_trait.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
454454
let new_args = new_trait.trait_ref.args;
455455
let old_args = old_trait.trait_ref.args;
456456

457-
if !new_args.types().eq(old_args.types()) {
457+
if !new_args.terms().eq(old_args.terms()) {
458458
// We can't compare lifetimes if the types are different,
459459
// so skip checking `old_clause`.
460460
return true;
@@ -624,7 +624,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
624624
}
625625

626626
fn is_param_no_infer(&self, args: GenericArgsRef<'tcx>) -> bool {
627-
self.is_of_param(args.type_at(0)) && !args.types().any(|t| t.has_infer_types())
627+
self.is_of_param(args.type_at(0)) && !args.terms().any(|t| t.has_infer_types())
628628
}
629629

630630
pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool {

‎compiler/rustc_trait_selection/src/traits/select/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12171217
// This suffices to allow chains like `FnMut` implemented in
12181218
// terms of `Fn` etc, but we could probably make this more
12191219
// precise still.
1220+
//
1221+
// FIXME(min_generic_const_args): Consider consts as well?
12201222
let unbound_input_types =
12211223
stack.fresh_trait_pred.skip_binder().trait_ref.args.types().any(|ty| ty.is_fresh());
12221224

0 commit comments

Comments
 (0)