From 91c81624b2ccb4bc6bdd521e8fedc70c45198db2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 14 Feb 2017 18:52:28 -0800 Subject: [PATCH 1/9] Release notes for 1.16 --- RELEASES.md | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 1de44ef7e6d05..606936778c49a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,194 @@ +Version 1.16.0 (2017-03-16) +=========================== + +Language +-------- + +* Lifetimes in statics and consts default to `'static`. [RFC 1623] +* [The compiler's `dead_code` lint now accounts for type aliases][38051]. +* [Uninhabitable enums (those without any variants) no longer permit wildcard + match patterns][38069] +* [Clean up semantics of `self` in an import list][38313] +* [`Self` may appear in `impl` headers][38920] +* [`Self` may appear in struct expressions][39282] + +Compiler +-------- + +* [`rustc` now supports `--emit=metadata`, which causes rustc to emit + a `.rmeta` file containing only crate metadata][38571]. This can be + used by tools like the Rust Language Service to perform + metadata-only builds. +* [Levenshtein based typo suggestions now work in most places, while + previously they worked only for fields and sometimes for local + variables][38927]. Together with the overhaul of "no + resolution"/"unexpected resolution" errors (#[38154]) they result in + large and systematic improvement in resolution diagnostics. +* [Fix `transmute::` where `T` requires a bigger alignment than + `U`][38670] +* [rustc: use -Xlinker when specifying an rpath with ',' in it][38798] +* [`rustc` no longer attempts to provide "consider using an explicit + lifetime" suggestions][37057]. They were inaccurate. + +Stabilized APIs +--------------- + +* [`VecDeque::truncate`] +* [`VecDeque::resize`] +* [`String::insert_str`] +* [`Duration::checked_add`] +* [`Duration::checked_sub`] +* [`Duration::checked_div`] +* [`Duration::checked_mul`] +* [`str::replacen`] +* [`str::repeat`] +* [`SocketAddr::is_ipv4`] +* [`SocketAddr::is_ipv6`] +* [`IpAddr::is_ipv4`] +* [`IpAddr::is_ipv6`] +* [`Vec::dedup_by`] +* [`Vec::dedup_by_key`] +* [`Result::unwrap_or_default`] +* [`<*const T>::wrapping_offset`] +* [`<*mut T>::wrapping_offset`] +* `CommandExt::creation_flags` +* [`File::set_permissions`] +* [`String::split_off`] + +Libraries +--------- + +* [`[T]::binary_search` and `[T]::binary_search_by_key` now take + their argument by `Borrow` parameter][37761] +* [All public types in std implement `Debug`][38006] +* [`IpAddr` implements `From` and `From`][38327] +* [`Ipv6Addr` implements `From<[u16; 8]>`][38131] +* [Ctrl-Z returns from `Stdin.read()` when reading from the console on + Windows][38274] +* [std: Fix partial writes in `LineWriter`][38062] +* [std: Clamp max read/write sizes on Unix][38062] +* [Use more specific panic message for `&str` slicing errors][38066] +* [`TcpListener::set_only_v6` is deprecated][38304]. This + functionality cannot be achieved in std currently. +* [`writeln!`, like `println!`, now accepts a form with no string + or formatting arguments, to just print a newline][38469] +* [Implement `iter::Sum` and `iter::Product` for `Result`][38580] +* [Reduce the size of static data in `std_unicode::tables`][38781] +* [`char::EscapeDebug`, `EscapeDefault`, `EscapeUnicode`, + `CaseMappingIter`, `ToLowercase`, `ToUppercase`, implement + `Display`][38909] +* [`Duration` implements `Sum`][38712] +* [`String` implements `ToSocketAddrs`][39048] + +Cargo +----- + +* [The `cargo check` command does a type check of a project without + building it][cargo/3296] +* [crates.io will display CI badges from Travis and AppVeyor, if + specified in Cargo.toml][cargo/3546] +* [crates.io will display categories listed in Cargo.toml][cargo/3301] +* [Compilation profiles accept integer values for `debug`, in addition + to `true` and `false`. These are passed to `rustc` as the value to + `-C debuginfo`][cargo/3534] +* [Implement `cargo --version --verbose`][cargo/3604] +* [All builds now output 'dep-info' build dependencies compatible with + make and ninja][cargo/3557] +* [Build all workspace members with `build --all`][cargo/3511] +* [Document all workspace members with `doc --all`][cargo/3515] +* [Path deps outside workspace are not members][cargo/3443] + +Misc +---- + +* [`rustdoc` has a `--sysroot` argument that, like `rustc`, specifies + the path to the Rust implementation][38589] +* [The `armv7-linux-androideabi` target no longer enables NEON + extensions, per Google's ABI guide][38413] +* [The stock standard library can be compiled for Redox OS][38401] +* [Rust has initial SPARC support][38726]. Tier 3. No builds + available. +* [Rust has experimental support for Nvidia PTX][38559]. Tier 3. No + builds available. +* [Fix backtraces on i686-pc-windows-gnu by disabling FPO][39379] + +Compatibility Notes +------------------- + +* [Uninhabitable enums (those without any variants) no longer permit wildcard + match patterns][38069] +* In this release, references to uninhabited types can not be + pattern-matched. This was accidentally allowed in 1.15. +* [The compiler's `dead_code` lint now accounts for type aliases][38051]. +* [Ctrl-Z returns from `Stdin.read()` when reading from the console on + Windows][38274] +* [Clean up semantics of `self` in an import list][38313] + +[37057]: https://github.com/rust-lang/rust/pull/37057 +[37761]: https://github.com/rust-lang/rust/pull/37761 +[38006]: https://github.com/rust-lang/rust/pull/38006 +[38051]: https://github.com/rust-lang/rust/pull/38051 +[38062]: https://github.com/rust-lang/rust/pull/38062 +[38062]: https://github.com/rust-lang/rust/pull/38622 +[38066]: https://github.com/rust-lang/rust/pull/38066 +[38069]: https://github.com/rust-lang/rust/pull/38069 +[38131]: https://github.com/rust-lang/rust/pull/38131 +[38154]: https://github.com/rust-lang/rust/pull/38154 +[38274]: https://github.com/rust-lang/rust/pull/38274 +[38304]: https://github.com/rust-lang/rust/pull/38304 +[38313]: https://github.com/rust-lang/rust/pull/38313 +[38314]: https://github.com/rust-lang/rust/pull/38314 +[38327]: https://github.com/rust-lang/rust/pull/38327 +[38401]: https://github.com/rust-lang/rust/pull/38401 +[38413]: https://github.com/rust-lang/rust/pull/38413 +[38469]: https://github.com/rust-lang/rust/pull/38469 +[38559]: https://github.com/rust-lang/rust/pull/38559 +[38571]: https://github.com/rust-lang/rust/pull/38571 +[38580]: https://github.com/rust-lang/rust/pull/38580 +[38589]: https://github.com/rust-lang/rust/pull/38589 +[38670]: https://github.com/rust-lang/rust/pull/38670 +[38712]: https://github.com/rust-lang/rust/pull/38712 +[38726]: https://github.com/rust-lang/rust/pull/38726 +[38781]: https://github.com/rust-lang/rust/pull/38781 +[38798]: https://github.com/rust-lang/rust/pull/38798 +[38909]: https://github.com/rust-lang/rust/pull/38909 +[38920]: https://github.com/rust-lang/rust/pull/38920 +[38927]: https://github.com/rust-lang/rust/pull/38927 +[39048]: https://github.com/rust-lang/rust/pull/39048 +[39282]: https://github.com/rust-lang/rust/pull/39282 +[39379]: https://github.com/rust-lang/rust/pull/39379 +[`<*const T>::wrapping_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset +[`<*mut T>::wrapping_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset +[`Duration::checked_add`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_add +[`Duration::checked_div`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_div +[`Duration::checked_mul`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_mul +[`Duration::checked_sub`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_sub +[`File::set_permissions`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.set_permissions +[`IpAddr::is_ipv4`]: https://doc.rust-lang.org/std/net/enum.IpAddr.html#method.is_ipv4 +[`IpAddr::is_ipv6`]: https://doc.rust-lang.org/std/net/enum.IpAddr.html#method.is_ipv6 +[`Result::unwrap_or_default`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_default +[`SocketAddr::is_ipv4`]: https://doc.rust-lang.org/std/net/enum.SocketAddr.html#method.is_ipv4 +[`SocketAddr::is_ipv6`]: https://doc.rust-lang.org/std/net/enum.SocketAddr.html#method.is_ipv6 +[`String::insert_str`]: https://doc.rust-lang.org/std/string/struct.String.html#method.insert_str +[`String::split_off`]: https://doc.rust-lang.org/std/string/struct.String.html#method.split_off +[`Vec::dedup_by_key`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.dedup_by_key +[`Vec::dedup_by`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.dedup_by +[`VecDeque::resize`]: https://doc.rust-lang.org/std/collections/vec_deque/struct.VecDeque.html#method.resize +[`VecDeque::truncate`]: https://doc.rust-lang.org/std/collections/vec_deque/struct.VecDeque.html#method.truncate +[`str::repeat`]: https://doc.rust-lang.org/std/primitive.str.html#method.repeat +[`str::replacen`]: https://doc.rust-lang.org/std/primitive.str.html#method.replacen +[cargo/3296]: https://github.com/rust-lang/cargo/pull/3296 +[cargo/3301]: https://github.com/rust-lang/cargo/pull/3301 +[cargo/3443]: https://github.com/rust-lang/cargo/pull/3443 +[cargo/3511]: https://github.com/rust-lang/cargo/pull/3511 +[cargo/3515]: https://github.com/rust-lang/cargo/pull/3515 +[cargo/3534]: https://github.com/rust-lang/cargo/pull/3534 +[cargo/3546]: https://github.com/rust-lang/cargo/pull/3546 +[cargo/3557]: https://github.com/rust-lang/cargo/pull/3557 +[cargo/3604]: https://github.com/rust-lang/cargo/pull/3604 +[RFC 1623]: https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md + + Version 1.15.1 (2017-02-09) =========================== From 3f45364eba9682e975b288eda7d36bcec8aa7654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 5 Mar 2017 21:18:22 -0300 Subject: [PATCH 2/9] Fix ICE: don't use `struct_variant` on enums Fix #40221 and add unittest. --- src/librustc_const_eval/pattern.rs | 6 ++++- src/test/ui/missing-items/issue-40221.rs | 26 ++++++++++++++++++++ src/test/ui/missing-items/issue-40221.stderr | 8 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/missing-items/issue-40221.rs create mode 100644 src/test/ui/missing-items/issue-40221.stderr diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index c6272613f4d09..e96b88f0c51cb 100644 --- a/src/librustc_const_eval/pattern.rs +++ b/src/librustc_const_eval/pattern.rs @@ -152,7 +152,11 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { Some(&adt_def.variants[variant_index]) } _ => if let ty::TyAdt(adt, _) = self.ty.sty { - Some(adt.struct_variant()) + if adt.is_univariant() { + Some(&adt.variants[0]) + } else { + None + } } else { None } diff --git a/src/test/ui/missing-items/issue-40221.rs b/src/test/ui/missing-items/issue-40221.rs new file mode 100644 index 0000000000000..9cf1c7d6de8a4 --- /dev/null +++ b/src/test/ui/missing-items/issue-40221.rs @@ -0,0 +1,26 @@ +// Copyright 2017 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 P { + C(PC), +} + +enum PC { + Q, + QA, +} + +fn test(proto: P) { + match proto { + P::C(PC::Q) => (), + } +} + +fn main() {} diff --git a/src/test/ui/missing-items/issue-40221.stderr b/src/test/ui/missing-items/issue-40221.stderr new file mode 100644 index 0000000000000..fc90c8a2b20be --- /dev/null +++ b/src/test/ui/missing-items/issue-40221.stderr @@ -0,0 +1,8 @@ +error[E0004]: non-exhaustive patterns: `C(QA)` not covered + --> $DIR/issue-40221.rs:21:11 + | +21 | match proto { + | ^^^^^ pattern `C(QA)` not covered + +error: aborting due to previous error + From 636299ab39073eac73b1c9b2340531b688d01a76 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 5 Mar 2017 08:14:21 +0000 Subject: [PATCH 3/9] Fix const expression macro invocations. --- src/librustc/hir/map/def_collector.rs | 21 +++++++++--------- src/librustc_resolve/build_reduced_graph.rs | 2 +- src/librustc_resolve/macros.rs | 18 ++++++++-------- src/test/run-pass/issue-40136.rs | 24 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 src/test/run-pass/issue-40136.rs diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index be8780f39b104..ccaf663c7ad2a 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -26,7 +26,7 @@ pub struct DefCollector<'a> { pub struct MacroInvocationData { pub mark: Mark, pub def_index: DefIndex, - pub const_integer: bool, + pub const_expr: bool, } impl<'a> DefCollector<'a> { @@ -65,10 +65,10 @@ impl<'a> DefCollector<'a> { self.parent_def = parent; } - pub fn visit_ast_const_integer(&mut self, expr: &Expr) { + pub fn visit_const_expr(&mut self, expr: &Expr) { match expr.node { // Find the node which will be used after lowering. - ExprKind::Paren(ref inner) => return self.visit_ast_const_integer(inner), + ExprKind::Paren(ref inner) => return self.visit_const_expr(inner), ExprKind::Mac(..) => return self.visit_macro_invoc(expr.id, true), // FIXME(eddyb) Closures should have separate // function definition IDs and expression IDs. @@ -79,11 +79,11 @@ impl<'a> DefCollector<'a> { self.create_def(expr.id, DefPathData::Initializer); } - fn visit_macro_invoc(&mut self, id: NodeId, const_integer: bool) { + fn visit_macro_invoc(&mut self, id: NodeId, const_expr: bool) { if let Some(ref mut visit) = self.visit_macro_invoc { visit(MacroInvocationData { mark: Mark::from_placeholder_id(id), - const_integer: const_integer, + const_expr: const_expr, def_index: self.parent_def.unwrap(), }) } @@ -142,7 +142,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } if let Some(ref expr) = v.node.disr_expr { - this.visit_ast_const_integer(expr); + this.visit_const_expr(expr); } }); } @@ -194,7 +194,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { let def = self.create_def(ti.id, def_data); self.with_parent(def, |this| { if let TraitItemKind::Const(_, Some(ref expr)) = ti.node { - this.create_def(expr.id, DefPathData::Initializer); + this.visit_const_expr(expr); } visit::walk_trait_item(this, ti); @@ -212,7 +212,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { let def = self.create_def(ii.id, def_data); self.with_parent(def, |this| { if let ImplItemKind::Const(_, ref expr) = ii.node { - this.create_def(expr.id, DefPathData::Initializer); + this.visit_const_expr(expr); } visit::walk_impl_item(this, ii); @@ -240,7 +240,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { match expr.node { ExprKind::Mac(..) => return self.visit_macro_invoc(expr.id, false), - ExprKind::Repeat(_, ref count) => self.visit_ast_const_integer(count), + ExprKind::Repeat(_, ref count) => self.visit_const_expr(count), ExprKind::Closure(..) => { let def = self.create_def(expr.id, DefPathData::ClosureExpr); self.parent_def = Some(def); @@ -255,10 +255,11 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { fn visit_ty(&mut self, ty: &'a Ty) { match ty.node { TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false), - TyKind::Array(_, ref length) => self.visit_ast_const_integer(length), + TyKind::Array(_, ref length) => self.visit_const_expr(length), TyKind::ImplTrait(..) => { self.create_def(ty.id, DefPathData::ImplTrait); } + TyKind::Typeof(ref expr) => self.visit_const_expr(expr), _ => {} } visit::walk_ty(self, ty); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index f74af416cde09..ca7c0ae67f2d8 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -498,7 +498,7 @@ impl<'a> Resolver<'a> { let invocation = self.arenas.alloc_invocation_data(InvocationData { module: Cell::new(self.get_extern_crate_root(def_id.krate)), def_index: CRATE_DEF_INDEX, - const_integer: false, + const_expr: false, legacy_scope: Cell::new(LegacyScope::Empty), expansion: Cell::new(LegacyScope::Empty), }); diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 682b3ff834fad..3594fb7b9f266 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -39,9 +39,9 @@ use syntax_pos::{Span, DUMMY_SP}; pub struct InvocationData<'a> { pub module: Cell>, pub def_index: DefIndex, - // True if this expansion is in a `const_integer` position, for example `[u32; m!()]`. - // c.f. `DefCollector::visit_ast_const_integer`. - pub const_integer: bool, + // True if this expansion is in a `const_expr` position, for example `[u32; m!()]`. + // c.f. `DefCollector::visit_const_expr`. + pub const_expr: bool, // The scope in which the invocation path is resolved. pub legacy_scope: Cell>, // The smallest scope that includes this invocation's expansion, @@ -54,7 +54,7 @@ impl<'a> InvocationData<'a> { InvocationData { module: Cell::new(graph_root), def_index: CRATE_DEF_INDEX, - const_integer: false, + const_expr: false, legacy_scope: Cell::new(LegacyScope::Empty), expansion: Cell::new(LegacyScope::Empty), } @@ -92,7 +92,7 @@ impl<'a> base::Resolver for Resolver<'a> { self.invocations.insert(mark, self.arenas.alloc_invocation_data(InvocationData { module: Cell::new(module), def_index: module.def_id().unwrap().index, - const_integer: false, + const_expr: false, legacy_scope: Cell::new(LegacyScope::Empty), expansion: Cell::new(LegacyScope::Empty), })); @@ -413,13 +413,13 @@ impl<'a> Resolver<'a> { fn collect_def_ids(&mut self, invocation: &'a InvocationData<'a>, expansion: &Expansion) { let Resolver { ref mut invocations, arenas, graph_root, .. } = *self; - let InvocationData { def_index, const_integer, .. } = *invocation; + let InvocationData { def_index, const_expr, .. } = *invocation; let visit_macro_invoc = &mut |invoc: map::MacroInvocationData| { invocations.entry(invoc.mark).or_insert_with(|| { arenas.alloc_invocation_data(InvocationData { def_index: invoc.def_index, - const_integer: invoc.const_integer, + const_expr: invoc.const_expr, module: Cell::new(graph_root), expansion: Cell::new(LegacyScope::Empty), legacy_scope: Cell::new(LegacyScope::Empty), @@ -430,9 +430,9 @@ impl<'a> Resolver<'a> { let mut def_collector = DefCollector::new(&mut self.definitions); def_collector.visit_macro_invoc = Some(visit_macro_invoc); def_collector.with_parent(def_index, |def_collector| { - if const_integer { + if const_expr { if let Expansion::Expr(ref expr) = *expansion { - def_collector.visit_ast_const_integer(expr); + def_collector.visit_const_expr(expr); } } expansion.visit_with(def_collector) diff --git a/src/test/run-pass/issue-40136.rs b/src/test/run-pass/issue-40136.rs new file mode 100644 index 0000000000000..db642812b4be4 --- /dev/null +++ b/src/test/run-pass/issue-40136.rs @@ -0,0 +1,24 @@ +// Copyright 2016 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. + +#![feature(associated_consts)] + +macro_rules! m { () => { 0 } } + +trait T { + const C: i32 = m!(); +} + +struct S; +impl S { + const C: i32 = m!(); +} + +fn main() {} From d735d956878309e2cb9143751c3f4e58e8e9ab1e Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Thu, 23 Feb 2017 19:03:30 +0200 Subject: [PATCH 4/9] trans: don't ICE when trying to create ADT trans-items ADTs are translated in-place from rustc_trans::callee, so no trans-items are needed. This fix will be superseded by the shimmir branch, but I prefer not to backport that to beta. Fixes #39823. --- src/librustc_trans/collector.rs | 18 +++++++----- src/test/run-pass/auxiliary/issue_39823.rs | 17 +++++++++++ src/test/run-pass/issue-39823.rs | 34 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 src/test/run-pass/auxiliary/issue_39823.rs create mode 100644 src/test/run-pass/issue-39823.rs diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 392c270c130a8..87cb0c343303d 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -615,19 +615,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { def_id: DefId) -> bool { match tcx.item_type(def_id).sty { - ty::TyFnDef(def_id, _, f) => { + ty::TyFnDef(def_id, _, _) => { // Some constructors also have type TyFnDef but they are // always instantiated inline and don't result in a // translation item. Same for FFI functions. if let Some(hir_map::NodeForeignItem(_)) = tcx.hir.get_if_local(def_id) { return false; } - - if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() { - if adt_def.variants.iter().any(|v| def_id == v.did) { - return false; - } - } } ty::TyClosure(..) => {} _ => return false @@ -689,6 +683,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool { + if let ty::TyFnDef(_, _, f) = tcx.item_type(def_id).sty { + if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() { + if adt_def.variants.iter().any(|v| def_id == v.did) { + // HACK: ADT constructors are translated in-place and + // do not have a trans-item. + return false; + } + } + } + if def_id.is_local() { true } else { diff --git a/src/test/run-pass/auxiliary/issue_39823.rs b/src/test/run-pass/auxiliary/issue_39823.rs new file mode 100644 index 0000000000000..5342601ac14ff --- /dev/null +++ b/src/test/run-pass/auxiliary/issue_39823.rs @@ -0,0 +1,17 @@ +// Copyright 2017 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. + +#![crate_type="rlib"] + +#[derive(Debug, PartialEq)] +pub struct RemoteC(pub u32); + +#[derive(Debug, PartialEq)] +pub struct RemoteG(pub T); diff --git a/src/test/run-pass/issue-39823.rs b/src/test/run-pass/issue-39823.rs new file mode 100644 index 0000000000000..061a55b03b218 --- /dev/null +++ b/src/test/run-pass/issue-39823.rs @@ -0,0 +1,34 @@ +// Copyright 2016 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. + +// aux-build:issue_39823.rs + +extern crate issue_39823; +use issue_39823::{RemoteC, RemoteG}; + +#[derive(Debug, PartialEq)] +struct LocalC(u32); + +#[derive(Debug, PartialEq)] +struct LocalG(T); + +fn main() { + let virtual_localc : &Fn(_) -> LocalC = &LocalC; + assert_eq!(virtual_localc(1), LocalC(1)); + + let virtual_localg : &Fn(_) -> LocalG = &LocalG; + assert_eq!(virtual_localg(1), LocalG(1)); + + let virtual_remotec : &Fn(_) -> RemoteC = &RemoteC; + assert_eq!(virtual_remotec(1), RemoteC(1)); + + let virtual_remoteg : &Fn(_) -> RemoteG = &RemoteG; + assert_eq!(virtual_remoteg(1), RemoteG(1)); +} From 64a3b620524db902c9995570f9ba8b40d41cb8d3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 9 Mar 2017 21:43:34 +0000 Subject: [PATCH 5/9] Bump prerelease version --- mk/main.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/main.mk b/mk/main.mk index 1563acfc29458..d2b9a13642f03 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.16.0 # An optional number to put after the label, e.g. '.2' -> '-beta.2' # NB Make sure it starts with a dot to conform to semver pre-release # versions (section 9) -CFG_PRERELEASE_VERSION=.3 +CFG_PRERELEASE_VERSION=.4 ifeq ($(CFG_RELEASE_CHANNEL),stable) # This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly" From 46928b84be8a1dfe60cc5a7be5f315edc7db426a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 9 Mar 2017 21:05:56 +0200 Subject: [PATCH 6/9] Rename expected_types_for_fn_args to expected_inputs_for_expected_output. --- src/librustc_typeck/check/callee.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 3a980c8e7642b..1b90d009b97c4 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Call the generic checker. let expected_arg_tys = - self.expected_types_for_fn_args(call_expr.span, + self.expected_inputs_for_expected_output(call_expr.span, expected, fn_sig.output(), fn_sig.inputs()); @@ -284,7 +284,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // do know the types expected for each argument and the return // type. - let expected_arg_tys = self.expected_types_for_fn_args(call_expr.span, + let expected_arg_tys = self.expected_inputs_for_expected_output(call_expr.span, expected, fn_sig.output().clone(), fn_sig.inputs()); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c435f9341253e..6e62c49224314 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2411,7 +2411,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match method_fn_ty.sty { ty::TyFnDef(def_id, .., ref fty) => { // HACK(eddyb) ignore self in the definition (see above). - let expected_arg_tys = self.expected_types_for_fn_args( + let expected_arg_tys = self.expected_inputs_for_expected_output( sp, expected, fty.sig.0.output(), @@ -2764,14 +2764,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { TypeAndSubsts { substs: substs, ty: substd_ty } } - /// Unifies the return type with the expected type early, for more coercions - /// and forward type information on the argument expressions. - fn expected_types_for_fn_args(&self, - call_span: Span, - expected_ret: Expectation<'tcx>, - formal_ret: Ty<'tcx>, - formal_args: &[Ty<'tcx>]) - -> Vec> { + /// Unifies the output type with the expected type early, for more coercions + /// and forward type information on the input expressions. + fn expected_inputs_for_expected_output(&self, + call_span: Span, + expected_ret: Expectation<'tcx>, + formal_ret: Ty<'tcx>, + formal_args: &[Ty<'tcx>]) + -> Vec> { let expected_args = expected_ret.only_has_type(self).and_then(|ret_ty| { self.fudge_regions_if_ok(&RegionVariableOrigin::Coercion(call_span), || { // Attempt to apply a subtyping relationship between the formal @@ -2794,7 +2794,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }).collect()) }).ok() }).unwrap_or(vec![]); - debug!("expected_types_for_fn_args(formal={:?} -> {:?}, expected={:?} -> {:?})", + debug!("expected_inputs_for_expected_output(formal={:?} -> {:?}, expected={:?} -> {:?})", formal_args, formal_ret, expected_args, expected_ret); expected_args From a0a352df8536b52414330135986de582e6be4423 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 9 Mar 2017 21:06:18 +0200 Subject: [PATCH 7/9] Propagate expected type hints through struct literals. --- src/librustc_typeck/check/mod.rs | 29 +++++++++++++++++++++-------- src/test/run-pass/issue-31260.rs | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/test/run-pass/issue-31260.rs diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6e62c49224314..377416aa057c0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3151,14 +3151,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_expr_struct_fields(&self, adt_ty: Ty<'tcx>, + expected: Expectation<'tcx>, expr_id: ast::NodeId, span: Span, variant: &'tcx ty::VariantDef, ast_fields: &'gcx [hir::Field], check_completeness: bool) { let tcx = self.tcx; - let (substs, adt_kind, kind_name) = match adt_ty.sty { - ty::TyAdt(adt, substs) => (substs, adt.adt_kind(), adt.variant_descr()), + + let adt_ty_hint = + self.expected_inputs_for_expected_output(span, expected, adt_ty, &[adt_ty]) + .get(0).cloned().unwrap_or(adt_ty); + + let (substs, hint_substs, adt_kind, kind_name) = match (&adt_ty.sty, &adt_ty_hint.sty) { + (&ty::TyAdt(adt, substs), &ty::TyAdt(_, hint_substs)) => { + (substs, hint_substs, adt.adt_kind(), adt.variant_descr()) + } _ => span_bug!(span, "non-ADT passed to check_expr_struct_fields") }; @@ -3173,10 +3181,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Typecheck each field. for field in ast_fields { - let expected_field_type; + let final_field_type; + let field_type_hint; if let Some(v_field) = remaining_fields.remove(&field.name.node) { - expected_field_type = self.field_ty(field.span, v_field, substs); + final_field_type = self.field_ty(field.span, v_field, substs); + field_type_hint = self.field_ty(field.span, v_field, hint_substs); seen_fields.insert(field.name.node, field.span); @@ -3188,7 +3198,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } else { error_happened = true; - expected_field_type = tcx.types.err; + final_field_type = tcx.types.err; + field_type_hint = tcx.types.err; if let Some(_) = variant.find_field_named(field.name.node) { let mut err = struct_span_err!(self.tcx.sess, field.name.span, @@ -3210,7 +3221,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Make sure to give a type to the field even if there's // an error, so we can continue typechecking - self.check_expr_coercable_to_type(&field.expr, expected_field_type); + let ty = self.check_expr_with_hint(&field.expr, field_type_hint); + self.demand_coerce(&field.expr, ty, final_field_type); } // Make sure the programmer specified correct number of fields. @@ -3320,6 +3332,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_expr_struct(&self, expr: &hir::Expr, + expected: Expectation<'tcx>, qpath: &hir::QPath, fields: &'gcx [hir::Field], base_expr: &'gcx Option>) -> Ty<'tcx> @@ -3338,7 +3351,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::QPath::TypeRelative(ref qself, _) => qself.span }; - self.check_expr_struct_fields(struct_ty, expr.id, path_span, variant, fields, + self.check_expr_struct_fields(struct_ty, expected, expr.id, path_span, variant, fields, base_expr.is_none()); if let &Some(ref base_expr) = base_expr { self.check_expr_has_type(base_expr, struct_ty); @@ -3883,7 +3896,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } hir::ExprStruct(ref qpath, ref fields, ref base_expr) => { - self.check_expr_struct(expr, qpath, fields, base_expr) + self.check_expr_struct(expr, expected, qpath, fields, base_expr) } hir::ExprField(ref base, ref field) => { self.check_field(expr, lvalue_pref, &base, field) diff --git a/src/test/run-pass/issue-31260.rs b/src/test/run-pass/issue-31260.rs new file mode 100644 index 0000000000000..e771fc7464d00 --- /dev/null +++ b/src/test/run-pass/issue-31260.rs @@ -0,0 +1,20 @@ +// Copyright 2017 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. + +pub struct Struct { + pub field: K, +} + +// Partial fix for #31260, doesn't work without {...}. +static STRUCT: Struct<&'static [u8]> = Struct { + field: {&[1]} +}; + +fn main() {} From eac7c8e167ee3ab0d7fdaf1f7bbd043caffb95fc Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 10 Mar 2017 06:00:03 +0000 Subject: [PATCH 8/9] Fix #39390 on beta. --- src/libsyntax/parse/parser.rs | 29 +++++++++++++------ .../{compile-fail => run-pass}/issue-39709.rs | 7 +++-- 2 files changed, 25 insertions(+), 11 deletions(-) rename src/test/{compile-fail => run-pass}/issue-39709.rs (75%) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 341e4b1b9480c..b7d1198af0b6c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -300,16 +300,27 @@ impl<'a> Parser<'a> { fn next_tok(&mut self) -> TokenAndSpan { loop { let tok = if let Some((tts, i)) = self.tts.pop() { - let tt = tts.get_tt(i); - if i + 1 < tts.len() { - self.tts.push((tts, i + 1)); - } - // FIXME(jseyfried): remove after fixing #39390 in #39419. - if self.quote_depth > 0 { - if let TokenTree::Sequence(sp, _) = tt { - self.span_err(sp, "attempted to repeat an expression containing no \ - syntax variables matched as repeating at this depth"); + let (tt, is_last) = if let &TokenTree::Sequence(span, ref seq) = &tts { + if i == 0 { + (TokenTree::Token(span, token::Dollar), false) + } else if i == 1 { + (TokenTree::Token(span, token::OpenDelim(token::Paren)), false) + } else if i < tts.len() + 2 { + (tts.get_tt(i - 2), false) + } else if i == tts.len() + 2 { + (TokenTree::Token(span, token::CloseDelim(token::Paren)), false) + } else if i == tts.len() + 3 && seq.separator.is_some() { + (TokenTree::Token(span, seq.separator.clone().unwrap()), false) + } else if seq.op == tokenstream::KleeneOp::ZeroOrMore { + (TokenTree::Token(span, token::BinOp(token::Star)), true) + } else { + (TokenTree::Token(span, token::BinOp(token::Plus)), true) } + } else { + (tts.get_tt(i), i + 1 == tts.len()) + }; + if !is_last { + self.tts.push((tts, i + 1)); } match tt { TokenTree::Token(sp, tok) => TokenAndSpan { tok: tok, sp: sp }, diff --git a/src/test/compile-fail/issue-39709.rs b/src/test/run-pass/issue-39709.rs similarity index 75% rename from src/test/compile-fail/issue-39709.rs rename to src/test/run-pass/issue-39709.rs index 0f66fe8439336..80d221e35d4ab 100644 --- a/src/test/compile-fail/issue-39709.rs +++ b/src/test/run-pass/issue-39709.rs @@ -8,8 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +macro_rules! id { ($($t:tt)*) => { $($t)* } } + fn main() { println!("{}", { macro_rules! x { ($()*) => {} } 33 }); - //~^ ERROR no syntax variables matched as repeating at this depth + id!(macro_rules! m { ($($i:ident),*) => { ($($i),*) } }); + let (foo, bar) = (0, 0); + assert_eq!(m!(foo, bar), (0, 0)); } - From 5599636b21d3705dc695fc2c7945ee4dc942dec0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 10 Mar 2017 18:18:11 +0000 Subject: [PATCH 9/9] Enable builds against prs --- .travis.yml | 4 +--- appveyor.yml | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88bd901e6b33d..b6d1a9060a4bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,9 +82,7 @@ env: script: - > - if [ "$ALLOW_PR" = "" ] && [ "$TRAVIS_BRANCH" != "auto" ]; then - echo skipping, not a full build; - elif [ "$TRAVIS_OS_NAME" = "osx" ]; then + if [ "$TRAVIS_OS_NAME" = "osx" ]; then travis_retry sh -c 'git submodule deinit -f . && git submodule update --init' && src/ci/run.sh; else diff --git a/appveyor.yml b/appveyor.yml index c617ac8a4e342..e7ce301974a28 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -130,10 +130,6 @@ cache: - "i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-auto-clean-trigger" - "x86_64-pc-windows-msvc/llvm -> src/rustllvm/llvm-auto-clean-trigger" -branches: - only: - - auto - before_deploy: - ps: | New-Item -Path deploy -ItemType directory