Skip to content

Commit a050490

Browse files
committed
---
yaml --- r: 40193 b: refs/heads/dist-snap c: 4da58a5 h: refs/heads/master i: 40191: 367ab00 v: v3
1 parent 2067871 commit a050490

File tree

8 files changed

+88
-160
lines changed

8 files changed

+88
-160
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: 0707780eace5bafa07c114319b9a0d774f196da4
10+
refs/heads/dist-snap: 4da58a5bd6f921b446e46cf65790975598289308
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libsyntax/ast.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,31 @@ enum struct_field_kind {
14441444
unnamed_field // element of a tuple-like struct
14451445
}
14461446

1447+
impl struct_field_kind : cmp::Eq {
1448+
pure fn eq(other: &struct_field_kind) -> bool {
1449+
match self {
1450+
named_field(ident_a, class_mutability_a, visibility_a) => {
1451+
match *other {
1452+
named_field(ident_b, class_mutability_b, visibility_b)
1453+
=> {
1454+
ident_a == ident_b &&
1455+
class_mutability_a == class_mutability_b &&
1456+
visibility_a == visibility_b
1457+
}
1458+
unnamed_field => false
1459+
}
1460+
}
1461+
unnamed_field => {
1462+
match *other {
1463+
named_field(*) => false,
1464+
unnamed_field => true
1465+
}
1466+
}
1467+
}
1468+
}
1469+
pure fn ne(other: &struct_field_kind) -> bool { !self.eq(other) }
1470+
}
1471+
14471472
#[auto_serialize]
14481473
#[auto_deserialize]
14491474
type struct_def = {
@@ -1452,7 +1477,10 @@ type struct_def = {
14521477
methods: ~[@method], /* methods */
14531478
/* (not including ctor or dtor) */
14541479
/* dtor is optional */
1455-
dtor: Option<class_dtor>
1480+
dtor: Option<class_dtor>,
1481+
/* ID of the constructor. This is only used for tuple- or enum-like
1482+
* structs. */
1483+
ctor_id: node_id
14561484
};
14571485

14581486
/*

branches/dist-snap/src/libsyntax/fold.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
280280
traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
281281
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
282282
methods: vec::map(struct_def.methods, |m| fld.fold_method(*m)),
283-
dtor: dtor
283+
dtor: dtor,
284+
ctor_id: fld.new_id(struct_def.ctor_id)
284285
};
285286
}
286287

@@ -563,7 +564,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
563564
|f| fld.fold_struct_field(*f)),
564565
methods: vec::map(struct_def.methods,
565566
|m| fld.fold_method(*m)),
566-
dtor: dtor
567+
dtor: dtor,
568+
ctor_id: fld.new_id(struct_def.ctor_id)
567569
})
568570
}
569571

branches/dist-snap/src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,12 +2722,14 @@ impl Parser {
27222722
self_id: self.get_id(),
27232723
body: d_body},
27242724
span: d_s}};
2725+
let _ = self.get_id(); // XXX: Workaround for crazy bug.
27252726
(class_name,
27262727
item_class(@{
27272728
traits: traits,
27282729
fields: move fields,
27292730
methods: move methods,
2730-
dtor: actual_dtor
2731+
dtor: actual_dtor,
2732+
ctor_id: self.get_id()
27312733
}, ty_params),
27322734
None)
27332735
}
@@ -3073,7 +3075,8 @@ impl Parser {
30733075
traits: ~[],
30743076
fields: move fields,
30753077
methods: move methods,
3076-
dtor: actual_dtor
3078+
dtor: actual_dtor,
3079+
ctor_id: self.get_id()
30773080
};
30783081
}
30793082

branches/dist-snap/src/rustc/middle/lint.rs

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ enum lint {
5454
deprecated_pattern,
5555
non_camel_case_types,
5656
structural_records,
57-
type_limits,
5857

5958
managed_heap_memory,
6059
owned_heap_memory,
@@ -187,11 +186,6 @@ fn get_lint_dict() -> lint_dict {
187186
desc: ~"allow legacy modes",
188187
default: forbid}),
189188

190-
(~"type_limits",
191-
@{lint: type_limits,
192-
desc: ~"comparisons made useless by limits of the types involved",
193-
default: warn})
194-
195189
/* FIXME(#3266)--make liveness warnings lintable
196190
(~"unused_variable",
197191
@{lint: unused_variable,
@@ -403,7 +397,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
403397
check_item_heap(cx, i);
404398
check_item_structural_records(cx, i);
405399
check_item_deprecated_modes(cx, i);
406-
check_item_type_limits(cx, i);
407400
}
408401

409402
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -437,122 +430,6 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
437430
visit::visit_item(it, (), visit);
438431
}
439432

440-
fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
441-
pure fn is_valid<T: cmp::Ord>(binop: ast::binop, v: T,
442-
min: T, max: T) -> bool {
443-
match binop {
444-
ast::lt => v <= max,
445-
ast::le => v < max,
446-
ast::gt => v >= min,
447-
ast::ge => v > min,
448-
ast::eq | ast::ne => v >= min && v <= max,
449-
_ => fail
450-
}
451-
}
452-
453-
pure fn rev_binop(binop: ast::binop) -> ast::binop {
454-
match binop {
455-
ast::lt => ast::gt,
456-
ast::le => ast::ge,
457-
ast::gt => ast::lt,
458-
ast::ge => ast::le,
459-
_ => binop
460-
}
461-
}
462-
463-
pure fn int_ty_range(int_ty: ast::int_ty) -> (i64, i64) {
464-
match int_ty {
465-
ast::ty_i => (int::min_value as i64, int::max_value as i64),
466-
ast::ty_char => (u32::min_value as i64, u32::max_value as i64),
467-
ast::ty_i8 => (i8::min_value as i64, i8::max_value as i64),
468-
ast::ty_i16 => (i16::min_value as i64, i16::max_value as i64),
469-
ast::ty_i32 => (i32::min_value as i64, i32::max_value as i64),
470-
ast::ty_i64 => (i64::min_value, i64::max_value)
471-
}
472-
}
473-
474-
pure fn uint_ty_range(uint_ty: ast::uint_ty) -> (u64, u64) {
475-
match uint_ty {
476-
ast::ty_u => (uint::min_value as u64, uint::max_value as u64),
477-
ast::ty_u8 => (u8::min_value as u64, u8::max_value as u64),
478-
ast::ty_u16 => (u16::min_value as u64, u16::max_value as u64),
479-
ast::ty_u32 => (u32::min_value as u64, u32::max_value as u64),
480-
ast::ty_u64 => (u64::min_value, u64::max_value)
481-
}
482-
}
483-
484-
fn check_limits(cx: ty::ctxt, binop: ast::binop, l: &ast::expr,
485-
r: &ast::expr) -> bool {
486-
let (lit, expr, swap) = match (l.node, r.node) {
487-
(ast::expr_lit(_), _) => (l, r, true),
488-
(_, ast::expr_lit(_)) => (r, l, false),
489-
_ => return true
490-
};
491-
// Normalize the binop so that the literal is always on the RHS in
492-
// the comparison
493-
let norm_binop = if (swap) {
494-
rev_binop(binop)
495-
} else {
496-
binop
497-
};
498-
match ty::get(ty::expr_ty(cx, @*expr)).sty {
499-
ty::ty_int(int_ty) => {
500-
let (min, max) = int_ty_range(int_ty);
501-
let lit_val: i64 = match lit.node {
502-
ast::expr_lit(@li) => match li.node {
503-
ast::lit_int(v, _) => v,
504-
ast::lit_uint(v, _) => v as i64,
505-
ast::lit_int_unsuffixed(v) => v,
506-
_ => return true
507-
},
508-
_ => fail
509-
};
510-
is_valid(norm_binop, lit_val, min, max)
511-
}
512-
ty::ty_uint(uint_ty) => {
513-
let (min, max): (u64, u64) = uint_ty_range(uint_ty);
514-
let lit_val: u64 = match lit.node {
515-
ast::expr_lit(@li) => match li.node {
516-
ast::lit_int(v, _) => v as u64,
517-
ast::lit_uint(v, _) => v,
518-
ast::lit_int_unsuffixed(v) => v as u64,
519-
_ => return true
520-
},
521-
_ => fail
522-
};
523-
is_valid(norm_binop, lit_val, min, max)
524-
}
525-
_ => true
526-
}
527-
}
528-
529-
pure fn is_comparison(binop: ast::binop) -> bool {
530-
match binop {
531-
ast::eq | ast::lt | ast::le |
532-
ast::ne | ast::ge | ast::gt => true,
533-
_ => false
534-
}
535-
}
536-
537-
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
538-
visit_expr: fn@(e: @ast::expr) {
539-
match e.node {
540-
ast::expr_binary(binop, @l, @r) => {
541-
if is_comparison(binop)
542-
&& !check_limits(cx, binop, &l, &r) {
543-
cx.sess.span_lint(
544-
type_limits, e.id, it.id, e.span,
545-
~"comparison is useless due to type limits");
546-
}
547-
}
548-
_ => ()
549-
}
550-
},
551-
.. *visit::default_simple_visitor()
552-
}));
553-
visit::visit_item(it, (), visit);
554-
}
555-
556433
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
557434
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
558435
visit_expr: fn@(e: @ast::expr) {

branches/dist-snap/src/rustc/middle/resolve.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use middle::pat_util::{pat_bindings};
99
use syntax::ast::{_mod, add, arm};
1010
use syntax::ast::{bind_by_ref, bind_by_implicit_ref, bind_by_value};
1111
use syntax::ast::{bitand, bitor, bitxor};
12-
use syntax::ast::{binding_mode, blk,
13-
capture_clause, class_ctor, class_dtor};
12+
use syntax::ast::{binding_mode, blk, capture_clause, class_ctor, class_dtor};
1413
use syntax::ast::{crate, crate_num, decl_item};
1514
use syntax::ast::{def, def_arg, def_binding, def_class, def_const, def_fn};
1615
use syntax::ast::{def_foreign_mod, def_id, def_label, def_local, def_mod};
@@ -39,7 +38,7 @@ use syntax::ast::{trait_ref, tuple_variant_kind, Ty, ty_bool, ty_char};
3938
use syntax::ast::{ty_f, ty_f32, ty_f64, ty_float, ty_i, ty_i16, ty_i32};
4039
use syntax::ast::{ty_i64, ty_i8, ty_int, ty_param, ty_path, ty_str, ty_u};
4140
use syntax::ast::{ty_u16, ty_u32, ty_u64, ty_u8, ty_uint, type_value_ns};
42-
use syntax::ast::{ty_param_bound};
41+
use syntax::ast::{ty_param_bound, unnamed_field};
4342
use syntax::ast::{variant, view_item, view_item_export, view_item_import};
4443
use syntax::ast::{view_item_use, view_path_glob, view_path_list};
4544
use syntax::ast::{view_path_simple, visibility, anonymous, named};
@@ -1179,12 +1178,22 @@ impl Resolver {
11791178
}
11801179

11811180
// These items live in both the type and value namespaces.
1182-
item_class(*) => {
1181+
item_class(struct_def, _) => {
11831182
let (name_bindings, new_parent) =
11841183
self.add_child(ident, parent, ForbidDuplicateTypes, sp);
11851184

1186-
(*name_bindings).define_type
1187-
(privacy, def_ty(local_def(item.id)), sp);
1185+
name_bindings.define_type(
1186+
privacy, def_ty(local_def(item.id)), sp);
1187+
1188+
// If this struct is tuple-like or enum-like, define a name
1189+
// in the value namespace.
1190+
if struct_def.fields.len() == 0 ||
1191+
struct_def.fields[0].node.kind == unnamed_field {
1192+
name_bindings.define_value(
1193+
privacy,
1194+
def_class(local_def(struct_def.ctor_id)),
1195+
sp);
1196+
}
11881197

11891198
// Record the def ID of this struct.
11901199
self.structs.insert(local_def(item.id), ());

branches/dist-snap/src/rustc/middle/typeck/collect.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ are represented as `ty_param()` instances.
2222

2323
use astconv::{ast_conv, ty_of_fn_decl, ty_of_arg, ast_ty_to_ty};
2424
use ast_util::trait_method_to_ty_method;
25+
use middle::ty::{FnMeta, FnSig, FnTyBase};
2526
use rscope::*;
2627
use ty::{FnTyBase, FnMeta, FnSig, InstantiatedTraitRef};
2728
use util::common::pluralize;
@@ -559,6 +560,39 @@ fn convert_struct(ccx: @crate_ctxt,
559560
write_ty_to_tcx(tcx, trait_ref.impl_id, tpt.ty);
560561
tcx.tcache.insert(local_def(trait_ref.impl_id), tpt);
561562
}
563+
564+
// If this struct is enum-like or tuple-like, create the type of its
565+
// constructor.
566+
if struct_def.fields.len() == 0 {
567+
// Enum-like.
568+
write_ty_to_tcx(tcx, struct_def.ctor_id, selfty);
569+
tcx.tcache.insert(local_def(struct_def.ctor_id), tpt);
570+
} else if struct_def.fields[0].node.kind == ast::unnamed_field {
571+
// Tuple-like.
572+
let ctor_fn_ty = ty::mk_fn(tcx, FnTyBase {
573+
meta: FnMeta {
574+
purity: ast::pure_fn,
575+
proto: ty::proto_bare,
576+
bounds: @~[],
577+
ret_style: ast::return_val,
578+
},
579+
sig: FnSig {
580+
inputs: do struct_def.fields.map |field| {
581+
{
582+
mode: ast::expl(ast::by_copy),
583+
ty: ccx.tcx.tcache.get(local_def(field.node.id)).ty
584+
}
585+
},
586+
output: selfty
587+
}
588+
});
589+
write_ty_to_tcx(tcx, struct_def.ctor_id, ctor_fn_ty);
590+
tcx.tcache.insert(local_def(struct_def.ctor_id), {
591+
bounds: tpt.bounds,
592+
region_param: tpt.region_param,
593+
ty: ctor_fn_ty
594+
});
595+
}
562596
}
563597

564598
fn convert_foreign(ccx: @crate_ctxt, i: @ast::foreign_item) {

branches/dist-snap/src/test/compile-fail/lint-type-limits.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)