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

Remove deferred sized checks (make them eager) #100652

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We just want to check sizedness, so instead of introducing
// placeholder lifetimes with probing, we just replace higher lifetimes
// with fresh vars.
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
let arg_span = args.get(i).map(|a| a.span);
let span = arg_span.unwrap_or(expr.span);
let input = self.replace_bound_vars_with_fresh_vars(
span,
infer::LateBoundRegionConversionTime::FnCall,
fn_sig.input(i),
);
self.require_type_is_sized_deferred(
input,
self.require_type_is_sized(
self.normalize_associated_types_in(span, input),
span,
traits::SizedArgumentType(None),
traits::SizedArgumentType(arg_span),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a somewhat unrelated fix, but it improves spans as well I think.

);
}
}
Expand All @@ -585,7 +586,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
infer::LateBoundRegionConversionTime::FnCall,
fn_sig.output(),
);
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
self.require_type_is_sized(
self.normalize_associated_types_in(expr.span, output),
expr.span,
traits::SizedReturnType,
);
}

// We always require that the type provided as the value for
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub fn require_type_is_sized_deferred(
&self,
ty: Ty<'tcx>,
span: Span,
code: traits::ObligationCauseCode<'tcx>,
) {
if !ty.references_error() {
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
}
}

pub fn register_bound(
&self,
ty: Ty<'tcx>,
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_typeck/src/check/inherited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ pub struct Inherited<'a, 'tcx> {

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

// Some additional `Sized` obligations badly affect type inference.
// These obligations are added in a later stage of typeck.
pub(super) deferred_sized_obligations:
RefCell<Vec<(Ty<'tcx>, Span, traits::ObligationCauseCode<'tcx>)>>,

// When we process a call like `c()` where `c` is a closure type,
// we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
// `FnOnce` closure. In that case, we defer full resolution of the
Expand Down Expand Up @@ -117,7 +112,6 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
infcx,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
locals: RefCell::new(Default::default()),
deferred_sized_obligations: RefCell::new(Vec::new()),
deferred_call_resolutions: RefCell::new(Default::default()),
deferred_cast_checks: RefCell::new(Vec::new()),
deferred_transmute_checks: RefCell::new(Vec::new()),
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@ fn typeck_with_fallback<'tcx>(
fcx.resolve_rvalue_scopes(def_id.to_def_id());
fcx.resolve_generator_interiors(def_id.to_def_id());

for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
let ty = fcx.normalize_ty(span, ty);
fcx.require_type_is_sized(ty, span, code);
}

fcx.select_all_obligations_or_error();

if !fcx.infcx.is_tainted_by_errors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ where
use std::convert::TryFrom;
<[T; N.get()]>::try_from(())
//~^ error: the trait bound
//~| error: the trait bound
//~| error: mismatched types
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/associated-types/associated-types-path-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:14
|
LL | f1(2u32, 4u32);
| ^^^^ the trait `Foo` is not implemented for `u32`
| -- ^^^^ the trait `Foo` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
= help: the trait `Foo` is implemented for `i32`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known
--> $DIR/feature-gate-unsized_fn_params.rs:24:9
|
LL | foo(*x);
| ^^ doesn't have a size known at compile-time
| --- ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
= note: all function arguments must have a statically known size
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | foo(&*x);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be followed up later

| +

error: aborting due to 2 previous errors

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/iterators/issue-28098.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn main() {
let _ = Iterator::next(&mut ());
//~^ ERROR `()` is not an iterator
//~| ERROR `()` is not an iterator

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

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

let _ = Iterator::next(&mut ());
//~^ ERROR `()` is not an iterator
Expand Down
28 changes: 6 additions & 22 deletions src/test/ui/iterators/issue-28098.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | let _ = Iterator::next(&mut ());
= help: the trait `Iterator` is not implemented for `()`

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

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

error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:2:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:18:28
--> $DIR/issue-28098.rs:17:28
|
LL | let _ = Iterator::next(&mut ());
| -------------- ^^^^^^^ `()` is not an iterator
Expand All @@ -46,7 +38,7 @@ LL | let _ = Iterator::next(&mut ());
= help: the trait `Iterator` is not implemented for `()`

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

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

error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:18:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error: aborting due to 8 previous errors
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0277`.
3 changes: 0 additions & 3 deletions src/test/ui/on-unimplemented/multiple-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ impl Index<Bar<usize>> for [i32] {
fn main() {
Index::index(&[] as &[i32], 2u32);
//~^ ERROR E0277
//~| ERROR E0277
Index::index(&[] as &[i32], Foo(2u32));
//~^ ERROR E0277
//~| ERROR E0277
Index::index(&[] as &[i32], Bar(2u32));
//~^ ERROR E0277
//~| ERROR E0277
}
39 changes: 3 additions & 36 deletions src/test/ui/on-unimplemented/multiple-impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL | Index::index(&[] as &[i32], 2u32);
<[i32] as Index<Foo<usize>>>

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

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

error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/multiple-impls.rs:33:5
|
LL | Index::index(&[] as &[i32], 2u32);
| ^^^^^^^^^^^^ trait message
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>

error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:36:5
|
LL | Index::index(&[] as &[i32], Foo(2u32));
| ^^^^^^^^^^^^ on impl for Foo
|
= help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>

error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:39:5
|
LL | Index::index(&[] as &[i32], Bar(2u32));
| ^^^^^^^^^^^^ on impl for Bar
|
= help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>

error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
1 change: 0 additions & 1 deletion src/test/ui/on-unimplemented/on-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ impl Index<usize> for [i32] {
fn main() {
Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
//~^ ERROR E0277
//~| ERROR E0277
}
11 changes: 1 addition & 10 deletions src/test/ui/on-unimplemented/on-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the trait `Index<usize>` is implemented for `[i32]`

error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/on-impl.rs:22:5
|
LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
| ^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the trait `Index<usize>` is implemented for `[i32]`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
9 changes: 7 additions & 2 deletions src/test/ui/unsized/issue-30355.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
--> $DIR/issue-30355.rs:5:8
|
LL | &X(*Y)
| ^^ doesn't have a size known at compile-time
| - ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: all function arguments must have a statically known size
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | &X(&*Y)
| +

error: aborting due to previous error

Expand Down