File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Expand file tree Collapse file tree 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 {
9999 |err| {
100100 err. span_label( local. span, "unnecessary `let` binding" ) ;
101101
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+ }
103106 err. multipart_suggestion(
104107 "return the expression directly" ,
105108 vec![
Original file line number Diff line number Diff line change @@ -135,4 +135,25 @@ mod no_lint_if_stmt_borrows {
135135 }
136136}
137137
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+
138159fn main ( ) { }
Original file line number Diff line number Diff line change 2727LL | 5
2828 |
2929
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
3145
You can’t perform that action at this time.
0 commit comments