From 176624fb4bcc7702a2a0cd859fccc3dec8e2f1ae Mon Sep 17 00:00:00 2001 From: Marcel Hellwig <921462+hellow554@users.noreply.github.com> Date: Thu, 21 Dec 2017 17:10:45 +0100 Subject: [PATCH 01/18] add kbd style tag to main.css in rustdoc --- src/librustdoc/html/static/rustdoc.css | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index e620abea2777b..c5d1ced0db9d4 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1107,3 +1107,17 @@ h3.important { left: -42px; margin-top: 2px; } + +kbd { + display: inline-block; + padding: 3px 5px; + font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + line-height: 10px; + color: #444d56; + vertical-align: middle; + background-color: #fafbfc; + border: solid 1px #d1d5da; + border-bottom-color: #c6cbd1; + border-radius: 3px; + box-shadow: inset 0 -1px 0 #c6cbd1; +} From 6e741df1bd252e9b9d9972dc7f689890686a2b1e Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 22 Dec 2017 13:29:02 +0100 Subject: [PATCH 02/18] moved colors of kbd tag into main.css --- src/librustdoc/html/static/rustdoc.css | 7 ++----- src/librustdoc/html/static/styles/main.css | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index c5d1ced0db9d4..40df2cb76176f 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1113,11 +1113,8 @@ kbd { padding: 3px 5px; font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; line-height: 10px; - color: #444d56; vertical-align: middle; - background-color: #fafbfc; - border: solid 1px #d1d5da; - border-bottom-color: #c6cbd1; + border: solid 1px; border-radius: 3px; - box-shadow: inset 0 -1px 0 #c6cbd1; + box-shadow: inset 0 -1px 0; } diff --git a/src/librustdoc/html/static/styles/main.css b/src/librustdoc/html/static/styles/main.css index c31808cfc0f6d..df8facccafa1f 100644 --- a/src/librustdoc/html/static/styles/main.css +++ b/src/librustdoc/html/static/styles/main.css @@ -343,3 +343,12 @@ pre.ignore:hover, .information:hover + pre.ignore { border-right-color: #000; } } + +kbd { + color: #444d56; + background-color: #fafbfc; + border-color: #d1d5da; + border-bottom-color: #c6cbd1; + box-shadow-color: #c6cbd1; +} + From 38e5d304fe72a49dc6fbac1870546620e3557680 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Mon, 15 Jan 2018 18:12:38 +0100 Subject: [PATCH 03/18] extended dt with kbd tags removed styling of dt tages, which would make them look like keys and added tag inside of dt tag. Added css style for kbd and removed some stylings for dt --- src/librustdoc/html/layout.rs | 18 ++++++++++-------- src/librustdoc/html/static/rustdoc.css | 15 +++++---------- src/librustdoc/html/static/styles/main.css | 5 ----- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 61de5f4bc4c45..3a18c6b8a809e 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -94,20 +94,22 @@ r##"

Keyboard Shortcuts

-
?
+
?
Show this help dialog
-
S
+
S
Focus the search field
-
+
Move up in search results
-
+
Move down in search results
-
+
Switch tab
-
+
Go to active search result
-
+ / -
-
Collapse/expand all sections
+
+
+
Expand all sections
+
-
+
Collapse all sections
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 40df2cb76176f..bc2a5e663a18e 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -585,18 +585,13 @@ body.blur > :not(#help) { flex: 0 0 auto; box-shadow: 0 0 6px rgba(0,0,0,.2); width: 550px; - height: 354px; + height: auto; border: 1px solid; } #help dt { - float: left; - border-radius: 4px; - border: 1px solid; - width: 23px; - text-align: center; - clear: left; - display: block; - margin-top: -1px; + float: left; + clear: left; + display: block; } #help dd { margin: 5px 35px; } #help .infos { padding-left: 0; } @@ -1111,7 +1106,7 @@ h3.important { kbd { display: inline-block; padding: 3px 5px; - font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + font: 15px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; line-height: 10px; vertical-align: middle; border: solid 1px; diff --git a/src/librustdoc/html/static/styles/main.css b/src/librustdoc/html/static/styles/main.css index df8facccafa1f..e28a328cca64d 100644 --- a/src/librustdoc/html/static/styles/main.css +++ b/src/librustdoc/html/static/styles/main.css @@ -194,11 +194,6 @@ a.test-arrow { border-color: #bfbfbf;; } -#help dt { - border-color: #bfbfbf; - background: #fff; -} - .since { color: grey; } From 090a968fe7680cce0d3aa8fde25a5dc48948e43e Mon Sep 17 00:00:00 2001 From: Ryan Cumming Date: Wed, 10 Jan 2018 20:13:03 +1100 Subject: [PATCH 04/18] Only link res_init() on GNU/*nix To workaround a bug in glibc <= 2.26 lookup_host() calls res_init() based on the glibc version detected at runtime. While this avoids calling res_init() on platforms where it's not required we will still end up linking against the symbol. This causes an issue on macOS where res_init() is implemented in a separate library (libresolv.9.dylib) from the main libc. While this is harmless for standalone programs it becomes a problem if Rust code is statically linked against another program. If the linked program doesn't already specify -lresolv it will cause the link to fail. This is captured in issue #46797 Fix this by hooking in to the glibc workaround in `cvt_gai` and only activating it for the "gnu" environment on Unix This should include all glibc platforms while excluding musl, windows-gnu, macOS, FreeBSD, etc. This has the side benefit of removing the #[cfg] in sys_common; only unix.rs has code related to the workaround now. --- src/libstd/sys/unix/l4re.rs | 4 ---- src/libstd/sys/unix/net.rs | 20 +++++++++++++------- src/libstd/sys_common/net.rs | 24 +++--------------------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index c3e8d0b7d95a8..2121848967939 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -437,9 +437,5 @@ pub mod net { pub fn lookup_host(_: &str) -> io::Result { unimpl!(); } - - pub fn res_init_if_glibc_before_2_26() -> io::Result<()> { - unimpl!(); - } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index e775f857f2b40..3f65975e60880 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -51,6 +51,10 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> { if err == 0 { return Ok(()) } + + // We may need to trigger a glibc workaround. See on_resolver_failure() for details. + on_resolver_failure(); + if err == EAI_SYSTEM { return Err(io::Error::last_os_error()) } @@ -377,21 +381,22 @@ impl IntoInner for Socket { // res_init unconditionally, we call it only when we detect we're linking // against glibc version < 2.26. (That is, when we both know its needed and // believe it's thread-safe). -pub fn res_init_if_glibc_before_2_26() -> io::Result<()> { +#[cfg(target_env = "gnu")] +fn on_resolver_failure() { // If the version fails to parse, we treat it the same as "not glibc". if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) { if let Some(version) = parse_glibc_version(version_str) { if version < (2, 26) { - let ret = unsafe { libc::res_init() }; - if ret != 0 { - return Err(io::Error::last_os_error()); - } + unsafe { libc::res_init() }; } } } - Ok(()) } +#[cfg(not(target_env = "gnu"))] +fn on_resolver_failure() {} + +#[cfg(target_env = "gnu")] fn glibc_version_cstr() -> Option<&'static CStr> { weak! { fn gnu_get_libc_version() -> *const libc::c_char @@ -405,6 +410,7 @@ fn glibc_version_cstr() -> Option<&'static CStr> { // Returns Some((major, minor)) if the string is a valid "x.y" version, // ignoring any extra dot-separated parts. Otherwise return None. +#[cfg(target_env = "gnu")] fn parse_glibc_version(version: &str) -> Option<(usize, usize)> { let mut parsed_ints = version.split(".").map(str::parse::).fuse(); match (parsed_ints.next(), parsed_ints.next()) { @@ -413,7 +419,7 @@ fn parse_glibc_version(version: &str) -> Option<(usize, usize)> { } } -#[cfg(test)] +#[cfg(all(test, taget_env = "gnu"))] mod test { use super::*; diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index c70b39995ebb0..b841afe1a5141 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -166,27 +166,9 @@ pub fn lookup_host(host: &str) -> io::Result { hints.ai_socktype = c::SOCK_STREAM; let mut res = ptr::null_mut(); unsafe { - match cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), &hints, &mut res)) { - Ok(_) => { - Ok(LookupHost { original: res, cur: res }) - }, - #[cfg(unix)] - Err(e) => { - // If we're running glibc prior to version 2.26, the lookup - // failure could be caused by caching a stale /etc/resolv.conf. - // We need to call libc::res_init() to clear the cache. But we - // shouldn't call it in on any other platform, because other - // res_init implementations aren't thread-safe. See - // https://github.com/rust-lang/rust/issues/41570 and - // https://github.com/rust-lang/rust/issues/43592. - use sys::net::res_init_if_glibc_before_2_26; - let _ = res_init_if_glibc_before_2_26(); - Err(e) - }, - // the cfg is needed here to avoid an "unreachable pattern" warning - #[cfg(not(unix))] - Err(e) => Err(e), - } + cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), &hints, &mut res)).map(|_| { + LookupHost { original: res, cur: res } + }) } } From 0e1ecbed8364716d131a466b3e3f09e74e52385e Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 16 Jan 2018 19:35:39 -0600 Subject: [PATCH 05/18] add Rust By Example to the bookshelf --- src/doc/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/index.md b/src/doc/index.md index 3784cc3c4b497..3add2774105e0 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -28,6 +28,7 @@ Rust provides a number of book-length sets of documentation, collectively nicknamed 'The Rust Bookshelf.' * [The Rust Programming Language][book] teaches you how to program in Rust. +* [Rust By Example][rbe] teaches you how to program in Rust using editable examples. * [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager. * [The Unstable Book][unstable-book] has documentation for unstable features. * [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust. @@ -51,6 +52,7 @@ before this policy was put into place. That work is being tracked [refchecklist]: https://github.com/rust-lang-nursery/reference/issues/9 [err]: error-index.html [book]: book/index.html +[rbe]: rust-by-example/index.html [nomicon]: nomicon/index.html [unstable-book]: unstable-book/index.html [rustdoc-book]: rustdoc/index.html From 839ff6fef61aff67a01e0f1c39d8190b2de9b65e Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 13 Jan 2018 23:28:00 +0000 Subject: [PATCH 06/18] Updated tests with fixed span location. --- src/test/ui/issue-46471-1.stderr | 2 +- src/test/ui/issue-46471.stderr | 2 +- src/test/ui/issue-46472.stderr | 2 +- src/test/ui/nll/capture-ref-in-struct.stderr | 2 +- src/test/ui/nll/closure-requirements/escape-argument.stderr | 2 +- .../ui/nll/closure-requirements/escape-upvar-nested.stderr | 2 +- src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr | 2 +- src/test/ui/nll/drop-no-may-dangle.stderr | 4 ++-- .../nll/maybe-initialized-drop-implicit-fragment-drop.stderr | 2 +- src/test/ui/nll/maybe-initialized-drop-with-fragment.stderr | 2 +- ...maybe-initialized-drop-with-uninitialized-fragments.stderr | 2 +- src/test/ui/nll/maybe-initialized-drop.stderr | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/ui/issue-46471-1.stderr b/src/test/ui/issue-46471-1.stderr index 9f12092f99cc0..97dfb458d2dfb 100644 --- a/src/test/ui/issue-46471-1.stderr +++ b/src/test/ui/issue-46471-1.stderr @@ -15,7 +15,7 @@ error[E0597]: `z` does not live long enough (Mir) 16 | &mut z | ^^^^^^ borrowed value does not live long enough 17 | }; - | - `z` dropped here while still borrowed + | - `z` dropped here while still borrowed ... 21 | } | - borrowed value needs to live until here diff --git a/src/test/ui/issue-46471.stderr b/src/test/ui/issue-46471.stderr index 19fc579d198ff..4c196bba5a1f1 100644 --- a/src/test/ui/issue-46471.stderr +++ b/src/test/ui/issue-46471.stderr @@ -16,7 +16,7 @@ error[E0597]: `x` does not live long enough (Mir) | ^^ borrowed value does not live long enough ... 18 | } - | - borrowed value only lives until here + | - borrowed value only lives until here | = note: borrowed value must be valid for the static lifetime... diff --git a/src/test/ui/issue-46472.stderr b/src/test/ui/issue-46472.stderr index 50df72fc2a020..2f332a7a55850 100644 --- a/src/test/ui/issue-46472.stderr +++ b/src/test/ui/issue-46472.stderr @@ -24,7 +24,7 @@ error[E0597]: borrowed value does not live long enough (Mir) | ^ temporary value does not live long enough ... 17 | } - | - temporary value only lives until here + | - temporary value only lives until here | note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:1... --> $DIR/issue-46472.rs:13:1 diff --git a/src/test/ui/nll/capture-ref-in-struct.stderr b/src/test/ui/nll/capture-ref-in-struct.stderr index 7e7487daa67a3..d05ec91be3026 100644 --- a/src/test/ui/nll/capture-ref-in-struct.stderr +++ b/src/test/ui/nll/capture-ref-in-struct.stderr @@ -5,7 +5,7 @@ error[E0597]: `y` does not live long enough | ^^ borrowed value does not live long enough ... 38 | } - | - borrowed value only lives until here + | - borrowed value only lives until here 39 | 40 | deref(p); | - borrow later used here diff --git a/src/test/ui/nll/closure-requirements/escape-argument.stderr b/src/test/ui/nll/closure-requirements/escape-argument.stderr index 09d5617b08ef5..ee29f2f9c5c59 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument.stderr @@ -30,7 +30,7 @@ error[E0597]: `y` does not live long enough | ^^ borrowed value does not live long enough 38 | //~^ ERROR `y` does not live long enough [E0597] 39 | } - | - borrowed value only lives until here + | - borrowed value only lives until here 40 | 41 | deref(p); | - borrow later used here diff --git a/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr b/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr index 430fb711c635d..501d299154737 100644 --- a/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr +++ b/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr @@ -57,7 +57,7 @@ error[E0597]: `y` does not live long enough | |_________^ borrowed value does not live long enough ... 36 | } - | - borrowed value only lives until here + | - borrowed value only lives until here 37 | 38 | deref(p); | - borrow later used here diff --git a/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr b/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr index 090bacbc17d07..556cd020f7ff5 100644 --- a/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr +++ b/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr @@ -34,7 +34,7 @@ error[E0597]: `y` does not live long enough | ^^^^^^^^^ borrowed value does not live long enough ... 36 | } - | - borrowed value only lives until here + | - borrowed value only lives until here 37 | 38 | deref(p); | - borrow later used here diff --git a/src/test/ui/nll/drop-no-may-dangle.stderr b/src/test/ui/nll/drop-no-may-dangle.stderr index ef850f3a568c0..dee5873ba3be1 100644 --- a/src/test/ui/nll/drop-no-may-dangle.stderr +++ b/src/test/ui/nll/drop-no-may-dangle.stderr @@ -8,7 +8,7 @@ error[E0506]: cannot assign to `v[..]` because it is borrowed | ^^^^^^^^^ assignment to borrowed `v[..]` occurs here ... 35 | } - | - borrow later used here, when `p` is dropped + | - borrow later used here, when `p` is dropped error[E0506]: cannot assign to `v[..]` because it is borrowed --> $DIR/drop-no-may-dangle.rs:34:5 @@ -19,7 +19,7 @@ error[E0506]: cannot assign to `v[..]` because it is borrowed 34 | v[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed | ^^^^^^^^^ assignment to borrowed `v[..]` occurs here 35 | } - | - borrow later used here, when `p` is dropped + | - borrow later used here, when `p` is dropped error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/maybe-initialized-drop-implicit-fragment-drop.stderr b/src/test/ui/nll/maybe-initialized-drop-implicit-fragment-drop.stderr index 3c685ce111a97..fbaaf5511ccd5 100644 --- a/src/test/ui/nll/maybe-initialized-drop-implicit-fragment-drop.stderr +++ b/src/test/ui/nll/maybe-initialized-drop-implicit-fragment-drop.stderr @@ -8,7 +8,7 @@ error[E0506]: cannot assign to `x` because it is borrowed | ^^^^^ assignment to borrowed `x` occurs here 33 | // FIXME ^ Should not error in the future with implicit dtors, only manually implemented ones 34 | } - | - borrow later used here, when `foo` is dropped + | - borrow later used here, when `foo` is dropped error: aborting due to previous error diff --git a/src/test/ui/nll/maybe-initialized-drop-with-fragment.stderr b/src/test/ui/nll/maybe-initialized-drop-with-fragment.stderr index 072818c7ce17b..5d526cda042e9 100644 --- a/src/test/ui/nll/maybe-initialized-drop-with-fragment.stderr +++ b/src/test/ui/nll/maybe-initialized-drop-with-fragment.stderr @@ -7,7 +7,7 @@ error[E0506]: cannot assign to `x` because it is borrowed 31 | x = 1; //~ ERROR cannot assign to `x` because it is borrowed [E0506] | ^^^^^ assignment to borrowed `x` occurs here 32 | } - | - borrow later used here, when `foo` is dropped + | - borrow later used here, when `foo` is dropped error: aborting due to previous error diff --git a/src/test/ui/nll/maybe-initialized-drop-with-uninitialized-fragments.stderr b/src/test/ui/nll/maybe-initialized-drop-with-uninitialized-fragments.stderr index 89117c2bfeafe..ecd60821194f8 100644 --- a/src/test/ui/nll/maybe-initialized-drop-with-uninitialized-fragments.stderr +++ b/src/test/ui/nll/maybe-initialized-drop-with-uninitialized-fragments.stderr @@ -8,7 +8,7 @@ error[E0506]: cannot assign to `x` because it is borrowed | ^^^^^ assignment to borrowed `x` occurs here 33 | // FIXME ^ This currently errors and it should not. 34 | } - | - borrow later used here, when `foo` is dropped + | - borrow later used here, when `foo` is dropped error: aborting due to previous error diff --git a/src/test/ui/nll/maybe-initialized-drop.stderr b/src/test/ui/nll/maybe-initialized-drop.stderr index 626307a80ed57..874d63a0441b6 100644 --- a/src/test/ui/nll/maybe-initialized-drop.stderr +++ b/src/test/ui/nll/maybe-initialized-drop.stderr @@ -6,7 +6,7 @@ error[E0506]: cannot assign to `x` because it is borrowed 26 | x = 1; //~ ERROR cannot assign to `x` because it is borrowed [E0506] | ^^^^^ assignment to borrowed `x` occurs here 27 | } - | - borrow later used here, when `wrap` is dropped + | - borrow later used here, when `wrap` is dropped error: aborting due to previous error From 13f8c82223202215909890ea772136350a29e752 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 13 Jan 2018 23:28:42 +0000 Subject: [PATCH 07/18] Fixed off-by-one spans in MIR borrowck errors. --- src/librustc_mir/build/scope.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index ddb4bf0e36ba7..389e06e933490 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -695,10 +695,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { if let DropKind::Value { .. } = drop_kind { scope.needs_cleanup = true; } + let region_scope_span = region_scope.span(self.hir.tcx(), &self.hir.region_scope_tree); - // Attribute scope exit drops to scope's closing brace - let scope_end = region_scope_span.with_lo(region_scope_span.hi()); + // Attribute scope exit drops to scope's closing brace. + // Without this check when finding the endpoint, we'll run into an ICE. + let scope_end = if region_scope_span.hi().0 == 0 { + region_scope_span + } else { + region_scope_span.end_point() + }; + scope.drops.push(DropData { span: scope_end, location: place.clone(), From b7228c8705db1557f3ebf207504ecd146ba1a5ee Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 14 Jan 2018 00:23:35 +0000 Subject: [PATCH 08/18] Moved overflow check into end_point function. --- src/librustc_mir/build/scope.rs | 7 +------ src/libsyntax_pos/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 389e06e933490..50e50b95f7750 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -699,12 +699,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let region_scope_span = region_scope.span(self.hir.tcx(), &self.hir.region_scope_tree); // Attribute scope exit drops to scope's closing brace. - // Without this check when finding the endpoint, we'll run into an ICE. - let scope_end = if region_scope_span.hi().0 == 0 { - region_scope_span - } else { - region_scope_span.end_point() - }; + let scope_end = region_scope_span.end_point(); scope.drops.push(DropData { span: scope_end, diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 85f0925b98210..5866d8e4aa932 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -219,7 +219,9 @@ impl Span { /// Returns a new span representing just the end-point of this span pub fn end_point(self) -> Span { let span = self.data(); - let lo = cmp::max(span.hi.0 - 1, span.lo.0); + // We can avoid an ICE by checking if subtraction would cause an overflow. + let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 }; + let lo = cmp::max(hi, span.lo.0); span.with_lo(BytePos(lo)) } From ee606c0e1c7b345e66ca26a4afbdc0e44c1547cd Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 14 Jan 2018 17:29:07 +0000 Subject: [PATCH 09/18] end_point handling multibyte characters correctly. --- src/librustc/infer/error_reporting/mod.rs | 3 +- src/librustc_borrowck/borrowck/check_loans.rs | 4 +- src/librustc_borrowck/borrowck/mod.rs | 3 +- src/librustc_mir/borrow_check/mod.rs | 3 +- src/librustc_mir/build/scope.rs | 2 +- src/librustc_mir/dataflow/impls/borrows.rs | 4 +- src/librustc_resolve/lib.rs | 4 +- src/librustc_typeck/check/mod.rs | 12 +++--- src/libsyntax/codemap.rs | 37 +++++++++++++++++++ src/libsyntax/parse/parser.rs | 8 ++-- src/libsyntax_pos/lib.rs | 16 -------- 11 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c477a0d383e21..4798403561d7a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -958,7 +958,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // `sp` only covers `T`, change it so that it covers // `T:` when appropriate let sp = if has_lifetimes { - sp.to(sp.next_point().next_point()) + sp.to(self.tcx.sess.codemap().next_point( + self.tcx.sess.codemap().next_point(sp))) } else { sp }; diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 908737669c5cb..d1cb8340a8e0f 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -484,8 +484,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { // 3. Where does old loan expire. let previous_end_span = - Some(old_loan.kill_scope.span(self.tcx(), &self.bccx.region_scope_tree) - .end_point()); + Some(self.tcx().sess.codemap().end_point( + old_loan.kill_scope.span(self.tcx(), &self.bccx.region_scope_tree))); let mut err = match (new_loan.kind, old_loan.kind) { (ty::MutBorrow, ty::MutBorrow) => diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 4529e4bab752c..d5999df5919e2 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1321,7 +1321,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { fn region_end_span(&self, region: ty::Region<'tcx>) -> Option { match *region { ty::ReScope(scope) => { - Some(scope.span(self.tcx, &self.region_scope_tree).end_point()) + Some(self.tcx.sess.codemap().end_point( + scope.span(self.tcx, &self.region_scope_tree))) } _ => None } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index b5836c65d675b..c397b859148cb 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1090,10 +1090,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { debug!("check_for_invalidation_at_exit({:?}): INVALID", place); // FIXME: should be talking about the region lifetime instead // of just a span here. + let span = self.tcx.sess.codemap().end_point(span); self.report_borrowed_value_does_not_live_long_enough( context, borrow, - span.end_point(), + span, flow_state.borrows.operator(), ) } diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 50e50b95f7750..a631ab27d1c87 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -699,7 +699,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let region_scope_span = region_scope.span(self.hir.tcx(), &self.hir.region_scope_tree); // Attribute scope exit drops to scope's closing brace. - let scope_end = region_scope_span.end_point(); + let scope_end = self.hir.tcx().sess.codemap().end_point(region_scope_span); scope.drops.push(DropData { span: scope_end, diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index f76aea19677d9..ad29db3e8e116 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -537,8 +537,8 @@ impl<'a, 'gcx, 'tcx> ActiveBorrows<'a, 'gcx, 'tcx> { Some(_) => None, None => { match self.0.region_span_map.get(region) { - Some(span) => Some(span.end_point()), - None => Some(self.0.mir.span.end_point()) + Some(span) => Some(self.0.tcx.sess.codemap().end_point(*span)), + None => Some(self.0.tcx.sess.codemap().end_point(self.0.mir.span)) } } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0a29441cef7ef..9c8560a033362 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2791,8 +2791,8 @@ impl<'a> Resolver<'a> { if let Some(sp) = self.current_type_ascription.last() { let mut sp = *sp; loop { // try to find the `:`, bail on first non-':'/non-whitespace - sp = sp.next_point(); - if let Ok(snippet) = cm.span_to_snippet(sp.to(sp.next_point())) { + sp = cm.next_point(sp); + if let Ok(snippet) = cm.span_to_snippet(sp.to(cm.next_point(sp))) { debug!("snippet {:?}", snippet); let line_sp = cm.lookup_char_pos(sp.hi()).line; let line_base_sp = cm.lookup_char_pos(base_span.lo()).line; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 69236d77ed328..e58feb654c79a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2410,7 +2410,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.span_label(def_s, "defined here"); } if sugg_unit { - let sugg_span = expr_sp.end_point(); + let sugg_span = sess.codemap().end_point(expr_sp); // remove closing `)` from the span let sugg_span = sugg_span.with_hi(sugg_span.lo()); err.span_suggestion( @@ -4400,10 +4400,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// statement and the return type has been left as default or has been specified as `()`. If so, /// it suggests adding a semicolon. fn suggest_missing_semicolon(&self, - err: &mut DiagnosticBuilder<'tcx>, - expression: &'gcx hir::Expr, - expected: Ty<'tcx>, - cause_span: Span) { + err: &mut DiagnosticBuilder<'tcx>, + expression: &'gcx hir::Expr, + expected: Ty<'tcx>, + cause_span: Span) { if expected.is_nil() { // `BlockTailExpression` only relevant if the tail expr would be // useful on its own. @@ -4415,7 +4415,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::ExprLoop(..) | hir::ExprMatch(..) | hir::ExprBlock(..) => { - let sp = cause_span.next_point(); + let sp = self.tcx.sess.codemap().next_point(cause_span); err.span_suggestion(sp, "try adding a semicolon", ";".to_string()); diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a58a61c36361b..e74066da0ac83 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -25,6 +25,7 @@ pub use self::ExpnFormat::*; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use std::cell::{RefCell, Ref}; +use std::cmp; use std::hash::Hash; use std::path::{Path, PathBuf}; use std::rc::Rc; @@ -607,6 +608,42 @@ impl CodeMap { self.span_until_char(sp, '{') } + /// Returns a new span representing just the end-point of this span + pub fn end_point(&self, sp: Span) -> Span { + let hi = sp.hi().0.checked_sub(1).unwrap_or(sp.hi().0); + let hi = self.get_start_of_char_bytepos(BytePos(hi)); + let lo = cmp::max(hi.0, sp.lo().0); + sp.with_lo(BytePos(lo)) + } + + /// Returns a new span representing the next character after the end-point of this span + pub fn next_point(&self, sp: Span) -> Span { + let hi = sp.lo().0.checked_add(1).unwrap_or(sp.lo().0); + let hi = self.get_start_of_char_bytepos(BytePos(hi)); + let lo = cmp::max(sp.hi().0, hi.0); + Span::new(BytePos(lo), BytePos(lo), sp.ctxt()) + } + + fn get_start_of_char_bytepos(&self, bpos: BytePos) -> BytePos { + let idx = self.lookup_filemap_idx(bpos); + let files = self.files.borrow(); + let map = &(*files)[idx]; + + for mbc in map.multibyte_chars.borrow().iter() { + if mbc.pos < bpos { + if bpos.to_usize() >= mbc.pos.to_usize() + mbc.bytes { + // If we do, then return the start of the character. + return mbc.pos; + } + } else { + break; + } + } + + // If this isn't a multibyte character, return the original position. + return bpos; + } + pub fn get_filemap(&self, filename: &FileName) -> Option> { for fm in self.files.borrow().iter() { if *filename == fm.name { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e7565d357397c..ad45db718a281 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -702,13 +702,15 @@ impl<'a> Parser<'a> { expect.clone() }; (format!("expected one of {}, found `{}`", expect, actual), - (self.prev_span.next_point(), format!("expected one of {} here", short_expect))) + (self.sess.codemap().next_point(self.prev_span), + format!("expected one of {} here", short_expect))) } else if expected.is_empty() { (format!("unexpected token: `{}`", actual), (self.prev_span, "unexpected token after this".to_string())) } else { (format!("expected {}, found `{}`", expect, actual), - (self.prev_span.next_point(), format!("expected {} here", expect))) + (self.sess.codemap().next_point(self.prev_span), + format!("expected {} here", expect))) }; let mut err = self.fatal(&msg_exp); let sp = if self.token == token::Token::Eof { @@ -3205,7 +3207,7 @@ impl<'a> Parser<'a> { // return. This won't catch blocks with an explicit `return`, but that would be caught by // the dead code lint. if self.eat_keyword(keywords::Else) || !cond.returns() { - let sp = lo.next_point(); + let sp = self.sess.codemap().next_point(lo); let mut err = self.diagnostic() .struct_span_err(sp, "missing condition for `if` statemement"); err.span_label(sp, "expected if condition here"); diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 5866d8e4aa932..dd1ec7284f690 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -216,22 +216,6 @@ impl Span { self.data().with_ctxt(ctxt) } - /// Returns a new span representing just the end-point of this span - pub fn end_point(self) -> Span { - let span = self.data(); - // We can avoid an ICE by checking if subtraction would cause an overflow. - let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 }; - let lo = cmp::max(hi, span.lo.0); - span.with_lo(BytePos(lo)) - } - - /// Returns a new span representing the next character after the end-point of this span - pub fn next_point(self) -> Span { - let span = self.data(); - let lo = cmp::max(span.hi.0, span.lo.0 + 1); - Span::new(BytePos(lo), BytePos(lo), span.ctxt) - } - /// Returns `self` if `self` is not the dummy span, and `other` otherwise. pub fn substitute_dummy(self, other: Span) -> Span { if self.source_equal(&DUMMY_SP) { other } else { self } From e1c927bc5875e12332d10fd079d18e2dd45bb5ee Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 16 Jan 2018 20:41:00 +0000 Subject: [PATCH 10/18] Replaced multi-byte character handling in end_point with potentially more performant variant. --- src/libsyntax/codemap.rs | 82 +++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index e74066da0ac83..76050f8dc09f0 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -610,38 +610,74 @@ impl CodeMap { /// Returns a new span representing just the end-point of this span pub fn end_point(&self, sp: Span) -> Span { - let hi = sp.hi().0.checked_sub(1).unwrap_or(sp.hi().0); - let hi = self.get_start_of_char_bytepos(BytePos(hi)); - let lo = cmp::max(hi.0, sp.lo().0); - sp.with_lo(BytePos(lo)) + let pos = sp.hi().0; + + let width = self.find_width_of_character_at_span(sp, false); + let corrected_end_position = pos.checked_sub(width).unwrap_or(pos); + + let end_point = BytePos(cmp::max(corrected_end_position, sp.lo().0)); + sp.with_lo(end_point) } /// Returns a new span representing the next character after the end-point of this span pub fn next_point(&self, sp: Span) -> Span { - let hi = sp.lo().0.checked_add(1).unwrap_or(sp.lo().0); - let hi = self.get_start_of_char_bytepos(BytePos(hi)); - let lo = cmp::max(sp.hi().0, hi.0); - Span::new(BytePos(lo), BytePos(lo), sp.ctxt()) + let pos = sp.lo().0; + + let width = self.find_width_of_character_at_span(sp, true); + let corrected_next_position = pos.checked_add(width).unwrap_or(pos); + + let next_point = BytePos(cmp::max(sp.hi().0, corrected_next_position)); + Span::new(next_point, next_point, sp.ctxt()) } - fn get_start_of_char_bytepos(&self, bpos: BytePos) -> BytePos { - let idx = self.lookup_filemap_idx(bpos); - let files = self.files.borrow(); - let map = &(*files)[idx]; + /// Finds the width of a character, either before or after the provided span. + fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 { + // Disregard malformed spans and assume a one-byte wide character. + if sp.lo() > sp.hi() { + return 1; + } - for mbc in map.multibyte_chars.borrow().iter() { - if mbc.pos < bpos { - if bpos.to_usize() >= mbc.pos.to_usize() + mbc.bytes { - // If we do, then return the start of the character. - return mbc.pos; - } - } else { - break; - } + let local_begin = self.lookup_byte_offset(sp.lo()); + let local_end = self.lookup_byte_offset(sp.hi()); + + let start_index = local_begin.pos.to_usize(); + let end_index = local_end.pos.to_usize(); + + // Disregard indexes that are at the start or end of their spans, they can't fit bigger + // characters. + if (!forwards && end_index == usize::min_value()) || + (forwards && start_index == usize::max_value()) { + return 1; + } + + let source_len = (local_begin.fm.end_pos - local_begin.fm.start_pos).to_usize(); + // Ensure indexes are also not malformed. + if start_index > end_index || end_index > source_len { + return 1; } - // If this isn't a multibyte character, return the original position. - return bpos; + // We need to extend the snippet to the end of the src rather than to end_index so when + // searching forwards for boundaries we've got somewhere to search. + let snippet = if let Some(ref src) = local_begin.fm.src { + let len = src.len(); + (&src[start_index..len]).to_string() + } else if let Some(src) = local_begin.fm.external_src.borrow().get_source() { + let len = src.len(); + (&src[start_index..len]).to_string() + } else { + return 1; + }; + + let mut target = if forwards { end_index + 1 } else { end_index - 1 }; + while !snippet.is_char_boundary(target - start_index) { + target = if forwards { target + 1 } else { target - 1 }; + } + + if forwards { + (target - end_index) as u32 + } else { + (end_index - target) as u32 + } } pub fn get_filemap(&self, filename: &FileName) -> Option> { From 9d4ca019ec3c85e0d96dcb68f8814b2abb3d1659 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 17 Jan 2018 10:01:57 +0000 Subject: [PATCH 11/18] next_point now handles creating spans over multibyte characters. --- src/libsyntax/codemap.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 76050f8dc09f0..cfb891f0faaf1 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -621,13 +621,17 @@ impl CodeMap { /// Returns a new span representing the next character after the end-point of this span pub fn next_point(&self, sp: Span) -> Span { - let pos = sp.lo().0; + let start_of_next_point = sp.hi().0; let width = self.find_width_of_character_at_span(sp, true); - let corrected_next_position = pos.checked_add(width).unwrap_or(pos); - - let next_point = BytePos(cmp::max(sp.hi().0, corrected_next_position)); - Span::new(next_point, next_point, sp.ctxt()) + // If the width is 1, then the next span should point to the same `lo` and `hi`. However, + // in the case of a multibyte character, where the width != 1, the next span should + // span multiple bytes to include the whole character. + let end_of_next_point = start_of_next_point.checked_add( + width - 1).unwrap_or(start_of_next_point); + + let end_of_next_point = BytePos(cmp::max(sp.lo().0 + 1, end_of_next_point)); + Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt()) } /// Finds the width of a character, either before or after the provided span. From 2161c3fc31766404f24fde93d11c227f987c190e Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 17 Jan 2018 14:30:16 +0000 Subject: [PATCH 12/18] Fix new test from rebase. --- src/test/ui/nll/return-ref-mut-issue-46557.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/nll/return-ref-mut-issue-46557.stderr b/src/test/ui/nll/return-ref-mut-issue-46557.stderr index 763e2bfd89294..cd77569dae0bf 100644 --- a/src/test/ui/nll/return-ref-mut-issue-46557.stderr +++ b/src/test/ui/nll/return-ref-mut-issue-46557.stderr @@ -5,7 +5,7 @@ error[E0597]: borrowed value does not live long enough | ^^^^^^^ temporary value does not live long enough 18 | x 19 | } - | - temporary value only lives until here + | - temporary value only lives until here | = note: borrowed value must be valid for lifetime '_#2r... From a1b72f7c58dc6c0d4a66903e9de9e12f4405074a Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 17 Jan 2018 16:41:58 +0000 Subject: [PATCH 13/18] Now handling case where span has same lo and hi. --- src/libsyntax/codemap.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index cfb891f0faaf1..8c1bdab28a9d5 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -637,7 +637,7 @@ impl CodeMap { /// Finds the width of a character, either before or after the provided span. fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 { // Disregard malformed spans and assume a one-byte wide character. - if sp.lo() > sp.hi() { + if sp.lo() >= sp.hi() { return 1; } @@ -671,11 +671,16 @@ impl CodeMap { } else { return 1; }; + debug!("DTW start {:?} end {:?}", start_index, end_index); + debug!("DTW snippet {:?}", snippet); let mut target = if forwards { end_index + 1 } else { end_index - 1 }; + debug!("DTW initial target {:?}", target); while !snippet.is_char_boundary(target - start_index) { target = if forwards { target + 1 } else { target - 1 }; + debug!("DTW update target {:?}", target); } + debug!("DTW final target {:?}", target); if forwards { (target - end_index) as u32 From 908aa388f9f0745f133a044d75e8c994c17f3152 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 16 Jan 2018 20:54:48 -0800 Subject: [PATCH 14/18] Deprecate std::net::lookup_host We intended to do this quite a while ago but it snuck through. --- src/libstd/net/addr.rs | 5 ++++- src/libstd/net/mod.rs | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 1ca7e66ed9ca9..fa430939f058c 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -12,7 +12,9 @@ use fmt; use hash; use io; use mem; -use net::{lookup_host, ntoh, hton, IpAddr, Ipv4Addr, Ipv6Addr}; +use net::{ntoh, hton, IpAddr, Ipv4Addr, Ipv6Addr}; +#[allow(deprecated)] +use net::lookup_host; use option; use sys::net::netc as c; use sys_common::{FromInner, AsInner, IntoInner}; @@ -845,6 +847,7 @@ impl ToSocketAddrs for (Ipv6Addr, u16) { } } +#[allow(deprecated)] fn resolve_socket_addr(s: &str, p: u16) -> io::Result> { let ips = lookup_host(s)?; let v: Vec<_> = ips.map(|mut a| { a.set_port(p); a }).collect(); diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index 9fcb93e2032b3..eb0e2e13b4cd2 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -134,12 +134,15 @@ fn each_addr(addr: A, mut f: F) -> io::Result iterator and returning socket \ addresses", issue = "27705")] +#[rustc_deprecated(since = "1.25", reason = "Use the ToSocketAddrs trait instead")] pub struct LookupHost(net_imp::LookupHost); #[unstable(feature = "lookup_host", reason = "unsure about the returned \ iterator and returning socket \ addresses", issue = "27705")] +#[rustc_deprecated(since = "1.25", reason = "Use the ToSocketAddrs trait instead")] +#[allow(deprecated)] impl Iterator for LookupHost { type Item = SocketAddr; fn next(&mut self) -> Option { self.0.next() } @@ -149,6 +152,8 @@ impl Iterator for LookupHost { iterator and returning socket \ addresses", issue = "27705")] +#[rustc_deprecated(since = "1.25", reason = "Use the ToSocketAddrs trait instead")] +#[allow(deprecated)] impl fmt::Debug for LookupHost { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("LookupHost { .. }") @@ -181,6 +186,8 @@ impl fmt::Debug for LookupHost { iterator and returning socket \ addresses", issue = "27705")] +#[rustc_deprecated(since = "1.25", reason = "Use the ToSocketAddrs trait instead")] +#[allow(deprecated)] pub fn lookup_host(host: &str) -> io::Result { net_imp::lookup_host(host).map(LookupHost) } From 0c946c01795b8a3c05273805764ca5d90cb1af60 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 18 Jan 2018 09:06:55 +0100 Subject: [PATCH 15/18] converted space to tab in css files --- src/librustdoc/html/static/rustdoc.css | 6 +++--- src/librustdoc/html/static/styles/main.css | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index bc2a5e663a18e..0f972927d8ecc 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -589,9 +589,9 @@ body.blur > :not(#help) { border: 1px solid; } #help dt { - float: left; - clear: left; - display: block; + float: left; + clear: left; + display: block; } #help dd { margin: 5px 35px; } #help .infos { padding-left: 0; } diff --git a/src/librustdoc/html/static/styles/main.css b/src/librustdoc/html/static/styles/main.css index e28a328cca64d..d4964376af261 100644 --- a/src/librustdoc/html/static/styles/main.css +++ b/src/librustdoc/html/static/styles/main.css @@ -340,10 +340,9 @@ pre.ignore:hover, .information:hover + pre.ignore { } kbd { - color: #444d56; - background-color: #fafbfc; - border-color: #d1d5da; - border-bottom-color: #c6cbd1; - box-shadow-color: #c6cbd1; + color: #444d56; + background-color: #fafbfc; + border-color: #d1d5da; + border-bottom-color: #c6cbd1; + box-shadow-color: #c6cbd1; } - From f66e711f8b7a62ff76bbf29df0dc21eac8000501 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 17 Jan 2018 00:00:17 +0100 Subject: [PATCH 16/18] Add E0659 for ambiguous names --- src/librustc_resolve/diagnostics.rs | 53 +++++++++++++++++++ src/librustc_resolve/lib.rs | 2 +- src/test/compile-fail/E0659.rs | 26 +++++++++ src/test/ui/imports/duplicate.stderr | 8 +-- src/test/ui/imports/macro-paths.stderr | 4 +- src/test/ui/imports/macros.stderr | 4 +- .../ui/imports/shadow_builtin_macros.stderr | 6 +-- 7 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 src/test/compile-fail/E0659.rs diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 564626ac39885..b181a2568b48e 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1621,6 +1621,59 @@ println!("const value: {}", SomeModule::PRIVATE); // ok! ``` "##, +E0659: r##" +An item usage is ambiguous. + +Erroneous code example: + +```compile_fail,E0659 +pub mod moon { + pub fn foo() {} +} + +pub mod earth { + pub fn foo() {} +} + +mod collider { + pub use moon::*; + pub use earth::*; +} + +fn main() { + collider::foo(); // ERROR: `foo` is ambiguous +} +``` + +This error generally appears when two items with the same name are imported into +a module. Here, the `foo` functions are imported and reexported from the +`collider` module and therefore, when we're using `collider::foo()`, both +functions collide. + +To solve this error, the best solution is generally to keep the path before the +item when using it. Example: + +``` +pub mod moon { + pub fn foo() {} +} + +pub mod earth { + pub fn foo() {} +} + +mod collider { + pub use moon; + pub use earth; +} + +fn main() { + collider::moon::foo(); // ok! + collider::earth::foo(); // ok! +} +``` +"##, + } register_diagnostics! { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0a29441cef7ef..aaddd3f5c7223 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3783,7 +3783,7 @@ impl<'a> Resolver<'a> { self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, &msg); } else { let mut err = - self.session.struct_span_err(span, &format!("`{}` is ambiguous", name)); + struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name); err.span_note(b1.span, &msg1); match b2.def() { Def::Macro(..) if b2.span == DUMMY_SP => diff --git a/src/test/compile-fail/E0659.rs b/src/test/compile-fail/E0659.rs new file mode 100644 index 0000000000000..4bd452b0aac3d --- /dev/null +++ b/src/test/compile-fail/E0659.rs @@ -0,0 +1,26 @@ +// 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. + +mod moon { + pub fn foo() {} +} + +mod earth { + pub fn foo() {} +} + +mod collider { + pub use moon::*; + pub use earth::*; +} + +fn main() { + collider::foo(); //~ ERROR E0659 +} diff --git a/src/test/ui/imports/duplicate.stderr b/src/test/ui/imports/duplicate.stderr index 30f2f517115f4..a74401314a18c 100644 --- a/src/test/ui/imports/duplicate.stderr +++ b/src/test/ui/imports/duplicate.stderr @@ -12,7 +12,7 @@ help: You can use `as` to change the binding name of the import 25 | use a::foo as Otherfoo; //~ ERROR the name `foo` is defined multiple times | ^^^^^^^^^^^^^^^^^^ -error: `foo` is ambiguous +error[E0659]: `foo` is ambiguous --> $DIR/duplicate.rs:56:9 | 56 | use self::foo::bar; //~ ERROR `foo` is ambiguous @@ -30,7 +30,7 @@ note: `foo` could also refer to the name imported here | ^^^^^^^^^^^ = note: consider adding an explicit import of `foo` to disambiguate -error: `foo` is ambiguous +error[E0659]: `foo` is ambiguous --> $DIR/duplicate.rs:45:5 | 45 | f::foo(); //~ ERROR `foo` is ambiguous @@ -48,7 +48,7 @@ note: `foo` could also refer to the name imported here | ^^^^ = note: consider adding an explicit import of `foo` to disambiguate -error: `foo` is ambiguous +error[E0659]: `foo` is ambiguous --> $DIR/duplicate.rs:46:5 | 46 | g::foo(); //~ ERROR `foo` is ambiguous @@ -66,7 +66,7 @@ note: `foo` could also refer to the name imported here | ^^^^ = note: consider adding an explicit import of `foo` to disambiguate -error: `foo` is ambiguous +error[E0659]: `foo` is ambiguous --> $DIR/duplicate.rs:59:9 | 59 | foo::bar(); //~ ERROR `foo` is ambiguous diff --git a/src/test/ui/imports/macro-paths.stderr b/src/test/ui/imports/macro-paths.stderr index 91b0b9756dad9..32d78666004c4 100644 --- a/src/test/ui/imports/macro-paths.stderr +++ b/src/test/ui/imports/macro-paths.stderr @@ -1,4 +1,4 @@ -error: `bar` is ambiguous +error[E0659]: `bar` is ambiguous --> $DIR/macro-paths.rs:25:5 | 25 | bar::m! { //~ ERROR ambiguous @@ -16,7 +16,7 @@ note: `bar` could also refer to the name imported here | ^^^^^^ = note: macro-expanded items do not shadow when used in a macro invocation path -error: `baz` is ambiguous +error[E0659]: `baz` is ambiguous --> $DIR/macro-paths.rs:35:5 | 35 | baz::m! { //~ ERROR ambiguous diff --git a/src/test/ui/imports/macros.stderr b/src/test/ui/imports/macros.stderr index 0b67613eb14b6..75294f7bf1256 100644 --- a/src/test/ui/imports/macros.stderr +++ b/src/test/ui/imports/macros.stderr @@ -15,7 +15,7 @@ note: `m` could also refer to the macro imported here 49 | use two_macros::m; | ^^^^^^^^^^^^^ -error: `m` is ambiguous +error[E0659]: `m` is ambiguous --> $DIR/macros.rs:28:5 | 28 | m! { //~ ERROR ambiguous @@ -33,7 +33,7 @@ note: `m` could also refer to the name imported here | ^^^^^^^^^^^^^ = note: macro-expanded macro imports do not shadow -error: `m` is ambiguous +error[E0659]: `m` is ambiguous --> $DIR/macros.rs:41:9 | 41 | m! { //~ ERROR ambiguous diff --git a/src/test/ui/imports/shadow_builtin_macros.stderr b/src/test/ui/imports/shadow_builtin_macros.stderr index 853ed98c30d4d..8f4325fa12c72 100644 --- a/src/test/ui/imports/shadow_builtin_macros.stderr +++ b/src/test/ui/imports/shadow_builtin_macros.stderr @@ -9,7 +9,7 @@ error: `panic` is already in scope | = note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560) -error: `panic` is ambiguous +error[E0659]: `panic` is ambiguous --> $DIR/shadow_builtin_macros.rs:27:14 | 27 | fn f() { panic!(); } //~ ERROR ambiguous @@ -23,7 +23,7 @@ note: `panic` could refer to the name imported here = note: `panic` is also a builtin macro = note: consider adding an explicit import of `panic` to disambiguate -error: `panic` is ambiguous +error[E0659]: `panic` is ambiguous --> $DIR/shadow_builtin_macros.rs:32:14 | 32 | fn f() { panic!(); } //~ ERROR ambiguous @@ -37,7 +37,7 @@ note: `panic` could refer to the name imported here = note: `panic` is also a builtin macro = note: macro-expanded macro imports do not shadow -error: `n` is ambiguous +error[E0659]: `n` is ambiguous --> $DIR/shadow_builtin_macros.rs:61:5 | 61 | n!(); //~ ERROR ambiguous From 005791b33f3f7a0f725065d580b89f0286c31236 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 18 Jan 2018 11:02:32 +0530 Subject: [PATCH 17/18] add target/ to ignored tidy dirs --- src/tools/tidy/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 61d71986b03eb..eee2902bfb6f7 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -69,6 +69,7 @@ fn filter_dirs(path: &Path) -> bool { "src/tools/miri", "src/librustc/mir/interpret", "src/librustc_mir/interpret", + "src/target", ]; skip.iter().any(|p| path.ends_with(p)) } From 9a4287d263748970ee1bf7ba116bbc5225962a4f Mon Sep 17 00:00:00 2001 From: Matthew Walinga Date: Thu, 18 Jan 2018 18:05:33 -0500 Subject: [PATCH 18/18] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54c507304f9f1..70376c120fc0a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -301,12 +301,12 @@ It's absolutely fine to have multiple build directories with different [pull-requests]: #pull-requests Pull requests are the primary mechanism we use to change Rust. GitHub itself -has some [great documentation][pull-requests] on using the Pull Request feature. +has some [great documentation][about-pull-requests] on using the Pull Request feature. We use the "fork and pull" model [described here][development-models], where contributors push changes to their personal fork and create pull requests to bring those changes into the source repository. -[pull-requests]: https://help.github.com/articles/about-pull-requests/ +[about-pull-requests]: https://help.github.com/articles/about-pull-requests/ [development-models]: https://help.github.com/articles/about-collaborative-development-models/ Please make pull requests against the `master` branch.