diff --git a/README.md b/README.md index 6ffffd523c916..605c2fc9a611a 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,14 @@ There is a lot more documentation in the [wiki]. The Rust community congregates in a few places: -* [StackOverflow] - Get help here. -* [/r/rust] - General discussion. +* [StackOverflow] - Direct questions about using the language here. +* [users.rust-lang.org] - General discussion, broader questions. * [internals.rust-lang.org] - For development of the Rust language itself. +* [/r/rust] - News and general discussion. [StackOverflow]: http://stackoverflow.com/questions/tagged/rust [/r/rust]: http://reddit.com/r/rust +[users.rust-lang.org]: http://users.rust-lang.org/ [internals.rust-lang.org]: http://internals.rust-lang.org/ ## License diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index b1deb8a36ade4..df2981a6c8334 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -25,17 +25,18 @@ pub enum Mode { } impl FromStr for Mode { - fn from_str(s: &str) -> Option { + type Err = (); + fn from_str(s: &str) -> Result { match s { - "compile-fail" => Some(CompileFail), - "run-fail" => Some(RunFail), - "run-pass" => Some(RunPass), - "run-pass-valgrind" => Some(RunPassValgrind), - "pretty" => Some(Pretty), - "debuginfo-lldb" => Some(DebugInfoLldb), - "debuginfo-gdb" => Some(DebugInfoGdb), - "codegen" => Some(Codegen), - _ => None, + "compile-fail" => Ok(CompileFail), + "run-fail" => Ok(RunFail), + "run-pass" => Ok(RunPass), + "run-pass-valgrind" => Ok(RunPassValgrind), + "pretty" => Ok(Pretty), + "debuginfo-lldb" => Ok(DebugInfoLldb), + "debuginfo-gdb" => Ok(DebugInfoGdb), + "codegen" => Ok(Codegen), + _ => Err(()), } } } diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 357ccec7cf352..b73623223fd4e 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -9,21 +9,20 @@ // except according to those terms. #![crate_type = "bin"] -#![allow(unknown_features)] -#![feature(slicing_syntax, unboxed_closures)] + #![feature(box_syntax)] +#![feature(collections)] +#![feature(core)] #![feature(int_uint)] -#![feature(test)] -#![feature(rustc_private)] -#![feature(std_misc)] -#![feature(path)] #![feature(io)] -#![feature(core)] -#![feature(collections)] #![feature(os)] +#![feature(path)] +#![feature(rustc_private)] +#![feature(slicing_syntax, unboxed_closures)] +#![feature(std_misc)] +#![feature(test)] #![feature(unicode)] -#![allow(unstable)] #![deny(warnings)] extern crate test; @@ -35,7 +34,6 @@ extern crate log; use std::os; use std::old_io; use std::old_io::fs; -use std::str::FromStr; use std::thunk::Thunk; use getopts::{optopt, optflag, reqopt}; use common::Config; @@ -140,9 +138,7 @@ pub fn parse_config(args: Vec ) -> Config { build_base: opt_path(matches, "build-base"), aux_base: opt_path(matches, "aux-base"), stage_id: matches.opt_str("stage-id").unwrap(), - mode: FromStr::from_str(matches.opt_str("mode") - .unwrap() - .as_slice()).expect("invalid mode"), + mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"), run_ignored: matches.opt_present("ignored"), filter: filter, logfile: matches.opt_str("logfile").map(|s| Path::new(s)), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index f83c27b75d6fc..66059d2d13d26 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -352,8 +352,8 @@ pub fn gdb_version_to_int(version_string: &str) -> int { panic!("{}", error_string); } - let major: int = components[0].parse().expect(error_string); - let minor: int = components[1].parse().expect(error_string); + let major: int = components[0].parse().ok().expect(error_string); + let minor: int = components[1].parse().ok().expect(error_string); return major * 1000 + minor; } @@ -363,6 +363,6 @@ pub fn lldb_version_to_int(version_string: &str) -> int { "Encountered LLDB version string with unexpected format: {}", version_string); let error_string = error_string.as_slice(); - let major: int = version_string.parse().expect(error_string); + let major: int = version_string.parse().ok().expect(error_string); return major; } diff --git a/src/doc/index.md b/src/doc/index.md index f385a9798ea3c..252a3125ebdf3 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -39,10 +39,12 @@ Overflow](http://stackoverflow.com/questions/tagged/rust). Searching for your problem might reveal someone who has asked it before! There is an active [subreddit](http://reddit.com/r/rust) with lots of -discussion about Rust. +discussion and news about Rust. -There is also a [developer forum](http://internals.rust-lang.org/), where the -development of Rust itself is discussed. +There is also a [user forum](http://users.rust-lang.org), for all +user-oriented discussion, and a [developer +forum](http://internals.rust-lang.org/), where the development of Rust +itself is discussed. # Specification diff --git a/src/doc/reference.md b/src/doc/reference.md index 59ac173f97a29..936c0aac79f16 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2994,7 +2994,7 @@ Some examples of call expressions: # fn add(x: i32, y: i32) -> i32 { 0 } let x: i32 = add(1i32, 2i32); -let pi: Option = "3.14".parse(); +let pi: Option = "3.14".parse().ok(); ``` ### Lambda expressions @@ -3518,7 +3518,7 @@ An example of each kind: ```{rust} let vec: Vec = vec![1, 2, 3]; let arr: [i32; 3] = [1, 2, 3]; -let s: &[i32] = vec.as_slice(); +let s: &[i32] = &vec; ``` As you can see, the `vec!` macro allows you to create a `Vec` easily. The diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index f01b62223ca81..162e533d8bb72 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -400,7 +400,7 @@ a function for that: let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); -let input_num: Option = input.parse(); +let input_num: Option = input.parse().ok(); ``` The `parse` function takes in a `&str` value and converts it into something. @@ -422,11 +422,13 @@ In this case, we say `x` is a `u32` explicitly, so Rust is able to properly tell `random()` what to generate. In a similar fashion, both of these work: ```{rust,ignore} -let input_num = "5".parse::(); // input_num: Option -let input_num: Option = "5".parse(); // input_num: Option +let input_num = "5".parse::().ok(); // input_num: Option +let input_num: Option = "5".parse().ok(); // input_num: Option ``` -Anyway, with us now converting our input to a number, our code looks like this: +Here we're converting the `Result` returned by `parse` to an `Option` by using +the `ok` method as well. Anyway, with us now converting our input to a number, +our code looks like this: ```{rust,ignore} use std::old_io; @@ -445,7 +447,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.parse(); + let input_num: Option = input.parse().ok(); println!("You guessed: {}", input_num); @@ -495,7 +497,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.parse(); + let input_num: Option = input.parse().ok(); let num = match input_num { Some(num) => num, @@ -562,7 +564,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); + let input_num: Option = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -638,7 +640,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); + let input_num: Option = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -714,7 +716,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); + let input_num: Option = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -770,7 +772,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); + let input_num: Option = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -847,7 +849,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); + let input_num: Option = input.trim().parse().ok(); let num = match input_num { Some(num) => num, diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index b4669b0819f9d..986ad23c665a7 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -100,7 +100,7 @@ To write a function that's generic over types of strings, use `&str`. ``` fn some_string_length(x: &str) -> uint { - x.len() + x.len() } fn main() { @@ -110,7 +110,7 @@ fn main() { let s = "Hello, world".to_string(); - println!("{}", some_string_length(s.as_slice())); + println!("{}", some_string_length(&s)); } ``` diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 5c7b406a6fc43..122cffe36975f 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -174,13 +174,13 @@ match origin { } ``` -If you want to match against a slice or array, you can use `[]`: +If you want to match against a slice or array, you can use `&`: ```{rust} fn main() { let v = vec!["match_this", "1"]; - match v.as_slice() { + match &v[] { ["match_this", second] => println!("The second element is {}", second), _ => {}, } diff --git a/src/doc/trpl/plugins.md b/src/doc/trpl/plugins.md index 6e8e2c7ffe292..5ff233b484415 100644 --- a/src/doc/trpl/plugins.md +++ b/src/doc/trpl/plugins.md @@ -82,7 +82,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) } }; - let mut text = text.as_slice(); + let mut text = &text; let mut total = 0; while !text.is_empty() { match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) { diff --git a/src/doc/trpl/standard-input.md b/src/doc/trpl/standard-input.md index 0c26fb2b44fa4..794b1df7563de 100644 --- a/src/doc/trpl/standard-input.md +++ b/src/doc/trpl/standard-input.md @@ -20,7 +20,7 @@ Let's go over these chunks, one by one: std::old_io::stdin(); ``` -This calls a function, `stdin()`, that lives inside the `std::io` module. As +This calls a function, `stdin()`, that lives inside the `std::old_io` module. As you can imagine, everything in `std` is provided by Rust, the 'standard library.' We'll talk more about the module system later. diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md index 51f9356bd2f9e..e05c6e172a49e 100644 --- a/src/doc/trpl/strings.md +++ b/src/doc/trpl/strings.md @@ -36,36 +36,16 @@ s.push_str(", world."); println!("{}", s); ``` -You can get a `&str` view into a `String` with the `as_slice()` method: +`String`s will coerece into `&str` with an `&`: -```{rust} +``` fn takes_slice(slice: &str) { println!("Got: {}", slice); } fn main() { let s = "Hello".to_string(); - takes_slice(s.as_slice()); -} -``` - -To compare a String to a constant string, prefer `as_slice()`... - -```{rust} -fn compare(string: String) { - if string.as_slice() == "Hello" { - println!("yes"); - } -} -``` - -... over `to_string()`: - -```{rust} -fn compare(string: String) { - if string == "Hello".to_string() { - println!("yes"); - } + takes_slice(&s); } ``` diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index 3acd1eefe89d0..2bd86fa987f4b 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -576,6 +576,10 @@ extern fn panic_fmt(args: &core::fmt::Arguments, #[lang = "eh_personality"] extern fn eh_personality() {} # #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 } # fn main() {} +# mod std { // for-loops +# pub use core::iter; +# pub use core::option; +# } ``` Note that there is one extra lang item here which differs from the examples diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 601f130341bf9..6b56c2b630346 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(unknown_features)] #![cfg_attr(rustc, feature(rustc_private))] #![cfg_attr(rustdoc, feature(rustdoc))] diff --git a/src/etc/emacs/README.md b/src/etc/emacs/README.md deleted file mode 100644 index 24470c258b375..0000000000000 --- a/src/etc/emacs/README.md +++ /dev/null @@ -1,79 +0,0 @@ -`rust-mode`: A major Emacs mode for editing Rust source code -============================================================ - -`rust-mode` makes editing [Rust](http://rust-lang.org) code with Emacs -enjoyable. - - -### Manual Installation - -To install manually, check out this repository and add this to your -`.emacs` file: - -```lisp -(add-to-list 'load-path "/path/to/rust-mode/") -(autoload 'rust-mode "rust-mode" nil t) -(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) -``` - -This associates `rust-mode` with `.rs` files. To enable it explicitly, do -M-x rust-mode. - -### `package.el` installation via Marmalade or MELPA - -It can be more convenient to use Emacs's package manager to handle -installation for you if you use many elisp libraries. If you have -`package.el` but haven't added Marmalade or MELPA, the community -package source, yet, add this to `~/.emacs.d/init.el`: - -Using Marmalade: - -```lisp -(require 'package) -(add-to-list 'package-archives - '("marmalade" . "http://marmalade-repo.org/packages/")) -(package-initialize) -``` - -Using MELPA: - -```lisp -(require 'package) -(add-to-list 'package-archives - '("melpa" . "http://melpa.milkbox.net/packages/") t) -(package-initialize) -``` - -Then do this to load the package listing: - -* M-x eval-buffer -* M-x package-refresh-contents - -If you use a version of Emacs prior to 24 that doesn't include -`package.el`, you can get it from [here](http://bit.ly/pkg-el23). - -If you have an older ELPA `package.el` installed from tromey.com, you -should upgrade in order to support installation from multiple sources. -The ELPA archive is deprecated and no longer accepting new packages, -so the version there (1.7.1) is very outdated. - -#### Install `rust-mode` - -One you have `package.el`, you can install `rust-mode` or any other -modes by choosing them from a list: - -* M-x package-list-packages - -Now, to install packages, move your cursor to them and press -i. This will mark the packages for installation. When -you're done with marking, press x, and ELPA will install -the packages for you (under `~/.emacs.d/elpa/`). - -* or using M-x package-install rust-mode - -### Tests via ERT - -The file `rust-mode-tests.el` contains tests that can be run via -[ERT](http://www.gnu.org/software/emacs/manual/html_node/ert/index.html). -You can use `run_rust_emacs_tests.sh` to run them in batch mode, if -Emacs is somewhere in your `$PATH`. diff --git a/src/etc/emacs/run_rust_emacs_tests.sh b/src/etc/emacs/run_rust_emacs_tests.sh deleted file mode 100755 index b35fcf870c4d3..0000000000000 --- a/src/etc/emacs/run_rust_emacs_tests.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# Copyright 2014 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. -# -# This runs the test for emacs rust-mode. -# It must be possible to find emacs via PATH. -emacs -batch -l rust-mode.el -l rust-mode-tests.el -f ert-run-tests-batch-and-exit diff --git a/src/etc/emacs/rust-mode-tests.el b/src/etc/emacs/rust-mode-tests.el deleted file mode 100644 index f255dbf15071b..0000000000000 --- a/src/etc/emacs/rust-mode-tests.el +++ /dev/null @@ -1,896 +0,0 @@ -;;; rust-mode-tests.el --- ERT tests for rust-mode.el - -(require 'rust-mode) -(require 'ert) -(require 'cl) - -(setq rust-test-fill-column 32) - -(defun rust-compare-code-after-manip (original point-pos manip-func expected got) - (equal expected got)) - -(defun rust-test-explain-bad-manip (original point-pos manip-func expected got) - (if (equal expected got) - nil - (list - ;; The (goto-char) and (insert) business here is just for - ;; convenience--after an error, you can copy-paste that into emacs eval to - ;; insert the bare strings into a buffer - "Rust code was manipulated wrong after:" - `(insert ,original) - `(goto-char ,point-pos) - 'expected `(insert ,expected) - 'got `(insert ,got) - (loop for i from 0 to (max (length original) (length expected)) - for oi = (if (< i (length got)) (elt got i)) - for ei = (if (< i (length expected)) (elt expected i)) - while (equal oi ei) - finally return `(first-difference-at - (goto-char ,(+ 1 i)) - expected ,(char-to-string ei) - got ,(char-to-string oi)))))) -(put 'rust-compare-code-after-manip 'ert-explainer - 'rust-test-explain-bad-manip) - -(defun rust-test-manip-code (original point-pos manip-func expected) - (with-temp-buffer - (rust-mode) - (insert original) - (goto-char point-pos) - (funcall manip-func) - (should (rust-compare-code-after-manip - original point-pos manip-func expected (buffer-string))))) - -(defun test-fill-paragraph (unfilled expected &optional start-pos end-pos) - "We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result. - -Also, the result should be the same regardless of whether the code is at the beginning or end of the file. (If you're not careful, that can make a difference.) So we test each position given above with the passed code at the beginning, the end, neither and both. So we do this a total of (end-pos - start-pos)*4 times. Oy." - (let* ((start-pos (or start-pos 1)) - (end-pos (or end-pos (length unfilled))) - (padding "\n \n") - (padding-len (length padding))) - (loop - for pad-at-beginning from 0 to 1 - do (loop for pad-at-end from 0 to 1 - with padding-beginning = (if (= 0 pad-at-beginning) "" padding) - with padding-end = (if (= 0 pad-at-end) "" padding) - with padding-adjust = (* padding-len pad-at-beginning) - with padding-beginning = (if (= 0 pad-at-beginning) "" padding) - with padding-end = (if (= 0 pad-at-end) "" padding) - ;; If we're adding space to the beginning, and our start position - ;; is at the very beginning, we want to test within the added space. - ;; Otherwise adjust the start and end for the beginning padding. - with start-pos = (if (= 1 start-pos) 1 (+ padding-adjust start-pos)) - with end-pos = (+ end-pos padding-adjust) - do (loop for pos from start-pos to end-pos - do (rust-test-manip-code - (concat padding-beginning unfilled padding-end) - pos - (lambda () - (let ((fill-column rust-test-fill-column)) - (fill-paragraph))) - (concat padding-beginning expected padding-end))))))) - -(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line () - (test-fill-paragraph - "/** - * This is a very very very very very very very long string - */" - "/** - * This is a very very very very - * very very very long string - */")) - - -(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-first-line () - (test-fill-paragraph - "/** This is a very very very very very very very long string - */" - "/** This is a very very very - * very very very very long - * string - */")) - -(ert-deftest fill-paragraph-multi-paragraph-multi-line-style-doc-comment () - (let - ((multi-paragraph-unfilled - "/** - * This is the first really really really really really really really long paragraph - * - * This is the second really really really really really really long paragraph - */")) - (test-fill-paragraph - multi-paragraph-unfilled - "/** - * This is the first really - * really really really really - * really really long paragraph - * - * This is the second really really really really really really long paragraph - */" - 1 89) - (test-fill-paragraph - multi-paragraph-unfilled - "/** - * This is the first really really really really really really really long paragraph - * - * This is the second really - * really really really really - * really long paragraph - */" - 90))) - -(ert-deftest fill-paragraph-multi-paragraph-single-line-style-doc-comment () - (let - ((multi-paragraph-unfilled - "/// This is the first really really really really really really really long paragraph -/// -/// This is the second really really really really really really long paragraph")) - (test-fill-paragraph - multi-paragraph-unfilled - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// This is the second really really really really really really long paragraph" - 1 86) - (test-fill-paragraph - multi-paragraph-unfilled - "/// This is the first really really really really really really really long paragraph -/// -/// This is the second really -/// really really really really -/// really long paragraph" - 87))) - -(ert-deftest fill-paragraph-multi-paragraph-single-line-style-indented () - (test-fill-paragraph - " // This is the first really really really really really really really long paragraph - // - // This is the second really really really really really really long paragraph" - " // This is the first really - // really really really - // really really really - // long paragraph - // - // This is the second really really really really really really long paragraph" 1 89)) - -(ert-deftest fill-paragraph-multi-line-style-inner-doc-comment () - (test-fill-paragraph - "/*! This is a very very very very very very very long string - */" - "/*! This is a very very very - * very very very very long - * string - */")) - -(ert-deftest fill-paragraph-single-line-style-inner-doc-comment () - (test-fill-paragraph - "//! This is a very very very very very very very long string" - "//! This is a very very very -//! very very very very long -//! string")) - -(ert-deftest fill-paragraph-prefixless-multi-line-doc-comment () - (test-fill-paragraph - "/** -This is my summary. Blah blah blah blah blah. Dilly dally dilly dally dilly dally doo. - -This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall. -*/" - "/** -This is my summary. Blah blah -blah blah blah. Dilly dally -dilly dally dilly dally doo. - -This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall. -*/" 4 90)) - -(ert-deftest fill-paragraph-with-no-space-after-star-prefix () - (test-fill-paragraph - "/** - *This is a very very very very very very very long string - */" - "/** - *This is a very very very very - *very very very long string - */")) - -(ert-deftest fill-paragraph-single-line-style-with-code-before () - (test-fill-paragraph - "fn foo() { } -/// This is my comment. This is more of my comment. This is even more." - "fn foo() { } -/// This is my comment. This is -/// more of my comment. This is -/// even more." 14)) - -(ert-deftest fill-paragraph-single-line-style-with-code-after () - (test-fill-paragraph - "/// This is my comment. This is more of my comment. This is even more. -fn foo() { }" - "/// This is my comment. This is -/// more of my comment. This is -/// even more. -fn foo() { }" 1 73)) - -(ert-deftest fill-paragraph-single-line-style-code-before-and-after () - (test-fill-paragraph - "fn foo() { } -/// This is my comment. This is more of my comment. This is even more. -fn bar() { }" - "fn foo() { } -/// This is my comment. This is -/// more of my comment. This is -/// even more. -fn bar() { }" 14 67)) - -(defun test-auto-fill (initial position inserted expected) - (rust-test-manip-code - initial - position - (lambda () - (unwind-protect - (progn - (let ((fill-column rust-test-fill-column)) - (auto-fill-mode) - (goto-char position) - (insert inserted) - (syntax-ppss-flush-cache 1) - (funcall auto-fill-function))) - (auto-fill-mode t))) - expected)) - -(ert-deftest auto-fill-multi-line-doc-comment () - (test-auto-fill - "/** - * - */" - 8 - "This is a very very very very very very very long string" - "/** - * This is a very very very very - * very very very long string - */")) - -(ert-deftest auto-fill-single-line-doc-comment () - (test-auto-fill - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// " - 103 - "This is the second really really really really really really long paragraph" - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// This is the second really -/// really really really really -/// really long paragraph" - )) - -(ert-deftest auto-fill-multi-line-prefixless () - (test-auto-fill - "/* - - */" - 4 - "This is a very very very very very very very long string" - "/* -This is a very very very very -very very very long string - */" - )) - -(defun test-indent (indented) - (let ((deindented (replace-regexp-in-string "^[[:blank:]]*" " " indented))) - (rust-test-manip-code - deindented - 1 - (lambda () (indent-region 1 (buffer-size))) - indented))) - - -(ert-deftest indent-struct-fields-aligned () - (test-indent - " -struct Foo { bar: int, - baz: int } - -struct Blah {x:int, - y:int, - z:String")) - -(ert-deftest indent-doc-comments () - (test-indent - " -/** - * This is a doc comment - * - */ - -/// So is this - -fn foo() { - /*! - * this is a nested doc comment - */ - - //! And so is this -}")) - -(ert-deftest indent-inside-braces () - (test-indent - " -// struct fields out one level: -struct foo { - a:int, - // comments too - b:char -} - -fn bar(x:Box) { // comment here should not affect the next indent - bla(); - bla(); -}")) - -(ert-deftest indent-top-level () - (test-indent - " -// Everything here is at the top level and should not be indented -#[attrib] -mod foo; - -pub static bar = Quux{a: b()} - -use foo::bar::baz; - -fn foo() { } -")) - -(ert-deftest indent-params-no-align () - (test-indent - " -// Indent out one level because no params appear on the first line -fn xyzzy( - a:int, - b:char) { } - -fn abcdef( - a:int, - b:char) - -> char -{ }")) - -(ert-deftest indent-params-align () - (test-indent - " -// Align the second line of params to the first -fn foo(a:int, - b:char) { } - -fn bar( a:int, - b:char) - -> int -{ } - -fn baz( a:int, // should work with a comment here - b:char) - -> int -{ } -")) - -(ert-deftest indent-square-bracket-alignment () - (test-indent - " -fn args_on_the_next_line( // with a comment - a:int, - b:String) { - let aaaaaa = [ - 1, - 2, - 3]; - let bbbbbbb = [1, 2, 3, - 4, 5, 6]; - let ccc = [ 10, 9, 8, - 7, 6, 5]; -} -")) - -(ert-deftest indent-nested-fns () - (test-indent - " -fn nexted_fns(a: fn(b:int, - c:char) - -> int, - d: int) - -> uint -{ - 0 -} -" - )) - -(ert-deftest indent-multi-line-expr () - (test-indent - " -fn foo() -{ - x(); - let a = - b(); -} -" - )) - -(ert-deftest indent-match () - (test-indent - " -fn foo() { - match blah { - Pattern => stuff(), - _ => whatever - } -} -" - )) - -(ert-deftest indent-match-multiline-pattern () - (test-indent - " -fn foo() { - match blah { - Pattern | - Pattern2 => { - hello() - }, - _ => whatever - } -} -" - )) - -(ert-deftest indent-indented-match () - (test-indent - " -fn foo() { - let x = - match blah { - Pattern | - Pattern2 => { - hello() - }, - _ => whatever - }; - y(); -} -" - )) - -(ert-deftest indent-curly-braces-within-parens () - (test-indent - " -fn foo() { - let x = - foo(bar(|x| { - only_one_indent_here(); - })); - y(); -} -" - )) - -(ert-deftest indent-weirdly-indented-block () - (rust-test-manip-code - " -fn foo() { - { -this_block_is_over_to_the_left_for_some_reason(); - } - -} -" - 16 - #'indent-for-tab-command - " -fn foo() { - { - this_block_is_over_to_the_left_for_some_reason(); - } - -} -" - )) - -(ert-deftest indent-multi-line-attrib () - (test-indent - " -#[attrib( - this, - that, - theotherthing)] -fn function_with_multiline_attribute() {} -" - )) - - -;; Make sure that in effort to cover match patterns we don't mistreat || or expressions -(ert-deftest indent-nonmatch-or-expression () - (test-indent - " -fn foo() { - let x = foo() || - bar(); -} -" - )) - -(setq rust-test-motion-string - " -fn fn1(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -fn fn2(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -pub fn fn3(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -struct Foo { - x: int -} -" - rust-test-region-string rust-test-motion-string - rust-test-indent-motion-string - " -fn blank_line(arg:int) -> bool { - -} - -fn indenting_closing_brace() { - if(true) { -} -} - -fn indenting_middle_of_line() { - if(true) { - push_me_out(); -} else { - pull_me_back_in(); -} -} - -fn indented_already() { - - // The previous line already has its spaces -} -" - - ;; Symbol -> (line column) - rust-test-positions-alist '((start-of-fn1 (2 0)) - (start-of-fn1-middle-of-line (2 15)) - (middle-of-fn1 (3 7)) - (end-of-fn1 (6 0)) - (between-fn1-fn2 (7 0)) - (start-of-fn2 (8 0)) - (middle-of-fn2 (10 4)) - (before-start-of-fn1 (1 0)) - (after-end-of-fn2 (13 0)) - (beginning-of-fn3 (14 0)) - (middle-of-fn3 (16 4)) - (middle-of-struct (21 10)) - (before-start-of-struct (19 0)) - (after-end-of-struct (23 0)) - (blank-line-indent-start (3 0)) - (blank-line-indent-target (3 4)) - (closing-brace-indent-start (8 1)) - (closing-brace-indent-target (8 5)) - (middle-push-indent-start (13 2)) - (middle-push-indent-target (13 9)) - (after-whitespace-indent-start (13 1)) - (after-whitespace-indent-target (13 8)) - (middle-pull-indent-start (15 19)) - (middle-pull-indent-target (15 12)) - (blank-line-indented-already-bol-start (20 0)) - (blank-line-indented-already-bol-target (20 4)) - (blank-line-indented-already-middle-start (20 2)) - (blank-line-indented-already-middle-target (20 4)) - (nonblank-line-indented-already-bol-start (21 0)) - (nonblank-line-indented-already-bol-target (21 4)) - (nonblank-line-indented-already-middle-start (21 2)) - (nonblank-line-indented-already-middle-target (21 4)))) - -(defun rust-get-buffer-pos (pos-symbol) - "Get buffer position from POS-SYMBOL. - -POS-SYMBOL is a symbol found in `rust-test-positions-alist'. -Convert the line-column information from that list into a buffer position value." - (interactive "P") - (pcase-let ((`(,line ,column) (cadr (assoc pos-symbol rust-test-positions-alist)))) - (save-excursion - (goto-line line) - (move-to-column column) - (point)))) - -;;; FIXME: Maybe add an ERT explainer function (something that shows the -;;; surrounding code of the final point, not just the position). -(defun rust-test-motion (source-code init-pos final-pos manip-func &optional &rest args) - "Test that MANIP-FUNC moves point from INIT-POS to FINAL-POS. - -If ARGS are provided, send them to MANIP-FUNC. - -INIT-POS, FINAL-POS are position symbols found in `rust-test-positions-alist'." - (with-temp-buffer - (rust-mode) - (insert source-code) - (goto-char (rust-get-buffer-pos init-pos)) - (apply manip-func args) - (should (equal (point) (rust-get-buffer-pos final-pos))))) - -(defun rust-test-region (source-code init-pos reg-beg reg-end manip-func &optional &rest args) - "Test that MANIP-FUNC marks region from REG-BEG to REG-END. - -INIT-POS is the initial position of point. -If ARGS are provided, send them to MANIP-FUNC. -All positions are position symbols found in `rust-test-positions-alist'." - (with-temp-buffer - (rust-mode) - (insert source-code) - (goto-char (rust-get-buffer-pos init-pos)) - (apply manip-func args) - (should (equal (list (region-beginning) (region-end)) - (list (rust-get-buffer-pos reg-beg) - (rust-get-buffer-pos reg-end)))))) - -(ert-deftest rust-beginning-of-defun-from-middle-of-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-from-end () - (rust-test-motion - rust-test-motion-string - 'end-of-fn1 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-before-open-brace () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1-middle-of-line - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-between-fns () - (rust-test-motion - rust-test-motion-string - 'between-fn1-fn2 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-with-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn2 - 'start-of-fn1 - #'beginning-of-defun 2)) - -(ert-deftest rust-beginning-of-defun-with-negative-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'beginning-of-fn3 - #'beginning-of-defun -2)) - -(ert-deftest rust-beginning-of-defun-pub-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn3 - 'beginning-of-fn3 - #'beginning-of-defun)) - -(ert-deftest rust-end-of-defun-from-middle-of-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-from-beg () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1 - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-before-open-brace () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1-middle-of-line - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-between-fns () - (rust-test-motion - rust-test-motion-string - 'between-fn1-fn2 - 'after-end-of-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-with-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'after-end-of-fn2 - #'end-of-defun 2)) - -(ert-deftest rust-end-of-defun-with-negative-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn3 - 'between-fn1-fn2 - #'end-of-defun -2)) - -(ert-deftest rust-mark-defun-from-middle-of-fn () - (rust-test-region - rust-test-region-string - 'middle-of-fn2 - 'between-fn1-fn2 'after-end-of-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-from-end () - (rust-test-region - rust-test-region-string - 'end-of-fn1 - 'before-start-of-fn1 'between-fn1-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-start-of-defun () - (rust-test-region - rust-test-region-string - 'start-of-fn2 - 'between-fn1-fn2 'after-end-of-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-from-middle-of-struct () - (rust-test-region - rust-test-region-string - 'middle-of-struct - 'before-start-of-struct 'after-end-of-struct - #'mark-defun)) - -(ert-deftest indent-line-blank-line-motion () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indent-start - 'blank-line-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-closing-brace-motion () - (rust-test-motion - rust-test-indent-motion-string - 'closing-brace-indent-start - 'closing-brace-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-middle-push-motion () - (rust-test-motion - rust-test-indent-motion-string - 'middle-push-indent-start - 'middle-push-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-after-whitespace-motion () - (rust-test-motion - rust-test-indent-motion-string - 'after-whitespace-indent-start - 'after-whitespace-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-middle-pull-motion () - (rust-test-motion - rust-test-indent-motion-string - 'middle-pull-indent-start - 'middle-pull-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-blank-line-indented-already-bol () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indented-already-bol-start - 'blank-line-indented-already-bol-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-blank-line-indented-already-middle () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indented-already-middle-start - 'blank-line-indented-already-middle-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-nonblank-line-indented-already-bol () - (rust-test-motion - rust-test-indent-motion-string - 'nonblank-line-indented-already-bol-start - 'nonblank-line-indented-already-bol-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-nonblank-line-indented-already-middle () - (rust-test-motion - rust-test-indent-motion-string - 'nonblank-line-indented-already-middle-start - 'nonblank-line-indented-already-middle-target - #'indent-for-tab-command)) - -(defun rust-test-fontify-string (str) - (with-temp-buffer - (rust-mode) - (insert str) - (font-lock-fontify-buffer) - (buffer-string))) - -(defun rust-test-group-str-by-face (str) - "Fontify `STR' in rust-mode and group it by face, returning a -list of substrings of `STR' each followed by its face." - (cl-loop with fontified = (rust-test-fontify-string str) - for start = 0 then end - while start - for end = (next-single-property-change start 'face fontified) - for prop = (get-text-property start 'face fontified) - for text = (substring-no-properties fontified start end) - if prop - append (list text prop))) - -(defun rust-test-font-lock (source face-groups) - "Test that `SOURCE' fontifies to the expected `FACE-GROUPS'" - (should (equal (rust-test-group-str-by-face source) - face-groups))) - -(ert-deftest font-lock-attribute-simple () - (rust-test-font-lock - "#[foo]" - '("#[foo]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-inner () - (rust-test-font-lock - "#![foo]" - '("#![foo]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-key-value () - (rust-test-font-lock - "#[foo = \"bar\"]" - '("#[foo = " font-lock-preprocessor-face - "\"bar\"" font-lock-string-face - "]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-around-comment () - (rust-test-font-lock - "#[foo /* bar */]" - '("#[foo " font-lock-preprocessor-face - "/* " font-lock-comment-delimiter-face - "bar */" font-lock-comment-face - "]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-inside-string () - (rust-test-font-lock - "\"#[foo]\"" - '("\"#[foo]\"" font-lock-string-face))) - -(ert-deftest font-lock-attribute-inside-comment () - (rust-test-font-lock - "/* #[foo] */" - '("/* " font-lock-comment-delimiter-face - "#[foo] */" font-lock-comment-face))) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el deleted file mode 100644 index dae685f3a540a..0000000000000 --- a/src/etc/emacs/rust-mode.el +++ /dev/null @@ -1,520 +0,0 @@ -;;; rust-mode.el --- A major emacs mode for editing Rust source code - -;; Version: 0.2.0 -;; Author: Mozilla -;; Url: https://github.com/rust-lang/rust -;; Keywords: languages - -;;; Commentary: -;; - -;;; Code: - -(eval-when-compile (require 'misc)) - -;; for GNU Emacs < 24.3 -(eval-when-compile - (unless (fboundp 'setq-local) - (defmacro setq-local (var val) - "Set variable VAR to value VAL in current buffer." - (list 'set (list 'make-local-variable (list 'quote var)) val)))) - -;; Syntax definitions and helpers -(defvar rust-mode-syntax-table - (let ((table (make-syntax-table))) - - ;; Operators - (dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@)) - (modify-syntax-entry i "." table)) - - ;; Strings - (modify-syntax-entry ?\" "\"" table) - (modify-syntax-entry ?\\ "\\" table) - - ;; mark _ as a word constituent so that identifiers - ;; such as xyz_type don't cause type to be highlighted - ;; as a keyword - (modify-syntax-entry ?_ "w" table) - - ;; Comments - (modify-syntax-entry ?/ ". 124b" table) - (modify-syntax-entry ?* ". 23" table) - (modify-syntax-entry ?\n "> b" table) - (modify-syntax-entry ?\^m "> b" table) - - table)) - -(defgroup rust-mode nil - "Support for Rust code." - :link '(url-link "http://www.rust-lang.org/") - :group 'languages) - -(defcustom rust-indent-offset 4 - "Indent Rust code by this number of spaces." - :type 'integer - :group 'rust-mode) - -(defcustom rust-indent-method-chain nil - "Indent Rust method chains, aligned by the '.' operators" - :type 'boolean - :group 'rust-mode) - -(defun rust-paren-level () (nth 0 (syntax-ppss))) -(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss))) -(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss)))) -(defun rust-rewind-irrelevant () - (let ((starting (point))) - (skip-chars-backward "[:space:]\n") - (if (looking-back "\\*/") (backward-char)) - (if (rust-in-str-or-cmnt) - (rust-rewind-past-str-cmnt)) - (if (/= starting (point)) - (rust-rewind-irrelevant)))) - -(defun rust-align-to-expr-after-brace () - (save-excursion - (forward-char) - ;; We don't want to indent out to the open bracket if the - ;; open bracket ends the line - (when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$")) - (when (looking-at "[[:space:]]") - (forward-word 1) - (backward-word 1)) - (current-column)))) - -(defun rust-align-to-method-chain () - (save-excursion - (previous-line) - (end-of-line) - (backward-word 1) - (backward-char) - (when (looking-at "\\..+\(.*\)\n") - (- (current-column) rust-indent-offset)))) - -(defun rust-rewind-to-beginning-of-current-level-expr () - (let ((current-level (rust-paren-level))) - (back-to-indentation) - (while (> (rust-paren-level) current-level) - (backward-up-list) - (back-to-indentation)))) - -(defun rust-mode-indent-line () - (interactive) - (let ((indent - (save-excursion - (back-to-indentation) - ;; Point is now at beginning of current line - (let* ((level (rust-paren-level)) - (baseline - ;; Our "baseline" is one level out from the indentation of the expression - ;; containing the innermost enclosing opening bracket. That - ;; way if we are within a block that has a different - ;; indentation than this mode would give it, we still indent - ;; the inside of it correctly relative to the outside. - (if (= 0 level) - 0 - (or - (when rust-indent-method-chain - (rust-align-to-method-chain)) - (save-excursion - (backward-up-list) - (rust-rewind-to-beginning-of-current-level-expr) - (+ (current-column) rust-indent-offset)))))) - (cond - ;; A function return type is indented to the corresponding function arguments - ((looking-at "->") - (save-excursion - (backward-list) - (or (rust-align-to-expr-after-brace) - (+ baseline rust-indent-offset)))) - - ;; A closing brace is 1 level unindended - ((looking-at "}") (- baseline rust-indent-offset)) - - ;;Line up method chains by their .'s - ((when (and rust-indent-method-chain - (looking-at "\..+\(.*\);?\n")) - (or - (let ((method-indent (rust-align-to-method-chain))) - (when method-indent - (+ method-indent rust-indent-offset))) - (+ baseline rust-indent-offset)))) - - - ;; Doc comments in /** style with leading * indent to line up the *s - ((and (nth 4 (syntax-ppss)) (looking-at "*")) - (+ 1 baseline)) - - ;; If we're in any other token-tree / sexp, then: - (t - (or - ;; If we are inside a pair of braces, with something after the - ;; open brace on the same line and ending with a comma, treat - ;; it as fields and align them. - (when (> level 0) - (save-excursion - (rust-rewind-irrelevant) - (backward-up-list) - ;; Point is now at the beginning of the containing set of braces - (rust-align-to-expr-after-brace))) - - (progn - (back-to-indentation) - ;; Point is now at the beginning of the current line - (if (or - ;; If this line begins with "else" or "{", stay on the - ;; baseline as well (we are continuing an expression, - ;; but the "else" or "{" should align with the beginning - ;; of the expression it's in.) - (looking-at "\\\\|{") - - (save-excursion - (rust-rewind-irrelevant) - ;; Point is now at the end of the previous ine - (or - ;; If we are at the first line, no indentation is needed, so stay at baseline... - (= 1 (line-number-at-pos (point))) - ;; ..or if the previous line ends with any of these: - ;; { ? : ( , ; [ } - ;; then we are at the beginning of an expression, so stay on the baseline... - (looking-back "[(,:;?[{}]\\|[^|]|") - ;; or if the previous line is the end of an attribute, stay at the baseline... - (progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#"))))) - baseline - - ;; Otherwise, we are continuing the same expression from the previous line, - ;; so add one additional indent level - (+ baseline rust-indent-offset)))))))))) - - ;; If we're at the beginning of the line (before or at the current - ;; indentation), jump with the indentation change. Otherwise, save the - ;; excursion so that adding the indentations will leave us at the - ;; equivalent position within the line to where we were before. - (if (<= (current-column) (current-indentation)) - (indent-line-to indent) - (save-excursion (indent-line-to indent))))) - - -;; Font-locking definitions and helpers -(defconst rust-mode-keywords - '("as" - "box" "break" - "const" "continue" "crate" - "do" - "else" "enum" "extern" - "false" "fn" "for" - "if" "impl" "in" - "let" "loop" - "match" "mod" "move" "mut" - "priv" "pub" - "ref" "return" - "self" "static" "struct" "super" - "true" "trait" "type" - "unsafe" "use" - "virtual" - "where" "while")) - -(defconst rust-special-types - '("u8" "i8" - "u16" "i16" - "u32" "i32" - "u64" "i64" - - "f32" "f64" - "float" "int" "uint" "isize" "usize" - "bool" - "str" "char")) - -(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") -(defconst rust-re-CamelCase "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*") -(defun rust-re-word (inner) (concat "\\<" inner "\\>")) -(defun rust-re-grab (inner) (concat "\\(" inner "\\)")) -(defun rust-re-grabword (inner) (rust-re-grab (rust-re-word inner))) -(defun rust-re-item-def (itype) - (concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident))) - -(defvar rust-mode-font-lock-keywords - (append - `( - ;; Keywords proper - (,(regexp-opt rust-mode-keywords 'words) . font-lock-keyword-face) - - ;; Special types - (,(regexp-opt rust-special-types 'words) . font-lock-type-face) - - ;; Attributes like `#[bar(baz)]` or `#![bar(baz)]` or `#[bar = "baz"]` - (,(rust-re-grab (concat "#\\!?\\[" rust-re-ident "[^]]*\\]")) - 1 font-lock-preprocessor-face keep) - - ;; Syntax extension invocations like `foo!`, highlight including the ! - (,(concat (rust-re-grab (concat rust-re-ident "!")) "[({[:space:][]") - 1 font-lock-preprocessor-face) - - ;; Field names like `foo:`, highlight excluding the : - (,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face) - - ;; Module names like `foo::`, highlight including the :: - (,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face) - - ;; Lifetimes like `'foo` - (,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1 font-lock-variable-name-face) - - ;; Character constants, since they're not treated as strings - ;; in order to have sufficient leeway to parse 'lifetime above. - (,(rust-re-grab "'[^']'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\[nrt]'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\x[[:xdigit:]]\\{2\\}'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\u[[:xdigit:]]\\{4\\}'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\U[[:xdigit:]]\\{8\\}'") 1 font-lock-string-face) - - ;; CamelCase Means Type Or Constructor - (,(rust-re-grabword rust-re-CamelCase) 1 font-lock-type-face) - ) - - ;; Item definitions - (mapcar #'(lambda (x) - (list (rust-re-item-def (car x)) - 1 (cdr x))) - '(("enum" . font-lock-type-face) - ("struct" . font-lock-type-face) - ("type" . font-lock-type-face) - ("mod" . font-lock-type-face) - ("use" . font-lock-type-face) - ("fn" . font-lock-function-name-face) - ("static" . font-lock-constant-face))))) - -(defun rust-fill-prefix-for-comment-start (line-start) - "Determine what to use for `fill-prefix' based on what is at the beginning of a line." - (let ((result - ;; Replace /* with same number of spaces - (replace-regexp-in-string - "\\(?:/\\*+\\)[!*]" - (lambda (s) - ;; We want the * to line up with the first * of the comment start - (concat (make-string (- (length s) 2) ?\x20) "*")) - line-start))) - ;; Make sure we've got at least one space at the end - (if (not (= (aref result (- (length result) 1)) ?\x20)) - (setq result (concat result " "))) - result)) - -(defun rust-in-comment-paragraph (body) - ;; We might move the point to fill the next comment, but we don't want it - ;; seeming to jump around on the user - (save-excursion - ;; If we're outside of a comment, with only whitespace and then a comment - ;; in front, jump to the comment and prepare to fill it. - (when (not (nth 4 (syntax-ppss))) - (beginning-of-line) - (when (looking-at (concat "[[:space:]\n]*" comment-start-skip)) - (goto-char (match-end 0)))) - - ;; We need this when we're moving the point around and then checking syntax - ;; while doing paragraph fills, because the cache it uses isn't always - ;; invalidated during this. - (syntax-ppss-flush-cache 1) - ;; If we're at the beginning of a comment paragraph with nothing but - ;; whitespace til the next line, jump to the next line so that we use the - ;; existing prefix to figure out what the new prefix should be, rather than - ;; inferring it from the comment start. - (let ((next-bol (line-beginning-position 2))) - (while (save-excursion - (end-of-line) - (syntax-ppss-flush-cache 1) - (and (nth 4 (syntax-ppss)) - (save-excursion - (beginning-of-line) - (looking-at paragraph-start)) - (looking-at "[[:space:]]*$") - (nth 4 (syntax-ppss next-bol)))) - (goto-char next-bol))) - - (syntax-ppss-flush-cache 1) - ;; If we're on the last line of a multiline-style comment that started - ;; above, back up one line so we don't mistake the * of the */ that ends - ;; the comment for a prefix. - (when (save-excursion - (and (nth 4 (syntax-ppss (line-beginning-position 1))) - (looking-at "[[:space:]]*\\*/"))) - (goto-char (line-end-position 0))) - (funcall body))) - -(defun rust-with-comment-fill-prefix (body) - (let* - ((line-string (buffer-substring-no-properties - (line-beginning-position) (line-end-position))) - (line-comment-start - (when (nth 4 (syntax-ppss)) - (cond - ;; If we're inside the comment and see a * prefix, use it - ((string-match "^\\([[:space:]]*\\*+[[:space:]]*\\)" - line-string) - (match-string 1 line-string)) - ;; If we're at the start of a comment, figure out what prefix - ;; to use for the subsequent lines after it - ((string-match (concat "[[:space:]]*" comment-start-skip) line-string) - (rust-fill-prefix-for-comment-start - (match-string 0 line-string)))))) - (fill-prefix - (or line-comment-start - fill-prefix))) - (funcall body))) - -(defun rust-find-fill-prefix () - (rust-with-comment-fill-prefix (lambda () fill-prefix))) - -(defun rust-fill-paragraph (&rest args) - "Special wrapping for `fill-paragraph' to handle multi-line comments with a * prefix on each line." - (rust-in-comment-paragraph - (lambda () - (rust-with-comment-fill-prefix - (lambda () - (let - ((fill-paragraph-function - (if (not (eq fill-paragraph-function 'rust-fill-paragraph)) - fill-paragraph-function)) - (fill-paragraph-handle-comment t)) - (apply 'fill-paragraph args) - t)))))) - -(defun rust-do-auto-fill (&rest args) - "Special wrapping for `do-auto-fill' to handle multi-line comments with a * prefix on each line." - (rust-with-comment-fill-prefix - (lambda () - (apply 'do-auto-fill args) - t))) - -(defun rust-fill-forward-paragraph (arg) - ;; This is to work around some funny behavior when a paragraph separator is - ;; at the very top of the file and there is a fill prefix. - (let ((fill-prefix nil)) (forward-paragraph arg))) - -(defun rust-comment-indent-new-line (&optional arg) - (rust-with-comment-fill-prefix - (lambda () (comment-indent-new-line arg)))) - -;;; Imenu support -(defvar rust-imenu-generic-expression - (append (mapcar #'(lambda (x) - (list nil (rust-re-item-def x) 1)) - '("enum" "struct" "type" "mod" "fn" "trait")) - `(("Impl" ,(rust-re-item-def "impl") 1))) - "Value for `imenu-generic-expression' in Rust mode. - -Create a flat index of the item definitions in a Rust file. - -Imenu will show all the enums, structs, etc. at the same level. -Implementations will be shown under the `Impl` subheading. Use -idomenu (imenu with `ido-mode') for best mileage.") - -;;; Defun Motions - -;;; Start of a Rust item -(defvar rust-top-item-beg-re - (concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*" - (regexp-opt - '("enum" "struct" "type" "mod" "use" "fn" "static" "impl" - "extern" "impl" "static" "trait")))) - -(defun rust-beginning-of-defun (&optional arg) - "Move backward to the beginning of the current defun. - -With ARG, move backward multiple defuns. Negative ARG means -move forward. - -This is written mainly to be used as `beginning-of-defun-function' for Rust. -Don't move to the beginning of the line. `beginning-of-defun', -which calls this, does that afterwards." - (interactive "p") - (re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\_>") - nil 'move (or arg 1))) - -(defun rust-end-of-defun () - "Move forward to the next end of defun. - -With argument, do it that many times. -Negative argument -N means move back to Nth preceding end of defun. - -Assume that this is called after beginning-of-defun. So point is -at the beginning of the defun body. - -This is written mainly to be used as `end-of-defun-function' for Rust." - (interactive "p") - ;; Find the opening brace - (re-search-forward "[{]" nil t) - (goto-char (match-beginning 0)) - ;; Go to the closing brace - (forward-sexp)) - -;; For compatibility with Emacs < 24, derive conditionally -(defalias 'rust-parent-mode - (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode)) - - -;;;###autoload -(define-derived-mode rust-mode rust-parent-mode "Rust" - "Major mode for Rust code." - :group 'rust-mode - :syntax-table rust-mode-syntax-table - - ;; Indentation - (setq-local indent-line-function 'rust-mode-indent-line) - - ;; Fonts - (setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil)) - - ;; Misc - (setq-local comment-start "// ") - (setq-local comment-end "") - (setq-local indent-tabs-mode nil) - - ;; Allow paragraph fills for comments - (setq-local comment-start-skip "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*") - (setq-local paragraph-start - (concat "[[:space:]]*\\(?:" comment-start-skip "\\|\\*/?[[:space:]]*\\|\\)$")) - (setq-local paragraph-separate paragraph-start) - (setq-local normal-auto-fill-function 'rust-do-auto-fill) - (setq-local fill-paragraph-function 'rust-fill-paragraph) - (setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph) - (setq-local adaptive-fill-function 'rust-find-fill-prefix) - (setq-local comment-multi-line t) - (setq-local comment-line-break-function 'rust-comment-indent-new-line) - (setq-local imenu-generic-expression rust-imenu-generic-expression) - (setq-local beginning-of-defun-function 'rust-beginning-of-defun) - (setq-local end-of-defun-function 'rust-end-of-defun)) - -;;;###autoload -(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) - -(defun rust-mode-reload () - (interactive) - (unload-feature 'rust-mode) - (require 'rust-mode) - (rust-mode)) - -;; Issue #6887: Rather than inheriting the 'gnu compilation error -;; regexp (which is broken on a few edge cases), add our own 'rust -;; compilation error regexp and use it instead. -(defvar rustc-compilation-regexps - (let ((file "\\([^\n]+\\)") - (start-line "\\([0-9]+\\)") - (start-col "\\([0-9]+\\)") - (end-line "\\([0-9]+\\)") - (end-col "\\([0-9]+\\)") - (error-or-warning "\\(?:[Ee]rror\\|\\([Ww]arning\\)\\)")) - (let ((re (concat "^" file ":" start-line ":" start-col - ": " end-line ":" end-col - " \\(?:[Ee]rror\\|\\([Ww]arning\\)\\):"))) - (cons re '(1 (2 . 4) (3 . 5) (6))))) - "Specifications for matching errors in rustc invocations. -See `compilation-error-regexp-alist for help on their format.") - -(eval-after-load 'compile - '(progn - (add-to-list 'compilation-error-regexp-alist-alist - (cons 'rustc rustc-compilation-regexps)) - (add-to-list 'compilation-error-regexp-alist 'rustc))) - -(provide 'rust-mode) - -;;; rust-mode.el ends here diff --git a/src/etc/gedit/readme.txt b/src/etc/gedit/readme.txt deleted file mode 100644 index e394f1916088f..0000000000000 --- a/src/etc/gedit/readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -Add syntax highlighting for Mozilla Rust in GtkSourceView (used by GEdit). - - -Instructions for Ubuntu Linux 12.04+ - -1) Close all instances of GEdit - -2) Copy the included "share" folder into "~/.local/" - -3) Open a shell in "~/.local/share/" and run "update-mime-database mime" diff --git a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang deleted file mode 100644 index 8291b38a9bd0b..0000000000000 --- a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang +++ /dev/null @@ -1,340 +0,0 @@ - - - - - - - text/x-rust - *.rs - // - /* - */ - - - -