@@ -76,7 +76,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
7676 }
7777
7878 if unbounds. len ( ) > 1 {
79- tcx . dcx ( ) . emit_err ( errors:: MultipleRelaxedDefaultBounds {
79+ self . dcx ( ) . emit_err ( errors:: MultipleRelaxedDefaultBounds {
8080 spans : unbounds. iter ( ) . map ( |ptr| ptr. span ) . collect ( ) ,
8181 } ) ;
8282 }
@@ -90,7 +90,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
9090 continue ;
9191 }
9292 // There was a `?Trait` bound, but it was not `?Sized`; warn.
93- tcx . dcx ( ) . span_warn (
93+ self . dcx ( ) . span_warn (
9494 unbound. span ,
9595 "relaxing a default bound only does something for `?Sized`; \
9696 all other traits are not bound by default",
@@ -310,7 +310,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
310310 duplicates
311311 . entry ( assoc_item. def_id )
312312 . and_modify ( |prev_span| {
313- tcx . dcx ( ) . emit_err ( errors:: ValueOfAssociatedStructAlreadySpecified {
313+ self . dcx ( ) . emit_err ( errors:: ValueOfAssociatedStructAlreadySpecified {
314314 span : constraint. span ,
315315 prev_span : * prev_span,
316316 item_name : constraint. ident ,
@@ -338,7 +338,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
338338 . into ( ) ,
339339 ty:: GenericParamDefKind :: Type { .. } => {
340340 let guar = * emitted_bad_param_err. get_or_insert_with ( || {
341- tcx . dcx ( ) . emit_err (
341+ self . dcx ( ) . emit_err (
342342 crate :: errors:: ReturnTypeNotationIllegalParam :: Type {
343343 span : path_span,
344344 param_span : tcx. def_span ( param. def_id ) ,
@@ -349,7 +349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
349349 }
350350 ty:: GenericParamDefKind :: Const { .. } => {
351351 let guar = * emitted_bad_param_err. get_or_insert_with ( || {
352- tcx . dcx ( ) . emit_err (
352+ self . dcx ( ) . emit_err (
353353 crate :: errors:: ReturnTypeNotationIllegalParam :: Const {
354354 span : path_span,
355355 param_span : tcx. def_span ( param. def_id ) ,
@@ -371,7 +371,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
371371 {
372372 alias_ty. into ( )
373373 } else {
374- return Err ( tcx . dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationOnNonRpitit {
374+ return Err ( self . dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationOnNonRpitit {
375375 span : constraint. span ,
376376 ty : tcx. liberate_late_bound_regions ( assoc_item. def_id , output) ,
377377 fn_span : tcx. hir ( ) . span_if_local ( assoc_item. def_id ) ,
@@ -417,7 +417,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
417417 let ty = alias_term
418418 . map_bound ( |alias| tcx. type_of ( alias. def_id ) . instantiate ( tcx, alias. args ) ) ;
419419 let ty =
420- check_assoc_const_binding_type ( tcx , constraint. ident , ty, constraint. hir_id ) ;
420+ check_assoc_const_binding_type ( self , constraint. ident , ty, constraint. hir_id ) ;
421421 tcx. feed_anon_const_type ( anon_const. def_id , ty:: EarlyBinder :: bind ( ty) ) ;
422422 }
423423
@@ -426,7 +426,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
426426
427427 match constraint. kind {
428428 hir:: AssocItemConstraintKind :: Equality { .. } if let ty:: AssocKind :: Fn = assoc_kind => {
429- return Err ( tcx . dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationEqualityBound {
429+ return Err ( self . dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationEqualityBound {
430430 span : constraint. span ,
431431 } ) ) ;
432432 }
@@ -462,7 +462,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
462462 late_bound_in_term,
463463 |br_name| {
464464 struct_span_code_err ! (
465- tcx . dcx( ) ,
465+ self . dcx( ) ,
466466 constraint. span,
467467 E0582 ,
468468 "binding for associated type `{}` references {}, \
@@ -519,7 +519,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
519519///
520520/// [^1]: <https://github.com/rust-lang/project-const-generics/issues/28>.
521521fn check_assoc_const_binding_type < ' tcx > (
522- tcx : TyCtxt < ' tcx > ,
522+ cx : & dyn HirTyLowerer < ' tcx > ,
523523 assoc_const : Ident ,
524524 ty : ty:: Binder < ' tcx , Ty < ' tcx > > ,
525525 hir_id : hir:: HirId ,
@@ -536,13 +536,14 @@ fn check_assoc_const_binding_type<'tcx>(
536536 }
537537
538538 let mut collector = GenericParamAndBoundVarCollector {
539- tcx ,
539+ cx ,
540540 params : Default :: default ( ) ,
541541 vars : Default :: default ( ) ,
542542 depth : ty:: INNERMOST ,
543543 } ;
544544 let mut guar = ty. visit_with ( & mut collector) . break_value ( ) ;
545545
546+ let tcx = cx. tcx ( ) ;
546547 let ty_note = ty
547548 . make_suggestable ( tcx, false , None )
548549 . map ( |ty| crate :: errors:: TyOfAssocConstBindingNote { assoc_const, ty } ) ;
@@ -556,7 +557,7 @@ fn check_assoc_const_binding_type<'tcx>(
556557 for index in collector. params {
557558 let param = generics. param_at ( index as _ , tcx) ;
558559 let is_self_param = param. name == rustc_span:: symbol:: kw:: SelfUpper ;
559- guar. get_or_insert ( tcx . dcx ( ) . emit_err ( crate :: errors:: ParamInTyOfAssocConstBinding {
560+ guar. get_or_insert ( cx . dcx ( ) . emit_err ( crate :: errors:: ParamInTyOfAssocConstBinding {
560561 span : assoc_const. span ,
561562 assoc_const,
562563 param_name : param. name ,
@@ -574,7 +575,7 @@ fn check_assoc_const_binding_type<'tcx>(
574575 } ) ) ;
575576 }
576577 for ( var_def_id, var_name) in collector. vars {
577- guar. get_or_insert ( tcx . dcx ( ) . emit_err (
578+ guar. get_or_insert ( cx . dcx ( ) . emit_err (
578579 crate :: errors:: EscapingBoundVarInTyOfAssocConstBinding {
579580 span : assoc_const. span ,
580581 assoc_const,
@@ -590,14 +591,14 @@ fn check_assoc_const_binding_type<'tcx>(
590591 Ty :: new_error ( tcx, guar)
591592}
592593
593- struct GenericParamAndBoundVarCollector < ' tcx > {
594- tcx : TyCtxt < ' tcx > ,
594+ struct GenericParamAndBoundVarCollector < ' a , ' tcx > {
595+ cx : & ' a dyn HirTyLowerer < ' tcx > ,
595596 params : FxIndexSet < u32 > ,
596597 vars : FxIndexSet < ( DefId , Symbol ) > ,
597598 depth : ty:: DebruijnIndex ,
598599}
599600
600- impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for GenericParamAndBoundVarCollector < ' tcx > {
601+ impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for GenericParamAndBoundVarCollector < ' _ , ' tcx > {
601602 type Result = ControlFlow < ErrorGuaranteed > ;
602603
603604 fn visit_binder < T : TypeVisitable < TyCtxt < ' tcx > > > (
@@ -620,7 +621,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
620621 ty:: BoundTyKind :: Param ( def_id, name) => ( def_id, name) ,
621622 ty:: BoundTyKind :: Anon => {
622623 let reported = self
623- . tcx
624+ . cx
624625 . dcx ( )
625626 . delayed_bug ( format ! ( "unexpected anon bound ty: {:?}" , bt. var) ) ;
626627 return ControlFlow :: Break ( reported) ;
@@ -643,7 +644,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
643644 ty:: BrNamed ( def_id, name) => ( def_id, name) ,
644645 ty:: BrAnon | ty:: BrEnv => {
645646 let guar = self
646- . tcx
647+ . cx
647648 . dcx ( )
648649 . delayed_bug ( format ! ( "unexpected bound region kind: {:?}" , br. kind) ) ;
649650 return ControlFlow :: Break ( guar) ;
@@ -661,7 +662,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
661662 self . params . insert ( param. index ) ;
662663 }
663664 ty:: ConstKind :: Bound ( db, ty:: BoundVar { .. } ) if db >= self . depth => {
664- let guar = self . tcx . dcx ( ) . delayed_bug ( "unexpected escaping late-bound const var" ) ;
665+ let guar = self . cx . dcx ( ) . delayed_bug ( "unexpected escaping late-bound const var" ) ;
665666 return ControlFlow :: Break ( guar) ;
666667 }
667668 _ if ct. has_param ( ) || ct. has_bound_vars ( ) => return ct. super_visit_with ( self ) ,
0 commit comments