Should the ConstArgHasType bound above be included in PrarmEnv (query from param_env_reveal_all_normalized)?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
fn parse_test<const LEN: usize>(path: [&'static str; LEN]) {
let target = ["doc"];
if target.iter().eq(&path) {
println!("get target str");
}
}
fn main() {
parse_test(["doc"]);
}
I am implementing an algorithm for function call detection,I identify function calls by iterating over the terminator in the MIR of the function body,recursively detect the functions called by each function
When I get an instance, I use this logic to detect the function it calls (callee)
fn callees_of<'tcx>(bcx: BtyCtxt<'_, 'tcx>, instance: ty::Instance<'tcx>) -> &'tcx Callees<'tcx> {
let param_env = bcx.tcx.param_env_reveal_all_normalized(instance.def_id());
let mir_body = bcx.instance_mir_expect(instance.def);
let callees = Callees::from_raw_mut(
bcx.tcx
.arena
.dropless
.alloc_from_iter(mir_body.basic_blocks.indices().map(|_| Default::default())),
);
... detect logic ...
}
I expected to see this happen: Can correctly obtain the normalize instance
Instead, this happened: In the above example, the bounds of paramenv contains a Binder { value: ConstArgHasType(LEN/#0, usize), bound_vars: [] } When I try to normalize this instance (I think only after normalization can I determine what function it calls) rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively -> <rustc_middle::ty::sty::ParamConst>::find_ty_from_env Function not included in paramenvConstArgHasTypeThis type is panic
Meta
rustc --version --verbose:
nightly-2024-10-09
Backtrace
<backtrace>
I want to know if my usage of getting ParamEnv is wrong, or I should merge ParamEnv and add Cosnt bound to ParamEnv (if so, I hope you can tell me how to merge ParamEnv)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Rust reproducer and the callees_of entry point, then inspect param_env_reveal_all_normalized and the reported rustc_trait_selection::traits::select::SelectionContext path. Determine whether ConstArgHasType should be represented in the ParamEnv or whether the caller is using the API incorrectly. Done means the behavior is established and the reproducer no longer reaches the reported panic, with an appropriate regression test if the issue identifies its location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100