Skip to content

Commit

Permalink
Merge pull request rust-lang#319 from oli-obk/memory
Browse files Browse the repository at this point in the history
Get some more rustc tests working
  • Loading branch information
oli-obk authored Aug 29, 2017
2 parents fb96a09 + 88fc45b commit 941fbf5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions miri/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
// In some cases in non-MIR libstd-mode, not having a destination is legit. Handle these early.
match &path[..] {
"std::panicking::rust_panic_with_hook" |
"core::panicking::panic_fmt::::panic_impl" |
"std::rt::begin_panic_fmt" => return err!(Panic),
_ => {}
}
Expand Down
13 changes: 3 additions & 10 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc::mir;
use rustc::traits::Reveal;
use rustc::ty::layout::{self, Layout, Size, Align, HasDataLayout};
use rustc::ty::subst::{Subst, Substs, Kind};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable, Binder};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::indexed_vec::Idx;
use syntax::codemap::{self, DUMMY_SP};
use syntax::ast::Mutability;
Expand Down Expand Up @@ -282,15 +282,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
// let's simply get rid of them
let without_lifetimes = self.tcx.erase_regions(&ty);
let substituted = without_lifetimes.subst(self.tcx, substs);
self.tcx.normalize_associated_type(&substituted)
}

pub fn erase_lifetimes<T>(&self, value: &Binder<T>) -> T
where
T: TypeFoldable<'tcx>,
{
let value = self.tcx.erase_late_bound_regions(value);
self.tcx.erase_regions(&value)
let substituted = self.tcx.normalize_associated_type(&substituted);
substituted
}

/// Return the size and aligment of the value at the given type.
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_mir/interpret/terminator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
match instance_ty.sty {
ty::TyFnDef(..) => {
let real_sig = instance_ty.fn_sig(self.tcx);
let sig = self.erase_lifetimes(&sig);
let real_sig = self.erase_lifetimes(&real_sig);
let real_sig = self.tcx.normalize_associated_type(&real_sig);
let sig = self.tcx.erase_late_bound_regions_and_normalize(&sig);
let real_sig = self.tcx.erase_late_bound_regions_and_normalize(&real_sig);
if !self.check_sig_compat(sig, real_sig)? {
return err!(FunctionPointerTyMismatch(real_sig, sig));
}
Expand All @@ -96,7 +95,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
}
};
let args = self.operands_to_args(args)?;
let sig = self.erase_lifetimes(&sig);
let sig = self.tcx.erase_late_bound_regions_and_normalize(&sig);
self.eval_fn_call(
fn_def,
destination,
Expand Down
20 changes: 20 additions & 0 deletions tests/run-pass/issue-27901.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

trait Stream { type Item; }
impl<'a> Stream for &'a str { type Item = u8; }
fn f<'s>(s: &'s str) -> (&'s str, <&'s str as Stream>::Item) {
(s, 42)
}

fn main() {
let fx = f as for<'t> fn(&'t str) -> (&'t str, <&'t str as Stream>::Item);
assert_eq!(fx("hi"), ("hi", 42));
}

0 comments on commit 941fbf5

Please sign in to comment.