Skip to content

Commit 5124e06

Browse files
committed
fix issue 144074, having so many same diagnostics makes it hard to recognize the root cause
1 parent 889701d commit 5124e06

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
399399
};
400400

401401
// Check the arguments.
402-
// We do this in a pretty awful way: first we type-check any arguments
403-
// that are not closures, then we type-check the closures. This is so
404-
// that we have more information about the types of arguments when we
405-
// type-check the functions. This isn't really the right way to do this.
402+
// More awful hacks: before we check argument types, try to do
403+
// an "opportunistic" trait resolution of any trait bounds on
404+
// the call. This helps coercions.
405+
self.select_obligations_where_possible(|_| {});
406406
for check_closures in [false, true] {
407-
// More awful hacks: before we check argument types, try to do
408-
// an "opportunistic" trait resolution of any trait bounds on
409-
// the call. This helps coercions.
410-
if check_closures {
411-
self.select_obligations_where_possible(|_| {})
412-
}
413-
414407
// Check each argument, to satisfy the input it was provided for
415408
// Visually, we're traveling down the diagonal of the compatibility matrix
416409
for (idx, arg) in provided_args.iter().enumerate() {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Struct<T>(T);
2+
fn assert_sized(_x: impl Sized) {}
3+
fn f() {
4+
assert_sized(Struct(*"")); //~ ERROR: the size for values of type `str` cannot be known at compilation time
5+
//~^ ERROR: the size for values of type `str` cannot be known at compilation time
6+
}
7+
8+
fn main() {
9+
f();
10+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/issue-144074.rs:4:25
3+
|
4+
LL | assert_sized(Struct(*""));
5+
| ------ ^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Sized` is not implemented for `str`
10+
note: required by a bound in `Struct`
11+
--> $DIR/issue-144074.rs:1:15
12+
|
13+
LL | struct Struct<T>(T);
14+
| ^ required by this bound in `Struct`
15+
help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression
16+
|
17+
LL - assert_sized(Struct(*""));
18+
LL + assert_sized(Struct(""));
19+
|
20+
21+
error[E0277]: the size for values of type `str` cannot be known at compilation time
22+
--> $DIR/issue-144074.rs:4:5
23+
|
24+
LL | assert_sized(Struct(*""));
25+
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
26+
|
27+
= help: the trait `Sized` is not implemented for `str`
28+
note: required by an implicit `Sized` bound in `Struct`
29+
--> $DIR/issue-144074.rs:1:15
30+
|
31+
LL | struct Struct<T>(T);
32+
| ^ required by the implicit `Sized` requirement on this type parameter in `Struct`
33+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
34+
--> $DIR/issue-144074.rs:1:15
35+
|
36+
LL | struct Struct<T>(T);
37+
| ^ - ...if indirection were used here: `Box<T>`
38+
| |
39+
| this could be changed to `T: ?Sized`...
40+
41+
error: aborting due to 2 previous errors
42+
43+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)