From c7312fbae4979c6d4fdfbd1f55a71cd47d82a480 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 May 2018 01:10:48 +0200 Subject: [PATCH 01/10] Fixes some style issues in rustdoc "implementations on Foreign types" --- src/librustdoc/html/static/main.js | 10 +++++++-- src/librustdoc/html/static/rustdoc.css | 23 +++++++++++++++++++-- src/librustdoc/html/static/themes/dark.css | 4 ++-- src/librustdoc/html/static/themes/light.css | 4 ++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index e0235bfc6945c..bb9a7e4723248 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1979,7 +1979,7 @@ onEach(e.getElementsByClassName('associatedconstant'), func); }); - function createToggle(otherMessage) { + function createToggle(otherMessage, extraClass) { var span = document.createElement('span'); span.className = 'toggle-label'; span.style.display = 'none'; @@ -1995,6 +1995,9 @@ var wrapper = document.createElement('div'); wrapper.className = 'toggle-wrapper'; + if (extraClass) { + wrapper.className += ' ' + extraClass; + } wrapper.appendChild(mainToggle); return wrapper; } @@ -2023,10 +2026,13 @@ } if (e.parentNode.id === "main") { var otherMessage; + var extraClass; if (hasClass(e, "type-decl")) { otherMessage = ' Show declaration'; + } else if (hasClass(e.childNodes[0], "impl-items")) { + extraClass = "marg-left"; } - e.parentNode.insertBefore(createToggle(otherMessage), e); + e.parentNode.insertBefore(createToggle(otherMessage, extraClass), e); if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") { collapseDocs(e.previousSibling.childNodes[0], "toggle"); } diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 4939505c53144..83abf35c85484 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -474,11 +474,30 @@ h4 > code, h3 > code, .invisible > code { margin-bottom: 15px; } +.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant { + margin-left: 20px; +} .content .impl-items .docblock, .content .impl-items .stability { margin-bottom: .6em; } -.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant { +.content .docblock > .impl-items { margin-left: 20px; + margin-top: -34px; +} +.content .docblock > .impl-items > h4 { + border-bottom: 0; +} +.content .docblock >.impl-items .table-display { + margin: 0; +} +.content .docblock >.impl-items table td { + padding: 0; +} +.toggle-wrapper.marg-left > .collapse-toggle { + left: -24px; +} +.content .docblock > .impl-items .table-display, .impl-items table td { + border: none; } .content .stability code { @@ -542,7 +561,7 @@ a { content: '\2002\00a7\2002'; } -.docblock a:hover, .docblock-short a:hover, .stability a { +.docblock a:not(.srclink):hover, .docblock-short a:not(.srclink):hover, .stability a { text-decoration: underline; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 493a75e25211d..765ef0cd415b7 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -33,7 +33,7 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t background: rgba(0, 0, 0, 0); } -.docblock code, .docblock-short code { +.docblock p > code, .docblock-short p > code { background-color: #2A2A2A; } pre { @@ -163,7 +163,7 @@ a { color: #ddd; } -.docblock a, .docblock-short a, .stability a { +.docblock a:not(.srclink), .docblock-short a:not(.srclink), .stability a { color: #D2991D; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 22f4635fb02e1..5971dc43deda4 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -35,7 +35,7 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t background: rgba(0, 0, 0, 0); } -.docblock code, .docblock-short code { +.docblock p > code, .docblock-short p > code { background-color: #F5F5F5; } pre { @@ -163,7 +163,7 @@ a { color: #000; } -.docblock a, .docblock-short a, .stability a { +.docblock a:not(.srclink), .docblock-short a:not(.srclink), .stability a { color: #3873AD; } From 9b6940d0b46284f24410050e9bfde0a9ab08d0fb Mon Sep 17 00:00:00 2001 From: Nicolas Koch Date: Wed, 30 May 2018 06:33:54 +0200 Subject: [PATCH 02/10] fs: copy: Use File::set_permissions instead of fs::set_permissions We already got the open file descriptor at this point. Don't make the kernel resolve the path again. --- src/libstd/sys/unix/fs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 889d21cad65aa..9d0d377905720 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -807,14 +807,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { let perm = reader.metadata()?.permissions(); let ret = io::copy(&mut reader, &mut writer)?; - set_permissions(to, perm)?; + writer.set_permissions(perm)?; Ok(ret) } #[cfg(any(target_os = "linux", target_os = "android"))] pub fn copy(from: &Path, to: &Path) -> io::Result { use cmp; - use fs::{File, set_permissions}; + use fs::File; use sync::atomic::{AtomicBool, Ordering}; // Kernel prior to 4.5 don't have copy_file_range @@ -886,7 +886,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { // Try again with fallback method assert_eq!(written, 0); let ret = io::copy(&mut reader, &mut writer)?; - set_permissions(to, perm)?; + writer.set_permissions(perm)?; return Ok(ret) }, _ => return Err(err), @@ -894,6 +894,6 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { } } } - set_permissions(to, perm)?; + writer.set_permissions(perm)?; Ok(written) } From c5ee3b6df1db2c4410b0e8d7a80a2885cf5628f1 Mon Sep 17 00:00:00 2001 From: Nicolas Koch Date: Wed, 30 May 2018 12:09:20 +0200 Subject: [PATCH 03/10] Remobve unused import --- src/libstd/sys/unix/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 9d0d377905720..758286fce6ca5 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -796,7 +796,7 @@ pub fn canonicalize(p: &Path) -> io::Result { #[cfg(not(any(target_os = "linux", target_os = "android")))] pub fn copy(from: &Path, to: &Path) -> io::Result { - use fs::{File, set_permissions}; + use fs::File; if !from.is_file() { return Err(Error::new(ErrorKind::InvalidInput, "the source path is not an existing regular file")) From d6b8c67ee6d7c657741909a847ab8dde178000cb Mon Sep 17 00:00:00 2001 From: uuttff8 Date: Wed, 30 May 2018 22:24:24 +0300 Subject: [PATCH 04/10] mod.rs isn't beautiful --- src/libcore/char/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/char/mod.rs b/src/libcore/char/mod.rs index 4f6c302247dd2..59bcf1383f47a 100644 --- a/src/libcore/char/mod.rs +++ b/src/libcore/char/mod.rs @@ -60,10 +60,10 @@ use fmt::{self, Write}; use iter::FusedIterator; // UTF-8 ranges and tags for encoding characters -const TAG_CONT: u8 = 0b1000_0000; -const TAG_TWO_B: u8 = 0b1100_0000; -const TAG_THREE_B: u8 = 0b1110_0000; -const TAG_FOUR_B: u8 = 0b1111_0000; +const TAG_CONT: u8 = 0b1000_0000; +const TAG_TWO_B: u8 = 0b1100_0000; +const TAG_THREE_B: u8 = 0b1110_0000; +const TAG_FOUR_B: u8 = 0b1111_0000; const MAX_ONE_B: u32 = 0x80; const MAX_TWO_B: u32 = 0x800; const MAX_THREE_B: u32 = 0x10000; From 3af6291effa78880e8318425d7327577eb265b66 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 31 May 2018 10:52:29 +1000 Subject: [PATCH 05/10] Tweak identifer lexing. By calling `bump()` after getting the first char, to avoid a redundant `ident_continue()` test on it. --- src/libsyntax/parse/lexer/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index c39eb1594b28b..02f76fa56e402 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -516,6 +516,7 @@ impl<'a> StringReader<'a> { return None; } let start = self.pos; + self.bump(); while ident_continue(self.ch) { self.bump(); } @@ -1155,6 +1156,7 @@ impl<'a> StringReader<'a> { } let start = self.pos; + self.bump(); while ident_continue(self.ch) { self.bump(); } From 5adba8e9d9cbd5f662f91984146b2341460dbd99 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 31 May 2018 13:37:44 +1000 Subject: [PATCH 06/10] Avoid an unnecessary `match` when lexing "<-". --- src/libsyntax/parse/lexer/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 02f76fa56e402..c3ad9eec0827f 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1302,11 +1302,7 @@ impl<'a> StringReader<'a> { } '-' => { self.bump(); - match self.ch.unwrap_or('\x00') { - _ => { - Ok(token::LArrow) - } - } + Ok(token::LArrow) } _ => { Ok(token::Lt) From 8f6441513e8ada486f6301d436a82a539baf34f7 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Tue, 29 May 2018 01:51:36 +0000 Subject: [PATCH 07/10] typeck: Do not pass the field check on field error If a struct pattern has a field error return an error. --- src/librustc_typeck/check/_match.rs | 13 ++++++-- src/test/ui/issue-51102.rs | 48 +++++++++++++++++++++++++++++ src/test/ui/issue-51102.stderr | 24 +++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/issue-51102.rs create mode 100644 src/test/ui/issue-51102.stderr diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 439c0e2d610fa..39b7e24377522 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -720,8 +720,11 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); self.demand_eqtype(pat.span, expected, pat_ty); // Type check subpatterns. - self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm); - pat_ty + if self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm) { + pat_ty + } else { + self.tcx.types.err + } } fn check_pat_path(&self, @@ -846,7 +849,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); variant: &'tcx ty::VariantDef, fields: &'gcx [Spanned], etc: bool, - def_bm: ty::BindingMode) { + def_bm: ty::BindingMode) -> bool { let tcx = self.tcx; let (substs, adt) = match adt_ty.sty { @@ -864,6 +867,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); // Keep track of which fields have already appeared in the pattern. let mut used_fields = FxHashMap(); + let mut no_field_errors = true; let mut inexistent_fields = vec![]; // Typecheck each field. @@ -879,6 +883,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); format!("multiple uses of `{}` in pattern", field.ident)) .span_label(*occupied.get(), format!("first use of `{}`", field.ident)) .emit(); + no_field_errors = false; tcx.types.err } Vacant(vacant) => { @@ -891,6 +896,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); }) .unwrap_or_else(|| { inexistent_fields.push((span, field.ident)); + no_field_errors = false; tcx.types.err }) } @@ -989,5 +995,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); diag.emit(); } } + no_field_errors } } diff --git a/src/test/ui/issue-51102.rs b/src/test/ui/issue-51102.rs new file mode 100644 index 0000000000000..c8f106687ae1c --- /dev/null +++ b/src/test/ui/issue-51102.rs @@ -0,0 +1,48 @@ +// Copyright 2018 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. + +enum SimpleEnum { + NoState, +} + +struct SimpleStruct { + no_state_here: u64, +} + +fn main() { + let _ = |simple| { + match simple { + SimpleStruct { + state: 0, + //~^ struct `SimpleStruct` does not have a field named `state` [E0026] + .. + } => (), + } + }; + + let _ = |simple| { + match simple { + SimpleStruct { + no_state_here: 0, + no_state_here: 1 + //~^ ERROR field `no_state_here` bound multiple times in the pattern [E0025] + } => (), + } + }; + + let _ = |simple| { + match simple { + SimpleEnum::NoState { + state: 0 + //~^ ERROR variant `SimpleEnum::NoState` does not have a field named `state` [E0026] + } => (), + } + }; +} diff --git a/src/test/ui/issue-51102.stderr b/src/test/ui/issue-51102.stderr new file mode 100644 index 0000000000000..a4bd0fb914fee --- /dev/null +++ b/src/test/ui/issue-51102.stderr @@ -0,0 +1,24 @@ +error[E0026]: struct `SimpleStruct` does not have a field named `state` + --> $DIR/issue-51102.rs:23:17 + | +LL | state: 0, + | ^^^^^^^^ struct `SimpleStruct` does not have this field + +error[E0025]: field `no_state_here` bound multiple times in the pattern + --> $DIR/issue-51102.rs:34:17 + | +LL | no_state_here: 0, + | ---------------- first use of `no_state_here` +LL | no_state_here: 1 + | ^^^^^^^^^^^^^^^^ multiple uses of `no_state_here` in pattern + +error[E0026]: variant `SimpleEnum::NoState` does not have a field named `state` + --> $DIR/issue-51102.rs:43:17 + | +LL | state: 0 + | ^^^^^^^^ variant `SimpleEnum::NoState` does not have this field + +error: aborting due to 3 previous errors + +Some errors occurred: E0025, E0026. +For more information about an error, try `rustc --explain E0025`. From 177337d5cc97db43c09be1521133886c67a94c86 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 1 Apr 2018 00:10:34 +0200 Subject: [PATCH 08/10] Stabilize short error format --- src/librustc/session/config.rs | 14 +------------- src/test/ui/short-error-format.rs | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 35538e5d02a23..cc8e8c7c31c20 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1799,19 +1799,7 @@ pub fn build_session_options_and_crate_config( Some("human") => ErrorOutputType::HumanReadable(color), Some("json") => ErrorOutputType::Json(false), Some("pretty-json") => ErrorOutputType::Json(true), - Some("short") => { - if nightly_options::is_unstable_enabled(matches) { - ErrorOutputType::Short(color) - } else { - early_error( - ErrorOutputType::default(), - &format!( - "the `-Z unstable-options` flag must also be passed to \ - enable the short error message option" - ), - ); - } - } + Some("short") => ErrorOutputType::Short(color), None => ErrorOutputType::HumanReadable(color), Some(arg) => early_error( diff --git a/src/test/ui/short-error-format.rs b/src/test/ui/short-error-format.rs index ecce824ca178b..3e6802c51c3a6 100644 --- a/src/test/ui/short-error-format.rs +++ b/src/test/ui/short-error-format.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --error-format=short -Zunstable-options +// compile-flags: --error-format=short fn foo(_: u32) {} From 426b63f8a3aed16b293a34345714c13c836e9276 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 May 2018 23:18:49 +0200 Subject: [PATCH 09/10] Make short-error format GNU compatible --- src/librustc_errors/emitter.rs | 2 +- src/test/ui/short-error-format.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 4d1d33e1325b8..f65acf08c86d8 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1047,7 +1047,7 @@ impl EmitterWriter { } } else { buffer.prepend(0, - &format!("{}:{}:{} - ", + &format!("{}:{}:{}: ", loc.file.name, cm.doctest_offset_line(loc.line), loc.col.0 + 1), diff --git a/src/test/ui/short-error-format.stderr b/src/test/ui/short-error-format.stderr index debe60b463226..f7461b837bdc1 100644 --- a/src/test/ui/short-error-format.stderr +++ b/src/test/ui/short-error-format.stderr @@ -1,3 +1,3 @@ -$DIR/short-error-format.rs:16:9 - error[E0308]: mismatched types -$DIR/short-error-format.rs:18:7 - error[E0599]: no method named `salut` found for type `u32` in the current scope +$DIR/short-error-format.rs:16:9: error[E0308]: mismatched types +$DIR/short-error-format.rs:18:7: error[E0599]: no method named `salut` found for type `u32` in the current scope error: aborting due to 2 previous errors From bad9fefdaef3aa240a0bfec86e7eccb442e452b4 Mon Sep 17 00:00:00 2001 From: Abhishek koserwal Date: Mon, 28 May 2018 17:27:15 +0530 Subject: [PATCH 10/10] Update build instructions --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 19ef96fae015c..04816762f14cb 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Read ["Installation"] from [The Book]. 3. Build and install: ```sh + $ git submodule update --init --recursive --progress $ ./x.py build && sudo ./x.py install ```