rustc_typeck: enforce argument type is sized

This commit is contained in:
Venkata Giri Reddy 2017-06-13 20:22:28 +00:00
parent 6db48380ce
commit 74cb315a10
4 changed files with 32 additions and 6 deletions

View file

@ -994,6 +994,15 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) {
// Check the pattern.
fcx.check_pat_arg(&arg.pat, arg_ty, true);
// Check that argument is Sized.
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
// for simple cases like `fn foo(x: Trait)`,
// where we would error once on the parameter as a whole, and once on the binding `x`.
if arg.pat.simple_name().is_none() {
fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::MiscObligation);
}
fcx.write_ty(arg.id, arg_ty);
}

View file

@ -8,9 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
fn _test(ref _p: str) {}
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied [E0277]
#[rustc_error]
fn main() { } //~ ERROR compilation successful
fn main() { }

View file

@ -0,0 +1,21 @@
// 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 <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.
use std::ops::Deref;
pub trait Foo {
fn baz(_: Self::Target) where Self: Deref {}
//~^ ERROR `<Self as std::ops::Deref>::Target: std::marker::Sized` is not satisfied
}
pub fn f(_: ToString) {}
//~^ ERROR the trait bound `std::string::ToString + 'static: std::marker::Sized` is not satisfied
fn main() { }

View file

@ -15,8 +15,6 @@ use std::ops::Deref;
pub trait Foo {
type A;
fn boo(&self) -> Self::A;
fn baz(_: Self::Target) where Self: Deref {}
}
impl Foo for isize {