提交 5a5c265e 编写于 作者: N Niko Matsakis

refactor common logic into `ParameterEnvironment::and()`

上级 194d4bc1
......@@ -1259,10 +1259,33 @@ pub struct ParameterEnvironment<'tcx> {
}
impl<'tcx> ParameterEnvironment<'tcx> {
pub fn and<T>(self, value: T) -> ParameterEnvironmentAnd<'tcx, T> {
ParameterEnvironmentAnd {
param_env: self,
value: value,
/// 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.)
///
/// NB: This is a mildly dubious thing to do, in that a function
/// (or other environment) might 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
pub fn and<T: TypeFoldable<'tcx>>(self, value: T) -> ParameterEnvironmentAnd<'tcx, T> {
assert!(!value.needs_infer());
if value.has_param_types() || value.has_self_ty() {
ParameterEnvironmentAnd {
param_env: self,
value: value,
}
} else {
ParameterEnvironmentAnd {
param_env: ParameterEnvironment::empty(),
value: value,
}
}
}
}
......
......@@ -724,11 +724,7 @@ pub fn moves_by_default(&'tcx self,
param_env: ParameterEnvironment<'tcx>,
span: Span)
-> bool {
if self.has_param_types() || self.has_self_ty() {
!tcx.at(span).is_copy_raw(param_env.and(self))
} else {
!tcx.is_copy_raw(ParameterEnvironment::empty().and(self))
}
!tcx.at(span).is_copy_raw(param_env.and(self))
}
pub fn is_sized(&'tcx self,
......@@ -736,11 +732,7 @@ pub fn is_sized(&'tcx self,
param_env: ParameterEnvironment<'tcx>,
span: Span)-> bool
{
if self.has_param_types() || self.has_self_ty() {
tcx.at(span).is_sized_raw(param_env.and(self))
} else {
tcx.is_sized_raw(ParameterEnvironment::empty().and(self))
}
tcx.at(span).is_sized_raw(param_env.and(self))
}
pub fn is_freeze(&'tcx self,
......@@ -748,11 +740,7 @@ pub fn is_freeze(&'tcx self,
param_env: ParameterEnvironment<'tcx>,
span: Span)-> bool
{
if self.has_param_types() || self.has_self_ty() {
tcx.at(span).is_freeze_raw(param_env.and(self))
} else {
tcx.is_freeze_raw(ParameterEnvironment::empty().and(self))
}
tcx.at(span).is_freeze_raw(param_env.and(self))
}
/// If `ty.needs_drop(...)` returns `true`, then `ty` is definitely
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册