File tree 3 files changed +40
-2
lines changed
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,10 @@ impl<'tcx> LateLintPass<'tcx> for Return {
99
99
|err| {
100
100
err. span_label( local. span, "unnecessary `let` binding" ) ;
101
101
102
- if let Some ( snippet) = snippet_opt( cx, initexpr. span) {
102
+ if let Some ( mut snippet) = snippet_opt( cx, initexpr. span) {
103
+ if !cx. typeck_results( ) . expr_adjustments( & retexpr) . is_empty( ) {
104
+ snippet. push_str( " as _" ) ;
105
+ }
103
106
err. multipart_suggestion(
104
107
"return the expression directly" ,
105
108
vec![
Original file line number Diff line number Diff line change @@ -135,4 +135,25 @@ mod no_lint_if_stmt_borrows {
135
135
}
136
136
}
137
137
138
+ mod issue_5729 {
139
+ use std:: sync:: Arc ;
140
+
141
+ trait Foo { }
142
+
143
+ trait FooStorage {
144
+ fn foo_cloned ( & self ) -> Arc < dyn Foo > ;
145
+ }
146
+
147
+ struct FooStorageImpl < T : Foo > {
148
+ foo : Arc < T > ,
149
+ }
150
+
151
+ impl < T : Foo + ' static > FooStorage for FooStorageImpl < T > {
152
+ fn foo_cloned ( & self ) -> Arc < dyn Foo > {
153
+ let clone = Arc :: clone ( & self . foo ) ;
154
+ clone
155
+ }
156
+ }
157
+ }
158
+
138
159
fn main ( ) { }
Original file line number Diff line number Diff line change 27
27
LL | 5
28
28
|
29
29
30
- error: aborting due to 2 previous errors
30
+ error: returning the result of a `let` binding from a block
31
+ --> $DIR/let_and_return.rs:154:13
32
+ |
33
+ LL | let clone = Arc::clone(&self.foo);
34
+ | ---------------------------------- unnecessary `let` binding
35
+ LL | clone
36
+ | ^^^^^
37
+ |
38
+ help: return the expression directly
39
+ |
40
+ LL |
41
+ LL | Arc::clone(&self.foo) as _
42
+ |
43
+
44
+ error: aborting due to 3 previous errors
31
45
You can’t perform that action at this time.
0 commit comments