Skip to content
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

Rollup of 9 pull requests #94535

Closed
wants to merge 28 commits into from
Closed
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
47aaf79
Add documentation about `BorrowedFd::to_owned`.
sunfishcode Jan 26, 2022
4c4e430
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.
sunfishcode Feb 4, 2022
7d603dc
x.py fmt
sunfishcode Feb 4, 2022
4c7fb9e
Add helper function to suggest multiple constraints
WaffleLapkin Feb 25, 2022
400d343
Suggest adding `Copy` bound when Adt is moved out
WaffleLapkin Feb 25, 2022
879efa8
Add a test for Adt copy suggestions
WaffleLapkin Feb 25, 2022
f0a16b8
Use rustfix in copy suggestion test
WaffleLapkin Mar 1, 2022
f287866
Demote Windows XP to no_std only
RandomInsano Mar 1, 2022
6739299
Miri/CTFE: properly treat overflow in (signed) division/rem as UB
RalfJung Mar 2, 2022
3768f0b
update char signess for openbsd
semarie Mar 2, 2022
fa8e1be
merge the char signess list of archs with freebsd as it is the same
semarie Mar 2, 2022
2d854f9
Remove num_cpus dependency from bootstrap, build-manifest and rustc_s…
bjorn3 Mar 2, 2022
ac891ea
Extend unused_doc_comments lint to check on blocks
GuillaumeGomez Mar 2, 2022
003c892
Fix Ok(()) suggestion when desugaring is involved.
m-ou-se Jan 19, 2022
85cc471
Add more tests for mismatched Option/Result return types.
m-ou-se Jan 19, 2022
b32cabf
Update test output.
m-ou-se Mar 2, 2022
628fbdf
Fix unused_doc_comments lint errors
GuillaumeGomez Mar 2, 2022
fce6cec
Update unused_doc_comments ui test
GuillaumeGomez Mar 2, 2022
6f0eb2a
Update stdarch submodule
GuillaumeGomez Mar 2, 2022
eee74bf
Rollup merge of #92061 - semarie:openbsd-archs, r=joshtriplett
matthiaskrgr Mar 2, 2022
27288b7
Rollup merge of #93072 - m-ou-se:compatible-variants-suggestion-with-…
matthiaskrgr Mar 2, 2022
0000fe0
Rollup merge of #93354 - sunfishcode:sunfishcode/document-borrowedfd-…
matthiaskrgr Mar 2, 2022
a78c98b
Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=josht…
matthiaskrgr Mar 2, 2022
bccb035
Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank
matthiaskrgr Mar 2, 2022
5a771d7
Rollup merge of #94499 - RandomInsano:patch-1, r=Dylan-DPC
matthiaskrgr Mar 2, 2022
1be3bc5
Rollup merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
matthiaskrgr Mar 2, 2022
f90307c
Rollup merge of #94524 - bjorn3:remove_num_cpus, r=Mark-Simulacrum
matthiaskrgr Mar 2, 2022
dc1a03b
Rollup merge of #94529 - GuillaumeGomez:unused-doc-comments-blocks, r…
matthiaskrgr Mar 2, 2022
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
21 changes: 19 additions & 2 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
@@ -276,11 +276,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// we suggest adding a separate return expression instead.
// (To avoid things like suggesting `Ok(while .. { .. })`.)
if expr_ty.is_unit() {
let mut id = expr.hir_id;
let mut parent;

// Unroll desugaring, to make sure this works for `for` loops etc.
loop {
parent = self.tcx.hir().get_parent_node(id);
if let Some(parent_span) = self.tcx.hir().opt_span(parent) {
if parent_span.find_ancestor_inside(expr.span).is_some() {
// The parent node is part of the same span, so is the result of the
// same expansion/desugaring and not the 'real' parent node.
id = parent;
continue;
}
}
break;
}

if let Some(hir::Node::Block(&hir::Block {
span: block_span, expr: Some(e), ..
})) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id))
})) = self.tcx.hir().find(parent)
{
if e.hir_id == expr.hir_id {
if e.hir_id == id {
if let Some(span) = expr.span.find_ancestor_inside(block_span) {
let return_suggestions =
if self.tcx.is_diagnostic_item(sym::Result, expected_adt.did) {
3 changes: 2 additions & 1 deletion src/test/ui/async-await/proper-span-for-type-error.fixed
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@
async fn a() {}

async fn foo() -> Result<(), i32> {
Ok(a().await) //~ ERROR mismatched types
a().await;
Ok(()) //~ ERROR mismatched types
}

fn main() {}
7 changes: 4 additions & 3 deletions src/test/ui/async-await/proper-span-for-type-error.stderr
Original file line number Diff line number Diff line change
@@ -6,10 +6,11 @@ LL | a().await
|
= note: expected enum `Result<(), i32>`
found unit type `()`
help: try wrapping the expression in `Ok`
help: try adding an expression at the end of the block
|
LL ~ a().await;
LL ~ Ok(())
|
LL | Ok(a().await)
| +++ +

error: aborting due to previous error

15 changes: 15 additions & 0 deletions src/test/ui/did_you_mean/compatible-variants.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,21 @@ fn b() -> Result<(), ()> {
//~| HELP try adding an expression
}

fn c() -> Option<()> {
for _ in [1, 2] {
//~^ ERROR mismatched types
f();
}
//~^ HELP try adding an expression
}

fn d() -> Option<()> {
c()?
//~^ ERROR incompatible types
//~| HELP try removing this `?`
//~| HELP try adding an expression
}

fn main() {
let _: Option<()> = while false {};
//~^ ERROR mismatched types
61 changes: 53 additions & 8 deletions src/test/ui/did_you_mean/compatible-variants.stderr
Original file line number Diff line number Diff line change
@@ -37,7 +37,52 @@ LL + Ok(())
|

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:27:25
--> $DIR/compatible-variants.rs:27:5
|
LL | fn c() -> Option<()> {
| ---------- expected `Option<()>` because of return type
LL | / for _ in [1, 2] {
LL | |
LL | | f();
LL | | }
| |_____^ expected enum `Option`, found `()`
|
= note: expected enum `Option<()>`
found unit type `()`
help: try adding an expression at the end of the block
|
LL ~ }
LL + None
|
LL ~ }
LL + Some(())
|

error[E0308]: `?` operator has incompatible types
--> $DIR/compatible-variants.rs:35:5
|
LL | c()?
| ^^^^ expected enum `Option`, found `()`
|
= note: `?` operator cannot convert from `()` to `Option<()>`
= note: expected enum `Option<()>`
found unit type `()`
help: try removing this `?`
|
LL - c()?
LL + c()
|
help: try adding an expression at the end of the block
|
LL ~ c()?;
LL + None
|
LL ~ c()?;
LL + Some(())
|

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:42:25
|
LL | let _: Option<()> = while false {};
| ---------- ^^^^^^^^^^^^^^ expected enum `Option`, found `()`
@@ -52,7 +97,7 @@ LL | let _: Option<()> = Some(while false {});
| +++++ +

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:31:9
--> $DIR/compatible-variants.rs:46:9
|
LL | while false {}
| ^^^^^^^^^^^^^^ expected enum `Option`, found `()`
@@ -69,7 +114,7 @@ LL + Some(())
|

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:35:31
--> $DIR/compatible-variants.rs:50:31
|
LL | let _: Result<i32, i32> = 1;
| ---------------- ^ expected enum `Result`, found integer
@@ -86,7 +131,7 @@ LL | let _: Result<i32, i32> = Err(1);
| ++++ +

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:38:26
--> $DIR/compatible-variants.rs:53:26
|
LL | let _: Option<i32> = 1;
| ----------- ^ expected enum `Option`, found integer
@@ -101,7 +146,7 @@ LL | let _: Option<i32> = Some(1);
| +++++ +

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:41:28
--> $DIR/compatible-variants.rs:56:28
|
LL | let _: Hey<i32, i32> = 1;
| ------------- ^ expected enum `Hey`, found integer
@@ -118,7 +163,7 @@ LL | let _: Hey<i32, i32> = Hey::B(1);
| +++++++ +

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:44:29
--> $DIR/compatible-variants.rs:59:29
|
LL | let _: Hey<i32, bool> = false;
| -------------- ^^^^^ expected enum `Hey`, found `bool`
@@ -133,7 +178,7 @@ LL | let _: Hey<i32, bool> = Hey::B(false);
| +++++++ +

error[E0308]: mismatched types
--> $DIR/compatible-variants.rs:48:19
--> $DIR/compatible-variants.rs:63:19
|
LL | let _ = Foo { bar };
| ^^^ expected enum `Option`, found `i32`
@@ -145,6 +190,6 @@ help: try wrapping the expression in `Some`
LL | let _ = Foo { bar: Some(bar) };
| ++++++++++ +

error: aborting due to 9 previous errors
error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0308`.