Skip to content

Fix typo in hir lowering lint diag #138518

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
Mar 15, 2025
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
6 changes: 4 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Applicability::MachineApplicable,
);
if !is_dyn_compatible {
diag.note(format!("`{trait_name}` it is dyn-incompatible, so it can't be `dyn`"));
diag.note(format!(
"`{trait_name}` is dyn-incompatible, otherwise a trait object could be used"
));
} else {
// No ampersand in suggestion if it's borrowed already
let (dyn_str, paren_dyn_str) =
if borrowed { ("dyn ", "(dyn ") } else { ("&dyn ", "&(dyn ") };

let sugg = if let hir::TyKind::TraitObject([_, _, ..], _) = self_ty.kind {
// There are more than one trait bound, we need surrounding parentheses.
// There is more than one trait bound, we need surrounding parentheses.
vec![
(self_ty.span.shrink_to_lo(), paren_dyn_str.to_string()),
(self_ty.span.shrink_to_hi(), ")".to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn id<F>(f: Copy) -> usize {
| ^^^^
|
= note: `Copy` it is dyn-incompatible, so it can't be `dyn`
= note: `Copy` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `Copy`
|
LL - fn id<F>(f: Copy) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/dyn-compatibility/avoid-ice-on-warning-3.new.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | trait A { fn g(b: B) -> B; }
| ^
|
= note: `B` it is dyn-incompatible, so it can't be `dyn`
= note: `B` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `B`
|
LL - trait A { fn g(b: B) -> B; }
Expand Down Expand Up @@ -32,7 +32,7 @@ error[E0782]: expected a type, found a trait
LL | trait B { fn f(a: A) -> A; }
| ^
|
= note: `A` it is dyn-incompatible, so it can't be `dyn`
= note: `A` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `A`
|
LL - trait B { fn f(a: A) -> A; }
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn concrete(b: B) -> B;
| ^
|
= note: `B` it is dyn-incompatible, so it can't be `dyn`
= note: `B` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `B`
|
LL - fn concrete(b: B) -> B;
Expand Down Expand Up @@ -32,7 +32,7 @@ error[E0782]: expected a type, found a trait
LL | fn f(a: A) -> A;
| ^
|
= note: `A` it is dyn-incompatible, so it can't be `dyn`
= note: `A` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `A`
|
LL - fn f(a: A) -> A;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rust-2021/ice-return-unsized-can-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn g(new: B) -> B;
| ^
|
= note: `B` it is dyn-incompatible, so it can't be `dyn`
= note: `B` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `B`
|
LL - fn g(new: B) -> B;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rust-2021/ice-unsized-fn-params-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn guard(_s: Copy) -> bool {
| ^^^^
|
= note: `Copy` it is dyn-incompatible, so it can't be `dyn`
= note: `Copy` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `Copy`
|
LL - fn guard(_s: Copy) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/rust-2021/ice-unsized-fn-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn g(b: B) -> B;
| ^
|
= note: `B` it is dyn-incompatible, so it can't be `dyn`
= note: `B` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `B`
|
LL - fn g(b: B) -> B;
Expand Down Expand Up @@ -32,7 +32,7 @@ error[E0782]: expected a type, found a trait
LL | fn f(a: A) -> A;
| ^
|
= note: `A` it is dyn-incompatible, so it can't be `dyn`
= note: `A` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `A`
|
LL - fn f(a: A) -> A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0782]: expected a type, found a trait
LL | fn f(a: A) -> A;
| ^
|
= note: `A` it is dyn-incompatible, so it can't be `dyn`
= note: `A` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `A`
|
LL - fn f(a: A) -> A;
Expand Down Expand Up @@ -32,7 +32,7 @@ error[E0782]: expected a type, found a trait
LL | fn f(b: B) -> B;
| ^
|
= note: `B` it is dyn-incompatible, so it can't be `dyn`
= note: `B` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `B`
|
LL - fn f(b: B) -> B;
Expand Down Expand Up @@ -60,7 +60,7 @@ error[E0782]: expected a type, found a trait
LL | fn f(&self, c: C) -> C;
| ^
|
= note: `C` it is dyn-incompatible, so it can't be `dyn`
= note: `C` is dyn-incompatible, otherwise a trait object could be used
help: use a new generic type parameter, constrained by `C`
|
LL - fn f(&self, c: C) -> C;
Expand Down
Loading