Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/analyze/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,12 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
) -> rty::Type<rty::Closed> {
if let Some(def_ty) = self.ctx.def_ty_with_args(def_id, args) {
let (impl_def_id, impl_args) = self.resolve_fn_def(def_id, args);
// otherwise nothing asks for a deferred impl method's type and its body goes unchecked
// an impl method annotated with its own spec is checked against that spec, not
// against the trait method's type, so the call must assume the impl's type
if impl_def_id != def_id {
let _ = self.ctx.def_ty_with_args(impl_def_id, impl_args);
if let Some(impl_ty) = self.ctx.def_ty_with_args(impl_def_id, impl_args) {
return impl_ty.ty;
}
}
return def_ty.ty;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/fail/trait_default_override_callable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@error-in-other-file: Unsat
//@compile-flags: -C debug-assertions=off

trait Tr {
fn m(&self) -> i64 {
2
}
}

struct A;

impl Tr for A {
#[thrust::callable]
fn m(&self) -> i64 {
1
}
}

fn main() {
assert!(A.m() == 2);
}
21 changes: 21 additions & 0 deletions tests/ui/pass/trait_default_override_callable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@check-pass
//@compile-flags: -C debug-assertions=off

trait Tr {
fn m(&self) -> i64 {
2
}
}

struct A;

impl Tr for A {
#[thrust::callable]
fn m(&self) -> i64 {
1
}
}

fn main() {
let _ = A.m();
}
Loading