Skip to content

Check other rvalues #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// translate them into the form that the NLL solver
/// understands. See the NLL module for mode details.
pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx> {
assert!(self.region_obligations.borrow().is_empty(),
"region_obligations not empty: {:#?}",
self.region_obligations.borrow());

self.borrow_region_constraints().take_and_reset_data()
}

Expand Down
15 changes: 15 additions & 0 deletions src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
body_id: ast::NodeId,
obligation: RegionObligation<'tcx>,
) {
debug!(
"register_region_obligation(body_id={:?}, obligation={:?})",
body_id,
obligation
);

self.region_obligations
.borrow_mut()
.push((body_id, obligation));
Expand Down Expand Up @@ -138,6 +144,8 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
"cannot process registered region obligations in a snapshot"
);

debug!("process_registered_region_obligations()");

// pull out the region obligations with the given `body_id` (leaving the rest)
let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
{
Expand All @@ -156,6 +164,13 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
cause,
} in my_region_obligations
{
debug!(
"process_registered_region_obligations: sup_type={:?} sub_region={:?} cause={:?}",
sup_type,
sub_region,
cause
);

let origin = SubregionOrigin::from_obligation_cause(
&cause,
|| infer::RelateParamBound(cause.span, sup_type),
Expand Down
21 changes: 21 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}))
}

/// Create an unsafe fn ty based on a safe fn ty.
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
let converted_sig = sig.map_bound(|s| {
let params_iter = match s.inputs()[0].sty {
ty::TyTuple(params, _) => {
params.into_iter().cloned()
}
_ => bug!(),
};
self.mk_fn_sig(
params_iter,
s.output(),
s.variadic,
hir::Unsafety::Normal,
abi::Abi::Rust
)
});

self.mk_fn_ptr(converted_sig)
}

// Interns a type/name combination, stores the resulting box in cx.interners,
// and returns the box as cast to an unsafe ptr (see comments for Ty above).
pub fn mk_ty(self, st: TypeVariants<'tcx>) -> Ty<'tcx> {
Expand Down
36 changes: 33 additions & 3 deletions src/librustc_mir/borrow_check/nll/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ impl<'tcx> UniversalRegions<'tcx> {
// In case we find more than one, reduce to one for
// convenience. This is to prevent us from generating more
// complex constraints, but it will cause spurious errors.
relation.mutual_immediate_postdominator(external_parents).cloned()
relation
.mutual_immediate_postdominator(external_parents)
.cloned()
}

/// True if fr1 is known to outlive fr2.
Expand Down Expand Up @@ -467,7 +469,27 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
substs.substs
}
ty::TyFnDef(_, substs) => substs,
_ => bug!(),

// FIXME. When we encounter other sorts of constant
// expressions, such as the `22` in `[foo; 22]`, we can
// get the type `usize` here. For now, just return an
// empty vector of substs in this case, since there are no
// generics in scope in such expressions right now.
//
// Eventually I imagine we could get a wider range of
// types. What is the best way to handle this? Should we
// be checking something other than the type of the def-id
// to figure out what to do (e.g. the def-key?).
ty::TyUint(..) => {
assert!(identity_substs.is_empty());
identity_substs
}

_ => span_bug!(
tcx.def_span(self.mir_def_id),
"unknown defining type: {:?}",
defining_ty
),
};

let global_mapping = iter::once((gcx.types.re_static, fr_static));
Expand Down Expand Up @@ -525,7 +547,15 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
ty::TyFnDef(def_id, _) => {
let sig = tcx.fn_sig(def_id);
let sig = indices.fold_to_region_vids(tcx, &sig);
return sig.inputs_and_output();
sig.inputs_and_output()
}

// FIXME: as above, this happens on things like `[foo;
// 22]`. For now, no inputs, one output, but it seems like
// we need a more general way to handle this category of
// MIR.
ty::TyUint(..) => {
ty::Binder::new_not_binding(tcx.mk_type_list(iter::once(defining_ty)))
}

_ => span_bug!(
Expand Down
Loading