Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c972b0d

Browse files
committedFeb 18, 2025·
Allow unsendable results when they're unused
When calling a method on a `uni T` value, we now allow the call even if the return value isn't sendable if and only if the result is guaranteed to never be used by the caller. This removes the need for explicit recovery in a variety of cases. This fixes #612. Changelog: added
1 parent 724685d commit c972b0d

File tree

2 files changed

+124
-107
lines changed

2 files changed

+124
-107
lines changed
 

‎compiler/src/hir.rs

+73-67
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ impl Comments {
6868
}
6969
}
7070

71+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
72+
pub(crate) enum Usage {
73+
Unused,
74+
Discarded,
75+
Used,
76+
}
77+
78+
impl Usage {
79+
pub(crate) fn is_unused(self) -> bool {
80+
matches!(self, Usage::Unused)
81+
}
82+
}
83+
7184
#[derive(Clone, Debug, PartialEq, Eq)]
7285
pub(crate) struct IntLiteral {
7386
pub(crate) value: i64,
@@ -144,16 +157,15 @@ pub(crate) struct ConstantRef {
144157
pub(crate) source: Option<Identifier>,
145158
pub(crate) name: String,
146159
pub(crate) resolved_type: types::TypeRef,
147-
pub(crate) unused: bool,
160+
pub(crate) usage: Usage,
148161
pub(crate) location: Location,
149162
}
150163

151164
#[derive(Clone, Debug, PartialEq, Eq)]
152165
pub(crate) struct IdentifierRef {
153166
pub(crate) name: String,
154167
pub(crate) kind: types::IdentifierKind,
155-
/// A flag indicating the result of this node is unused.
156-
pub(crate) unused: bool,
168+
pub(crate) usage: Usage,
157169
pub(crate) location: Location,
158170
}
159171

@@ -173,8 +185,7 @@ pub(crate) struct Call {
173185
pub(crate) parens: bool,
174186
/// A flag indicating if the call resides directly in a `mut` expression.
175187
pub(crate) in_mut: bool,
176-
/// A flag indicating the result of this node is unused.
177-
pub(crate) unused: bool,
188+
pub(crate) usage: Usage,
178189
pub(crate) location: Location,
179190
}
180191

@@ -229,7 +240,7 @@ pub(crate) struct AssignSetter {
229240
pub(crate) name: Identifier,
230241
pub(crate) value: Expression,
231242
pub(crate) location: Location,
232-
pub(crate) unused: bool,
243+
pub(crate) usage: Usage,
233244
pub(crate) expected_type: types::TypeRef,
234245
}
235246

@@ -622,6 +633,16 @@ impl Expression {
622633
pub(crate) fn is_recover(&self) -> bool {
623634
matches!(self, Expression::Recover(_))
624635
}
636+
637+
pub(crate) fn set_usage(&mut self, usage: Usage) {
638+
match self {
639+
Expression::Call(c) => c.usage = usage,
640+
Expression::IdentifierRef(c) => c.usage = usage,
641+
Expression::ConstantRef(c) => c.usage = usage,
642+
Expression::AssignSetter(c) => c.usage = usage,
643+
_ => {}
644+
}
645+
}
625646
}
626647

627648
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -2123,7 +2144,7 @@ impl<'a> LowerToHir<'a> {
21232144
},
21242145
parens: false,
21252146
in_mut: false,
2126-
unused: false,
2147+
usage: Usage::Used,
21272148
arguments: Vec::new(),
21282149
location: loc,
21292150
}));
@@ -2156,7 +2177,7 @@ impl<'a> LowerToHir<'a> {
21562177
let var_ref = Expression::IdentifierRef(Box::new(IdentifierRef {
21572178
name: ARRAY_LIT_VAR.to_string(),
21582179
kind: types::IdentifierKind::Unknown,
2159-
unused: false,
2180+
usage: Usage::Used,
21602181
location: node.location,
21612182
}));
21622183

@@ -2178,7 +2199,7 @@ impl<'a> LowerToHir<'a> {
21782199
},
21792200
parens: true,
21802201
in_mut: false,
2181-
unused: false,
2202+
usage: Usage::Used,
21822203
arguments: vec![Argument::Positional(Box::new(
21832204
PositionalArgument {
21842205
value: arg,
@@ -2208,7 +2229,7 @@ impl<'a> LowerToHir<'a> {
22082229
source: None,
22092230
name: ARRAY_INTERNAL_NAME.to_string(),
22102231
resolved_type: types::TypeRef::Unknown,
2211-
unused: false,
2232+
usage: Usage::Used,
22122233
location: node.location,
22132234
},
22142235
))),
@@ -2218,7 +2239,7 @@ impl<'a> LowerToHir<'a> {
22182239
},
22192240
parens: true,
22202241
in_mut: false,
2221-
unused: false,
2242+
usage: Usage::Used,
22222243
arguments: vec![Argument::Positional(Box::new(
22232244
PositionalArgument {
22242245
value: Expression::Int(Box::new(IntLiteral {
@@ -2321,22 +2342,7 @@ impl<'a> LowerToHir<'a> {
23212342
}
23222343

23232344
fn expressions(&mut self, node: ast::Expressions) -> Vec<Expression> {
2324-
let mut nodes = self.values(node.values);
2325-
let max = nodes.len().saturating_sub(1);
2326-
2327-
for (idx, node) in nodes.iter_mut().enumerate() {
2328-
let rem = idx < max;
2329-
2330-
match node {
2331-
Expression::Call(c) => c.unused = rem,
2332-
Expression::IdentifierRef(c) => c.unused = rem,
2333-
Expression::ConstantRef(c) => c.unused = rem,
2334-
Expression::AssignSetter(c) => c.unused = rem,
2335-
_ => {}
2336-
}
2337-
}
2338-
2339-
nodes
2345+
self.values(node.values)
23402346
}
23412347

23422348
fn values(&mut self, nodes: Vec<ast::Expression>) -> Vec<Expression> {
@@ -2495,7 +2501,7 @@ impl<'a> LowerToHir<'a> {
24952501
},
24962502
parens: true,
24972503
in_mut: false,
2498-
unused: false,
2504+
usage: Usage::Used,
24992505
arguments: vec![Argument::Positional(Box::new(
25002506
PositionalArgument {
25012507
value: self.expression(node.right),
@@ -2521,7 +2527,7 @@ impl<'a> LowerToHir<'a> {
25212527
source: self.optional_identifier(node.source),
25222528
name: node.name,
25232529
resolved_type: types::TypeRef::Unknown,
2524-
unused: false,
2530+
usage: Usage::Used,
25252531
location: node.location,
25262532
})
25272533
}
@@ -2530,7 +2536,7 @@ impl<'a> LowerToHir<'a> {
25302536
Box::new(IdentifierRef {
25312537
kind: types::IdentifierKind::Unknown,
25322538
name: node.name,
2533-
unused: false,
2539+
usage: Usage::Used,
25342540
location: node.location,
25352541
})
25362542
}
@@ -2564,7 +2570,7 @@ impl<'a> LowerToHir<'a> {
25642570
name: self.identifier(node.name),
25652571
parens: node.arguments.is_some(),
25662572
in_mut: false,
2567-
unused: false,
2573+
usage: Usage::Used,
25682574
arguments: self.optional_call_arguments(node.arguments),
25692575
location: node.location,
25702576
}))
@@ -2725,7 +2731,7 @@ impl<'a> LowerToHir<'a> {
27252731
let receiver = Expression::IdentifierRef(Box::new(IdentifierRef {
27262732
kind: types::IdentifierKind::Unknown,
27272733
name: variable.name.clone(),
2728-
unused: false,
2734+
usage: Usage::Used,
27292735
location: variable.location,
27302736
}));
27312737

@@ -2741,7 +2747,7 @@ impl<'a> LowerToHir<'a> {
27412747
receiver: Some(receiver),
27422748
parens: true,
27432749
in_mut: false,
2744-
unused: false,
2750+
usage: Usage::Used,
27452751
arguments: vec![Argument::Positional(Box::new(
27462752
PositionalArgument {
27472753
value: self.expression(node.value),
@@ -2780,7 +2786,7 @@ impl<'a> LowerToHir<'a> {
27802786
receiver: Some(receiver),
27812787
parens: true,
27822788
in_mut: false,
2783-
unused: false,
2789+
usage: Usage::Used,
27842790
arguments: vec![Argument::Positional(Box::new(
27852791
PositionalArgument {
27862792
value: self.expression(node.value),
@@ -2801,7 +2807,7 @@ impl<'a> LowerToHir<'a> {
28012807
name: self.identifier(node.name),
28022808
value: self.expression(node.value),
28032809
location: node.location,
2804-
unused: false,
2810+
usage: Usage::Used,
28052811
expected_type: types::TypeRef::Unknown,
28062812
})
28072813
}
@@ -2835,7 +2841,7 @@ impl<'a> LowerToHir<'a> {
28352841
name: name.clone(),
28362842
parens: false,
28372843
in_mut: false,
2838-
unused: false,
2844+
usage: Usage::Used,
28392845
arguments: Vec::new(),
28402846
location: getter_loc,
28412847
}));
@@ -2849,7 +2855,7 @@ impl<'a> LowerToHir<'a> {
28492855
receiver: Some(getter_rec),
28502856
parens: true,
28512857
in_mut: false,
2852-
unused: false,
2858+
usage: Usage::Used,
28532859
arguments: vec![Argument::Positional(Box::new(
28542860
PositionalArgument {
28552861
value: self.expression(node.value),
@@ -2863,7 +2869,7 @@ impl<'a> LowerToHir<'a> {
28632869
location: node.location,
28642870
})),
28652871
location: node.location,
2866-
unused: false,
2872+
usage: Usage::Used,
28672873
expected_type: types::TypeRef::Unknown,
28682874
})
28692875
}
@@ -5587,7 +5593,7 @@ mod tests {
55875593
},
55885594
parens: false,
55895595
in_mut: false,
5590-
unused: false,
5596+
usage: Usage::Used,
55915597
arguments: Vec::new(),
55925598
location: cols(12, 13)
55935599
})),
@@ -5628,7 +5634,7 @@ mod tests {
56285634
source: None,
56295635
name: "$Array".to_string(),
56305636
resolved_type: types::TypeRef::Unknown,
5631-
unused: false,
5637+
usage: Usage::Used,
56325638
location: cols(8, 11),
56335639
}
56345640
))),
@@ -5638,7 +5644,7 @@ mod tests {
56385644
},
56395645
parens: true,
56405646
in_mut: false,
5641-
unused: false,
5647+
usage: Usage::Used,
56425648
arguments: vec![Argument::Positional(Box::new(
56435649
PositionalArgument {
56445650
value: Expression::Int(Box::new(
@@ -5662,7 +5668,7 @@ mod tests {
56625668
IdentifierRef {
56635669
name: "$array".to_string(),
56645670
kind: types::IdentifierKind::Unknown,
5665-
unused: false,
5671+
usage: Usage::Used,
56665672
location: cols(8, 11),
56675673
}
56685674
))),
@@ -5672,7 +5678,7 @@ mod tests {
56725678
},
56735679
parens: true,
56745680
in_mut: false,
5675-
unused: false,
5681+
usage: Usage::Used,
56765682
arguments: vec![Argument::Positional(Box::new(
56775683
PositionalArgument {
56785684
value: Expression::Int(Box::new(IntLiteral {
@@ -5688,7 +5694,7 @@ mod tests {
56885694
Expression::IdentifierRef(Box::new(IdentifierRef {
56895695
name: "$array".to_string(),
56905696
kind: types::IdentifierKind::Unknown,
5691-
unused: false,
5697+
usage: Usage::Used,
56925698
location: cols(8, 11),
56935699
})),
56945700
],
@@ -5730,7 +5736,7 @@ mod tests {
57305736
source: None,
57315737
name: "$Array".to_string(),
57325738
resolved_type: types::TypeRef::Unknown,
5733-
unused: false,
5739+
usage: Usage::Used,
57345740
location: loc(2, 4, 15, 15),
57355741
}
57365742
))),
@@ -5740,7 +5746,7 @@ mod tests {
57405746
},
57415747
parens: true,
57425748
in_mut: false,
5743-
unused: false,
5749+
usage: Usage::Used,
57445750
arguments: vec![Argument::Positional(Box::new(
57455751
PositionalArgument {
57465752
value: Expression::Int(Box::new(
@@ -5761,7 +5767,7 @@ mod tests {
57615767
Expression::IdentifierRef(Box::new(IdentifierRef {
57625768
name: "$array".to_string(),
57635769
kind: types::IdentifierKind::Unknown,
5764-
unused: false,
5770+
usage: Usage::Used,
57655771
location: loc(2, 4, 15, 15),
57665772
})),
57675773
],
@@ -5833,7 +5839,7 @@ mod tests {
58335839
}))),
58345840
parens: true,
58355841
in_mut: false,
5836-
unused: false,
5842+
usage: Usage::Used,
58375843
arguments: vec![Argument::Positional(Box::new(
58385844
PositionalArgument {
58395845
value: Expression::Int(Box::new(IntLiteral {
@@ -5879,7 +5885,7 @@ mod tests {
58795885
source: None,
58805886
name: "A".to_string(),
58815887
resolved_type: types::TypeRef::Unknown,
5882-
unused: false,
5888+
usage: Usage::Used,
58835889
location: cols(8, 8)
58845890
}))
58855891
);
@@ -5897,7 +5903,7 @@ mod tests {
58975903
IdentifierRef {
58985904
kind: types::IdentifierKind::Unknown,
58995905
name: "a".to_string(),
5900-
unused: false,
5906+
usage: Usage::Used,
59015907
location: cols(8, 8)
59025908
}
59035909
))),
@@ -5907,7 +5913,7 @@ mod tests {
59075913
},
59085914
parens: false,
59095915
in_mut: false,
5910-
unused: false,
5916+
usage: Usage::Used,
59115917
arguments: Vec::new(),
59125918
location: cols(8, 10)
59135919
}))
@@ -5923,7 +5929,7 @@ mod tests {
59235929
Expression::IdentifierRef(Box::new(IdentifierRef {
59245930
kind: types::IdentifierKind::Unknown,
59255931
name: "a".to_string(),
5926-
unused: false,
5932+
usage: Usage::Used,
59275933
location: cols(8, 8)
59285934
}))
59295935
);
@@ -5944,7 +5950,7 @@ mod tests {
59445950
},
59455951
parens: true,
59465952
in_mut: false,
5947-
unused: false,
5953+
usage: Usage::Used,
59485954
arguments: vec![Argument::Positional(Box::new(
59495955
PositionalArgument {
59505956
value: Expression::Int(Box::new(IntLiteral {
@@ -5975,7 +5981,7 @@ mod tests {
59755981
},
59765982
parens: true,
59775983
in_mut: false,
5978-
unused: false,
5984+
usage: Usage::Used,
59795985
arguments: vec![Argument::Named(Box::new(NamedArgument {
59805986
index: 0,
59815987
name: Identifier {
@@ -6007,7 +6013,7 @@ mod tests {
60076013
IdentifierRef {
60086014
kind: types::IdentifierKind::Unknown,
60096015
name: "a".to_string(),
6010-
unused: false,
6016+
usage: Usage::Used,
60116017
location: cols(8, 8)
60126018
}
60136019
))),
@@ -6017,7 +6023,7 @@ mod tests {
60176023
},
60186024
parens: false,
60196025
in_mut: false,
6020-
unused: false,
6026+
usage: Usage::Used,
60216027
arguments: Vec::new(),
60226028
location: cols(8, 10)
60236029
}))
@@ -6189,13 +6195,13 @@ mod tests {
61896195
IdentifierRef {
61906196
kind: types::IdentifierKind::Unknown,
61916197
name: "a".to_string(),
6192-
unused: false,
6198+
usage: Usage::Used,
61936199
location: cols(8, 8)
61946200
}
61956201
))),
61966202
parens: true,
61976203
in_mut: false,
6198-
unused: false,
6204+
usage: Usage::Used,
61996205
arguments: vec![Argument::Positional(Box::new(
62006206
PositionalArgument {
62016207
value: Expression::Int(Box::new(IntLiteral {
@@ -6229,7 +6235,7 @@ mod tests {
62296235
receiver: Expression::IdentifierRef(Box::new(IdentifierRef {
62306236
kind: types::IdentifierKind::Unknown,
62316237
name: "a".to_string(),
6232-
unused: false,
6238+
usage: Usage::Used,
62336239
location: cols(8, 8)
62346240
})),
62356241
name: Identifier {
@@ -6242,7 +6248,7 @@ mod tests {
62426248
location: cols(14, 14)
62436249
})),
62446250
location: cols(8, 14),
6245-
unused: false,
6251+
usage: Usage::Used,
62466252
expected_type: types::TypeRef::Unknown,
62476253
}))
62486254
);
@@ -6259,7 +6265,7 @@ mod tests {
62596265
receiver: Expression::IdentifierRef(Box::new(IdentifierRef {
62606266
kind: types::IdentifierKind::Unknown,
62616267
name: "a".to_string(),
6262-
unused: false,
6268+
usage: Usage::Used,
62636269
location: cols(8, 8)
62646270
})),
62656271
name: Identifier {
@@ -6274,7 +6280,7 @@ mod tests {
62746280
IdentifierRef {
62756281
kind: types::IdentifierKind::Unknown,
62766282
name: "a".to_string(),
6277-
unused: false,
6283+
usage: Usage::Used,
62786284
location: cols(8, 8)
62796285
}
62806286
))),
@@ -6284,13 +6290,13 @@ mod tests {
62846290
},
62856291
parens: false,
62866292
in_mut: false,
6287-
unused: false,
6293+
usage: Usage::Used,
62886294
arguments: Vec::new(),
62896295
location: cols(8, 10)
62906296
}))),
62916297
parens: true,
62926298
in_mut: false,
6293-
unused: false,
6299+
usage: Usage::Used,
62946300
arguments: vec![Argument::Positional(Box::new(
62956301
PositionalArgument {
62966302
value: Expression::Int(Box::new(IntLiteral {
@@ -6308,7 +6314,7 @@ mod tests {
63086314
location: cols(8, 15)
63096315
})),
63106316
location: cols(8, 15),
6311-
unused: false,
6317+
usage: Usage::Used,
63126318
expected_type: types::TypeRef::Unknown,
63136319
}))
63146320
);
@@ -6333,7 +6339,7 @@ mod tests {
63336339
}))),
63346340
parens: true,
63356341
in_mut: false,
6336-
unused: false,
6342+
usage: Usage::Used,
63376343
arguments: vec![Argument::Positional(Box::new(
63386344
PositionalArgument {
63396345
value: Expression::Int(Box::new(IntLiteral {
@@ -6724,7 +6730,7 @@ mod tests {
67246730
},
67256731
parens: true,
67266732
in_mut: false,
6727-
unused: false,
6733+
usage: Usage::Used,
67286734
arguments: Vec::new(),
67296735
location: cols(12, 14)
67306736
})),

‎compiler/src/type_check/expressions.rs

+51-40
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,12 @@ impl MethodCall {
526526
.resolve(expected)
527527
}
528528

529-
fn check_sendable(&mut self, state: &mut State, location: Location) {
529+
fn check_sendable(
530+
&mut self,
531+
state: &mut State,
532+
usage: hir::Usage,
533+
location: Location,
534+
) {
530535
if !self.require_sendable {
531536
return;
532537
}
@@ -561,7 +566,7 @@ impl MethodCall {
561566
// we can't "leak" a reference through the arguments (because they too
562567
// are immutable), and the returned value can't refer to `self` because
563568
// we don't allow references anywhere in the type or its sub types.
564-
let ret_sendable = if ref_safe {
569+
let ret_sendable = if ref_safe || !matches!(usage, hir::Usage::Used) {
565570
self.return_type.is_sendable_output(&state.db)
566571
} else {
567572
self.return_type.is_sendable(&state.db)
@@ -800,12 +805,7 @@ impl<'a> Expressions<'a> {
800805
&bounds,
801806
);
802807

803-
checker.expressions_with_return(
804-
returns,
805-
&mut node.body,
806-
&mut scope,
807-
node.location,
808-
);
808+
checker.method_body(returns, &mut node.body, &mut scope, node.location);
809809
}
810810

811811
fn define_instance_method(&mut self, node: &mut hir::DefineInstanceMethod) {
@@ -833,12 +833,7 @@ impl<'a> Expressions<'a> {
833833
&bounds,
834834
);
835835

836-
checker.expressions_with_return(
837-
returns,
838-
&mut node.body,
839-
&mut scope,
840-
node.location,
841-
);
836+
checker.method_body(returns, &mut node.body, &mut scope, node.location);
842837
}
843838

844839
fn define_async_method(&mut self, node: &mut hir::DefineAsyncMethod) {
@@ -865,12 +860,7 @@ impl<'a> Expressions<'a> {
865860
&bounds,
866861
);
867862

868-
checker.expressions_with_return(
869-
returns,
870-
&mut node.body,
871-
&mut scope,
872-
node.location,
873-
);
863+
checker.method_body(returns, &mut node.body, &mut scope, node.location);
874864
}
875865

876866
fn define_static_method(&mut self, node: &mut hir::DefineStaticMethod) {
@@ -896,12 +886,7 @@ impl<'a> Expressions<'a> {
896886
&bounds,
897887
);
898888

899-
checker.expressions_with_return(
900-
returns,
901-
&mut node.body,
902-
&mut scope,
903-
node.location,
904-
);
889+
checker.method_body(returns, &mut node.body, &mut scope, node.location);
905890
}
906891

907892
fn define_field_types(
@@ -1093,7 +1078,7 @@ impl<'a> CheckConstant<'a> {
10931078

10941079
call.check_arguments(self.state, loc);
10951080
call.resolve_return_type(self.state);
1096-
call.check_sendable(self.state, loc);
1081+
call.check_sendable(self.state, hir::Usage::Used, loc);
10971082

10981083
node.resolved_type = call.return_type;
10991084
node.resolved_type
@@ -1310,7 +1295,26 @@ impl<'a> CheckMethodBody<'a> {
13101295
nodes: &mut [hir::Expression],
13111296
scope: &mut LexicalScope,
13121297
) -> Vec<TypeRef> {
1313-
nodes.iter_mut().map(|n| self.expression(n, scope)).collect()
1298+
let mut types = Vec::with_capacity(nodes.len());
1299+
let max = nodes.len().saturating_sub(1);
1300+
1301+
for (idx, node) in nodes.iter_mut().enumerate() {
1302+
let usage = if idx == max
1303+
&& matches!(scope.kind, ScopeKind::Method)
1304+
&& scope.return_type.is_nil(self.db())
1305+
{
1306+
hir::Usage::Discarded
1307+
} else if idx < max {
1308+
hir::Usage::Unused
1309+
} else {
1310+
hir::Usage::Used
1311+
};
1312+
1313+
node.set_usage(usage);
1314+
types.push(self.expression(node, scope));
1315+
}
1316+
1317+
types
13141318
}
13151319

13161320
fn input_expressions(
@@ -1332,7 +1336,7 @@ impl<'a> CheckMethodBody<'a> {
13321336
.value_type_as_owned(self.db())
13331337
}
13341338

1335-
fn expressions_with_return(
1339+
fn method_body(
13361340
&mut self,
13371341
returns: TypeRef,
13381342
nodes: &mut [hir::Expression],
@@ -1606,6 +1610,12 @@ impl<'a> CheckMethodBody<'a> {
16061610
node: &mut hir::DefineVariable,
16071611
scope: &mut LexicalScope,
16081612
) -> TypeRef {
1613+
let discard = node.name.name == IGNORE_VARIABLE;
1614+
1615+
if discard {
1616+
node.value.set_usage(hir::Usage::Discarded);
1617+
}
1618+
16091619
let value_type = self.input_expression(&mut node.value, scope);
16101620

16111621
if !value_type.is_assignable(self.db()) {
@@ -1644,7 +1654,7 @@ impl<'a> CheckMethodBody<'a> {
16441654

16451655
node.resolved_type = var_type;
16461656

1647-
if name == IGNORE_VARIABLE {
1657+
if discard {
16481658
return rtype;
16491659
}
16501660

@@ -2417,7 +2427,7 @@ impl<'a> CheckMethodBody<'a> {
24172427
new_scope.variables.add_variable(name, var);
24182428
}
24192429

2420-
self.expressions_with_return(
2430+
self.method_body(
24212431
return_type,
24222432
&mut node.body,
24232433
&mut new_scope,
@@ -2547,7 +2557,7 @@ impl<'a> CheckMethodBody<'a> {
25472557
call.check_type_bounds(self.state, loc);
25482558
call.check_arguments(self.state, loc);
25492559
call.resolve_return_type(self.state);
2550-
call.check_sendable(self.state, loc);
2560+
call.check_sendable(self.state, node.usage, loc);
25512561

25522562
let returns = call.return_type;
25532563

@@ -2559,7 +2569,7 @@ impl<'a> CheckMethodBody<'a> {
25592569
type_arguments: call.type_arguments,
25602570
});
25612571

2562-
if node.unused && returns.must_use(self.db(), rec) {
2572+
if node.usage.is_unused() && returns.must_use(self.db(), rec) {
25632573
self.state.diagnostics.unused_result(self.file(), node.location);
25642574
}
25652575

@@ -2674,7 +2684,8 @@ impl<'a> CheckMethodBody<'a> {
26742684
call.check_type_bounds(self.state, loc);
26752685
call.check_arguments(self.state, loc);
26762686
call.resolve_return_type(self.state);
2677-
call.check_sendable(self.state, loc);
2687+
call.check_sendable(self.state, node.usage, loc);
2688+
26782689
let returns = call.return_type;
26792690

26802691
node.kind = IdentifierKind::Method(CallInfo {
@@ -2685,7 +2696,7 @@ impl<'a> CheckMethodBody<'a> {
26852696
type_arguments: call.type_arguments,
26862697
});
26872698

2688-
if node.unused && returns.must_use(self.db(), rec) {
2699+
if node.usage.is_unused() && returns.must_use(self.db(), rec) {
26892700
self.state.diagnostics.unused_result(self.file(), node.location);
26902701
}
26912702

@@ -3290,7 +3301,7 @@ impl<'a> CheckMethodBody<'a> {
32903301

32913302
call.check_arguments(self.state, loc);
32923303
call.resolve_return_type(self.state);
3293-
call.check_sendable(self.state, loc);
3304+
call.check_sendable(self.state, node.usage, loc);
32943305

32953306
let returns = call.return_type;
32963307
let rec_info = Receiver::with_receiver(self.db(), receiver, method);
@@ -3303,7 +3314,7 @@ impl<'a> CheckMethodBody<'a> {
33033314
type_arguments: call.type_arguments,
33043315
});
33053316

3306-
if node.unused && returns.must_use(self.db(), receiver) {
3317+
if node.usage.is_unused() && returns.must_use(self.db(), receiver) {
33073318
self.state.diagnostics.unused_result(self.file(), node.location);
33083319
}
33093320

@@ -3515,7 +3526,7 @@ impl<'a> CheckMethodBody<'a> {
35153526
(scope.surrounding_type, self.call_without_receiver(node, scope))
35163527
};
35173528

3518-
if node.unused && typ.must_use(self.db(), rec) {
3529+
if node.usage.is_unused() && typ.must_use(self.db(), rec) {
35193530
self.state.diagnostics.unused_result(self.file(), node.location);
35203531
}
35213532

@@ -3753,7 +3764,7 @@ impl<'a> CheckMethodBody<'a> {
37533764
self.call_arguments(&mut node.arguments, &mut call, scope);
37543765
call.check_arguments(self.state, loc);
37553766
call.resolve_return_type(self.state);
3756-
call.check_sendable(self.state, loc);
3767+
call.check_sendable(self.state, node.usage, loc);
37573768

37583769
let returns = call.return_type;
37593770
let rec_info = Receiver::with_receiver(self.db(), receiver, method);
@@ -3871,7 +3882,7 @@ impl<'a> CheckMethodBody<'a> {
38713882
self.call_arguments(&mut node.arguments, &mut call, scope);
38723883
call.check_arguments(self.state, loc);
38733884
call.resolve_return_type(self.state);
3874-
call.check_sendable(self.state, loc);
3885+
call.check_sendable(self.state, node.usage, loc);
38753886

38763887
let returns = call.return_type;
38773888

0 commit comments

Comments
 (0)
Please sign in to comment.