Skip to content

Commit 79479b9

Browse files
committed
---
yaml --- r: 162419 b: refs/heads/try c: 770378a h: refs/heads/master i: 162417: f6761c9 162415: 00f2d53 v: v3
1 parent c90ce0b commit 79479b9

File tree

11 files changed

+70
-16
lines changed

11 files changed

+70
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cafe2966770ff377aad6dd9fd808e68055587c58
5-
refs/heads/try: bc9de771d5f2ab71a0e3b0eb27a92c65e8ddd4b9
5+
refs/heads/try: 770378a313a573776b16237a46b75bafa49072c1
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/middle/traits/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub enum ObligationCauseCode<'tcx> {
9494

9595
// Types of fields (other than the last) in a struct must be sized.
9696
FieldSized,
97+
98+
// Only Sized types can be made into objects
99+
ObjectSized,
97100
}
98101

99102
pub type Obligations<'tcx> = subst::VecPerParamSpace<Obligation<'tcx>>;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,12 +1775,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17751775
}
17761776
ty::UnsizeVtable(ref ty_trait, self_ty) => {
17771777
vtable::check_object_safety(self.tcx(), ty_trait, span);
1778+
17781779
// If the type is `Foo+'a`, ensures that the type
17791780
// being cast to `Foo+'a` implements `Foo`:
17801781
vtable::register_object_cast_obligations(self,
1781-
span,
1782-
ty_trait,
1783-
self_ty);
1782+
span,
1783+
ty_trait,
1784+
self_ty);
17841785

17851786
// If the type is `Foo+'a`, ensures that the type
17861787
// being cast to `Foo+'a` outlives `'a`:

branches/try/src/librustc/middle/typeck/check/vtable.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use middle::typeck::infer;
2121
use std::rc::Rc;
2222
use syntax::ast;
2323
use syntax::codemap::Span;
24+
use util::common::ErrorReported;
2425
use util::ppaux::{UserString, Repr, ty_to_string};
2526

2627
pub fn check_object_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
@@ -238,6 +239,20 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
238239
referent_ty: Ty<'tcx>)
239240
-> Rc<ty::TraitRef<'tcx>>
240241
{
242+
// We can only make objects from sized types.
243+
let sized_obligation =
244+
traits::obligation_for_builtin_bound(
245+
fcx.tcx(),
246+
traits::ObligationCause::new(span, traits::ObjectSized),
247+
referent_ty,
248+
ty::BoundSized);
249+
match sized_obligation {
250+
Ok(sized_obligation) => {
251+
fcx.register_obligation(sized_obligation);
252+
}
253+
Err(ErrorReported) => { }
254+
}
255+
241256
// This is just for better error reporting. Kinda goofy. The object type stuff
242257
// needs some refactoring so there is a more convenient type to pass around.
243258
let object_trait_ty =
@@ -543,5 +558,9 @@ fn note_obligation_cause<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
543558
"only the last field of a struct or enum variant \
544559
may have a dynamically sized type")
545560
}
561+
traits::ObjectSized => {
562+
span_note!(tcx.sess, obligation.cause.span,
563+
"only sized types can be made into objects");
564+
}
546565
}
547566
}

branches/try/src/librustc/util/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use syntax::ast;
2020
use syntax::visit;
2121
use syntax::visit::Visitor;
2222

23-
// An error has already been reported to the user, so no need to continue checking.
23+
// Useful type to use with `Result<>` indicate that an error has already
24+
// been reported to the user, so no need to continue checking.
2425
#[deriving(Clone,Show)]
2526
pub struct ErrorReported;
2627

branches/try/src/libstd/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,17 @@ pub mod builtin {
557557
/// A macro which expands to the column number on which it was invoked.
558558
///
559559
/// The expanded expression has type `uint`, and the returned column is not
560-
/// the invocation of the `col!()` macro itself, but rather the first macro
561-
/// invocation leading up to the invocation of the `col!()` macro.
560+
/// the invocation of the `column!()` macro itself, but rather the first macro
561+
/// invocation leading up to the invocation of the `column!()` macro.
562562
///
563563
/// # Example
564564
///
565565
/// ```
566-
/// let current_col = col!();
566+
/// let current_col = column!();
567567
/// println!("defined on column: {}", current_col);
568568
/// ```
569569
#[macro_export]
570-
macro_rules! col( () => ({ /* compiler built-in */ }) )
570+
macro_rules! column( () => ({ /* compiler built-in */ }) )
571571

572572
/// A macro which expands to the file name from which it was invoked.
573573
///

branches/try/src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
413413
syntax_expanders.insert(intern("line"),
414414
builtin_normal_expander(
415415
ext::source_util::expand_line));
416-
syntax_expanders.insert(intern("col"),
416+
syntax_expanders.insert(intern("column"),
417417
builtin_normal_expander(
418-
ext::source_util::expand_col));
418+
ext::source_util::expand_column));
419419
syntax_expanders.insert(intern("file"),
420420
builtin_normal_expander(
421421
ext::source_util::expand_file));

branches/try/src/libsyntax/ext/source_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
3838
base::MacExpr::new(cx.expr_uint(topmost, loc.line))
3939
}
4040

41-
/* col!(): expands to the current column number */
42-
pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
41+
/* column!(): expands to the current column number */
42+
pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4343
-> Box<base::MacResult+'static> {
44-
base::check_zero_tts(cx, sp, tts, "col!");
44+
base::check_zero_tts(cx, sp, tts, "column!");
4545

4646
let topmost = cx.original_span_in_file();
4747
let loc = cx.codemap().lookup_char_pos(topmost.lo);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// Test that we cannot create objects from unsized types.
12+
13+
trait Foo for Sized? {}
14+
impl Foo for str {}
15+
16+
fn test<Sized? T: Foo>(t: &T) {
17+
let u: &Foo = t;
18+
//~^ ERROR `core::kinds::Sized` is not implemented for the type `T`
19+
20+
let v: &Foo = t as &Foo;
21+
//~^ ERROR `core::kinds::Sized` is not implemented for the type `T`
22+
}
23+
24+
fn main() {
25+
let _: &[&Foo] = &["hi"];
26+
//~^ ERROR `core::kinds::Sized` is not implemented for the type `str`
27+
28+
let _: &Foo = "hi" as &Foo;
29+
//~^ ERROR `core::kinds::Sized` is not implemented for the type `str`
30+
}

branches/try/src/test/compile-fail/issue-14366.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
fn main() {
1212
let _x = "test" as &::std::any::Any;
1313
//~^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
14-
//~^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
14+
//~^^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
1515
}

branches/try/src/test/run-pass/syntax-extension-source-utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! indirect_line( () => ( line!() ) )
2525

2626
pub fn main() {
2727
assert_eq!(line!(), 27);
28-
//assert!((col!() == 11));
28+
//assert!((column!() == 11));
2929
assert_eq!(indirect_line!(), 29);
3030
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
3131
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());

0 commit comments

Comments
 (0)