]> git.lizzy.rs Git - rust.git/commitdiff
librustc: Try to resolve before coercions.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Tue, 3 Jun 2014 19:38:00 +0000 (15:38 -0400)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Tue, 3 Jun 2014 19:38:04 +0000 (15:38 -0400)
src/librustc/back/archive.rs
src/librustc/middle/typeck/check/demand.rs
src/test/compile-fail/issue-7573.rs
src/test/run-pass/issue-14589.rs [new file with mode: 0644]
src/test/run-pass/issue-4446.rs

index 1c60e4fbe92c912196cbad11326d628e34081675..0b6540640b4cf60e8f6bd06c696bf474f756957d 100644 (file)
@@ -110,7 +110,7 @@ pub fn add_rlib(&mut self, rlib: &Path, name: &str,
                     lto: bool) -> io::IoResult<()> {
         let object = format!("{}.o", name);
         let bytecode = format!("{}.bc.deflate", name);
-        let mut ignore = vec!(METADATA_FILENAME, bytecode.as_slice());
+        let mut ignore = vec!(bytecode.as_slice(), METADATA_FILENAME);
         if lto {
             ignore.push(object.as_slice());
         }
index dc9aa1b7e8cb23c257c46a6d3826936b7ef85069..10d44ecede6cc4f9b687782a2226045c458932dc 100644 (file)
 use middle::ty;
 use middle::typeck::check::FnCtxt;
 use middle::typeck::infer;
+use middle::typeck::infer::resolve_type;
+use middle::typeck::infer::resolve::try_resolve_tvar_shallow;
 
 use std::result::{Err, Ok};
 use std::result;
 use syntax::ast;
 use syntax::codemap::Span;
+use util::ppaux::Repr;
 
 // Requires that the two types unify, and prints an error message if they
 // don't.
@@ -58,6 +61,13 @@ pub fn eqtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
 // Checks that the type `actual` can be coerced to `expected`.
 pub fn coerce(fcx: &FnCtxt, sp: Span, expected: ty::t, expr: &ast::Expr) {
     let expr_ty = fcx.expr_ty(expr);
+    debug!("demand::coerce(expected = {}, expr_ty = {})",
+           expected.repr(fcx.ccx.tcx),
+           expr_ty.repr(fcx.ccx.tcx));
+    let expected = if ty::type_needs_infer(expected) {
+        resolve_type(fcx.infcx(), expected,
+                     try_resolve_tvar_shallow).unwrap_or(expected)
+    } else { expected };
     match fcx.mk_assignty(expr, expr_ty, expected) {
       result::Ok(()) => { /* ok */ }
       result::Err(ref err) => {
index 0ce3a62343f275bcb4093d23ad0a076af6061756..0e978a09edd2d8669ae60c7dd7f147e6978065ae 100644 (file)
@@ -24,9 +24,11 @@ fn new(s: &str) -> CrateId {
 }
 
 pub fn remove_package_from_database() {
-    let mut lines_to_use: Vec<&CrateId> = Vec::new(); //~ ERROR cannot infer an appropriate lifetime
+    let mut lines_to_use: Vec<&CrateId> = Vec::new();
     let push_id = |installed_id: &CrateId| {
         lines_to_use.push(installed_id);
+        //~^ ERROR cannot infer an appropriate lifetime for automatic coercion due to
+        // conflicting requirements
     };
     list_database(push_id);
 
diff --git a/src/test/run-pass/issue-14589.rs b/src/test/run-pass/issue-14589.rs
new file mode 100644 (file)
index 0000000..afc2fc6
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2014 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// All 3 expressions should work in that the argument gets
+// coerced to a trait object
+
+fn main() {
+    send::<Box<Foo>>(box Output(0));
+    Test::<Box<Foo>>::foo(box Output(0));
+    Test::<Box<Foo>>.send(box Output(0));
+}
+
+fn send<T>(_: T) {}
+
+struct Test<T>;
+impl<T> Test<T> {
+    fn foo(_: T) {}
+    fn send(&self, _: T) {}
+}
+
+trait Foo {}
+struct Output(int);
+impl Foo for Output {}
index f74c30687ca8a0ddb22f039537e2d02e518ccc59..2266e62eb77cb6b0669da83c9c58efb96e61850c 100644 (file)
@@ -13,9 +13,9 @@
 pub fn main() {
     let (tx, rx) = channel();
 
+    tx.send("hello, world");
+
     spawn(proc() {
         println(rx.recv());
     });
-
-    tx.send("hello, world");
 }