Skip to content

Allow const parameters in array sizes to be unified #60742

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

Merged
merged 17 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Display rather than Debug printing for const mismatch
  • Loading branch information
varkor committed May 28, 2019
commit f13317ca2ee16163ee121fbdf28eb2184840b6dd
2 changes: 1 addition & 1 deletion src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
&format!("trait `{}`", values.found))
}
ConstMismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
write!(f, "expected `{}`, found `{}`", values.expected, values.found)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0308]: mismatched types
--> $DIR/cannot-infer-type-for-const-param.rs:10:22
|
LL | let _ = Foo::<3>([1, 2, 3]);
| ^^^^^^^^^ expected `Const { ty: usize, val: Unevaluated(DefId(0:18 ~ cannot_infer_type_for_const_param[317d]::main[0]::{{constant}}[0]), []) }`, found `Const { ty: usize, val: Scalar(0x0000000000000003) }`
| ^^^^^^^^^ expected `3`, found `3usize`
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 really weird? I assume the 3 is @oli-obk's printing of same-crate anon consts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's because it can't infer the specific type, rather than an issue with printing. This is a bug, though, which should be fixed by #60839. (Which is ready to go as soon as this one is.)

Copy link
Member

Choose a reason for hiding this comment

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

I mean that the printing output is from Unevaluated for the 3 in Foo::<3> and not the value 3.

Copy link
Contributor

Choose a reason for hiding this comment

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

ugh, ok I did not envision user facing effects from that. So.... should I just do _ or {{unevaluated}} or sth?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to jump to something else here, but we should consider it carefully.
_ is clearly the conservative choice, as for "unevaluated" - I don't like that name too much, it just happened to be useful in ty::Const (and we could/should pick another name).

|
= note: expected type `[u8; _]`
found type `[u8; 3]`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-array-oob-arith.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/const-array-oob-arith.rs:7:45
|
LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5];
| ^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000002) }`, found `Const { ty: usize, val: Scalar(0x0000000000000001) }`
| ^^^ expected `2usize`, found `1usize`
|
= note: expected type `[i32; 2]`
found type `[i32; 1]`
Expand All @@ -11,7 +11,7 @@ error[E0308]: mismatched types
--> $DIR/const-array-oob-arith.rs:8:44
|
LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99];
| ^^^^^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000001) }`, found `Const { ty: usize, val: Scalar(0x0000000000000002) }`
| ^^^^^^^ expected `1usize`, found `2usize`
|
= note: expected type `[i32; 1]`
found type `[i32; 2]`
Expand Down