Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 16, 2020
1 parent 5b36c18 commit 509cb33
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/librustc/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} else {
// We still want to verify whether all the return types conform to each other.
for expr in &visitor.0 {
if let Some(returned_ty) = tables.node_type_opt(expr.hir_id) {
if let Some(ty) = last_ty {
all_returns_have_same_type &= ty == returned_ty;
}
last_ty = Some(returned_ty);
}
let returned_ty = tables.node_type_opt(expr.hir_id);
all_returns_have_same_type &= last_ty == returned_ty || last_ty.is_none();
last_ty = returned_ty;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
&snippet[5..]
));
}
err.help("alternatively, create a new `enum` with a variant for each returned type");
let impl_trait_msg = "for information on `impl Trait`, see \
<https://doc.rust-lang.org/book/ch10-02-traits.html\
#returning-types-that-implement-traits>";
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/impl-trait/equality.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LL | 0_u32
|
= note: to return `impl Trait`, all returned values must be of the same type
= help: you can instead return a trait object using `Box<dyn Foo>`
= help: alternatively, create a new `enum` with a variant for each returned type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
= 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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LL | 1u32
|
= note: to return `impl Trait`, all returned values must be of the same type
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
= help: alternatively, create a new `enum` with a variant for each returned type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
= 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>

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

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

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

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

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

Expand Down

0 comments on commit 509cb33

Please sign in to comment.