Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a6a29b
Use associated_type_bounds where applicable - closes #61738
iluuu1994 Jul 31, 2019
322a7d6
Add test for issue 36804
jackh726 Aug 8, 2019
3d231ac
Add missing #![feature(associated_type_bounds)]
iluuu1994 Aug 8, 2019
77bfd7f
Don't use associated type bounds in docs until it is stable
iluuu1994 Aug 9, 2019
c076392
Tweak mismatched types error on break expressions
estebank Aug 6, 2019
799b13a
Do not suggest using ! with break
estebank Aug 7, 2019
4fbbf99
Be more accurate when mentioning type of found match arms
estebank Aug 7, 2019
01a6139
Change wording for function without return value
estebank Aug 7, 2019
94fe8a3
Suggest calling function on type error when finding bare fn
estebank Aug 7, 2019
195d837
When suggesting fn call use an appropriate number of placeholder argu…
estebank Aug 8, 2019
b7f7756
Recover parser from `foo(_, _)`
estebank Aug 8, 2019
0d53f69
review comments
estebank Aug 8, 2019
efa62d6
Tweak wording of fn without explicit return
estebank Aug 8, 2019
52da091
Differentiate between tuple structs and tuple variants
estebank Aug 8, 2019
5a54945
Extend suggestion support for traits and foreign items
estebank Aug 8, 2019
33d1082
review comment: review wording or missing return error
estebank Aug 8, 2019
bc1a4f5
review comments: typo and rewording
estebank Aug 8, 2019
45a5bc7
fix tests
estebank Aug 9, 2019
7c96d90
More explicit diagnostic when using a `vec![]` in a pattern
estebank Aug 9, 2019
75c5ad2
review comments: use structured suggestion
estebank Aug 9, 2019
4dd96d2
check against more collisions for TypeId of fn pointer
RalfJung Aug 9, 2019
b9865d9
Mention that tuple structs are private if their fields are
estebank Aug 9, 2019
cbcc7dd
Give built-in macros stable addresses in the standard library
petrochenkov Jul 27, 2019
0ef7c28
resolve: Populate external modules in more automatic and lazy way
petrochenkov Jul 29, 2019
3ee614b
resolve: Populate external traits lazily as well
petrochenkov Jul 30, 2019
2cb9207
resolve: Move some code around
petrochenkov Jul 30, 2019
a38cbcf
Rollup merge of #63056 - petrochenkov:macstd2, r=alexcrichton
Centril Aug 10, 2019
a14318d
Rollup merge of #63149 - petrochenkov:lazypop2, r=eddyb
Centril Aug 10, 2019
5379a7d
Rollup merge of #63337 - estebank:break-ee0308, r=Centril
Centril Aug 10, 2019
a29196d
Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=Centril
Centril Aug 10, 2019
45d089a
Rollup merge of #63394 - jackh726:issue-36804, r=jonas-schievink
Centril Aug 10, 2019
9ece794
Rollup merge of #63399 - estebank:vec-in-pat, r=Centril
Centril Aug 10, 2019
664b34d
Rollup merge of #63419 - RalfJung:typeid, r=alexcrichton
Centril Aug 10, 2019
2dfa3a9
Rollup merge of #63423 - estebank:priv-tuple, r=zackmdavis
Centril Aug 10, 2019
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
Prev Previous commit
Next Next commit
Tweak mismatched types error on break expressions
  • Loading branch information
estebank committed Aug 9, 2019
commit c076392143e483f60429d148ac58522e423eea9e
16 changes: 15 additions & 1 deletion src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
coerce.coerce(self, &cause, e, e_ty);
} else {
assert!(e_ty.is_unit());
coerce.coerce_forced_unit(self, &cause, &mut |_| (), true);
let ty = coerce.expected_ty();
coerce.coerce_forced_unit(self, &cause, &mut |err| {
let msg = "give it a value of the expected type";
let label = destination.label
.map(|l| format!(" {}", l.ident))
.unwrap_or_else(String::new);
let sugg = format!("break{} {}", label, match ty.sty {
ty::Bool => "true",
ty::Char => "'a'",
ty::Int(_) | ty::Uint(_) => "42",
ty::Float(_) => "3.14159",
_ => "value",
});
err.span_suggestion(expr.span, msg, sugg, Applicability::HasPlaceholders);
}, false);
}
} else {
// If `ctxt.coerce` is `None`, we can just ignore
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/issues/issue-27042.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ error[E0308]: mismatched types
--> $DIR/issue-27042.rs:6:16
|
LL | loop { break };
| ^^^^^ expected (), found i32
| ^^^^^
| |
| expected i32, found ()
| help: give it a value of the expected type: `break 42`
|
= note: expected type `()`
found type `i32`
= note: expected type `i32`
found type `()`

error[E0308]: mismatched types
--> $DIR/issue-27042.rs:8:9
Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/loops/loop-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:4:31
|
LL | let val: ! = loop { break break; };
| ^^^^^ expected (), found !
| ^^^^^
| |
| expected !, found ()
| help: give it a value of the expected type: `break value`
|
= note: expected type `()`
found type `!`
= note: expected type `!`
found type `()`

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:11:19
Expand Down Expand Up @@ -153,10 +156,13 @@ error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:90:9
|
LL | break;
| ^^^^^ expected (), found integer
| ^^^^^
| |
| expected integer, found ()
| help: give it a value of the expected type: `break value`
|
= note: expected type `()`
found type `{integer}`
= note: expected type `{integer}`
found type `()`

error: aborting due to 16 previous errors

Expand Down
27 changes: 18 additions & 9 deletions src/test/ui/loops/loop-labeled-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@ error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:3:29
|
LL | let _: i32 = loop { break };
| ^^^^^ expected (), found i32
| ^^^^^
| |
| expected i32, found ()
| help: give it a value of the expected type: `break 42`
|
= note: expected type `()`
found type `i32`
= note: expected type `i32`
found type `()`

error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:6:37
|
LL | let _: i32 = 'inner: loop { break 'inner };
| ^^^^^^^^^^^^ expected (), found i32
| ^^^^^^^^^^^^
| |
| expected i32, found ()
| help: give it a value of the expected type: `break 'inner 42`
|
= note: expected type `()`
found type `i32`
= note: expected type `i32`
found type `()`

error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:9:45
|
LL | let _: i32 = 'inner2: loop { loop { break 'inner2 } };
| ^^^^^^^^^^^^^ expected (), found i32
| ^^^^^^^^^^^^^
| |
| expected i32, found ()
| help: give it a value of the expected type: `break 'inner2 42`
|
= note: expected type `()`
found type `i32`
= note: expected type `i32`
found type `()`

error: aborting due to 3 previous errors

Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/loops/loop-properly-diverging-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ error[E0308]: mismatched types
--> $DIR/loop-properly-diverging-2.rs:2:23
|
LL | let x: i32 = loop { break };
| ^^^^^ expected (), found i32
| ^^^^^
| |
| expected i32, found ()
| help: give it a value of the expected type: `break 42`
|
= note: expected type `()`
found type `i32`
= note: expected type `i32`
found type `()`

error: aborting due to previous error

Expand Down