-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
We currently don't store the origin of const inference variables. This is needed to emit more helpful error messages.
For type inference variables, this is done using https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/struct.InferCtxtInner.html#method.type_variables and then
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/type_variable/struct.TypeVariableTable.html#method.var_origin.
We use this to provide better diagnostics in case type inference fails:
rust/src/librustc_infer/infer/error_reporting/need_type_info.rs
Lines 198 to 201 in 9912925
let ty_vars = &inner.type_variables(); | |
let var_origin = ty_vars.var_origin(ty_vid); | |
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind { | |
let parent_def_id = def_id.and_then(|def_id| self.tcx.parent(def_id)); |
A similar mechanism should probably also be used for consts.
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
varkor commentedon Sep 13, 2020
It would be good to have some examples of where diagnostics are subpar because of this missing feature, to decide if it's a prerequisite for stabilising
min_const_generics
.lcnr commentedon Sep 13, 2020
yeah, will look a bit into some interesting test cases here in the near future hopefully
lcnr commentedon Sep 14, 2020
One issue here is something like this:
which results in
for
baz<T>
we instead getbtw I am not actually sure if this issue makes sense, we already have the origin of const infer values stored, so
I don't actually think we need to add a new storage here 😆 we "just" have to use the current one
pickfire commentedon Sep 14, 2020
Is there any suggestion for user on how to fix this?
8 remaining items