Skip to content

Commit 85f90a4

Browse files
committed
Auto merge of #125960 - jieyouxu:rollup-1s7f6lr, r=jieyouxu
Rollup of 8 pull requests Successful merges: - #124486 (Add tracking issue and unstable book page for `"vectorcall"` ABI) - #125504 (Change pedantically incorrect OnceCell/OnceLock wording) - #125608 (Avoid follow-up errors if the number of generic parameters already doesn't match) - #125690 (ARM Target Docs Update) - #125750 (Align `Term` methods with `GenericArg` methods, add `Term::expect_*`) - #125818 (Handle no values cfgs with `--print=check-cfg`) - #125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE) - #125919 (Remove stray "this") r? `@ghost` `@rustbot` modify labels: rollup
2 parents 27529d5 + a04a603 commit 85f90a4

File tree

57 files changed

+385
-277
lines changed

Some content is hidden

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

57 files changed

+385
-277
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn push_debuginfo_type_name<'tcx>(
263263
let ExistentialProjection { def_id: item_def_id, term, .. } =
264264
tcx.instantiate_bound_regions_with_erased(bound);
265265
// FIXME(associated_const_equality): allow for consts here
266-
(item_def_id, term.ty().unwrap())
266+
(item_def_id, term.expect_type())
267267
})
268268
.collect();
269269

compiler/rustc_driver_impl/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,17 @@ fn print_crate_info(
814814
match expected_values {
815815
ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")),
816816
ExpectedValues::Some(values) => {
817-
check_cfgs.extend(values.iter().map(|value| {
818-
if let Some(value) = value {
819-
format!("{name}=\"{value}\"")
820-
} else {
821-
name.to_string()
822-
}
823-
}))
817+
if !values.is_empty() {
818+
check_cfgs.extend(values.iter().map(|value| {
819+
if let Some(value) = value {
820+
format!("{name}=\"{value}\"")
821+
} else {
822+
name.to_string()
823+
}
824+
}))
825+
} else {
826+
check_cfgs.push(format!("{name}="))
827+
}
824828
}
825829
}
826830
}

compiler/rustc_feature/src/unstable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ declare_features! (
177177

178178
/// Allows using the `unadjusted` ABI; perma-unstable.
179179
(internal, abi_unadjusted, "1.16.0", None),
180-
/// Allows using the `vectorcall` ABI.
181-
(unstable, abi_vectorcall, "1.7.0", None),
182180
/// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`.
183181
(internal, allocator_internals, "1.20.0", None),
184182
/// Allows using `#[allow_internal_unsafe]`. This is an
@@ -243,6 +241,8 @@ declare_features! (
243241
// feature-group-start: internal feature gates
244242
// -------------------------------------------------------------------------
245243

244+
/// Allows using the `vectorcall` ABI.
245+
(unstable, abi_vectorcall, "1.7.0", Some(124485)),
246246
/// Allows features specific to auto traits.
247247
/// Renamed from `optin_builtin_traits`.
248248
(unstable, auto_traits, "1.50.0", Some(13231)),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ fn try_report_async_mismatch<'tcx>(
22812281
&& let Some(proj) = proj.no_bound_vars()
22822282
&& infcx.can_eq(
22832283
error.root_obligation.param_env,
2284-
proj.term.ty().unwrap(),
2284+
proj.term.expect_type(),
22852285
impl_sig.output(),
22862286
)
22872287
{

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
267267
.explicit_item_bounds(future_ty.def_id)
268268
.iter_instantiated_copied(tcx, future_ty.args)
269269
.find_map(|(clause, _)| match clause.kind().no_bound_vars()? {
270-
ty::ClauseKind::Projection(proj) => proj.term.ty(),
270+
ty::ClauseKind::Projection(proj) => proj.term.as_type(),
271271
_ => None,
272272
})
273273
else {

compiler/rustc_hir_analysis/src/check/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ fn fn_sig_suggestion<'tcx>(
441441
output = if let ty::Alias(_, alias_ty) = *output.kind() {
442442
tcx.explicit_item_super_predicates(alias_ty.def_id)
443443
.iter_instantiated_copied(tcx, alias_ty.args)
444-
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
444+
.find_map(|(bound, _)| {
445+
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()
446+
})
445447
.unwrap_or_else(|| {
446448
span_bug!(
447449
ident.span,

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
702702
pub(crate) fn complain_about_missing_assoc_tys(
703703
&self,
704704
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
705-
potential_assoc_types: Vec<Span>,
705+
potential_assoc_types: Vec<usize>,
706706
trait_bounds: &[hir::PolyTraitRef<'_>],
707707
) {
708708
if associated_types.values().all(|v| v.is_empty()) {

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
214214
if let Some(&param) = params.peek() {
215215
if param.index == 0 {
216216
if let GenericParamDefKind::Type { .. } = param.kind {
217+
assert_eq!(&args[..], &[]);
217218
args.push(
218219
self_ty
219220
.map(|ty| ty.into())
220-
.unwrap_or_else(|| ctx.inferred_kind(None, param, true)),
221+
.unwrap_or_else(|| ctx.inferred_kind(&args, param, true)),
221222
);
222223
params.next();
223224
}
@@ -267,7 +268,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
267268
// Since this is a const impl, we need to insert a host arg at the end of
268269
// `PartialEq`'s generics, but this errors since `Rhs` isn't specified.
269270
// To work around this, we infer all arguments until we reach the host param.
270-
args.push(ctx.inferred_kind(Some(&args), param, infer_args));
271+
args.push(ctx.inferred_kind(&args, param, infer_args));
271272
params.next();
272273
}
273274
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
@@ -281,7 +282,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
281282
GenericParamDefKind::Const { .. },
282283
_,
283284
) => {
284-
args.push(ctx.provided_kind(param, arg));
285+
args.push(ctx.provided_kind(&args, param, arg));
285286
args_iter.next();
286287
params.next();
287288
}
@@ -292,7 +293,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
292293
) => {
293294
// We expected a lifetime argument, but got a type or const
294295
// argument. That means we're inferring the lifetimes.
295-
args.push(ctx.inferred_kind(None, param, infer_args));
296+
args.push(ctx.inferred_kind(&args, param, infer_args));
296297
force_infer_lt = Some((arg, param));
297298
params.next();
298299
}
@@ -388,7 +389,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
388389
(None, Some(&param)) => {
389390
// If there are fewer arguments than parameters, it means
390391
// we're inferring the remaining arguments.
391-
args.push(ctx.inferred_kind(Some(&args), param, infer_args));
392+
args.push(ctx.inferred_kind(&args, param, infer_args));
392393
params.next();
393394
}
394395

@@ -474,16 +475,9 @@ pub(crate) fn check_generic_arg_count(
474475
return Ok(());
475476
}
476477

477-
if provided_args > max_expected_args {
478-
invalid_args.extend(
479-
gen_args.args[max_expected_args..provided_args].iter().map(|arg| arg.span()),
480-
);
481-
};
478+
invalid_args.extend(min_expected_args..provided_args);
482479

483480
let gen_args_info = if provided_args > min_expected_args {
484-
invalid_args.extend(
485-
gen_args.args[min_expected_args..provided_args].iter().map(|arg| arg.span()),
486-
);
487481
let num_redundant_args = provided_args - min_expected_args;
488482
GenericArgsInfo::ExcessLifetimes { num_redundant_args }
489483
} else {
@@ -538,11 +532,7 @@ pub(crate) fn check_generic_arg_count(
538532
let num_default_params = expected_max - expected_min;
539533

540534
let gen_args_info = if provided > expected_max {
541-
invalid_args.extend(
542-
gen_args.args[args_offset + expected_max..args_offset + provided]
543-
.iter()
544-
.map(|arg| arg.span()),
545-
);
535+
invalid_args.extend((expected_max..provided).map(|i| i + args_offset));
546536
let num_redundant_args = provided - expected_max;
547537

548538
// Provide extra note if synthetic arguments like `impl Trait` are specified.
@@ -610,7 +600,7 @@ pub(crate) fn check_generic_arg_count(
610600
explicit_late_bound,
611601
correct: lifetimes_correct
612602
.and(args_correct)
613-
.map_err(|reported| GenericArgCountMismatch { reported: Some(reported), invalid_args }),
603+
.map_err(|reported| GenericArgCountMismatch { reported, invalid_args }),
614604
}
615605
}
616606

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+47-31
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,11 @@ pub(crate) enum GenericArgPosition {
215215

216216
/// A marker denoting that the generic arguments that were
217217
/// provided did not match the respective generic parameters.
218-
#[derive(Clone, Default, Debug)]
218+
#[derive(Clone, Debug)]
219219
pub struct GenericArgCountMismatch {
220-
/// Indicates whether a fatal error was reported (`Some`), or just a lint (`None`).
221-
pub reported: Option<ErrorGuaranteed>,
222-
/// A list of spans of arguments provided that were not valid.
223-
pub invalid_args: Vec<Span>,
220+
pub reported: ErrorGuaranteed,
221+
/// A list of indices of arguments provided that were not valid.
222+
pub invalid_args: Vec<usize>,
224223
}
225224

226225
/// Decorates the result of a generic argument count mismatch
@@ -240,13 +239,14 @@ pub trait GenericArgsLowerer<'a, 'tcx> {
240239

241240
fn provided_kind(
242241
&mut self,
242+
preceding_args: &[ty::GenericArg<'tcx>],
243243
param: &ty::GenericParamDef,
244244
arg: &GenericArg<'tcx>,
245245
) -> ty::GenericArg<'tcx>;
246246

247247
fn inferred_kind(
248248
&mut self,
249-
args: Option<&[ty::GenericArg<'tcx>]>,
249+
preceding_args: &[ty::GenericArg<'tcx>],
250250
param: &ty::GenericParamDef,
251251
infer_args: bool,
252252
) -> ty::GenericArg<'tcx>;
@@ -404,10 +404,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
404404
self_ty.is_some(),
405405
);
406406

407-
if let Err(err) = &arg_count.correct
408-
&& let Some(reported) = err.reported
409-
{
410-
self.set_tainted_by_errors(reported);
407+
if let Err(err) = &arg_count.correct {
408+
self.set_tainted_by_errors(err.reported);
411409
}
412410

413411
// Skip processing if type has no generic parameters.
@@ -425,6 +423,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
425423
span: Span,
426424
inferred_params: Vec<Span>,
427425
infer_args: bool,
426+
incorrect_args: &'a Result<(), GenericArgCountMismatch>,
428427
}
429428

430429
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
@@ -439,11 +438,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
439438

440439
fn provided_kind(
441440
&mut self,
441+
preceding_args: &[ty::GenericArg<'tcx>],
442442
param: &ty::GenericParamDef,
443443
arg: &GenericArg<'tcx>,
444444
) -> ty::GenericArg<'tcx> {
445445
let tcx = self.lowerer.tcx();
446446

447+
if let Err(incorrect) = self.incorrect_args {
448+
if incorrect.invalid_args.contains(&(param.index as usize)) {
449+
return param.to_error(tcx, preceding_args);
450+
}
451+
}
452+
447453
let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| {
448454
if has_default {
449455
tcx.check_optional_stability(
@@ -506,11 +512,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
506512

507513
fn inferred_kind(
508514
&mut self,
509-
args: Option<&[ty::GenericArg<'tcx>]>,
515+
preceding_args: &[ty::GenericArg<'tcx>],
510516
param: &ty::GenericParamDef,
511517
infer_args: bool,
512518
) -> ty::GenericArg<'tcx> {
513519
let tcx = self.lowerer.tcx();
520+
521+
if let Err(incorrect) = self.incorrect_args {
522+
if incorrect.invalid_args.contains(&(param.index as usize)) {
523+
return param.to_error(tcx, preceding_args);
524+
}
525+
}
514526
match param.kind {
515527
GenericParamDefKind::Lifetime => self
516528
.lowerer
@@ -529,15 +541,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
529541
GenericParamDefKind::Type { has_default, .. } => {
530542
if !infer_args && has_default {
531543
// No type parameter provided, but a default exists.
532-
let args = args.unwrap();
533-
if args.iter().any(|arg| match arg.unpack() {
534-
GenericArgKind::Type(ty) => ty.references_error(),
535-
_ => false,
536-
}) {
544+
if let Some(prev) =
545+
preceding_args.iter().find_map(|arg| match arg.unpack() {
546+
GenericArgKind::Type(ty) => ty.error_reported().err(),
547+
_ => None,
548+
})
549+
{
537550
// Avoid ICE #86756 when type error recovery goes awry.
538-
return Ty::new_misc_error(tcx).into();
551+
return Ty::new_error(tcx, prev).into();
539552
}
540-
tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into()
553+
tcx.at(self.span)
554+
.type_of(param.def_id)
555+
.instantiate(tcx, preceding_args)
556+
.into()
541557
} else if infer_args {
542558
self.lowerer.ty_infer(Some(param), self.span).into()
543559
} else {
@@ -557,7 +573,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
557573
// FIXME(effects) see if we should special case effect params here
558574
if !infer_args && has_default {
559575
tcx.const_param_default(param.def_id)
560-
.instantiate(tcx, args.unwrap())
576+
.instantiate(tcx, preceding_args)
561577
.into()
562578
} else {
563579
if infer_args {
@@ -571,6 +587,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
571587
}
572588
}
573589
}
590+
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
591+
&& generics.has_self
592+
&& !tcx.has_attr(def_id, sym::const_trait)
593+
{
594+
let reported = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
595+
span,
596+
modifier: constness.as_str(),
597+
});
598+
self.set_tainted_by_errors(reported);
599+
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
600+
}
574601

575602
let mut args_ctx = GenericArgsCtxt {
576603
lowerer: self,
@@ -579,19 +606,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
579606
generic_args: segment.args(),
580607
inferred_params: vec![],
581608
infer_args: segment.infer_args,
609+
incorrect_args: &arg_count.correct,
582610
};
583-
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
584-
&& generics.has_self
585-
&& !tcx.has_attr(def_id, sym::const_trait)
586-
{
587-
let e = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
588-
span,
589-
modifier: constness.as_str(),
590-
});
591-
self.set_tainted_by_errors(e);
592-
arg_count.correct =
593-
Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] });
594-
}
595611
let args = lower_generic_args(
596612
tcx,
597613
def_id,

compiler/rustc_hir_analysis/src/impl_wf_check.rs

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ fn enforce_impl_params_are_constrained(
8686
let impl_predicates = tcx.predicates_of(impl_def_id);
8787
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);
8888

89+
impl_trait_ref.error_reported()?;
90+
8991
let mut input_parameters = cgp::parameters_for_impl(tcx, impl_self_ty, impl_trait_ref);
9092
cgp::identify_constrained_generic_params(
9193
tcx,

compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
485485
};
486486

487487
// Since this is a return parameter type it is safe to unwrap.
488-
let ret_param_ty = projection.skip_binder().term.ty().unwrap();
488+
let ret_param_ty = projection.skip_binder().term.expect_type();
489489
let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
490490
debug!(?ret_param_ty);
491491

@@ -956,7 +956,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
956956
let output_ty = self.resolve_vars_if_possible(predicate.term);
957957
debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty);
958958
// This is a projection on a Fn trait so will always be a type.
959-
Some(output_ty.ty().unwrap())
959+
Some(output_ty.expect_type())
960960
}
961961

962962
/// Converts the types that the user supplied, in case that doing

0 commit comments

Comments
 (0)