diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-01-14 18:45:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-14 18:45:27 +0100 |
| commit | f04f97cea4823aec0f412007a0c068fbccc37596 (patch) | |
| tree | 4e364895ba44c6a470e0bacfdb9ff91ce5a41306 | |
| parent | 43134714f529d087aecb8c6327ca282c2fa261f1 (diff) | |
| parent | 6821adb65145463ffe51e044cbe37ea823059222 (diff) | |
| download | rust-f04f97cea4823aec0f412007a0c068fbccc37596.tar.gz rust-f04f97cea4823aec0f412007a0c068fbccc37596.zip | |
Rollup merge of #106820 - m-ou-se:macro-type-error-thing, r=estebank
Deprioritize fulfillment errors that come from expansions. Fixes (part of?) #69455
5 files changed, 23 insertions, 16 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 41a64a844ce..9fcf02e8dc0 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -454,9 +454,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - for (error, suppressed) in iter::zip(errors, is_suppressed) { - if !suppressed { - self.report_fulfillment_error(error, body_id); + for from_expansion in [false, true] { + for (error, suppressed) in iter::zip(errors, &is_suppressed) { + if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion { + self.report_fulfillment_error(error, body_id); + } } } diff --git a/tests/ui/inference/cannot-infer-partial-try-return.stderr b/tests/ui/inference/cannot-infer-partial-try-return.stderr index 2a56aaa44fe..888c321bc47 100644 --- a/tests/ui/inference/cannot-infer-partial-try-return.stderr +++ b/tests/ui/inference/cannot-infer-partial-try-return.stderr @@ -1,8 +1,6 @@ error[E0282]: type annotations needed --> $DIR/cannot-infer-partial-try-return.rs:20:9 | -LL | infallible()?; - | ------------- type must be known at this point LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | diff --git a/tests/ui/inference/question-mark-type-infer.stderr b/tests/ui/inference/question-mark-type-infer.stderr index 9b822714f82..a9cb7e5257c 100644 --- a/tests/ui/inference/question-mark-type-infer.stderr +++ b/tests/ui/inference/question-mark-type-infer.stderr @@ -1,8 +1,13 @@ error[E0282]: type annotations needed - --> $DIR/question-mark-type-infer.rs:10:30 + --> $DIR/question-mark-type-infer.rs:10:21 | LL | l.iter().map(f).collect()? - | ^ cannot infer type + | ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect` + | +help: consider specifying the generic argument + | +LL | l.iter().map(f).collect::<Vec<_>>()? + | ++++++++++ error: aborting due to previous error diff --git a/tests/ui/issues/issue-69455.stderr b/tests/ui/issues/issue-69455.stderr index 9d11cf19ea7..fc343bb54aa 100644 --- a/tests/ui/issues/issue-69455.stderr +++ b/tests/ui/issues/issue-69455.stderr @@ -1,14 +1,16 @@ -error[E0282]: type annotations needed - --> $DIR/issue-69455.rs:29:20 +error[E0284]: type annotations needed + --> $DIR/issue-69455.rs:29:41 | LL | println!("{}", 23u64.test(xs.iter().sum())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `new_display` + | ---- ^^^ cannot infer type of the type parameter `S` declared on the associated function `sum` + | | + | type must be known at this point | - = 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) + = note: cannot satisfy `<u64 as Test<_>>::Output == _` help: consider specifying the generic argument | -LL | println!("{}", 23u64.test(xs.iter().sum())::<T>); - | +++++ +LL | println!("{}", 23u64.test(xs.iter().sum::<S>())); + | +++++ error[E0283]: type annotations needed --> $DIR/issue-69455.rs:29:41 @@ -33,5 +35,5 @@ LL | println!("{}", 23u64.test(xs.iter().sum::<S>())); error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0283. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0283, E0284. +For more information about an error, try `rustc --explain E0283`. diff --git a/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr index be60cda68b9..e544b369515 100644 --- a/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr +++ b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `(Vec<T>,)` --> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9 | LL | let (x, ) = (vec![], ); - | ^^^^^ + | ^^^^^ ---------- type must be known at this point | help: consider giving this pattern a type, where the type for type parameter `T` is specified | |
