Skip to content

Commit 759ebda

Browse files
authored
Rollup merge of rust-lang#49262 - oli-obk:fixed_size_array_len, r=estebank
Produce nice array lengths on a best effort basis fixes rust-lang#49208 r? @estebank
2 parents 1247bef + b48a26c commit 759ebda

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

src/librustc/traits/error_reporting.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
443443
} else {
444444
4
445445
};
446+
447+
let normalize = |candidate| self.tcx.global_tcx().infer_ctxt().enter(|ref infcx| {
448+
let normalized = infcx
449+
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
450+
.normalize(candidate)
451+
.ok();
452+
match normalized {
453+
Some(normalized) => format!("\n {:?}", normalized.value),
454+
None => format!("\n {:?}", candidate),
455+
}
456+
});
457+
446458
err.help(&format!("the following implementations were found:{}{}",
447-
&impl_candidates[0..end].iter().map(|candidate| {
448-
format!("\n {:?}", candidate)
449-
}).collect::<String>(),
459+
&impl_candidates[0..end].iter().map(normalize).collect::<String>(),
450460
if impl_candidates.len() > 5 {
451461
format!("\nand {} others", impl_candidates.len() - 4)
452462
} else {

src/librustc/ty/sty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
16701670
pub struct Const<'tcx> {
16711671
pub ty: Ty<'tcx>,
16721672

1673-
// FIXME(eddyb) Replace this with a miri value.
16741673
pub val: ConstVal<'tcx>,
16751674
}
16761675

src/librustc/util/ppaux.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,8 @@ define_print! {
11771177
ConstVal::Value(Value::ByVal(PrimVal::Bytes(sz))) => {
11781178
write!(f, "{}", sz)?;
11791179
}
1180-
ConstVal::Unevaluated(_def_id, substs) => {
1181-
write!(f, "<unevaluated{:?}>", &substs[..])?;
1180+
ConstVal::Unevaluated(_def_id, _substs) => {
1181+
write!(f, "_")?;
11821182
}
11831183
_ => {
11841184
write!(f, "{:?}", sz)?;

src/test/ui/did_you_mean/bad-assoc-ty.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ error[E0223]: ambiguous associated type
4646
LL | type A = [u8; 4]::AssocTy;
4747
| ^^^^^^^^^^^^^^^^ ambiguous associated type
4848
|
49-
= note: specify the type using the syntax `<[u8; <unevaluated[]>] as Trait>::AssocTy`
49+
= note: specify the type using the syntax `<[u8; _] as Trait>::AssocTy`
5050

5151
error[E0223]: ambiguous associated type
5252
--> $DIR/bad-assoc-ty.rs:15:10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// https://github.com/rust-lang/rust/issues/49208
12+
13+
trait Foo {
14+
fn foo();
15+
}
16+
17+
impl Foo for [(); 1] {
18+
fn foo() {}
19+
}
20+
21+
fn main() {
22+
<[(); 0] as Foo>::foo() //~ ERROR E0277
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `[(); 0]: Foo` is not satisfied
2+
--> $DIR/unevaluated_fixed_size_array_len.rs:22:5
3+
|
4+
LL | <[(); 0] as Foo>::foo() //~ ERROR E0277
5+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[(); 0]`
6+
|
7+
= help: the following implementations were found:
8+
<[(); 1] as Foo>
9+
note: required by `Foo::foo`
10+
--> $DIR/unevaluated_fixed_size_array_len.rs:14:5
11+
|
12+
LL | fn foo();
13+
| ^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)