Skip to content

Commit f04f97c

Browse files
authored
Rollup merge of #106820 - m-ou-se:macro-type-error-thing, r=estebank
Deprioritize fulfillment errors that come from expansions. Fixes (part of?) #69455
2 parents 4313471 + 6821adb commit f04f97c

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
454454
}
455455
}
456456

457-
for (error, suppressed) in iter::zip(errors, is_suppressed) {
458-
if !suppressed {
459-
self.report_fulfillment_error(error, body_id);
457+
for from_expansion in [false, true] {
458+
for (error, suppressed) in iter::zip(errors, &is_suppressed) {
459+
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
460+
self.report_fulfillment_error(error, body_id);
461+
}
460462
}
461463
}
462464

tests/ui/inference/cannot-infer-partial-try-return.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0282]: type annotations needed
22
--> $DIR/cannot-infer-partial-try-return.rs:20:9
33
|
4-
LL | infallible()?;
5-
| ------------- type must be known at this point
64
LL | Ok(())
75
| ^^ cannot infer type of the type parameter `E` declared on the enum `Result`
86
|

tests/ui/inference/question-mark-type-infer.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/question-mark-type-infer.rs:10:30
2+
--> $DIR/question-mark-type-infer.rs:10:21
33
|
44
LL | l.iter().map(f).collect()?
5-
| ^ cannot infer type
5+
| ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | l.iter().map(f).collect::<Vec<_>>()?
10+
| ++++++++++
611

712
error: aborting due to previous error
813

tests/ui/issues/issue-69455.stderr

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
error[E0282]: type annotations needed
2-
--> $DIR/issue-69455.rs:29:20
1+
error[E0284]: type annotations needed
2+
--> $DIR/issue-69455.rs:29:41
33
|
44
LL | println!("{}", 23u64.test(xs.iter().sum()));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `new_display`
5+
| ---- ^^^ cannot infer type of the type parameter `S` declared on the associated function `sum`
6+
| |
7+
| type must be known at this point
68
|
7-
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
= note: cannot satisfy `<u64 as Test<_>>::Output == _`
810
help: consider specifying the generic argument
911
|
10-
LL | println!("{}", 23u64.test(xs.iter().sum())::<T>);
11-
| +++++
12+
LL | println!("{}", 23u64.test(xs.iter().sum::<S>()));
13+
| +++++
1214

1315
error[E0283]: type annotations needed
1416
--> $DIR/issue-69455.rs:29:41
@@ -33,5 +35,5 @@ LL | println!("{}", 23u64.test(xs.iter().sum::<S>()));
3335

3436
error: aborting due to 2 previous errors
3537

36-
Some errors have detailed explanations: E0282, E0283.
37-
For more information about an error, try `rustc --explain E0282`.
38+
Some errors have detailed explanations: E0283, E0284.
39+
For more information about an error, try `rustc --explain E0283`.

tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `(Vec<T>,)`
22
--> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9
33
|
44
LL | let (x, ) = (vec![], );
5-
| ^^^^^
5+
| ^^^^^ ---------- type must be known at this point
66
|
77
help: consider giving this pattern a type, where the type for type parameter `T` is specified
88
|

0 commit comments

Comments
 (0)