diff --git a/src/analyze/local_def.rs b/src/analyze/local_def.rs index 6a9cdf1b..366eaf85 100644 --- a/src/analyze/local_def.rs +++ b/src/analyze/local_def.rs @@ -232,11 +232,9 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> { // `def_ty_with_args` directly. fn precompute_callable_param_contracts(&mut self, sig: &mir_ty::FnSig<'tcx>) { for input_ty in sig.inputs() { - let inst = - mir_ty::EarlyBinder::bind(*input_ty).instantiate(self.tcx, self.generic_args); let inst = self .tcx - .normalize_erasing_regions(mir_ty::TypingEnv::fully_monomorphized(), inst); + .normalize_erasing_regions(mir_ty::TypingEnv::fully_monomorphized(), *input_ty); let (fn_def_id, fn_args) = match inst.kind() { mir_ty::TyKind::Closure(def_id, args) => { (*def_id, self.tcx.mk_args(args.as_closure().parent_args())) diff --git a/tests/ui/fail/trait_impl_lifetime_param.rs b/tests/ui/fail/trait_impl_lifetime_param.rs new file mode 100644 index 00000000..bafe10a8 --- /dev/null +++ b/tests/ui/fail/trait_impl_lifetime_param.rs @@ -0,0 +1,33 @@ +//@error-in-other-file: Unsat +//@compile-flags: -C debug-assertions=off + +#[thrust_macros::context] +trait Get { + #[thrust_macros::requires(true)] + #[thrust_macros::ensures(result >= 0)] + fn get(&self) -> i64; +} + +struct R<'a> { + r: &'a i64, +} + +impl<'a> thrust_models::Model for R<'a> { + type Ty = Self; +} + +impl<'a> Get for R<'a> { + fn get(&self) -> i64 { + if *self.r >= 0 { + *self.r + } else { + -1 + } + } +} + +fn main() { + let x = 5; + let r = R { r: &x }; + assert!(r.get() >= 0); +} diff --git a/tests/ui/pass/trait_impl_lifetime_param.rs b/tests/ui/pass/trait_impl_lifetime_param.rs new file mode 100644 index 00000000..9f86f7b1 --- /dev/null +++ b/tests/ui/pass/trait_impl_lifetime_param.rs @@ -0,0 +1,33 @@ +//@check-pass +//@compile-flags: -C debug-assertions=off + +#[thrust_macros::context] +trait Get { + #[thrust_macros::requires(true)] + #[thrust_macros::ensures(result >= 0)] + fn get(&self) -> i64; +} + +struct R<'a> { + r: &'a i64, +} + +impl<'a> thrust_models::Model for R<'a> { + type Ty = Self; +} + +impl<'a> Get for R<'a> { + fn get(&self) -> i64 { + if *self.r >= 0 { + *self.r + } else { + 0 + } + } +} + +fn main() { + let x = 5; + let r = R { r: &x }; + assert!(r.get() >= 0); +}