Skip to content

Fix duplicated type annotation suggestion #99075

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 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,14 @@ impl Diagnostic {
self
}

/// Clear any existing suggestions.
pub fn clear_suggestions(&mut self) -> &mut Self {
if let Ok(suggestions) = &mut self.suggestions {
suggestions.clear();
}
self
}

/// Helper for pushing to `self.suggestions`, if available (not disable).
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
if let Ok(suggestions) = &mut self.suggestions {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);

forward!(pub fn disable_suggestions(&mut self,) -> &mut Self);
forward!(pub fn clear_suggestions(&mut self,) -> &mut Self);

forward!(pub fn multipart_suggestion(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
// |
// = note: cannot satisfy `_: Tt`

// Clear any more general suggestions in favor of our specific one
err.clear_suggestions();

err.span_suggestion_verbose(
span.shrink_to_hi(),
&format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ LL | #[derive(SessionDiagnostic)]
|
= help: normalized in stderr
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:538:19
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:539:19
|
LL | arg: impl IntoDiagnosticArg,
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
Expand Down
8 changes: 0 additions & 8 deletions src/test/ui/inference/erase-type-params-in-label.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ note: required by a bound in `foo`
|
LL | fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
| ^^^^^^^ required by this bound in `foo`
help: consider giving `foo` an explicit type, where the type for type parameter `W` is specified
|
LL | let foo: Foo<i32, &str, W, Z> = foo(1, "");
| ++++++++++++++++++++++
help: consider specifying the type arguments in the function call
|
LL | let foo = foo::<T, K, W, Z>(1, "");
Expand All @@ -31,10 +27,6 @@ note: required by a bound in `bar`
|
LL | fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
| ^^^^^^^ required by this bound in `bar`
help: consider giving `bar` an explicit type, where the type for type parameter `Z` is specified
|
LL | let bar: Bar<i32, &str, Z> = bar(1, "");
| +++++++++++++++++++
help: consider specifying the type arguments in the function call
|
LL | let bar = bar::<T, K, Z>(1, "");
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/inference/issue-71732.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ note: required by a bound in `HashMap::<K, V, S>::get`
|
LL | K: Borrow<Q>,
| ^^^^^^^^^ required by this bound in `HashMap::<K, V, S>::get`
help: consider specifying the generic argument
|
LL | .get::<Q>(&"key".into())
| +++++
help: consider specifying the type argument in the function call
|
LL | .get::<Q>(&"key".into())
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/traits/issue-77982.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ note: required by a bound in `HashMap::<K, V, S>::get`
|
LL | K: Borrow<Q>,
| ^^^^^^^^^ required by this bound in `HashMap::<K, V, S>::get`
help: consider specifying the generic argument
|
LL | opts.get::<Q>(opt.as_ref());
| +++++
help: consider specifying the type argument in the function call
|
LL | opts.get::<Q>(opt.as_ref());
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/traits/multidispatch-convert-ambig-dest.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ LL | fn test<T,U>(_: T, _: U)
| ---- required by a bound in this
LL | where T : Convert<U>
| ^^^^^^^^^^ required by this bound in `test`
help: consider specifying the generic arguments
|
LL | test::<i32, U>(22, std::default::Default::default());
| ++++++++++
help: consider specifying the type arguments in the function call
|
LL | test::<T, U>(22, std::default::Default::default());
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/type/type-annotation-needed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ note: required by a bound in `foo`
|
LL | fn foo<T: Into<String>>(x: i32) {}
| ^^^^^^^^^^^^ required by this bound in `foo`
help: consider specifying the generic argument
|
LL | foo::<T>(42);
| +++++
help: consider specifying the type argument in the function call
|
LL | foo::<T>(42);
Expand Down