Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The shared resolver guard also rejects previously supported qualified inherent-method targets that do not require trait-instance resolution.
1 open issue
What changed in this PR
This PR addresses #4998 by reporting unsupported const-generic contract target paths as resolution errors instead of compiler panics.
Changes:
- Makes
instantiate_path_argsreturn aResultand reject unsupported const-generic paths. - Adds regression cases for explicit, omitted, and mixed type/const arguments.
| File | Description |
|---|---|
tests/expected/function-contract/const_generic_path.rs |
Tests an explicit const argument in a trait-method target. |
tests/expected/function-contract/const_generic_path.expected |
Specifies the expected unsupported-path diagnostic. |
tests/expected/function-contract/const_generic_omitted.rs |
Tests an omitted argument on a const-only type. |
tests/expected/function-contract/const_generic_omitted.expected |
Specifies the diagnostic for omitted const arguments. |
tests/expected/function-contract/const_generic_mixed.rs |
Tests explicit arguments on a mixed type/const-generic type. |
tests/expected/function-contract/const_generic_mixed.expected |
Specifies the diagnostic for mixed generic arguments. |
kani-compiler/src/kani_middle/resolve/type_resolution.rs |
Adds fallible path instantiation and const-generic rejection. |
Review effort: Balanced
…the shared resolver Qualified inherent-method targets on const-generic types resolve again; the const-generic trait/contract rejection (the panic fix) is unchanged, just moved to the Instance::resolve call site where the ICE originates. Adds a regression test for the qualified inherent spelling.
Covers `<Buf<4>>::get`: the qualified inherent spelling resolves and its contract verifies, confirming the guard does not over-reject the inherent path.
|
@feliperodri Thanks for running the Copilot review. I addressed the comment and updated the branch. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
1 resolved since last review
Review effort: Lite
| // A const-generic self type would reach `Instance::resolve` below with a free const | ||
| // parameter (this resolver does not instantiate const arguments) and ICE. Reject it first. | ||
| if let TyKind::RigidTy(RigidTy::Adt(_, self_args)) = ty.kind() { | ||
| let has_const = self_args.0.iter().any(|arg| matches!(arg, GenericArgKind::Const(_))); | ||
| if has_const { | ||
| return Err(ResolveError::UnsupportedPath { kind: "const generic arguments" }); | ||
| } | ||
| } |
| } | ||
| } | ||
|
|
||
| pub fn bar<const C: usize>(x: &Foo<C>) -> bool { |
feliperodri
left a comment
There was a problem hiding this comment.
Approach looks right: the error is raised at the call site, and inherent-method targets are untouched.
Before merge:
regression (ubuntu-24.04)fails on this head. Please check the log. If it's the unusedxinmain.rsthat Copilot flagged, fix it and re-run.- The guard only checks ADTs. Please test a const-generic array self type (e.g.
impl Trait for [u8; N]), or explain why it can't reachInstance::resolve. - This is an ICE, so please add
[C] Bugand[F] Crash. - The branch is behind
main. Please update it.
…cking#5135) ## Summary Fix trait method resolution for stubs and function contracts when the method declares its own generic parameters. Previously, the resolver could identify a concrete trait implementation but failed to construct the complete generic argument list required by `Instance::resolve`. Method-level type, const, and lifetime parameters could therefore prevent valid trait method targets from resolving. ## Changes - Include method-level generic arguments when resolving trait method implementations. - Reconstruct the complete generic argument layout, including trait defaults and erased lifetime slots, using `ctor_args_with_lifetimes`. - Return the resolved implementation's function definition. - Improve diagnostics by distinguishing invalid generic arguments, unsupported trait-level const generics, and genuinely missing trait implementations. Remove the outdated note claiming generic trait methods are unsupported. - Add positive and negative regression tests for trait/method generics, method-level const generics, lifetimes, trait defaults, contracts, and stub signature validation. - Add regressions for standard-library `FromIterator<char>` and `Extend<char>` methods on `String`. - Add generic `stub_verified` tests, including multiple method instantiations and precondition failures. - Cover the specialization/`FnMut` case from model-checking#4908, including a negative test demonstrating that a weak contract does not guarantee sorting. ## Testing - Local validation: **807 passed, 18 previously ignored, 0 failures** across the compiler unit tests, Expected/UI suites, and relevant Stubbing/FunctionContracts tests. - Standard-library, verified-stub, and specialization regressions were checked with the solver, including expected negative results. - Confirmed that the corresponding reproductions fail during resolution on the unmodified upstream baseline. - Build, formatting, and Clippy checks pass locally. - Full repository CI has not been run locally. ## Related issues and work Closes model-checking#4908. This resolves the trait method generic-argument resolution limitation affecting `#[kani::stub]`, `#[kani::stub_verified]`, and `#[kani::proof_for_contract]`. This is a follow-up to model-checking#4587, which introduced trait method implementation stubbing. It is separate from model-checking#4999 (const-generic self-type ICE handling), model-checking#4986 (trait-object argument resolution), and model-checking#5116 (contract attributes on specialization `default fn` methods). Trait-level const generic arguments remain unsupported in this resolution path. Paths still require appropriate qualification or imports. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.


Resolves #4998
A
proof_for_contractorstubtarget whose self type has a const generic parameter made kani-compiler panic during compilation instead of reporting an error. For example, withstruct Buf<const N: usize>, the target<Buf<4> as Get>::gethit an internalcannot find N/#0 in param-envpanic.The panic is in
Instance::resolve: this resolver does not instantiate const arguments, so a const-generic self type reaches instance resolution with a free const parameter and ICEs.The guard sits at that call site, in
resolve_in_trait_impl. A const-generic self type is refused there with the resolver's existingUnsupportedPatherror. Inherent-method targets (<Buf<4>>::method) resolve withoutInstance::resolveand are left untouched, so they keep resolving.This errors gracefully. It does not add support for instantiating const arguments.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.