提交 80b4c45e 编写于 作者: N Niko Matsakis

change `ParamEnv::and` to sometimes keep the environment [VIC]

In general, we've been moving towards a semantics where you can have
contradictory where-clauses, and we try to honor them.  There are
already existing run-pass tests where we take that philosophy as
well (e.g., `compile-fail/issue-36839.rs`). The current behavior of
`and`, where it strips the environment, breaks that code.
上级 64d4ed30
......@@ -1439,31 +1439,38 @@ pub fn without_caller_bounds(self) -> Self {
}
/// Creates a suitable environment in which to perform trait
/// queries on the given value. This will either be `self` *or*
/// the empty environment, depending on whether `value` references
/// type parameters that are in scope. (If it doesn't, then any
/// judgements should be completely independent of the context,
/// and hence we can safely use the empty environment so as to
/// enable more sharing across functions.)
/// queries on the given value. When type-checking, this is simply
/// the pair of the environment plus value. But when reveal is set to
/// All, then if `value` does not reference any type parameters, we will
/// pair it with the empty environment. This improves caching and is generally
/// invisible.
///
/// NB: This is a mildly dubious thing to do, in that a function
/// (or other environment) might have wacky where-clauses like
/// NB: We preserve the environment when type-checking because it
/// is possible for the user to have wacky where-clauses like
/// `where Box<u32>: Copy`, which are clearly never
/// satisfiable. The code will at present ignore these,
/// effectively, when type-checking the body of said
/// function. This preserves existing behavior in any
/// case. --nmatsakis
/// satisfiable. We generally want to behave as if they were true,
/// although the surrounding function is never reachable.
pub fn and<T: TypeFoldable<'tcx>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
assert!(!value.needs_infer());
if value.has_param_types() || value.has_self_ty() {
ParamEnvAnd {
param_env: self,
value,
match self.reveal {
Reveal::UserFacing => {
ParamEnvAnd {
param_env: self,
value,
}
}
} else {
ParamEnvAnd {
param_env: self.without_caller_bounds(),
value,
Reveal::All => {
if value.needs_infer() || value.has_param_types() || value.has_self_ty() {
ParamEnvAnd {
param_env: self,
value,
}
} else {
ParamEnvAnd {
param_env: self.without_caller_bounds(),
value,
}
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册