Skip to content

Commit 467bf0f

Browse files
committed
Actually include changes to fix sendability checks
"I fixed it!" he said, only to realize he forgot to commit the actual changes in addition to the tests. Oops!
1 parent d71ae84 commit 467bf0f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

compiler/src/mir/passes.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ impl<'a> LowerMethod<'a> {
18081808
}
18091809

18101810
fn tuple_literal(&mut self, node: hir::TupleLiteral) -> RegisterId {
1811-
self.check_inferred(node.resolved_type, false, node.location);
1811+
self.check_inferred(node.resolved_type, node.location);
18121812

18131813
let tup = self.new_register(node.resolved_type);
18141814
let id = node.type_id.unwrap();
@@ -1922,7 +1922,7 @@ impl<'a> LowerMethod<'a> {
19221922
let loc = InstructionLocation::new(node.name.location);
19231923
let reg = match node.kind {
19241924
types::CallKind::Call(info) => {
1925-
self.check_inferred(info.returns, true, node.location);
1925+
self.check_inferred(info.returns, node.location);
19261926

19271927
let rec = if info.receiver.is_explicit() {
19281928
node.receiver.map(|expr| self.expression(expr))
@@ -1936,7 +1936,7 @@ impl<'a> LowerMethod<'a> {
19361936
self.call_method(info, rec, args, node.name.location)
19371937
}
19381938
types::CallKind::GetField(info) => {
1939-
self.check_inferred(info.variable_type, false, node.location);
1939+
self.check_inferred(info.variable_type, node.location);
19401940

19411941
let typ = info.variable_type;
19421942
let rec = self.expression(node.receiver.unwrap());
@@ -1980,7 +1980,7 @@ impl<'a> LowerMethod<'a> {
19801980
}
19811981
}
19821982
types::CallKind::CallClosure(info) => {
1983-
self.check_inferred(info.returns, true, node.location);
1983+
self.check_inferred(info.returns, node.location);
19841984

19851985
let returns = info.returns;
19861986
let rec = self.expression(node.receiver.unwrap());
@@ -2014,7 +2014,7 @@ impl<'a> LowerMethod<'a> {
20142014
reg
20152015
}
20162016
types::CallKind::TypeInstance(info) => {
2017-
self.check_inferred(info.resolved_type, false, node.location);
2017+
self.check_inferred(info.resolved_type, node.location);
20182018

20192019
let ins = self.new_register(info.resolved_type);
20202020
let tid = info.type_id;
@@ -2168,11 +2168,8 @@ impl<'a> LowerMethod<'a> {
21682168
}
21692169
}
21702170

2171-
fn check_inferred(&mut self, typ: TypeRef, call: bool, location: Location) {
2172-
// For calls we start with a depth of 1 such that we can disallow
2173-
// methods returning borrows of data that can't be borrowed (e.g. a
2174-
// borrow of a unique value).
2175-
match typ.verify_type(self.db(), call as usize) {
2171+
fn check_inferred(&mut self, typ: TypeRef, location: Location) {
2172+
match typ.verify_type(self.db(), 0) {
21762173
Ok(()) => {}
21772174
Err(VerificationError::Incomplete) => {
21782175
self.state.diagnostics.cant_infer_type(
@@ -2227,7 +2224,7 @@ impl<'a> LowerMethod<'a> {
22272224
let loc = InstructionLocation::new(node.location);
22282225
let reg = match node.kind {
22292226
types::CallKind::Call(info) => {
2230-
self.check_inferred(info.returns, true, node.location);
2227+
self.check_inferred(info.returns, node.location);
22312228

22322229
let rec = if info.receiver.is_explicit() {
22332230
Some(self.expression(node.receiver))
@@ -3520,7 +3517,7 @@ impl<'a> LowerMethod<'a> {
35203517
}
35213518

35223519
fn closure(&mut self, node: hir::Closure) -> RegisterId {
3523-
self.check_inferred(node.resolved_type, false, node.location);
3520+
self.check_inferred(node.resolved_type, node.location);
35243521

35253522
let module = self.module;
35263523
let closure_id = node.closure_id.unwrap();

types/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,14 @@ impl TypeRef {
47754775
pub fn is_sendable_output(self, db: &Database) -> bool {
47764776
match self {
47774777
TypeRef::Uni(_) | TypeRef::Never | TypeRef::Error => true,
4778+
// We may encounter Any() values when processing fields of generic
4779+
// types. In those cases we've already checked the type assigned to
4780+
// those parameters and so we can allow them.
4781+
//
4782+
// The alternative is to expose a type's type arguments when
4783+
// processing fields, but then we end up performing duplicate work
4784+
// and have to complicate the implementation of this method a lot.
4785+
TypeRef::Any(_) => true,
47784786
// Enums use the `Unknown` type for each generated field, generating
47794787
// the final types when lowering to LLVM. This means we need to
47804788
// treat such types as sendable.

0 commit comments

Comments
 (0)