From 88fc45b37cb6bdae3d7102e79e247179a4130b2d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 29 Aug 2017 11:32:10 +0200 Subject: [PATCH] Get some more rustc tests working --- miri/fn_call.rs | 1 + src/librustc_mir/interpret/eval_context.rs | 13 +++---------- src/librustc_mir/interpret/terminator/mod.rs | 7 +++---- tests/run-pass/issue-27901.rs | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 tests/run-pass/issue-27901.rs diff --git a/miri/fn_call.rs b/miri/fn_call.rs index 7dc8f54849f0a..a74a53fa75888 100644 --- a/miri/fn_call.rs +++ b/miri/fn_call.rs @@ -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), _ => {} } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 044f37947d30e..2a4515959d1fe 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -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; @@ -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(&self, value: &Binder) -> 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. diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index 60893fcec18b3..ebd6649c447c7 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -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)); } @@ -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, diff --git a/tests/run-pass/issue-27901.rs b/tests/run-pass/issue-27901.rs new file mode 100644 index 0000000000000..b7a9daaf8abd4 --- /dev/null +++ b/tests/run-pass/issue-27901.rs @@ -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 or the MIT license +// , 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)); +}