Skip to content

Commit b603b80

Browse files
---
yaml --- r: 145106 b: refs/heads/try2 c: bf37de9 h: refs/heads/master v: v3
1 parent 887566e commit b603b80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+314
-191
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c8c3c3bdd641411134c53117f4c0a449195d1e10
8+
refs/heads/try2: bf37de9fc675a90d12c37fd0e8acdfe4107545f9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial-conditions.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn read_int_pairs() -> ~[(int,int)] {
9191
[a, b] => {
9292
9393
// 5. Try parsing both fields as ints.
94-
match (from_str::<int>(a), from_str::<int>(b)) {
94+
match (int::from_str(a), int::from_str(b)) {
9595
9696
// 6. If parsing succeeded for both, push both.
9797
(Some(a), Some(b)) => pairs.push((a,b)),
@@ -124,7 +124,7 @@ for conveying a value of type `T`, represented as `Some(T)`
124124
_or_ the sentinel `None`, to indicate the absence of a `T` value.
125125
For simple APIs, it may be sufficient to encode errors as `Option<T>`,
126126
returning `Some(T)` on success and `None` on error.
127-
In the example program, the call to `from_str::<int>` returns `Option<int>`
127+
In the example program, the call to `int::from_str` returns `Option<int>`
128128
with the understanding that "all parse errors" result in `None`.
129129
The resulting `Option<int>` values are matched against the pattern `(Some(a), Some(b))`
130130
in steps 5 and 6 in the example program,
@@ -161,7 +161,7 @@ This second mechanism for indicating an error is called a `Result`.
161161
The type `std::result::Result<T,E>` is another simple `enum` type with two forms, `Ok(T)` and `Err(E)`.
162162
The `Result` type is not substantially different from the `Option` type in terms of its ergonomics.
163163
Its main advantage is that the error constructor `Err(E)` can convey _more detail_ about the error.
164-
For example, the `from_str` API could be reformed
164+
For example, the `int::from_str` API could be reformed
165165
to return a `Result` carrying an informative description of a parse error,
166166
like this:
167167

@@ -172,7 +172,7 @@ enum IntParseErr {
172172
BadChar(char)
173173
}
174174
175-
fn from_str(&str) -> Result<int,IntParseErr> {
175+
fn int::from_str(&str) -> Result<int,IntParseErr> {
176176
// ...
177177
}
178178
~~~~
@@ -297,8 +297,8 @@ fn read_int_pairs() -> ~[(int,int)] {
297297
let line = fi.read_line();
298298
let fields = line.word_iter().to_owned_vec();
299299
match fields {
300-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
301-
from_str::<int>(b).unwrap())),
300+
[a, b] => pairs.push((int::from_str(a).unwrap(),
301+
int::from_str(b).unwrap())),
302302
303303
// Explicitly fail on malformed lines.
304304
_ => fail!()
@@ -398,8 +398,8 @@ fn read_int_pairs() -> ~[(int,int)] {
398398
let line = fi.read_line();
399399
let fields = line.word_iter().to_owned_vec();
400400
match fields {
401-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
402-
from_str::<int>(b).unwrap())),
401+
[a, b] => pairs.push((int::from_str(a).unwrap(),
402+
int::from_str(b).unwrap())),
403403
404404
// On malformed lines, call the condition handler and
405405
// push whatever the condition handler returns.
@@ -475,8 +475,8 @@ fn read_int_pairs() -> ~[(int,int)] {
475475
let line = fi.read_line();
476476
let fields = line.word_iter().to_owned_vec();
477477
match fields {
478-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
479-
from_str::<int>(b).unwrap())),
478+
[a, b] => pairs.push((int::from_str(a).unwrap(),
479+
int::from_str(b).unwrap())),
480480
_ => pairs.push(malformed_line::cond.raise(line.clone()))
481481
}
482482
}
@@ -553,8 +553,8 @@ fn read_int_pairs() -> ~[(int,int)] {
553553
let line = fi.read_line();
554554
let fields = line.word_iter().to_owned_vec();
555555
match fields {
556-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
557-
from_str::<int>(b).unwrap())),
556+
[a, b] => pairs.push((int::from_str(a).unwrap(),
557+
int::from_str(b).unwrap())),
558558
559559
// On malformed lines, call the condition handler and
560560
// either ignore the line (if the handler returns `None`)
@@ -649,8 +649,8 @@ fn read_int_pairs() -> ~[(int,int)] {
649649
let line = fi.read_line();
650650
let fields = line.word_iter().to_owned_vec();
651651
match fields {
652-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
653-
from_str::<int>(b).unwrap())),
652+
[a, b] => pairs.push((int::from_str(a).unwrap(),
653+
int::from_str(b).unwrap())),
654654
655655
// On malformed lines, call the condition handler and
656656
// take action appropriate to the enum value returned.
@@ -776,7 +776,7 @@ fn main() {
776776
// Parse an int; if parsing fails, call the condition handler and
777777
// return whatever it returns.
778778
fn parse_int(x: &str) -> int {
779-
match from_str::<int>(x) {
779+
match int::from_str(x) {
780780
Some(v) => v,
781781
None => malformed_int::cond.raise(x.to_owned())
782782
}
@@ -833,8 +833,8 @@ There are three other things to note in this variant of the example program:
833833
so long as the `raise` occurs within a callee (of any depth) of the logic protected by the `trap` call,
834834
it will invoke the handler.
835835

836-
- This variant insulates callers from a design choice in the library:
837-
the `from_str` function was designed to return an `Option<int>`,
836+
- This variant insulates callers from a design choice in the `int` library:
837+
the `int::from_str` function was designed to return an `Option<int>`,
838838
but this program insulates callers from that choice,
839839
routing all `None` values that arise from parsing integers in this file into the condition.
840840

@@ -873,4 +873,4 @@ To compensate for this risk, correct C++ and Java code must program in an extrem
873873
or else risk introducing silent and very difficult-to-debug errors due to control resuming in a corrupted heap after a caught exception.
874874
These errors are frequently memory-safety errors, which Rust strives to eliminate,
875875
and so Rust unwinding is unrecoverable within a single task:
876-
once unwinding starts, the entire local heap of a task is destroyed and the task is terminated.
876+
once unwinding starts, the entire local heap of a task is destroyed and the task is terminated.

branches/try2/src/libextra/fileinput.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ mod test {
538538

539539
do input_vec_state(filenames) |line, state| {
540540
let nums: ~[&str] = line.split_iter(' ').collect();
541-
let file_num = from_str::<uint>(nums[0]).unwrap();
542-
let line_num = from_str::<uint>(nums[1]).unwrap();
541+
let file_num = uint::from_str(nums[0]).unwrap();
542+
let line_num = uint::from_str(nums[1]).unwrap();
543543
assert_eq!(line_num, state.line_num_file);
544544
assert_eq!(file_num * 3 + line_num, state.line_num);
545545
true

branches/try2/src/libextra/semver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::io::{ReaderUtil};
1919
use std::io;
2020
use std::option::{Option, Some, None};
2121
use std::to_str::ToStr;
22+
use std::uint;
2223

2324
#[deriving(Clone, Eq)]
2425
pub enum Identifier {
@@ -139,7 +140,7 @@ fn take_nonempty_prefix(rdr: @io::Reader,
139140

140141
fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
141142
let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit);
142-
match from_str::<uint>(s) {
143+
match uint::from_str(s) {
143144
None => { bad_parse::cond.raise(()); (0, ch) },
144145
Some(i) => (i, ch)
145146
}
@@ -148,7 +149,7 @@ fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
148149
fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
149150
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
150151
if s.iter().all(char::is_digit) {
151-
match from_str::<uint>(s) {
152+
match uint::from_str(s) {
152153
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
153154
Some(i) => (Numeric(i), ch)
154155
}

branches/try2/src/libextra/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use std::task;
3737
use std::to_str::ToStr;
3838
use std::f64;
3939
use std::os;
40+
use std::uint;
4041

4142

4243
// The name of a test. By convention this follows the rules for rust
@@ -252,7 +253,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
252253
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
253254

254255
let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
255-
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| from_str::<f64>(s).unwrap());
256+
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| f64::from_str(s).unwrap());
256257

257258
let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
258259
let save_metrics = save_metrics.map_move(|s| Path(s));
@@ -280,7 +281,7 @@ pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
280281
None => None,
281282
Some(s) => {
282283
match s.split_iter('.').to_owned_vec() {
283-
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
284+
[a, b] => match (uint::from_str(a), uint::from_str(b)) {
284285
(Some(a), Some(b)) => Some((a,b)),
285286
_ => None
286287
},

branches/try2/src/librustc/middle/trans/debuginfo.rs

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use middle::trans::adt;
6060
use middle::trans;
6161
use middle::ty;
6262
use middle::pat_util;
63-
use util::ppaux::ty_to_str;
63+
use util::ppaux;
6464

6565
use std::c_str::ToCStr;
6666
use std::hashmap::HashMap;
@@ -742,7 +742,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
742742
codemap::dummy_sp());
743743

744744
// Add self type name to <...> clause of function name
745-
let actual_self_type_name = ty_to_str(cx.tcx, actual_self_type);
745+
let actual_self_type_name = ppaux::ty_to_str(cx.tcx, actual_self_type);
746746
name_to_append_suffix_to.push_str(actual_self_type_name);
747747
if generics.is_type_parameterized() {
748748
name_to_append_suffix_to.push_str(",");
@@ -779,7 +779,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
779779
let actual_type_metadata = type_metadata(cx, actual_type, codemap::dummy_sp());
780780

781781
// Add actual type name to <...> clause of function name
782-
let actual_type_name = ty_to_str(cx.tcx, actual_type);
782+
let actual_type_name = ppaux::ty_to_str(cx.tcx, actual_type);
783783
name_to_append_suffix_to.push_str(actual_type_name);
784784

785785
if index != generics.ty_params.len() - 1 {
@@ -1039,7 +1039,7 @@ fn pointer_type_metadata(cx: &mut CrateContext,
10391039
-> DIType {
10401040
let pointer_llvm_type = type_of::type_of(cx, pointer_type);
10411041
let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
1042-
let name = ty_to_str(cx.tcx, pointer_type);
1042+
let name = ppaux::ty_to_str(cx.tcx, pointer_type);
10431043
let ptr_metadata = do name.with_c_str |name| {
10441044
unsafe {
10451045
llvm::LLVMDIBuilderCreatePointerType(
@@ -1059,7 +1059,7 @@ fn struct_metadata(cx: &mut CrateContext,
10591059
substs: &ty::substs,
10601060
span: Span)
10611061
-> DICompositeType {
1062-
let struct_name = ty_to_str(cx.tcx, struct_type);
1062+
let struct_name = ppaux::ty_to_str(cx.tcx, struct_type);
10631063
debug!("struct_metadata: %s", struct_name);
10641064

10651065
let struct_llvm_type = type_of::type_of(cx, struct_type);
@@ -1098,7 +1098,7 @@ fn tuple_metadata(cx: &mut CrateContext,
10981098
component_types: &[ty::t],
10991099
span: Span)
11001100
-> DICompositeType {
1101-
let tuple_name = ty_to_str(cx.tcx, tuple_type);
1101+
let tuple_name = ppaux::ty_to_str(cx.tcx, tuple_type);
11021102
let tuple_llvm_type = type_of::type_of(cx, tuple_type);
11031103

11041104
let component_descriptions = do component_types.map |&component_type| {
@@ -1127,7 +1127,7 @@ fn enum_metadata(cx: &mut CrateContext,
11271127
enum_def_id: ast::DefId,
11281128
span: Span)
11291129
-> DIType {
1130-
let enum_name = ty_to_str(cx.tcx, enum_type);
1130+
let enum_name = ppaux::ty_to_str(cx.tcx, enum_type);
11311131

11321132
let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx,
11331133
enum_def_id,
@@ -1502,7 +1502,7 @@ fn vec_metadata(cx: &mut CrateContext,
15021502
let (element_size, element_align) = size_and_align_of(cx, element_llvm_type);
15031503

15041504
let vec_llvm_type = Type::vec(cx.sess.targ_cfg.arch, &element_llvm_type);
1505-
let vec_type_name: &str = fmt!("[%s]", ty_to_str(cx.tcx, element_type));
1505+
let vec_type_name: &str = fmt!("[%s]", ppaux::ty_to_str(cx.tcx, element_type));
15061506

15071507
let member_llvm_types = vec_llvm_type.field_types();
15081508

@@ -1556,7 +1556,7 @@ fn boxed_vec_metadata(cx: &mut CrateContext,
15561556

15571557
let element_llvm_type = type_of::type_of(cx, element_type);
15581558
let vec_llvm_type = Type::vec(cx.sess.targ_cfg.arch, &element_llvm_type);
1559-
let vec_type_name: &str = fmt!("[%s]", ty_to_str(cx.tcx, element_type));
1559+
let vec_type_name: &str = fmt!("[%s]", ppaux::ty_to_str(cx.tcx, element_type));
15601560
let vec_metadata = vec_metadata(cx, element_type, span);
15611561

15621562
return boxed_type_metadata(
@@ -1576,7 +1576,7 @@ fn vec_slice_metadata(cx: &mut CrateContext,
15761576
debug!("vec_slice_metadata: %?", ty::get(vec_type));
15771577

15781578
let slice_llvm_type = type_of::type_of(cx, vec_type);
1579-
let slice_type_name = ty_to_str(cx.tcx, vec_type);
1579+
let slice_type_name = ppaux::ty_to_str(cx.tcx, vec_type);
15801580

15811581
let member_llvm_types = slice_llvm_type.field_types();
15821582
assert!(slice_layout_is_correct(cx, member_llvm_types, element_type));
@@ -1648,10 +1648,47 @@ fn subroutine_type_metadata(cx: &mut CrateContext,
16481648
};
16491649
}
16501650

1651+
fn trait_metadata(cx: &mut CrateContext,
1652+
def_id: ast::DefId,
1653+
trait_type: ty::t,
1654+
substs: &ty::substs,
1655+
trait_store: ty::TraitStore,
1656+
mutability: ast::Mutability,
1657+
builtinBounds: &ty::BuiltinBounds,
1658+
usage_site_span: Span)
1659+
-> DIType {
1660+
// The implementation provided here is a stub. It makes sure that the trait type is
1661+
// assigned the correct name, size, namespace, and source location. But it does not describe
1662+
// the trait's methods.
1663+
let path = ty::item_path(cx.tcx, def_id);
1664+
let ident = path.last().ident();
1665+
let name = ppaux::trait_store_to_str(cx.tcx, trait_store)
1666+
+ ppaux::mutability_to_str(mutability)
1667+
+ token::ident_to_str(&ident);
1668+
// Add type and region parameters
1669+
let name = ppaux::parameterized(cx.tcx, name, &substs.regions, substs.tps);
1670+
1671+
let (containing_scope,
1672+
definition_span) = get_namespace_and_span_for_item(cx, def_id, usage_site_span);
1673+
1674+
let file_name = span_start(cx, definition_span).file.name;
1675+
let file_metadata = file_metadata(cx, file_name);
1676+
1677+
let trait_llvm_type = type_of::type_of(cx, trait_type);
1678+
1679+
return composite_type_metadata(cx,
1680+
trait_llvm_type,
1681+
name,
1682+
[],
1683+
containing_scope,
1684+
file_metadata,
1685+
definition_span);
1686+
}
1687+
16511688
fn unimplemented_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
16521689
debug!("unimplemented_type_metadata: %?", ty::get(t));
16531690

1654-
let name = ty_to_str(cx.tcx, t);
1691+
let name = ppaux::ty_to_str(cx.tcx, t);
16551692
let metadata = do fmt!("NYI<%s>", name).with_c_str |name| {
16561693
unsafe {
16571694
llvm::LLVMDIBuilderCreateBasicType(
@@ -1681,7 +1718,7 @@ fn type_metadata(cx: &mut CrateContext,
16811718
type_in_box: ty::t)
16821719
-> DIType {
16831720

1684-
let content_type_name: &str = ty_to_str(cx.tcx, type_in_box);
1721+
let content_type_name: &str = ppaux::ty_to_str(cx.tcx, type_in_box);
16851722
let content_llvm_type = type_of::type_of(cx, type_in_box);
16861723
let content_type_metadata = type_metadata(
16871724
cx,
@@ -1773,9 +1810,8 @@ fn type_metadata(cx: &mut CrateContext,
17731810
ty::ty_closure(ref closurety) => {
17741811
subroutine_type_metadata(cx, &closurety.sig, usage_site_span)
17751812
},
1776-
ty::ty_trait(_did, ref _substs, ref _vstore, _, _bounds) => {
1777-
cx.sess.span_note(usage_site_span, "debuginfo for trait NYI");
1778-
unimplemented_type_metadata(cx, t)
1813+
ty::ty_trait(def_id, ref substs, trait_store, mutability, ref bounds) => {
1814+
trait_metadata(cx, def_id, t, substs, trait_store, mutability, bounds, usage_site_span)
17791815
},
17801816
ty::ty_struct(def_id, ref substs) => {
17811817
struct_metadata(cx, t, def_id, substs, usage_site_span)

branches/try2/src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~st
235235
}
236236
}
237237

238-
fn mutability_to_str(m: ast::Mutability) -> ~str {
238+
pub fn mutability_to_str(m: ast::Mutability) -> ~str {
239239
match m {
240240
ast::MutMutable => ~"mut ",
241241
ast::MutImmutable => ~"",

0 commit comments

Comments
 (0)