@@ -103,22 +103,31 @@ pub struct SelectionContext<'cx, 'tcx> {
103
103
/// require themselves.
104
104
freshener : TypeFreshener < ' cx , ' tcx > ,
105
105
106
- /// If `true`, indicates that the evaluation should be conservative
107
- /// and consider the possibility of types outside this crate.
106
+ /// During coherence we have to assume that other crates may add
107
+ /// additional impls which we currently don't know about.
108
+ ///
109
+ /// To deal with this evaluation should be conservative
110
+ /// and consider the possibility of impls from outside this crate.
108
111
/// This comes up primarily when resolving ambiguity. Imagine
109
112
/// there is some trait reference `$0: Bar` where `$0` is an
110
113
/// inference variable. If `intercrate` is true, then we can never
111
114
/// say for sure that this reference is not implemented, even if
112
115
/// there are *no impls at all for `Bar`*, because `$0` could be
113
116
/// bound to some type that in a downstream crate that implements
114
- /// `Bar`. This is the suitable mode for coherence. Elsewhere,
115
- /// though, we set this to false, because we are only interested
116
- /// in types that the user could actually have written --- in
117
- /// other words, we consider `$0: Bar` to be unimplemented if
117
+ /// `Bar`.
118
+ ///
119
+ /// Outside of coherence we set this to false because we are only
120
+ /// interested in types that the user could actually have written.
121
+ /// In other words, we consider `$0: Bar` to be unimplemented if
118
122
/// there is no type that the user could *actually name* that
119
123
/// would satisfy it. This avoids crippling inference, basically.
120
124
intercrate : bool ,
121
-
125
+ /// If `intercrate` is set, we remember predicates which were
126
+ /// considered ambiguous because of impls potentially added in other crates.
127
+ /// This is used in coherence to give improved diagnostics.
128
+ /// We don't do his until we detect a coherence error because it can
129
+ /// lead to false overflow results (#47139) and because always
130
+ /// computing it may negatively impact performance.
122
131
intercrate_ambiguity_causes : Option < Vec < IntercrateAmbiguityCause > > ,
123
132
124
133
/// The mode that trait queries run in, which informs our error handling
@@ -240,11 +249,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
240
249
}
241
250
}
242
251
243
- /// Enables tracking of intercrate ambiguity causes. These are
244
- /// used in coherence to give improved diagnostics. We don't do
245
- /// this until we detect a coherence error because it can lead to
246
- /// false overflow results (#47139) and because it costs
247
- /// computation time.
252
+ /// Enables tracking of intercrate ambiguity causes. See
253
+ /// the documentation of [`Self::intercrate_ambiguity_causes`] for more.
248
254
pub fn enable_tracking_intercrate_ambiguity_causes ( & mut self ) {
249
255
assert ! ( self . intercrate) ;
250
256
assert ! ( self . intercrate_ambiguity_causes. is_none( ) ) ;
0 commit comments