Skip to content

Commit 33212bf

Browse files
Remove deferred sized checks
1 parent 4033686 commit 33212bf

File tree

14 files changed

+37
-107
lines changed

14 files changed

+37
-107
lines changed

compiler/rustc_typeck/src/check/expr.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
561561
// We just want to check sizedness, so instead of introducing
562562
// placeholder lifetimes with probing, we just replace higher lifetimes
563563
// with fresh vars.
564-
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
564+
let arg_span = args.get(i).map(|a| a.span);
565+
let span = arg_span.unwrap_or(expr.span);
565566
let input = self.replace_bound_vars_with_fresh_vars(
566567
span,
567568
infer::LateBoundRegionConversionTime::FnCall,
568569
fn_sig.input(i),
569570
);
570-
self.require_type_is_sized_deferred(
571-
input,
571+
self.require_type_is_sized(
572+
self.normalize_associated_types_in(span, input),
572573
span,
573-
traits::SizedArgumentType(None),
574+
traits::SizedArgumentType(arg_span),
574575
);
575576
}
576577
}
@@ -585,7 +586,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585586
infer::LateBoundRegionConversionTime::FnCall,
586587
fn_sig.output(),
587588
);
588-
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
589+
self.require_type_is_sized(
590+
self.normalize_associated_types_in(expr.span, output),
591+
expr.span,
592+
traits::SizedReturnType,
593+
);
589594
}
590595

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

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

-11
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
442442
}
443443
}
444444

445-
pub fn require_type_is_sized_deferred(
446-
&self,
447-
ty: Ty<'tcx>,
448-
span: Span,
449-
code: traits::ObligationCauseCode<'tcx>,
450-
) {
451-
if !ty.references_error() {
452-
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
453-
}
454-
}
455-
456445
pub fn register_bound(
457446
&self,
458447
ty: Ty<'tcx>,

compiler/rustc_typeck/src/check/inherited.rs

-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ pub struct Inherited<'a, 'tcx> {
3535

3636
pub(super) fulfillment_cx: RefCell<Box<dyn TraitEngine<'tcx>>>,
3737

38-
// Some additional `Sized` obligations badly affect type inference.
39-
// These obligations are added in a later stage of typeck.
40-
pub(super) deferred_sized_obligations:
41-
RefCell<Vec<(Ty<'tcx>, Span, traits::ObligationCauseCode<'tcx>)>>,
42-
4338
// When we process a call like `c()` where `c` is a closure type,
4439
// we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
4540
// `FnOnce` closure. In that case, we defer full resolution of the
@@ -117,7 +112,6 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
117112
infcx,
118113
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
119114
locals: RefCell::new(Default::default()),
120-
deferred_sized_obligations: RefCell::new(Vec::new()),
121115
deferred_call_resolutions: RefCell::new(Default::default()),
122116
deferred_cast_checks: RefCell::new(Vec::new()),
123117
deferred_transmute_checks: RefCell::new(Vec::new()),

compiler/rustc_typeck/src/check/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,6 @@ fn typeck_with_fallback<'tcx>(
467467
fcx.resolve_rvalue_scopes(def_id.to_def_id());
468468
fcx.resolve_generator_interiors(def_id.to_def_id());
469469

470-
for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
471-
let ty = fcx.normalize_ty(span, ty);
472-
fcx.require_type_is_sized(ty, span, code);
473-
}
474-
475470
fcx.select_all_obligations_or_error();
476471

477472
if !fcx.infcx.is_tainted_by_errors() {

src/test/incremental/const-generics/hash-tyvid-regression-1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ where
99
use std::convert::TryFrom;
1010
<[T; N.get()]>::try_from(())
1111
//~^ error: the trait bound
12-
//~| error: the trait bound
1312
//~| error: mismatched types
1413
}
1514

src/test/ui/associated-types/associated-types-path-2.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
3333
--> $DIR/associated-types-path-2.rs:29:14
3434
|
3535
LL | f1(2u32, 4u32);
36-
| ^^^^ the trait `Foo` is not implemented for `u32`
36+
| -- ^^^^ the trait `Foo` is not implemented for `u32`
37+
| |
38+
| required by a bound introduced by this call
3739
|
3840
= help: the trait `Foo` is implemented for `i32`
3941

src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known
1515
--> $DIR/feature-gate-unsized_fn_params.rs:24:9
1616
|
1717
LL | foo(*x);
18-
| ^^ doesn't have a size known at compile-time
18+
| --- ^^ doesn't have a size known at compile-time
19+
| |
20+
| required by a bound introduced by this call
1921
|
2022
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
21-
= note: all function arguments must have a statically known size
2223
= help: unsized fn params are gated as an unstable feature
24+
help: function arguments must have a statically known size, borrowed types always have a known size
25+
|
26+
LL | foo(&*x);
27+
| +
2328

2429
error: aborting due to 2 previous errors
2530

src/test/ui/iterators/issue-28098.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fn main() {
22
let _ = Iterator::next(&mut ());
33
//~^ ERROR `()` is not an iterator
4-
//~| ERROR `()` is not an iterator
54

65
for _ in false {}
76
//~^ ERROR `bool` is not an iterator
@@ -17,7 +16,6 @@ pub fn other() {
1716

1817
let _ = Iterator::next(&mut ());
1918
//~^ ERROR `()` is not an iterator
20-
//~| ERROR `()` is not an iterator
2119

2220
let _ = Iterator::next(&mut ());
2321
//~^ ERROR `()` is not an iterator

src/test/ui/iterators/issue-28098.stderr

+6-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let _ = Iterator::next(&mut ());
99
= help: the trait `Iterator` is not implemented for `()`
1010

1111
error[E0277]: `bool` is not an iterator
12-
--> $DIR/issue-28098.rs:6:14
12+
--> $DIR/issue-28098.rs:5:14
1313
|
1414
LL | for _ in false {}
1515
| ^^^^^ `bool` is not an iterator
@@ -18,7 +18,7 @@ LL | for _ in false {}
1818
= note: required because of the requirements on the impl of `IntoIterator` for `bool`
1919

2020
error[E0277]: `()` is not an iterator
21-
--> $DIR/issue-28098.rs:9:28
21+
--> $DIR/issue-28098.rs:8:28
2222
|
2323
LL | let _ = Iterator::next(&mut ());
2424
| -------------- ^^^^^^^ `()` is not an iterator
@@ -28,15 +28,7 @@ LL | let _ = Iterator::next(&mut ());
2828
= help: the trait `Iterator` is not implemented for `()`
2929

3030
error[E0277]: `()` is not an iterator
31-
--> $DIR/issue-28098.rs:2:13
32-
|
33-
LL | let _ = Iterator::next(&mut ());
34-
| ^^^^^^^^^^^^^^ `()` is not an iterator
35-
|
36-
= help: the trait `Iterator` is not implemented for `()`
37-
38-
error[E0277]: `()` is not an iterator
39-
--> $DIR/issue-28098.rs:18:28
31+
--> $DIR/issue-28098.rs:17:28
4032
|
4133
LL | let _ = Iterator::next(&mut ());
4234
| -------------- ^^^^^^^ `()` is not an iterator
@@ -46,7 +38,7 @@ LL | let _ = Iterator::next(&mut ());
4638
= help: the trait `Iterator` is not implemented for `()`
4739

4840
error[E0277]: `()` is not an iterator
49-
--> $DIR/issue-28098.rs:22:28
41+
--> $DIR/issue-28098.rs:20:28
5042
|
5143
LL | let _ = Iterator::next(&mut ());
5244
| -------------- ^^^^^^^ `()` is not an iterator
@@ -56,22 +48,14 @@ LL | let _ = Iterator::next(&mut ());
5648
= help: the trait `Iterator` is not implemented for `()`
5749

5850
error[E0277]: `bool` is not an iterator
59-
--> $DIR/issue-28098.rs:25:14
51+
--> $DIR/issue-28098.rs:23:14
6052
|
6153
LL | for _ in false {}
6254
| ^^^^^ `bool` is not an iterator
6355
|
6456
= help: the trait `Iterator` is not implemented for `bool`
6557
= note: required because of the requirements on the impl of `IntoIterator` for `bool`
6658

67-
error[E0277]: `()` is not an iterator
68-
--> $DIR/issue-28098.rs:18:13
69-
|
70-
LL | let _ = Iterator::next(&mut ());
71-
| ^^^^^^^^^^^^^^ `()` is not an iterator
72-
|
73-
= help: the trait `Iterator` is not implemented for `()`
74-
75-
error: aborting due to 8 previous errors
59+
error: aborting due to 6 previous errors
7660

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

src/test/ui/on-unimplemented/multiple-impls.rs

-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ impl Index<Bar<usize>> for [i32] {
3232
fn main() {
3333
Index::index(&[] as &[i32], 2u32);
3434
//~^ ERROR E0277
35-
//~| ERROR E0277
3635
Index::index(&[] as &[i32], Foo(2u32));
3736
//~^ ERROR E0277
38-
//~| ERROR E0277
3937
Index::index(&[] as &[i32], Bar(2u32));
4038
//~^ ERROR E0277
41-
//~| ERROR E0277
4239
}

src/test/ui/on-unimplemented/multiple-impls.stderr

+3-36
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | Index::index(&[] as &[i32], 2u32);
1212
<[i32] as Index<Foo<usize>>>
1313

1414
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
15-
--> $DIR/multiple-impls.rs:36:18
15+
--> $DIR/multiple-impls.rs:35:18
1616
|
1717
LL | Index::index(&[] as &[i32], Foo(2u32));
1818
| ------------ ^^^^^^^^^^^^^ on impl for Foo
@@ -25,7 +25,7 @@ LL | Index::index(&[] as &[i32], Foo(2u32));
2525
<[i32] as Index<Foo<usize>>>
2626

2727
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
28-
--> $DIR/multiple-impls.rs:39:18
28+
--> $DIR/multiple-impls.rs:37:18
2929
|
3030
LL | Index::index(&[] as &[i32], Bar(2u32));
3131
| ------------ ^^^^^^^^^^^^^ on impl for Bar
@@ -37,39 +37,6 @@ LL | Index::index(&[] as &[i32], Bar(2u32));
3737
<[i32] as Index<Bar<usize>>>
3838
<[i32] as Index<Foo<usize>>>
3939

40-
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
41-
--> $DIR/multiple-impls.rs:33:5
42-
|
43-
LL | Index::index(&[] as &[i32], 2u32);
44-
| ^^^^^^^^^^^^ trait message
45-
|
46-
= help: the trait `Index<u32>` is not implemented for `[i32]`
47-
= help: the following other types implement trait `Index<Idx>`:
48-
<[i32] as Index<Bar<usize>>>
49-
<[i32] as Index<Foo<usize>>>
50-
51-
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
52-
--> $DIR/multiple-impls.rs:36:5
53-
|
54-
LL | Index::index(&[] as &[i32], Foo(2u32));
55-
| ^^^^^^^^^^^^ on impl for Foo
56-
|
57-
= help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
58-
= help: the following other types implement trait `Index<Idx>`:
59-
<[i32] as Index<Bar<usize>>>
60-
<[i32] as Index<Foo<usize>>>
61-
62-
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
63-
--> $DIR/multiple-impls.rs:39:5
64-
|
65-
LL | Index::index(&[] as &[i32], Bar(2u32));
66-
| ^^^^^^^^^^^^ on impl for Bar
67-
|
68-
= help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
69-
= help: the following other types implement trait `Index<Idx>`:
70-
<[i32] as Index<Bar<usize>>>
71-
<[i32] as Index<Foo<usize>>>
72-
73-
error: aborting due to 6 previous errors
40+
error: aborting due to 3 previous errors
7441

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

src/test/ui/on-unimplemented/on-impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ impl Index<usize> for [i32] {
2121
fn main() {
2222
Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
2323
//~^ ERROR E0277
24-
//~| ERROR E0277
2524
}

src/test/ui/on-unimplemented/on-impl.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
99
= help: the trait `Index<u32>` is not implemented for `[i32]`
1010
= help: the trait `Index<usize>` is implemented for `[i32]`
1111

12-
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
13-
--> $DIR/on-impl.rs:22:5
14-
|
15-
LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
16-
| ^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
17-
|
18-
= help: the trait `Index<u32>` is not implemented for `[i32]`
19-
= help: the trait `Index<usize>` is implemented for `[i32]`
20-
21-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
2213

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

src/test/ui/unsized/issue-30355.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
22
--> $DIR/issue-30355.rs:5:8
33
|
44
LL | &X(*Y)
5-
| ^^ doesn't have a size known at compile-time
5+
| - ^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `[u8]`
8-
= note: all function arguments must have a statically known size
910
= help: unsized fn params are gated as an unstable feature
11+
help: function arguments must have a statically known size, borrowed types always have a known size
12+
|
13+
LL | &X(&*Y)
14+
| +
1015

1116
error: aborting due to previous error
1217

0 commit comments

Comments
 (0)