Skip to content

librustc: Try to resolve before coercions. #14628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'a> Archive<'a> {
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());
}
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/middle/typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
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.
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/issue-7573.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ impl 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);

Expand Down
30 changes: 30 additions & 0 deletions src/test/run-pass/issue-14589.rs
Original file line number Diff line number Diff line change
@@ -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 {}
4 changes: 2 additions & 2 deletions src/test/run-pass/issue-4446.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::io::println;
pub fn main() {
let (tx, rx) = channel();

tx.send("hello, world");

spawn(proc() {
println(rx.recv());
});

tx.send("hello, world");
}