Skip to content

Commit 9c0e783

Browse files
authored
Rollup merge of #103863 - compiler-errors:fulfillcx-less, r=wesleywiser
Use `TraitEngine` in more places, restrict visibility of `FulfillmentCtxt` constructor Most places that are constructing a `FulfillmentContext` should be constructing a `TraitEngine` generically, so later on if/when we're transitioning it'll be easier. Logical extension of #99746
2 parents a7cd4f2 + 27fddcf commit 9c0e783

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use rustc_span::{self, BytePos, DesugaringKind, Span};
6262
use rustc_target::spec::abi::Abi;
6363
use rustc_trait_selection::infer::InferCtxtExt as _;
6464
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
65+
use rustc_trait_selection::traits::TraitEngineExt as _;
6566
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
6667

6768
use smallvec::{smallvec, SmallVec};
@@ -1038,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10381039
let Ok(ok) = coerce.coerce(source, target) else {
10391040
return false;
10401041
};
1041-
let mut fcx = traits::FulfillmentContext::new_in_snapshot();
1042+
let mut fcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx);
10421043
fcx.register_predicate_obligations(self, ok.obligations);
10431044
fcx.select_where_possible(&self).is_empty()
10441045
})

compiler/rustc_trait_selection/src/autoderef.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::errors::AutoDerefReachedRecursionLimit;
22
use crate::traits::query::evaluate_obligation::InferCtxtExt;
3-
use crate::traits::{self, TraitEngine};
3+
use crate::traits::{self, TraitEngine, TraitEngineExt};
44
use rustc_hir as hir;
55
use rustc_infer::infer::InferCtxt;
66
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
@@ -139,7 +139,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
139139
return None;
140140
}
141141

142-
let mut fulfillcx = traits::FulfillmentContext::new_in_snapshot();
142+
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
143143
let normalized_ty = fulfillcx.normalize_projection_type(
144144
&self.infcx,
145145
self.param_env,

compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct FulfillmentContext<'tcx> {
1919
}
2020

2121
impl FulfillmentContext<'_> {
22-
pub(crate) fn new() -> Self {
22+
pub(super) fn new() -> Self {
2323
FulfillmentContext {
2424
obligations: FxIndexSet::default(),
2525
relationships: FxHashMap::default(),

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ pub mod on_unimplemented;
33
pub mod suggestions;
44

55
use super::{
6-
FulfillmentContext, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes,
7-
Obligation, ObligationCause, ObligationCauseCode, OutputTypeParameterMismatch, Overflow,
8-
PredicateObligation, SelectionContext, SelectionError, TraitNotObjectSafe,
6+
FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation, ObligationCause,
7+
ObligationCauseCode, OutputTypeParameterMismatch, Overflow, PredicateObligation,
8+
SelectionContext, SelectionError, TraitNotObjectSafe,
99
};
1010
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
1111
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1212
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
13+
use crate::traits::engine::TraitEngineExt as _;
1314
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
1415
use crate::traits::query::normalize::AtExt as _;
1516
use crate::traits::specialize::to_pretty_impl_header;
@@ -352,7 +353,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
352353
})
353354
.to_predicate(self.tcx),
354355
);
355-
let mut fulfill_cx = FulfillmentContext::new_in_snapshot();
356+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx);
356357
fulfill_cx.register_predicate_obligation(self, obligation);
357358
if fulfill_cx.select_all_or_error(self).is_empty() {
358359
return Ok((

compiler/rustc_trait_selection/src/traits/fulfill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ static_assert_size!(PendingPredicateObligation<'_>, 72);
8585

8686
impl<'a, 'tcx> FulfillmentContext<'tcx> {
8787
/// Creates a new fulfillment context.
88-
pub fn new() -> FulfillmentContext<'tcx> {
88+
pub(super) fn new() -> FulfillmentContext<'tcx> {
8989
FulfillmentContext {
9090
predicates: ObligationForest::new(),
9191
relationships: FxHashMap::default(),
9292
usable_in_snapshot: false,
9393
}
9494
}
9595

96-
pub fn new_in_snapshot() -> FulfillmentContext<'tcx> {
96+
pub(super) fn new_in_snapshot() -> FulfillmentContext<'tcx> {
9797
FulfillmentContext {
9898
predicates: ObligationForest::new(),
9999
relationships: FxHashMap::default(),

src/test/ui/chalkify/trait-objects.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ LL | f(2);
2222
| ^^^^ expected an `Fn<(i32,)>` closure, found `dyn Fn(i32) -> i32`
2323
|
2424
= help: the trait `Fn<(i32,)>` is not implemented for `dyn Fn(i32) -> i32`
25+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
26+
|
27+
LL | fn main() where dyn Fn(i32) -> i32: Fn<(i32,)> {
28+
| ++++++++++++++++++++++++++++++++++++
2529

2630
error: aborting due to 3 previous errors
2731

0 commit comments

Comments
 (0)