From 5c60d1d902da615a770ef211217a46d92b3aaae7 Mon Sep 17 00:00:00 2001 From: Barosl Lee Date: Thu, 2 Jul 2015 03:55:18 +0900 Subject: [PATCH 1/9] Preserve escape sequences in documentation comments on macro expansion Escape sequences in documentation comments must not be parsed as a normal string when expanding a macro, otherwise some innocent but invalid-escape-sequence-looking comments will trigger an ICE. Although this commit replaces normal string literals with raw string literals in macro expansion, this shouldn't be much a problem considering documentation comments are converted into attributes before being passed to a macro anyways. Fixes #25929. Fixes #25943. --- src/libsyntax/ast.rs | 2 +- src/test/run-pass/macro-doc-escapes.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/macro-doc-escapes.rs diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e844b206cc0a..a944acad84df 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1104,7 +1104,7 @@ impl TokenTree { tts: vec![TtToken(sp, token::Ident(token::str_to_ident("doc"), token::Plain)), TtToken(sp, token::Eq), - TtToken(sp, token::Literal(token::Str_(name), None))], + TtToken(sp, token::Literal(token::StrRaw(name, 0), None))], close_span: sp, })) } diff --git a/src/test/run-pass/macro-doc-escapes.rs b/src/test/run-pass/macro-doc-escapes.rs new file mode 100644 index 000000000000..ea92f0ffebe6 --- /dev/null +++ b/src/test/run-pass/macro-doc-escapes.rs @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +// When expanding a macro, documentation attributes (including documentation comments) must be +// passed "as is" without being parsed. Otherwise, some text will be incorrectly interpreted as +// escape sequences, leading to an ICE. +// +// Related issues: #25929, #25943 + +macro_rules! homura { + (#[$x:meta]) => () +} + +homura! { + /// \madoka \x41 +} + +fn main() { } From a5d8c43687b55a561511f8eec40ff899ad9f20b7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Jul 2015 13:16:59 +0200 Subject: [PATCH 2/9] Improve register_diagnostics macro --- src/libsyntax/diagnostics/macros.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index 055ade46a3f0..8c2d2a251aab 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -63,6 +63,9 @@ macro_rules! fileline_help { macro_rules! register_diagnostics { ($($code:tt),*) => ( $(register_diagnostic! { $code })* + ); + ($($code:tt),*,) => ( + $(register_diagnostic! { $code })* ) } From 10702319872e2dddb59d1400fe74357f5a98e712 Mon Sep 17 00:00:00 2001 From: Wei-Ming Yang Date: Fri, 17 Jul 2015 15:47:14 +0800 Subject: [PATCH 3/9] Update vec.rs improve the 'Unsafety' section of `collections::vec::Vec::::from_raw_parts`. --- src/libcollections/vec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3848263c5309..2127ac11436b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -231,6 +231,7 @@ impl Vec { /// /// * `ptr` needs to have been previously allocated via `String`/`Vec` /// (at least, it's highly likely to be incorrect if it wasn't). + /// * `length` needs to be the length that less than or equal to `capacity`. /// * `capacity` needs to be the capacity that the pointer was allocated with. /// /// Violating these may cause problems like corrupting the allocator's From 6e58043e75a750a22bbc62586ec5b8f91c7d00e1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 Jul 2015 11:21:05 +0200 Subject: [PATCH 4/9] Improve register_long_diagnostics macro --- src/libsyntax/diagnostics/macros.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index 8c2d2a251aab..669b930ecc92 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -73,5 +73,8 @@ macro_rules! register_diagnostics { macro_rules! register_long_diagnostics { ($($code:tt: $description:tt),*) => ( $(register_diagnostic! { $code, $description })* + ); + ($($code:tt: $description:tt),*,) => ( + $(register_diagnostic! { $code, $description })* ) } From d0e1b06fc0d20d1a6a0a2213134bcc84658e96a0 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 17 Jul 2015 13:15:06 -0400 Subject: [PATCH 5/9] Clean up some wording around globs. Globs used to be a feature you'd turn on, but now they're not, so this sounds a bit odd. --- src/doc/trpl/testing.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index 759543140b57..a5a0127031ae 100644 --- a/src/doc/trpl/testing.md +++ b/src/doc/trpl/testing.md @@ -250,11 +250,10 @@ that our tests are entirely left out of a normal build. The second change is the `use` declaration. Because we're in an inner module, we need to bring our test function into scope. This can be annoying if you have -a large module, and so this is a common use of the `glob` feature. Let's change -our `src/lib.rs` to make use of it: +a large module, and so this is a common use of globs. Let's change our +`src/lib.rs` to make use of it: ```rust,ignore - pub fn add_two(a: i32) -> i32 { a + 2 } From b3a9cd3a69a3b6d0729dbfe1af4db8ccfc359679 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 17 Jul 2015 14:35:09 -0400 Subject: [PATCH 6/9] DRY --- src/librustdoc/html/static/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1eb1556a25d2..b3ad4774091f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -115,7 +115,7 @@ case "s": case "S": ev.preventDefault(); - $(".search-input").focus(); + focusSearchBar() break; case "?": @@ -960,5 +960,5 @@ // Sets the focus on the search bar at the top of the page function focusSearchBar() { - document.getElementsByName('search')[0].focus(); + $('.search-input').focus(); } From 02ae661cfda9129c5fc810d0b83bbd4498dc10f7 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Fri, 17 Jul 2015 20:55:11 +0200 Subject: [PATCH 7/9] doc: add missing space --- src/libcollections/vec_deque.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 117b3544f026..5a3778c3656f 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -946,7 +946,7 @@ impl VecDeque { /// let mut buf = VecDeque::new(); /// buf.push_back(10); /// buf.push_back(12); - /// buf.insert(1,11); + /// buf.insert(1, 11); /// assert_eq!(Some(&11), buf.get(1)); /// ``` pub fn insert(&mut self, i: usize, t: T) { From 94b1ca8448a2bcf25091bfb182ddac29b3b1f2a1 Mon Sep 17 00:00:00 2001 From: Alisdair Owens Date: Thu, 16 Jul 2015 19:21:11 +0100 Subject: [PATCH 8/9] Write diagnostics for E0364 and E0365 --- src/librustc_resolve/diagnostics.rs | 60 ++++++++++++++++++++++++- src/librustc_resolve/resolve_imports.rs | 13 +++++- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 939991da2030..c7125c38aa97 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -197,6 +197,64 @@ See the Types section of the reference for more information about the primitive types: http://doc.rust-lang.org/reference.html#types +"##, + +E0364: r##" +Private items cannot be publicly re-exported. This error indicates that +you attempted to `pub use` a type or value that was not itself public. + +Here is an example that demonstrates the error: + +``` +mod foo { + const X: u32 = 1; +} +pub use foo::X; +``` + +The solution to this problem is to ensure that the items that you are +re-exporting are themselves marked with `pub`: + +``` +mod foo { + pub const X: u32 = 1; +} +pub use foo::X; +``` + +See the 'Use Declarations' section of the reference for more information +on this topic: + +http://doc.rust-lang.org/reference.html#use-declarations +"##, + +E0365: r##" +Private modules cannot be publicly re-exported. This error indicates +that you attempted to `pub use` a module that was not itself public. + +Here is an example that demonstrates the error: + +``` +mod foo { + pub const X: u32 = 1; +} +pub use foo as foo2; + +``` +The solution to this problem is to ensure that the module that you are +re-exporting is itself marked with `pub`: + +``` +pub mod foo { + pub const X: u32 = 1; +} +pub use foo as foo2; +``` + +See the 'Use Declarations' section of the reference for more information +on this topic: + +http://doc.rust-lang.org/reference.html#use-declarations "## } @@ -208,8 +266,6 @@ register_diagnostics! { E0254, // import conflicts with imported crate in this module E0257, E0258, - E0364, // item is private - E0365, // item is private E0401, // can't use type parameters from outer function E0402, // cannot use an outer type parameter in this context E0403, // the name `{}` is already used diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index e797da7b8f64..c876d28f0de4 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -434,8 +434,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { value_result = BoundResult(target_module.clone(), (*child_name_bindings).clone()); if directive.is_public && !child_name_bindings.is_public(ValueNS) { - let msg = format!("`{}` is private", source); + let msg = format!("`{}` is private, and cannot be reexported", + token::get_name(source)); + let note_msg = + format!("Consider marking `{}` as `pub` in the imported module", + token::get_name(source)); span_err!(self.resolver.session, directive.span, E0364, "{}", &msg); + self.resolver.session.span_note(directive.span, ¬e_msg); pub_err = true; } } @@ -444,8 +449,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { type_result = BoundResult(target_module.clone(), (*child_name_bindings).clone()); if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) { - let msg = format!("`{}` is private", source); + let msg = format!("`{}` is private, and cannot be reexported", + token::get_name(source)); + let note_msg = format!("Consider declaring module {} as `pub mod`", + token::get_name(source)); span_err!(self.resolver.session, directive.span, E0365, "{}", &msg); + self.resolver.session.span_note(directive.span, ¬e_msg); } } } From 8638dc7f9ae55d9b3102d152b2e2cca92bb83acf Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 18 Jul 2015 03:06:35 +0530 Subject: [PATCH 9/9] nit --- src/librustc_resolve/resolve_imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c876d28f0de4..ec02963980bd 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -451,7 +451,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) { let msg = format!("`{}` is private, and cannot be reexported", token::get_name(source)); - let note_msg = format!("Consider declaring module {} as `pub mod`", + let note_msg = format!("Consider declaring module `{}` as a `pub mod`", token::get_name(source)); span_err!(self.resolver.session, directive.span, E0365, "{}", &msg); self.resolver.session.span_note(directive.span, ¬e_msg);