Skip to content

Commit 2480982

Browse files
authored
Unrolled build for rust-lang#120293
Rollup merge of rust-lang#120293 - estebank:issue-102629, r=nnethercote Deduplicate more sized errors on call exprs Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2 parents 5ad7454 + a984193 commit 2480982

File tree

87 files changed

+268
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+268
-321
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7777
callee_expr,
7878
Expectation::NoExpectation,
7979
arg_exprs,
80+
Some(call_expr),
8081
),
8182
_ => self.check_expr(callee_expr),
8283
};

compiler/rustc_hir_typeck/src/expr.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177177
expr: &'tcx hir::Expr<'tcx>,
178178
expected: Expectation<'tcx>,
179179
) -> Ty<'tcx> {
180-
self.check_expr_with_expectation_and_args(expr, expected, &[])
180+
self.check_expr_with_expectation_and_args(expr, expected, &[], None)
181181
}
182182

183183
/// Same as `check_expr_with_expectation`, but allows us to pass in the arguments of a
@@ -187,6 +187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
187187
expr: &'tcx hir::Expr<'tcx>,
188188
expected: Expectation<'tcx>,
189189
args: &'tcx [hir::Expr<'tcx>],
190+
call: Option<&'tcx hir::Expr<'tcx>>,
190191
) -> Ty<'tcx> {
191192
if self.tcx().sess.verbose_internals() {
192193
// make this code only run with -Zverbose-internals because it is probably slow
@@ -233,7 +234,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
233234
let ty = ensure_sufficient_stack(|| match &expr.kind {
234235
hir::ExprKind::Path(
235236
qpath @ (hir::QPath::Resolved(..) | hir::QPath::TypeRelative(..)),
236-
) => self.check_expr_path(qpath, expr, args),
237+
) => self.check_expr_path(qpath, expr, args, call),
237238
_ => self.check_expr_kind(expr, expected),
238239
});
239240
let ty = self.resolve_vars_if_possible(ty);
@@ -300,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
300301
ExprKind::Path(QPath::LangItem(lang_item, _)) => {
301302
self.check_lang_item_path(lang_item, expr)
302303
}
303-
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, &[]),
304+
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, &[], None),
304305
ExprKind::InlineAsm(asm) => {
305306
// We defer some asm checks as we may not have resolved the input and output types yet (they may still be infer vars).
306307
self.deferred_asm_checks.borrow_mut().push((asm, expr.hir_id));
@@ -514,6 +515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
514515
qpath: &'tcx hir::QPath<'tcx>,
515516
expr: &'tcx hir::Expr<'tcx>,
516517
args: &'tcx [hir::Expr<'tcx>],
518+
call: Option<&'tcx hir::Expr<'tcx>>,
517519
) -> Ty<'tcx> {
518520
let tcx = self.tcx;
519521
let (res, opt_ty, segs) =
@@ -530,7 +532,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530532
let e = report_unexpected_variant_res(tcx, res, qpath, expr.span, E0533, "value");
531533
Ty::new_error(tcx, e)
532534
}
533-
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
535+
_ => {
536+
self.instantiate_value_path(
537+
segs,
538+
opt_ty,
539+
res,
540+
call.map_or(expr.span, |e| e.span),
541+
expr.span,
542+
expr.hir_id,
543+
)
544+
.0
545+
}
534546
};
535547

536548
if let ty::FnDef(did, _) = *ty.kind() {
@@ -585,7 +597,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585597
infer::BoundRegionConversionTime::FnCall,
586598
fn_sig.output(),
587599
);
588-
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
600+
self.require_type_is_sized_deferred(
601+
output,
602+
call.map_or(expr.span, |e| e.span),
603+
traits::SizedCallReturnType,
604+
);
589605
}
590606

591607
// We always require that the type provided as the value for

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10731073
self_ty: Option<LoweredTy<'tcx>>,
10741074
res: Res,
10751075
span: Span,
1076+
path_span: Span,
10761077
hir_id: hir::HirId,
10771078
) -> (Ty<'tcx>, Res) {
10781079
let tcx = self.tcx;
@@ -1106,7 +1107,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11061107
match container {
11071108
ty::TraitContainer => callee::check_legal_trait_for_method_call(
11081109
tcx,
1109-
span,
1110+
path_span,
11101111
None,
11111112
span,
11121113
container_id,

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
923923

924924
// Type-check the path.
925925
let (pat_ty, pat_res) =
926-
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id);
926+
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
927927
if let Some(err) =
928928
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
929929
{
@@ -1078,7 +1078,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10781078

10791079
// Type-check the path.
10801080
let (pat_ty, res) =
1081-
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id);
1081+
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
10821082
if !pat_ty.is_fn() {
10831083
let e = report_unexpected_res(res);
10841084
return Ty::new_error(tcx, e);

compiler/rustc_middle/src/traits/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ pub enum ObligationCauseCode<'tcx> {
292292
SizedArgumentType(Option<hir::HirId>),
293293
/// Return type must be `Sized`.
294294
SizedReturnType,
295+
/// Return type of a call expression must be `Sized`.
296+
SizedCallReturnType,
295297
/// Yield type must be `Sized`.
296298
SizedYieldType,
297299
/// Inline asm operand type must be `Sized`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
32923292
err.help("unsized fn params are gated as an unstable feature");
32933293
}
32943294
}
3295-
ObligationCauseCode::SizedReturnType => {
3295+
ObligationCauseCode::SizedReturnType | ObligationCauseCode::SizedCallReturnType => {
32963296
err.note("the return type of a function must have a statically known size");
32973297
}
32983298
ObligationCauseCode::SizedYieldType => {

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,15 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24932493
expr_finder.visit_expr(self.tcx.hir().body(body_id).value);
24942494

24952495
if let Some(hir::Expr {
2496-
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
2496+
kind:
2497+
hir::ExprKind::Call(
2498+
hir::Expr {
2499+
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
2500+
..
2501+
},
2502+
_,
2503+
)
2504+
| hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
24972505
..
24982506
}) = expr_finder.result
24992507
&& let [

tests/ui/anonymous-higher-ranked-lifetime.stderr

+33-22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ error[E0631]: type mismatch in closure arguments
22
--> $DIR/anonymous-higher-ranked-lifetime.rs:2:5
33
|
44
LL | f1(|_: (), _: ()| {});
5-
| ^^ -------------- found signature defined here
6-
| |
5+
| ^^^--------------^^^^
6+
| | |
7+
| | found signature defined here
78
| expected due to this
89
|
910
= note: expected closure signature `for<'a, 'b> fn(&'a (), &'b ()) -> _`
@@ -22,8 +23,9 @@ error[E0631]: type mismatch in closure arguments
2223
--> $DIR/anonymous-higher-ranked-lifetime.rs:3:5
2324
|
2425
LL | f2(|_: (), _: ()| {});
25-
| ^^ -------------- found signature defined here
26-
| |
26+
| ^^^--------------^^^^
27+
| | |
28+
| | found signature defined here
2729
| expected due to this
2830
|
2931
= note: expected closure signature `for<'a, 'b> fn(&'a (), &'b ()) -> _`
@@ -42,8 +44,9 @@ error[E0631]: type mismatch in closure arguments
4244
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
4345
|
4446
LL | f3(|_: (), _: ()| {});
45-
| ^^ -------------- found signature defined here
46-
| |
47+
| ^^^--------------^^^^
48+
| | |
49+
| | found signature defined here
4750
| expected due to this
4851
|
4952
= note: expected closure signature `for<'a> fn(&(), &'a ()) -> _`
@@ -62,8 +65,9 @@ error[E0631]: type mismatch in closure arguments
6265
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:5
6366
|
6467
LL | f4(|_: (), _: ()| {});
65-
| ^^ -------------- found signature defined here
66-
| |
68+
| ^^^--------------^^^^
69+
| | |
70+
| | found signature defined here
6771
| expected due to this
6872
|
6973
= note: expected closure signature `for<'r, 'a> fn(&'a (), &'r ()) -> _`
@@ -82,8 +86,9 @@ error[E0631]: type mismatch in closure arguments
8286
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
8387
|
8488
LL | f5(|_: (), _: ()| {});
85-
| ^^ -------------- found signature defined here
86-
| |
89+
| ^^^--------------^^^^
90+
| | |
91+
| | found signature defined here
8792
| expected due to this
8893
|
8994
= note: expected closure signature `for<'r> fn(&'r (), &'r ()) -> _`
@@ -102,8 +107,9 @@ error[E0631]: type mismatch in closure arguments
102107
--> $DIR/anonymous-higher-ranked-lifetime.rs:7:5
103108
|
104109
LL | g1(|_: (), _: ()| {});
105-
| ^^ -------------- found signature defined here
106-
| |
110+
| ^^^--------------^^^^
111+
| | |
112+
| | found signature defined here
107113
| expected due to this
108114
|
109115
= note: expected closure signature `for<'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>) -> _`
@@ -122,8 +128,9 @@ error[E0631]: type mismatch in closure arguments
122128
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
123129
|
124130
LL | g2(|_: (), _: ()| {});
125-
| ^^ -------------- found signature defined here
126-
| |
131+
| ^^^--------------^^^^
132+
| | |
133+
| | found signature defined here
127134
| expected due to this
128135
|
129136
= note: expected closure signature `for<'a> fn(&'a (), for<'a> fn(&'a ())) -> _`
@@ -142,8 +149,9 @@ error[E0631]: type mismatch in closure arguments
142149
--> $DIR/anonymous-higher-ranked-lifetime.rs:9:5
143150
|
144151
LL | g3(|_: (), _: ()| {});
145-
| ^^ -------------- found signature defined here
146-
| |
152+
| ^^^--------------^^^^
153+
| | |
154+
| | found signature defined here
147155
| expected due to this
148156
|
149157
= note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>) -> _`
@@ -162,8 +170,9 @@ error[E0631]: type mismatch in closure arguments
162170
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
163171
|
164172
LL | g4(|_: (), _: ()| {});
165-
| ^^ -------------- found signature defined here
166-
| |
173+
| ^^^--------------^^^^
174+
| | |
175+
| | found signature defined here
167176
| expected due to this
168177
|
169178
= note: expected closure signature `for<'a> fn(&'a (), for<'r> fn(&'r ())) -> _`
@@ -182,8 +191,9 @@ error[E0631]: type mismatch in closure arguments
182191
--> $DIR/anonymous-higher-ranked-lifetime.rs:11:5
183192
|
184193
LL | h1(|_: (), _: (), _: (), _: ()| {});
185-
| ^^ ---------------------------- found signature defined here
186-
| |
194+
| ^^^----------------------------^^^^
195+
| | |
196+
| | found signature defined here
187197
| expected due to this
188198
|
189199
= note: expected closure signature `for<'a, 'b> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'b (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
@@ -202,8 +212,9 @@ error[E0631]: type mismatch in closure arguments
202212
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
203213
|
204214
LL | h2(|_: (), _: (), _: (), _: ()| {});
205-
| ^^ ---------------------------- found signature defined here
206-
| |
215+
| ^^^----------------------------^^^^
216+
| | |
217+
| | found signature defined here
207218
| expected due to this
208219
|
209220
= note: expected closure signature `for<'t0, 'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`

tests/ui/associated-types/associated-types-path-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ pub fn f1_uint_uint() {
2929
f1(2u32, 4u32);
3030
//~^ ERROR `u32: Foo` is not satisfied
3131
//~| ERROR `u32: Foo` is not satisfied
32-
//~| ERROR `u32: Foo` is not satisfied
3332
}
3433

3534
pub fn f1_uint_int() {
3635
f1(2u32, 4i32);
3736
//~^ ERROR `u32: Foo` is not satisfied
3837
//~| ERROR `u32: Foo` is not satisfied
39-
//~| ERROR `u32: Foo` is not satisfied
4038
}
4139

4240
pub fn f2_int() {

tests/ui/associated-types/associated-types-path-2.stderr

+4-20
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ note: required by a bound in `f1`
3131
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
3232
| ^^^ required by this bound in `f1`
3333

34-
error[E0277]: the trait bound `u32: Foo` is not satisfied
35-
--> $DIR/associated-types-path-2.rs:29:5
36-
|
37-
LL | f1(2u32, 4u32);
38-
| ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32`
39-
|
40-
= help: the trait `Foo` is implemented for `i32`
41-
4234
error[E0277]: the trait bound `u32: Foo` is not satisfied
4335
--> $DIR/associated-types-path-2.rs:29:14
4436
|
@@ -48,7 +40,7 @@ LL | f1(2u32, 4u32);
4840
= help: the trait `Foo` is implemented for `i32`
4941

5042
error[E0277]: the trait bound `u32: Foo` is not satisfied
51-
--> $DIR/associated-types-path-2.rs:36:8
43+
--> $DIR/associated-types-path-2.rs:35:8
5244
|
5345
LL | f1(2u32, 4i32);
5446
| -- ^^^^ the trait `Foo` is not implemented for `u32`
@@ -63,23 +55,15 @@ LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
6355
| ^^^ required by this bound in `f1`
6456

6557
error[E0277]: the trait bound `u32: Foo` is not satisfied
66-
--> $DIR/associated-types-path-2.rs:36:5
67-
|
68-
LL | f1(2u32, 4i32);
69-
| ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32`
70-
|
71-
= help: the trait `Foo` is implemented for `i32`
72-
73-
error[E0277]: the trait bound `u32: Foo` is not satisfied
74-
--> $DIR/associated-types-path-2.rs:36:14
58+
--> $DIR/associated-types-path-2.rs:35:14
7559
|
7660
LL | f1(2u32, 4i32);
7761
| ^^^^ the trait `Foo` is not implemented for `u32`
7862
|
7963
= help: the trait `Foo` is implemented for `i32`
8064

8165
error[E0308]: mismatched types
82-
--> $DIR/associated-types-path-2.rs:43:18
66+
--> $DIR/associated-types-path-2.rs:41:18
8367
|
8468
LL | let _: i32 = f2(2i32);
8569
| --- ^^^^^^^^ expected `i32`, found `u32`
@@ -91,7 +75,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn
9175
LL | let _: i32 = f2(2i32).try_into().unwrap();
9276
| ++++++++++++++++++++
9377

94-
error: aborting due to 8 previous errors
78+
error: aborting due to 6 previous errors
9579

9680
Some errors have detailed explanations: E0277, E0308.
9781
For more information about an error, try `rustc --explain E0277`.

tests/ui/associated-types/associated-types-unconstrained.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn bar() -> isize;
55
| ------------------ `Foo::bar` defined here
66
...
77
LL | let x: isize = Foo::bar();
8-
| ^^^^^^^^ cannot call associated function of trait
8+
| ^^^^^^^^^^ cannot call associated function of trait
99
|
1010
help: use the fully-qualified path to the only available implementation
1111
|

tests/ui/async-await/async-is-unwindsafe.stderr

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
error[E0277]: the type `&mut Context<'_>` may not be safely transferred across an unwind boundary
22
--> $DIR/async-is-unwindsafe.rs:12:5
33
|
4-
LL | is_unwindsafe(async {
5-
| _____^^^^^^^^^^^^^_-
6-
| | |
7-
| | `&mut Context<'_>` may not be safely transferred across an unwind boundary
8-
LL | |
9-
LL | | use std::ptr::null;
10-
LL | | use std::task::{Context, RawWaker, RawWakerVTable, Waker};
11-
... |
12-
LL | | drop(cx_ref);
13-
LL | | });
14-
| |_____- within this `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}`
4+
LL | is_unwindsafe(async {
5+
| _____^_____________-
6+
| |_____|
7+
| ||
8+
LL | ||
9+
LL | || use std::ptr::null;
10+
LL | || use std::task::{Context, RawWaker, RawWakerVTable, Waker};
11+
... ||
12+
LL | || drop(cx_ref);
13+
LL | || });
14+
| ||_____-^ `&mut Context<'_>` may not be safely transferred across an unwind boundary
15+
| |_____|
16+
| within this `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}`
1517
|
1618
= help: within `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>`
1719
= note: `UnwindSafe` is implemented for `&Context<'_>`, but not for `&mut Context<'_>`

0 commit comments

Comments
 (0)