Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors on const mismatches #90987

Closed

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.

@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 17, 2021
@b-naber
Copy link
Contributor Author

b-naber commented Nov 17, 2021

r? @BoxyUwU

@rust-highfive rust-highfive assigned BoxyUwU and unassigned jackh726 Nov 17, 2021
@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from d7d3787 to 978b853 Compare November 17, 2021 20:06
@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 978b853 to c3d3f4d Compare November 17, 2021 20:38
LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs updating to print out with substs applied too

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@b-naber
Copy link
Contributor Author

b-naber commented Nov 18, 2021

Don't see why CI fails, I did bless those tests.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 18, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 18, 2021

Can you check if this handles precedence right 🤔
if we have a const mismatch of like 3 * 2 + N and 3 * M where M is 2 + N i.e.

fn foo<const M: usize>() -> [(); 3 * M];
let _: [(); 3 * 2 + N] foo::<{ 2 + N }>();

do we get a silly error message like expected `3 * 2 + N` found `3 * 2 + N`

@b-naber
Copy link
Contributor Author

b-naber commented Nov 19, 2021

yeah we do, but I think it shouldn't be too hard to include precedence of operations here when constructing the suggestion. I can try that.

@bors
Copy link
Contributor

bors commented Nov 21, 2021

☔ The latest upstream changes (presumably #91104) made this pull request unmergeable. Please resolve the merge conflicts.

@b-naber
Copy link
Contributor Author

b-naber commented Nov 23, 2021

Taking precedence into account when applying substitutions is anything but straightforward. I'd prefer to do this in another PR, since this is basically more effort than the original PR.

For now I'd suggest we just fall back to the unsubstituted suggestion, in case we would output the same suggestion as the error.

@b-naber
Copy link
Contributor Author

b-naber commented Nov 23, 2021

@BoxyUwU Would that be ok for you?

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 03909d7 to 27facbf Compare November 24, 2021 16:54
@b-naber
Copy link
Contributor Author

b-naber commented Nov 24, 2021

Did decide to implement this, wasn't as hard as I initially thought.

@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 27facbf to 517c887 Compare November 24, 2021 17:17
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 517c887 to 08f70c5 Compare November 24, 2021 18:27
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 0ba4a85 to 3e2ee2c Compare November 25, 2021 14:28
@rust-log-analyzer

This comment has been minimized.

@b-naber
Copy link
Contributor Author

b-naber commented Nov 25, 2021

Ok, I only blessed the tests in ui/const-generics, but they all passed in that CI run. So it seems as if for some reason the try_create_suggestion_for_mismatched_const call returns None in CI, but Some(suggestion) locally on my machine. I'm completely flabbergasted as to why that might be. Is const-generics somehow platform dependent?

@bors
Copy link
Contributor

bors commented Dec 16, 2021

☔ The latest upstream changes (presumably #91996) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines 287 to 298
ty::ConstKind::Value(ConstValue::Scalar(scalar)) => match scalar.to_i64() {
Ok(s) => {
let s = format!("{}", s);

if applied_subst {
return Some(PrintStyle::Braces(None, s));
} else {
return Some(PrintStyle::NoBraces(s));
}
}
Err(_) => return None,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the cause of the CI failures. the CI is failing on 32 bit stuff which means if we have a usize scalar here and call .to_i64 we get an InterpErrorInfo(InterpErrorInfoInner { kind: scalar size mismatch: expected 8 bytes but got 4 bytes instead, backtrace: None }) from this call but on 64bit it works fine because the sizes match.

the docs for to_i64 say "Fails if the scalar is a pointer" but I guess that is wrong .-.
this code would also just be wrong if the scalar was a u128 or something since those values cant all fit in a i128

not sure exactly what the right thing to replace this with is but we surely have code somewhere for printing this out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a great catch. I'll try to figure out how to handle this correctly here.

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from a5e50e3 to 57d137e Compare December 24, 2021 14:29
@rust-log-analyzer

This comment has been minimized.

@b-naber
Copy link
Contributor Author

b-naber commented Dec 24, 2021

For some reason I had to add the Cargo.lock file during the rebase (otherwise it wouldn't allow the rebase to continue). This seems to cause problems with CI now. What am I supposed to do here?

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 57d137e to 6ed9dfd Compare December 28, 2021 09:18
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the const-type-mismatch-diagnostics branch from 6ed9dfd to 7b72ba8 Compare December 28, 2021 11:08
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 1600/12522
i................................................................................................... 1700/12522
.................................................................................................... 1800/12522
............i....................................................................................... 1900/12522
.F............................................F..................................................... 2000/12522
..............................................FF.................................................... 2200/12522
...............................................................................................i.... 2300/12522
.......................................................................................ii........... 2400/12522
.................................................................................................... 2500/12522
---

---- [ui] ui/const-generics/defaults/generic-expr-default.rs stdout ----
diff of stderr:

4 LL | pub fn needs_evaluatable_bound<const N1: usize>() -> Foo<N1> {
6    |
6    |
-    = help: try adding a `where` bound using this expression: `where [(); { N1 + 1 }]:`
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=i686-unknown-linux-gnu
+    = help: try adding a `where` bound using this expression: `where [(); { N + 1 }]:`
9 error: unconstrained generic constant
10   --> $DIR/generic-expr-default.rs:14:58



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/defaults/generic-expr-default/generic-expr-default.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/defaults/generic-expr-default.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/defaults/generic-expr-default.rs" "-Zthreads=1" "--target=i686-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/defaults/generic-expr-default" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/defaults/generic-expr-default/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/defaults/generic-expr-default.rs:5:54
   |
LL | pub fn needs_evaluatable_bound<const N1: usize>() -> Foo<N1> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { N + 1 }]:`
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/defaults/generic-expr-default.rs:14:58
   |
   |
LL | fn needs_evaluatable_bound_alias<T, const N: usize>() -> FooAlias<N>
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { N + 1 }]:`
error: aborting due to 2 previous errors


------------------------------------------
------------------------------------------


---- [ui] ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs#full stdout ----
diff of stderr:

4 LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
6    |
6    |
-    = help: try adding a `where` bound using this expression: `where [(); { 0 + N }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 0 + N]:`
9 error: overly complex generic constant
10   --> $DIR/array-size-in-generic-struct-param.rs:19:15



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full/array-size-in-generic-struct-param.full.stderr
To only update this specific test, also pass `--test-args const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs`


error in revision `full`: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs" "-Zthreads=1" "--target=i686-unknown-linux-gnu" "--cfg" "full" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs:8:38
   |
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); 0 + N]:`
error: overly complex generic constant
  --> /checkout/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs:19:15
   |
   |
LL |     arr: [u8; CFG.arr_size],
   |               ^^^^^^^^^^^^ field access is not supported in generic constant
   |
   = help: consider moving this anonymous constant into a `const` function

error: aborting due to 2 previous errors



------------------------------------------


---- [ui] ui/const-generics/mismatched-const-errors.rs stdout ----
diff of stderr:

4 LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
6    |
6    |
-    = help: try adding a `where` bound using this expression: `where [(); { N + 2 + 1 }]:`
+    = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
8 note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 2}, N>`
10    |

20   --> $DIR/mismatched-const-errors.rs:9:30
21    |
21    |
22 LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
-    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ N + 2 + 1 }`
+    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ M + 1 }`
25    = note: expected type `N`
25    = note: expected type `N`
-               found type `{ N + 2 + 1 }`
+               found type `{ M + 1 }`
28 error: unconstrained generic constant
29   --> $DIR/mismatched-const-errors.rs:15:30


31 LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
33    |
33    |
-    = help: try adding a `where` bound using this expression: `where [(); { N + 1 + 1 }]:`
+    = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
35 note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N + 1 }>`
37    |

47   --> $DIR/mismatched-const-errors.rs:15:30
48    |
48    |
49 LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
-    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ N + 1 + 1 }`
+    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ M + 1 }`
51    |
52    = note: expected type `{ N + 1 }`
-               found type `{ N + 1 + 1 }`
+               found type `{ M + 1 }`
55 error: unconstrained generic constant
56   --> $DIR/mismatched-const-errors.rs:21:30


58 LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
60    |
60    |
-    = help: try adding a `where` bound using this expression: `where [(); { N + 1 + 1 }]:`
+    = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
62 note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N - 1}>`
64    |

74   --> $DIR/mismatched-const-errors.rs:21:30
75    |
75    |
76 LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
-    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N - 1}`, found `{ N + 1 + 1 }`
+    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N - 1}`, found `{ M + 1 }`
78    |
79    = note: expected type `{ N - 1}`
-               found type `{ N + 1 + 1 }`
+               found type `{ M + 1 }`
82 error: unconstrained generic constant
83   --> $DIR/mismatched-const-errors.rs:27:44


85 LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
87    |
87    |
-    = help: try adding a `where` bound using this expression: `where [(); { N - 1 + 1 }]:`
+    = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
89 note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N - 1}, N>`
91    |

101   --> $DIR/mismatched-const-errors.rs:27:44
102    |
102    |
103 LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
-    |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ N - 1 + 1 }`
+    |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ M + 1 }`
106    = note: expected type `N`
106    = note: expected type `N`
-               found type `{ N - 1 + 1 }`
+               found type `{ M + 1 }`
109 error: unconstrained generic constant
110   --> $DIR/mismatched-const-errors.rs:33:30


112 LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
114    |
114    |
-    = help: try adding a `where` bound using this expression: `where [(); { N + N + 1 }]:`
+    = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
116 note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + N }, { 2 * N }>`
118    |

128   --> $DIR/mismatched-const-errors.rs:33:30
129    |
129    |
130 LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
-    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ 2 * N }`, found `{ N + N + 1 }`
+    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ 2 * N }`, found `{ M + 1 }`
132    |
133    = note: expected type `{ 2 * N }`
-               found type `{ N + N + 1 }`
+               found type `{ M + 1 }`
136 error: aborting due to 10 previous errors
137 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-errors/mismatched-const-errors.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/mismatched-const-errors.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/mismatched-const-errors.rs" "-Zthreads=1" "--target=i686-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-errors" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-errors/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:9:30
   |
LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 2}, N>`
   |
   |
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
   |                      ^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `HasTrait`
   |
   |
LL | pub struct HasTrait<T: Trait>(T);
   |                        ^^^^^ required by this bound in `HasTrait`
error[E0308]: mismatched types
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:9:30
   |
   |
LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ M + 1 }`
   = note: expected type `N`
   = note: expected type `N`
              found type `{ M + 1 }`
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:15:30
   |
   |
LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N + 1 }>`
   |
   |
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
   |                      ^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `HasTrait`
   |
   |
LL | pub struct HasTrait<T: Trait>(T);
   |                        ^^^^^ required by this bound in `HasTrait`
error[E0308]: mismatched types
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:15:30
   |
   |
LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ M + 1 }`
   |
   = note: expected type `{ N + 1 }`
              found type `{ M + 1 }`
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:21:30
   |
   |
LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N - 1}>`
   |
   |
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
   |                      ^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `HasTrait`
   |
   |
LL | pub struct HasTrait<T: Trait>(T);
   |                        ^^^^^ required by this bound in `HasTrait`
error[E0308]: mismatched types
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:21:30
   |
   |
LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N - 1}`, found `{ M + 1 }`
   |
   = note: expected type `{ N - 1}`
              found type `{ M + 1 }`
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:27:44
   |
   |
LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N - 1}, N>`
   |
   |
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
   |                      ^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `HasTrait`
   |
   |
LL | pub struct HasTrait<T: Trait>(T);
   |                        ^^^^^ required by this bound in `HasTrait`
error[E0308]: mismatched types
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:27:44
   |
   |
LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
   |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ M + 1 }`
   = note: expected type `N`
   = note: expected type `N`
              found type `{ M + 1 }`
error: unconstrained generic constant
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:33:30
   |
   |
LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
   |
   |
   = help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + N }, { 2 * N }>`
   |
   |
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
   |                      ^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `HasTrait`
   |
   |
LL | pub struct HasTrait<T: Trait>(T);
   |                        ^^^^^ required by this bound in `HasTrait`
error[E0308]: mismatched types
  --> /checkout/src/test/ui/const-generics/mismatched-const-errors.rs:33:30
   |
   |
LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ 2 * N }`, found `{ M + 1 }`
   |
   = note: expected type `{ 2 * N }`
              found type `{ M + 1 }`
error: aborting due to 10 previous errors

For more information about this error, try `rustc --explain E0308`.


------------------------------------------


---- [ui] ui/const-generics/mismatched-const-types-precedence.rs stdout ----
diff of stderr:

4 LL |   let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
6    |
6    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N + K } }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * {M + K}]:`
8 note: required by a bound in `foo`
10    |


17 LL |   let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
19    |
19    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N + K }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * 2 + N + K]:`
22 error[E0308]: mismatched types
23   --> $DIR/mismatched-const-types-precedence.rs:6:33

24    |
24    |
25 LL |   let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
-    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N + K`, found `{ 3 * { 2 + N + K } }`
+    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N + K`, found `3 * {M + K}`
27    |
28    = note: expected type `3 * 2 + N + K`
-               found type `{ 3 * { 2 + N + K } }`
+               found type `3 * {M + K}`
31 error: unconstrained generic constant
32   --> $DIR/mismatched-const-types-precedence.rs:6:33


34 LL |   let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
36    |
36    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N + K } }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * {M + K}]:`
38 note: required by a bound in `foo`
40    |


55 LL |   let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
57    |
57    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * M * K]:`
59 note: required by a bound in `foo2`
61    |


68 LL |   let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
70    |
70    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N * K }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * 2 + N * K]:`
73 error[E0308]: mismatched types
74   --> $DIR/mismatched-const-types-precedence.rs:18:33

75    |
75    |
76 LL |   let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
-    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K`, found `{ 3 * { 2 + N } * K }`
+    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K`, found `3 * M * K`
78    |
79    = note: expected type `3 * 2 + N * K`
-               found type `{ 3 * { 2 + N } * K }`
+               found type `3 * M * K`
82 error: unconstrained generic constant
83   --> $DIR/mismatched-const-types-precedence.rs:18:33


85 LL |   let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
87    |
87    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * M * K]:`
89 note: required by a bound in `foo2`
91    |


106 LL |   let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
108    |
108    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K + L }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * M * {K + L}]:`
110 note: required by a bound in `foo3`
112    |


121 LL |   let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
123    |
123    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N * K + L }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * 2 + N * K + L]:`
126 error[E0308]: mismatched types
127   --> $DIR/mismatched-const-types-precedence.rs:30:37

128    |
128    |
129 LL |   let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
-    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K + L`, found `{ 3 * { 2 + N } * K + L }`
+    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K + L`, found `3 * M * {K + L}`
131    |
132    = note: expected type `3 * 2 + N * K + L`
-               found type `{ 3 * { 2 + N } * K + L }`
+               found type `3 * M * {K + L}`
135 error: unconstrained generic constant
136   --> $DIR/mismatched-const-types-precedence.rs:30:37


138 LL |   let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
140    |
140    |
-    = help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K + L }]:`
+    = help: try adding a `where` bound using this expression: `where [(); 3 * M * {K + L}]:`
142 note: required by a bound in `foo3`
144    |


The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-types-precedence/mismatched-const-types-precedence.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/mismatched-const-types-precedence.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/mismatched-const-types-precedence.rs" "-Zthreads=1" "--target=i686-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-types-precedence" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mismatched-const-types-precedence/auxiliary"
---
test result: FAILED. 12345 passed; 4 failed; 173 ignored; 0 measured; 0 filtered out; finished in 106.82s



command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/i686-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-i686-unknown-linux-gnu" "--suite" "ui" "--mode" "ui" "--target" "i686-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-12/bin/FileCheck" "--pass" "check" "--nodejs" "/usr/bin/node" "--linker" "cc" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "12.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hellonew hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--channel" "nightly" "--color" "always"


Build completed unsuccessfully in 0:01:49

@bors
Copy link
Contributor

bors commented Jan 4, 2022

☔ The latest upstream changes (presumably #92556) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

Ping from triage:
@b-naber can you post your status on this PR? It has sat idle for almost a month.

@b-naber
Copy link
Contributor Author

b-naber commented Jan 24, 2022

@BoxyUwU Any ideas why try_to_string doesn't work in light of what you said about the origin of the CI failures? I also find it weird that CI passed prior to the 'implement precedence for anon const mismatch' commit even though `to_i64' was used in the 'allow AbstractConsts to be printed' commit already (Actually it looks as if CI never passed). And there isn't any other existing function to print Scalars in non-hex representation.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 26, 2022

Not sure why your code isnt working but I looked around a bit and I think PrettyPrinter::pretty_print_const_scalar can be used to get it printed properly.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2022
@JohnCSimon
Copy link
Member

@b-naber
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Mar 20, 2022
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Mar 20, 2022
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