Skip to content

Commit 503e19d

Browse files
committed
Auto merge of #101629 - compiler-errors:issue-101623, r=sanxiyn
Be careful about `expr_ty_adjusted` when noting block tail type Fixes #101623
2 parents efa717b + 44738ee commit 503e19d

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2714,12 +2714,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
27142714
Some(t) if t.hir_owner == parent_id => t,
27152715
_ => self.tcx.typeck(parent_id),
27162716
};
2717-
let ty = typeck_results.expr_ty_adjusted(expr);
2718-
let span = expr.peel_blocks().span;
2717+
let expr = expr.peel_blocks();
2718+
let ty = typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error());
2719+
let span = expr.span;
27192720
if Some(span) != err.span.primary_span() {
27202721
err.span_label(
27212722
span,
2722-
&if ty.references_error() {
2723+
if ty.references_error() {
27232724
String::new()
27242725
} else {
27252726
format!("this tail expression is of type `{:?}`", ty)

src/test/ui/expr/malformed_closure/ruby_style_closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | let p = Some(45).and_then({
1414
LL | |
1515
LL | | |x| println!("doubling {}", x);
1616
LL | | Some(x * 2)
17-
| | -----------
17+
| | ----------- this tail expression is of type `std::option::Option<_>`
1818
LL | |
1919
LL | | });
2020
| |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub struct Stuff {
2+
inner: *mut (),
3+
}
4+
5+
pub struct Wrap<T>(T);
6+
7+
fn fun<T>(t: T) -> Wrap<T> {
8+
todo!()
9+
}
10+
11+
pub trait Trait<'de> {
12+
fn do_stuff(_: Wrap<&'de mut Self>);
13+
}
14+
15+
impl<'a> Trait<'a> for () {
16+
fn do_stuff(_: Wrap<&'a mut Self>) {}
17+
}
18+
19+
fn fun2(t: &mut Stuff) -> () {
20+
let Stuff { inner, .. } = t;
21+
Trait::do_stuff({ fun(&mut *inner) });
22+
//~^ ERROR the trait bound `*mut (): Trait<'_>` is not satisfied
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `*mut (): Trait<'_>` is not satisfied
2+
--> $DIR/issue-101623.rs:21:21
3+
|
4+
LL | Trait::do_stuff({ fun(&mut *inner) });
5+
| --------------- ^^----------------^^
6+
| | |
7+
| | the trait `Trait<'_>` is not implemented for `*mut ()`
8+
| required by a bound introduced by this call
9+
|
10+
= help: the trait `Trait<'a>` is implemented for `()`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)