Skip to content

Commit 4d0cd45

Browse files
committed
---
yaml --- r: 104570 b: refs/heads/try c: 1ac5e84 h: refs/heads/master v: v3
1 parent fb6f6d2 commit 4d0cd45

File tree

14 files changed

+152
-308
lines changed

14 files changed

+152
-308
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5-
refs/heads/try: 780adfffc39bcb9d32685bd36e2f6b6e6a178dee
5+
refs/heads/try: 1ac5e84e9179fd9c02b5f8d6c46eaab58baa6e4b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/emacs/rust-mode-tests.el

Lines changed: 1 addition & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -425,108 +425,6 @@ fn foo()
425425
"
426426
))
427427

428-
(ert-deftest indent-match ()
429-
(test-indent
430-
"
431-
fn foo() {
432-
match blah {
433-
Pattern => stuff(),
434-
_ => whatever
435-
}
436-
}
437-
"
438-
))
439-
440-
(ert-deftest indent-match-multiline-pattern ()
441-
(test-indent
442-
"
443-
fn foo() {
444-
match blah {
445-
Pattern |
446-
Pattern2 => {
447-
hello()
448-
},
449-
_ => whatever
450-
}
451-
}
452-
"
453-
))
454-
455-
(ert-deftest indent-indented-match ()
456-
(test-indent
457-
"
458-
fn foo() {
459-
let x =
460-
match blah {
461-
Pattern |
462-
Pattern2 => {
463-
hello()
464-
},
465-
_ => whatever
466-
};
467-
y();
468-
}
469-
"
470-
))
471-
472-
(ert-deftest indent-curly-braces-within-parens ()
473-
(test-indent
474-
"
475-
fn foo() {
476-
let x =
477-
foo(bar(|x| {
478-
only_one_indent_here();
479-
}));
480-
y();
481-
}
482-
"
483-
))
484-
485-
(ert-deftest indent-weirdly-indented-block ()
486-
(rust-test-manip-code
487-
"
488-
fn foo() {
489-
{
490-
this_block_is_over_to_the_left_for_some_reason();
491-
}
492-
493-
}
494-
"
495-
16
496-
#'indent-for-tab-command
497-
"
498-
fn foo() {
499-
{
500-
this_block_is_over_to_the_left_for_some_reason();
501-
}
502-
503-
}
504-
"
505-
))
506-
507-
(ert-deftest indent-multi-line-attrib ()
508-
(test-indent
509-
"
510-
#[attrib(
511-
this,
512-
that,
513-
theotherthing)]
514-
fn function_with_multiline_attribute() {}
515-
"
516-
))
517-
518-
519-
;; Make sure that in effort to cover match patterns we don't mistreat || or expressions
520-
(ert-deftest indent-nonmatch-or-expression ()
521-
(test-indent
522-
"
523-
fn foo() {
524-
let x = foo() ||
525-
bar();
526-
}
527-
"
528-
))
529-
530428
(setq rust-test-motion-string
531429
"
532430
fn fn1(arg: int) -> bool {
@@ -552,26 +450,6 @@ struct Foo {
552450
}
553451
"
554452
rust-test-region-string rust-test-motion-string
555-
rust-test-indent-motion-string
556-
"
557-
fn blank_line(arg:int) -> bool {
558-
559-
}
560-
561-
fn indenting_closing_brace() {
562-
if(true) {
563-
}
564-
}
565-
566-
fn indenting_middle_of_line() {
567-
if(true) {
568-
push_me_out();
569-
} else {
570-
pull_me_back_in();
571-
}
572-
}
573-
"
574-
575453
;; Symbol -> (line column)
576454
rust-test-positions-alist '((start-of-fn1 (2 0))
577455
(start-of-fn1-middle-of-line (2 15))
@@ -586,17 +464,7 @@ fn indenting_middle_of_line() {
586464
(middle-of-fn3 (16 4))
587465
(middle-of-struct (21 10))
588466
(before-start-of-struct (19 0))
589-
(after-end-of-struct (23 0))
590-
(blank-line-indent-start (3 0))
591-
(blank-line-indent-target (3 4))
592-
(closing-brace-indent-start (8 1))
593-
(closing-brace-indent-target (8 5))
594-
(middle-push-indent-start (13 2))
595-
(middle-push-indent-target (13 9))
596-
(after-whitespace-indent-start (13 1))
597-
(after-whitespace-indent-target (13 8))
598-
(middle-pull-indent-start (15 19))
599-
(middle-pull-indent-target (15 12))))
467+
(after-end-of-struct (23 0))))
600468

601469
(defun rust-get-buffer-pos (pos-symbol)
602470
"Get buffer position from POS-SYMBOL.
@@ -758,38 +626,3 @@ All positions are position symbols found in `rust-test-positions-alist'."
758626
'middle-of-struct
759627
'before-start-of-struct 'after-end-of-struct
760628
#'mark-defun))
761-
762-
(ert-deftest indent-line-blank-line-motion ()
763-
(rust-test-motion
764-
rust-test-indent-motion-string
765-
'blank-line-indent-start
766-
'blank-line-indent-target
767-
#'indent-for-tab-command))
768-
769-
(ert-deftest indent-line-closing-brace-motion ()
770-
(rust-test-motion
771-
rust-test-indent-motion-string
772-
'closing-brace-indent-start
773-
'closing-brace-indent-target
774-
#'indent-for-tab-command))
775-
776-
(ert-deftest indent-line-middle-push-motion ()
777-
(rust-test-motion
778-
rust-test-indent-motion-string
779-
'middle-push-indent-start
780-
'middle-push-indent-target
781-
#'indent-for-tab-command))
782-
783-
(ert-deftest indent-line-after-whitespace-motion ()
784-
(rust-test-motion
785-
rust-test-indent-motion-string
786-
'after-whitespace-indent-start
787-
'after-whitespace-indent-target
788-
#'indent-for-tab-command))
789-
790-
(ert-deftest indent-line-middle-pull-motion ()
791-
(rust-test-motion
792-
rust-test-indent-motion-string
793-
'middle-pull-indent-start
794-
'middle-pull-indent-target
795-
#'indent-for-tab-command))

branches/try/src/etc/emacs/rust-mode.el

Lines changed: 46 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -59,95 +59,70 @@
5959
(backward-word 1))
6060
(current-column))))
6161

62-
(defun rust-rewind-to-beginning-of-current-level-expr ()
63-
(let ((current-level (rust-paren-level)))
64-
(back-to-indentation)
65-
(while (> (rust-paren-level) current-level)
66-
(backward-up-list)
67-
(back-to-indentation))))
68-
6962
(defun rust-mode-indent-line ()
7063
(interactive)
7164
(let ((indent
7265
(save-excursion
7366
(back-to-indentation)
74-
;; Point is now at beginning of current line
75-
(let* ((level (rust-paren-level))
76-
(baseline
77-
;; Our "baseline" is one level out from the indentation of the expression
78-
;; containing the innermost enclosing opening bracket. That
79-
;; way if we are within a block that has a different
80-
;; indentation than this mode would give it, we still indent
81-
;; the inside of it correctly relative to the outside.
82-
(if (= 0 level)
83-
0
84-
(save-excursion
85-
(backward-up-list)
86-
(rust-rewind-to-beginning-of-current-level-expr)
87-
(+ (current-column) rust-indent-offset)))))
67+
(let ((level (rust-paren-level)))
8868
(cond
8969
;; A function return type is indented to the corresponding function arguments
9070
((looking-at "->")
9171
(save-excursion
9272
(backward-list)
9373
(or (rust-align-to-expr-after-brace)
94-
(+ baseline rust-indent-offset))))
74+
(* rust-indent-offset (+ 1 level)))))
9575

9676
;; A closing brace is 1 level unindended
97-
((looking-at "}") (- baseline rust-indent-offset))
77+
((looking-at "}") (* rust-indent-offset (- level 1)))
9878

9979
;; Doc comments in /** style with leading * indent to line up the *s
10080
((and (nth 4 (syntax-ppss)) (looking-at "*"))
101-
(+ 1 baseline))
81+
(+ 1 (* rust-indent-offset level)))
10282

10383
;; If we're in any other token-tree / sexp, then:
104-
(t
105-
(or
106-
;; If we are inside a pair of braces, with something after the
107-
;; open brace on the same line and ending with a comma, treat
108-
;; it as fields and align them.
109-
(when (> level 0)
110-
(save-excursion
111-
(rust-rewind-irrelevant)
112-
(backward-up-list)
113-
;; Point is now at the beginning of the containing set of braces
114-
(rust-align-to-expr-after-brace)))
115-
116-
(progn
117-
(back-to-indentation)
118-
;; Point is now at the beginning of the current line
119-
(if (or
120-
;; If this line begins with "else" or "{", stay on the
121-
;; baseline as well (we are continuing an expression,
122-
;; but the "else" or "{" should align with the beginning
123-
;; of the expression it's in.)
124-
(looking-at "\\<else\\>\\|{")
125-
126-
(save-excursion
127-
(rust-rewind-irrelevant)
128-
;; Point is now at the end of the previous ine
129-
(or
130-
;; If we are at the first line, no indentation is needed, so stay at baseline...
131-
(= 1 (line-number-at-pos (point)))
132-
;; ..or if the previous line ends with any of these:
133-
;; { ? : ( , ; [ }
134-
;; then we are at the beginning of an expression, so stay on the baseline...
135-
(looking-back "[(,:;?[{}]\\|[^|]|")
136-
;; or if the previous line is the end of an attribute, stay at the baseline...
137-
(progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#")))))
138-
baseline
139-
140-
;; Otherwise, we are continuing the same expression from the previous line,
141-
;; so add one additional indent level
142-
(+ baseline rust-indent-offset))))))))))
143-
(when (not (eq (current-indentation) indent))
144-
;; If we're at the beginning of the line (before or at the current
145-
;; indentation), jump with the indentation change. Otherwise, save the
146-
;; excursion so that adding the indentations will leave us at the
147-
;; equivalent position within the line to where we were before.
148-
(if (<= (current-column) (current-indentation))
149-
(indent-line-to indent)
150-
(save-excursion (indent-line-to indent))))))
84+
;; - [ or ( means line up with the opening token
85+
;; - { means indent to either nesting-level * rust-indent-offset,
86+
;; or one further indent from that if either current line
87+
;; begins with 'else', or previous line didn't end in
88+
;; semi, comma or brace (other than whitespace and line
89+
;; comments) , and wasn't an attribute. But if we have
90+
;; something after the open brace and ending with a comma,
91+
;; treat it as fields and align them. PHEW.
92+
((> level 0)
93+
(let ((pt (point)))
94+
(rust-rewind-irrelevant)
95+
(backward-up-list)
96+
(or (and (looking-at "[[({]")
97+
(rust-align-to-expr-after-brace))
98+
(progn
99+
(goto-char pt)
100+
(back-to-indentation)
101+
(if (looking-at "\\<else\\>")
102+
(* rust-indent-offset (+ 1 level))
103+
(progn
104+
(goto-char pt)
105+
(beginning-of-line)
106+
(rust-rewind-irrelevant)
107+
(end-of-line)
108+
(if (looking-back
109+
"[[,;{}(][[:space:]]*\\(?://.*\\)?")
110+
(* rust-indent-offset level)
111+
(back-to-indentation)
112+
(if (looking-at "#")
113+
(* rust-indent-offset level)
114+
(* rust-indent-offset (+ 1 level))))))))))
115+
116+
;; Otherwise we're in a column-zero definition
117+
(t 0))))))
118+
(cond
119+
;; If we're to the left of the indentation, reindent and jump to it.
120+
((<= (current-column) indent)
121+
(indent-line-to indent))
122+
123+
;; We're to the right; if it needs indent, do so but save excursion.
124+
((not (eq (current-indentation) indent))
125+
(save-excursion (indent-line-to indent))))))
151126

152127

153128
;; Font-locking definitions and helpers

branches/try/src/librustc/middle/kind.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
315315
match e.node {
316316
ExprUnary(UnBox, interior) => {
317317
let interior_type = ty::expr_ty(cx.tcx, interior);
318-
let _ = check_static(cx.tcx, interior_type, interior.span);
318+
let _ = check_durable(cx.tcx, interior_type, interior.span);
319319
}
320320
ExprCast(source, _) => {
321321
let source_ty = ty::expr_ty(cx.tcx, source);
@@ -474,13 +474,13 @@ pub fn check_send(cx: &Context, ty: ty::t, sp: Span) -> bool {
474474
}
475475
}
476476

477-
pub fn check_static(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
477+
// note: also used from middle::typeck::regionck!
478+
pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
478479
if !ty::type_is_static(tcx, ty) {
479480
match ty::get(ty).sty {
480481
ty::ty_param(..) => {
481-
tcx.sess.span_err(sp,
482-
format!("value may contain references; \
483-
add `'static` bound to `{}`", ty_to_str(tcx, ty)));
482+
tcx.sess.span_err(sp, "value may contain references; \
483+
add `'static` bound");
484484
}
485485
_ => {
486486
tcx.sess.span_err(sp, "value may contain references");
@@ -578,7 +578,7 @@ pub fn check_cast_for_escaping_regions(
578578
if target_params.iter().any(|x| x == &source_param) {
579579
/* case (2) */
580580
} else {
581-
check_static(cx.tcx, ty, source_span); /* case (3) */
581+
check_durable(cx.tcx, ty, source_span); /* case (3) */
582582
}
583583
}
584584
_ => {}

0 commit comments

Comments
 (0)