diff options
| author | Michael Goulet <michael@errs.io> | 2024-10-31 00:09:34 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-10-31 00:09:52 +0000 |
| commit | 06a49b609f763cacf76a4fcdd3ae8f142e0b8b2d (patch) | |
| tree | b071a8e4acf4043424afc3e0e20d589d46191473 /compiler/rustc_hir_analysis/src | |
| parent | e356279bdfe6840236877b298f0c577e0f9221ff (diff) | |
| download | rust-06a49b609f763cacf76a4fcdd3ae8f142e0b8b2d.tar.gz rust-06a49b609f763cacf76a4fcdd3ae8f142e0b8b2d.zip | |
Validate associated type bounds on ?
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 9b0d21bc009..738b3133128 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -681,11 +681,32 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Some(self_ty), ); + let tcx = self.tcx(); + let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id); + debug!(?bound_vars); + + let poly_trait_ref = ty::Binder::bind_with_vars( + ty::TraitRef::new_from_args(tcx, trait_def_id, generic_args), + bound_vars, + ); + let polarity = match polarity { rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive, rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative, rustc_ast::BoundPolarity::Maybe(_) => { - // No-op. + // Validate associated type at least. We may want to reject these + // outright in the future... + for constraint in trait_segment.args().constraints { + let _ = self.lower_assoc_item_constraint( + trait_ref.hir_ref_id, + poly_trait_ref, + constraint, + &mut Default::default(), + &mut Default::default(), + constraint.span, + predicate_filter, + ); + } return arg_count; } }; @@ -699,15 +720,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }); } - let tcx = self.tcx(); - let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id); - debug!(?bound_vars); - - let poly_trait_ref = ty::Binder::bind_with_vars( - ty::TraitRef::new_from_args(tcx, trait_def_id, generic_args), - bound_vars, - ); - match predicate_filter { PredicateFilter::All | PredicateFilter::SelfOnly @@ -758,11 +770,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // since we should have emitted an error for them earlier, and they // would not be well-formed! if polarity != ty::PredicatePolarity::Positive { - assert!( - self.dcx().has_errors().is_some(), + self.dcx().span_delayed_bug( + constraint.span, "negative trait bounds should not have assoc item constraints", ); - continue; + break; } // Specify type to assert that error was already reported in `Err` case. |
