Skip to content

Commit 509cb33

Browse files
committed
review comments
1 parent 5b36c18 commit 509cb33

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/librustc/traits/error_reporting/suggestions.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
624624
} else {
625625
// We still want to verify whether all the return types conform to each other.
626626
for expr in &visitor.0 {
627-
if let Some(returned_ty) = tables.node_type_opt(expr.hir_id) {
628-
if let Some(ty) = last_ty {
629-
all_returns_have_same_type &= ty == returned_ty;
630-
}
631-
last_ty = Some(returned_ty);
632-
}
627+
let returned_ty = tables.node_type_opt(expr.hir_id);
628+
all_returns_have_same_type &= last_ty == returned_ty || last_ty.is_none();
629+
last_ty = returned_ty;
633630
}
634631
}
635632

src/librustc_typeck/check/coercion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13721372
&snippet[5..]
13731373
));
13741374
}
1375+
err.help("alternatively, create a new `enum` with a variant for each returned type");
13751376
let impl_trait_msg = "for information on `impl Trait`, see \
13761377
<https://doc.rust-lang.org/book/ch10-02-traits.html\
13771378
#returning-types-that-implement-traits>";

src/test/ui/impl-trait/equality.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LL | 0_u32
1212
|
1313
= note: to return `impl Trait`, all returned values must be of the same type
1414
= help: you can instead return a trait object using `Box<dyn Foo>`
15+
= help: alternatively, create a new `enum` with a variant for each returned type
1516
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
1617
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
1718

src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LL | 1u32
1212
|
1313
= note: to return `impl Trait`, all returned values must be of the same type
1414
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
15+
= help: alternatively, create a new `enum` with a variant for each returned type
1516
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
1617
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
1718

@@ -29,6 +30,7 @@ LL | return 1u32;
2930
|
3031
= note: to return `impl Trait`, all returned values must be of the same type
3132
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
33+
= help: alternatively, create a new `enum` with a variant for each returned type
3234
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
3335
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
3436

@@ -46,6 +48,7 @@ LL | 1u32
4648
|
4749
= note: to return `impl Trait`, all returned values must be of the same type
4850
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
51+
= help: alternatively, create a new `enum` with a variant for each returned type
4952
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
5053
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
5154

@@ -75,6 +78,7 @@ LL | _ => 1u32,
7578
|
7679
= note: to return `impl Trait`, all returned values must be of the same type
7780
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
81+
= help: alternatively, create a new `enum` with a variant for each returned type
7882
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
7983
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
8084

@@ -94,6 +98,7 @@ LL | | }
9498
|
9599
= note: to return `impl Trait`, all returned values must be of the same type
96100
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
101+
= help: alternatively, create a new `enum` with a variant for each returned type
97102
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
98103
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
99104

@@ -111,6 +116,7 @@ LL | 1u32
111116
|
112117
= note: to return `impl Trait`, all returned values must be of the same type
113118
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
119+
= help: alternatively, create a new `enum` with a variant for each returned type
114120
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
115121
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
116122

0 commit comments

Comments
 (0)