Skip to content

Improve errors on const mismatches#90987

Closed
b-naber wants to merge 11 commits intorust-lang:masterfrom
b-naber:const-type-mismatch-diagnostics
Closed

Improve errors on const mismatches#90987
b-naber wants to merge 11 commits intorust-lang:masterfrom
b-naber:const-type-mismatch-diagnostics

Conversation

@b-naber
Copy link
Contributor

@b-naber b-naber commented Nov 17, 2021

Fixes #86198

This allows us to suggest a correct anonymous constant in case there's a mismatch, e.g. in:

trait Trait {}
struct HasCastInTraitImpl<const N: usize, const M: usize>;
impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
pub struct HasTrait<T: Trait>(T);
fn foo<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1 }, { N + 1}>> { loop {} }

we now get a mismatch const error of the following form:

error[E0308]: mismatched types
  --> $DIR/mismatched-const-errors.rs:15:30
   |
LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ N + 1 + 1 }`
   |
   = note: expected type `{ N + 1 }`
              found type `{ N + 1 + 1 }`

instead of the found { M + 1 } constant that was previously output.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generic const exprs in diagnostics aren't printed with substs applied

9 participants