Skip to content

Commit 5cba29d

Browse files
committed
auto merge of #18142 : arielb1/rust/return-type-sized, r=eddyb
Fixes #18107 r? @eddyb
2 parents c121cba + 0eb17e3 commit 5cba29d

File tree

9 files changed

+52
-14
lines changed

9 files changed

+52
-14
lines changed

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub enum ObligationCauseCode {
7777
AssignmentLhsSized, // L = X implies that L is Sized
7878
StructInitializerSized, // S { ... } must be Sized
7979
VariableType(ast::NodeId), // Type of each variable must be Sized
80+
ReturnType, // Return type must be Sized
8081
RepeatVec, // [T,..n] --> T must be Copy
8182

8283
// Captures of variable the given id by a closure (span is the

src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,12 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
555555

556556
// Remember return type so that regionck can access it later.
557557
let fn_sig_tys: Vec<ty::t> =
558-
arg_tys.iter()
559-
.chain([ret_ty].iter())
560-
.map(|&ty| ty)
561-
.collect();
558+
arg_tys.iter().chain([ret_ty].iter()).map(|&ty| ty).collect();
562559
debug!("fn-sig-map: fn_id={} fn_sig_tys={}",
563560
fn_id,
564561
fn_sig_tys.repr(tcx));
565-
inherited.fn_sig_map
566-
.borrow_mut()
567-
.insert(fn_id, fn_sig_tys);
562+
563+
inherited.fn_sig_map.borrow_mut().insert(fn_id, fn_sig_tys);
568564

569565
{
570566
let mut visit = GatherLocalsVisitor { fcx: &fcx, };
@@ -591,6 +587,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
591587

592588
visit.visit_block(body);
593589
}
590+
fcx.require_type_is_sized(ret_ty, decl.output.span, traits::ReturnType);
594591

595592
check_block_with_expected(&fcx, body, ExpectHasType(ret_ty));
596593

src/librustc/middle/typeck/check/vtable2.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,20 @@ fn note_obligation_cause(fcx: &FnCtxt,
366366
traits::RepeatVec => {
367367
tcx.sess.span_note(
368368
obligation.cause.span,
369-
format!(
370-
"the `Copy` trait is required because the \
371-
repeated element will be copied").as_slice());
369+
"the `Copy` trait is required because the \
370+
repeated element will be copied");
372371
}
373372
traits::VariableType(_) => {
374373
tcx.sess.span_note(
375374
obligation.cause.span,
376375
"all local variables must have a statically known size");
377376
}
377+
traits::ReturnType => {
378+
tcx.sess.span_note(
379+
obligation.cause.span,
380+
"the return type of a function must have a \
381+
statically known size");
382+
}
378383
traits::AssignmentLhsSized => {
379384
tcx.sess.span_note(
380385
obligation.cause.span,

src/test/auxiliary/lang-item-public.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#![no_std]
1212
#![feature(lang_items)]
1313

14+
#[lang="sized"]
15+
pub trait Sized for Sized? {}
16+
1417
#[lang="fail"]
1518
fn fail(_: &(&'static str, &'static str, uint)) -> ! { loop {} }
1619

src/test/compile-fail/issue-17025.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ enum A {
1313
C([Box<A>]),
1414
}
1515

16-
fn c(c:char) -> A {
17-
B(c) //~ ERROR cannot move a value of type A: the size of A cannot be statically determined
16+
fn c(c:char) {
17+
B(c);
18+
//~^ ERROR cannot move a value of type A: the size of A cannot be statically determined
1819
}
1920

2021
pub fn main() {}

src/test/compile-fail/issue-18107.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
13+
pub trait AbstractRenderer {}
14+
15+
fn _create_render(_: &()) ->
16+
AbstractRenderer
17+
//~^ ERROR: the trait `core::kinds::Sized` is not implemented
18+
{
19+
match 0u {
20+
_ => unimplemented!()
21+
}
22+
}
23+
24+
fn main() {
25+
}

src/test/compile-fail/issue-5883.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ struct Struct {
1414
r: A+'static
1515
}
1616

17-
fn new_struct(r: A+'static) -> Struct {
17+
fn new_struct(r: A+'static)
18+
-> Struct { //~^ ERROR the trait `core::kinds::Sized` is not implemented
1819
//~^ ERROR the trait `core::kinds::Sized` is not implemented
1920
Struct { r: r }
2021
//~^ ERROR the trait `core::kinds::Sized` is not implemented

src/test/compile-fail/privacy4.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(globs)]
11+
#![feature(globs, lang_items)]
1212
#![no_std] // makes debugging this test *a lot* easier (during resolve)
1313

14+
#[lang = "sized"] pub trait Sized for Sized? {}
15+
1416
// Test to make sure that private items imported through globs remain private
1517
// when they're used.
1618

src/test/compile-fail/required-lang-item.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(lang_items)]
1112
#![no_std]
1213

14+
#[lang="sized"] pub trait Sized for Sized? {}
15+
1316
// error-pattern:requires `start` lang_item
1417

1518
fn main() {}

0 commit comments

Comments
 (0)