@@ -892,14 +892,9 @@ fn lint_session(cx: @mut Context) -> visit::vt<()> {
892892}
893893
894894fn lint_unnecessary_allocations( cx: @mut Context ) -> visit:: vt<( ) > {
895- // If the expression `e` has an allocated type, but `t` dictates that it's
896- // something like a slice (doesn't need allocation), emit a warning with the
897- // specified span.
898- //
899- // Currently, this only applies to string and vector literals with sigils in
900- // front. Those can have the sigil removed to get a borrowed pointer
901- // automatically.
902- fn check ( cx : @mut Context , e : @ast:: expr , t : ty:: t ) {
895+ // Warn if string and vector literals with sigils are immediately borrowed.
896+ // Those can have the sigil removed.
897+ fn check ( cx : @mut Context , e : @ast:: expr ) {
903898 match e. node {
904899 ast:: expr_vstore( e2, ast:: expr_vstore_uniq) |
905900 ast:: expr_vstore( e2, ast:: expr_vstore_box) => {
@@ -914,9 +909,9 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
914909 _ => return
915910 }
916911
917- match ty :: get ( t ) . sty {
918- ty:: ty_estr ( ty:: vstore_slice ( * ) ) |
919- ty :: ty_evec ( _ , ty:: vstore_slice ( * ) ) => {
912+ match cx . tcx . adjustments . find_copy ( & e . id ) {
913+ Some ( @ ty:: AutoDerefRef ( ty:: AutoDerefRef {
914+ autoref : Some ( ty:: AutoBorrowVec ( * ) ) , _ } ) ) => {
920915 cx. span_lint ( unnecessary_allocation,
921916 e. span , "unnecessary allocation, the sigil can be \
922917 removed") ;
@@ -927,23 +922,7 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
927922 }
928923
929924 let visit_expr: @fn ( @ast:: expr ) = |e| {
930- match e. node {
931- ast:: expr_call( c, ref args, _) => {
932- let t = ty:: node_id_to_type ( cx. tcx , c. id ) ;
933- let s = ty:: ty_fn_sig ( t) ;
934- for vec:: each2( * args, s. inputs) |e, t| {
935- check( cx, * e, * t) ;
936- }
937- }
938- ast:: expr_method_call ( _, _, _, ref args, _) => {
939- let t = ty:: node_id_to_type ( cx. tcx , e. callee_id ) ;
940- let s = ty:: ty_fn_sig ( t) ;
941- for vec:: each2( * args, s. inputs) |e, t| {
942- check( cx, * e, * t) ;
943- }
944- }
945- _ => { }
946- }
925+ check ( cx, e) ;
947926 } ;
948927
949928 visit:: mk_simple_visitor ( @visit:: SimpleVisitor {
0 commit comments