diff options
| author | Michael Goulet <michael@errs.io> | 2023-11-06 21:29:08 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-11-06 21:29:08 +0000 |
| commit | c17d33f1df9492ad993da3d8b0ddfcfe08bd652e (patch) | |
| tree | 7f4e1067eb7cc43cd50ce193a86cd111f1db55ec /compiler | |
| parent | aea82b268a7680b736be00e837eb8e32bc42a2da (diff) | |
| download | rust-c17d33f1df9492ad993da3d8b0ddfcfe08bd652e.tar.gz rust-c17d33f1df9492ad993da3d8b0ddfcfe08bd652e.zip | |
Extend builtin/auto trait args with error when they have >1 argument
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index cf52e6726a1..08208cc6047 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2389,12 +2389,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ) }); - let obligation = Obligation::new( - self.tcx(), - cause.clone(), - param_env, - ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]), - ); + let tcx = self.tcx(); + let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 { + ty::TraitRef::new(tcx, trait_def_id, [normalized_ty]) + } else { + // If this is an ill-formed auto/built-in trait, then synthesize + // new error args for the missing generics. + let err_args = ty::GenericArgs::extend_with_error( + tcx, + trait_def_id, + &[normalized_ty.into()], + ); + ty::TraitRef::new(tcx, trait_def_id, err_args) + }; + + let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref); obligations.push(obligation); obligations }) |
