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. 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 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 d003ef74f054b..bef044d05c286 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1343,7 +1343,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 ddb4bf0e36ba7..a631ab27d1c87 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -695,10 +695,12 @@ 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. + let scope_end = self.hir.tcx().sess.codemap().end_point(region_scope_span); + scope.drops.push(DropData { span: scope_end, location: place.clone(), 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/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 3f0f1a1a4cb58..8a29155d12d5b 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 5b9b3767cb62f..eca6536bb48f7 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; @@ -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/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/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 b41874a56b8e7..34b04de86735e 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; } #help dd { margin: 5px 35px; } #help .infos { padding-left: 0; } @@ -1134,3 +1129,14 @@ h3.important { left: -42px; margin-top: 2px; } + +kbd { + display: inline-block; + padding: 3px 5px; + font: 15px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + line-height: 10px; + vertical-align: middle; + border: solid 1px; + border-radius: 3px; + 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 c79413c0852ce..bd74056242442 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; } @@ -348,3 +343,11 @@ pre.ignore:hover, .information:hover + pre.ignore { border-bottom-color: #e0e0e0; } } + +kbd { + color: #444d56; + background-color: #fafbfc; + border-color: #d1d5da; + border-bottom-color: #c6cbd1; + box-shadow-color: #c6cbd1; +} 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) } 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 } + }) } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a58a61c36361b..8c1bdab28a9d5 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,87 @@ 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 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 start_of_next_point = sp.hi().0; + + let width = self.find_width_of_character_at_span(sp, true); + // 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. + 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; + } + + 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; + } + + // 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; + }; + 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 + } else { + (end_index - target) as u32 + } + } + 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 3d58104260f9a..1689e8eeb4ef4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -704,13 +704,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 { @@ -3210,7 +3212,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 85f0925b98210..dd1ec7284f690 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -216,20 +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(); - let lo = cmp::max(span.hi.0 - 1, 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 } 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 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 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... 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)) }