Skip to content

Commit b33d72e

Browse files
committed
---
yaml --- r: 148959 b: refs/heads/try2 c: 104002b h: refs/heads/master i: 148957: dca0056 148955: 6af4918 148951: d6f1992 148943: a51886d 148927: a421b16 v: v3
1 parent fce0b1b commit b33d72e

File tree

8 files changed

+93
-238
lines changed

8 files changed

+93
-238
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: 14cb4be6e90d0c5eb42a3eef58d083acc8e51837
8+
refs/heads/try2: 104002be6ff9636f897434bd588da398c34dc1f0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/driver/driver.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
518518
let (outputs, trans) = {
519519
let (expanded_crate, ast_map) = {
520520
let crate = phase_1_parse_input(sess, cfg, input);
521+
if sess.show_span() {
522+
front::show_span::run(sess, &crate);
523+
return;
524+
}
521525
if stop_after_phase_1(sess) { return; }
522526
let loader = &mut Loader::new(sess);
523527
phase_2_configure_and_expand(sess, loader, crate)

branches/try2/src/librustc/driver/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ debugging_opts!(
6060
BORROWCK_STATS,
6161
NO_LANDING_PADS,
6262
DEBUG_LLVM,
63+
SHOW_SPAN,
6364
COUNT_TYPE_SIZES,
6465
META_STATS,
6566
NO_OPT,
@@ -95,6 +96,7 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
9596
("no-landing-pads", "omit landing pads for unwinding",
9697
NO_LANDING_PADS),
9798
("debug-llvm", "enable debug output from LLVM", DEBUG_LLVM),
99+
("show-span", "show spans", SHOW_SPAN),
98100
("count-type-sizes", "count the sizes of aggregate types",
99101
COUNT_TYPE_SIZES),
100102
("meta-stats", "gather metadata statistics", META_STATS),
@@ -351,6 +353,9 @@ impl Session_ {
351353
pub fn no_landing_pads(&self) -> bool {
352354
self.debugging_opt(NO_LANDING_PADS)
353355
}
356+
pub fn show_span(&self) -> bool {
357+
self.debugging_opt(SHOW_SPAN)
358+
}
354359

355360
// DEPRECATED. This function results in a lot of allocations when they
356361
// are not necessary.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
use syntax::ast;
12+
use syntax::visit;
13+
use syntax::visit::Visitor;
14+
15+
use driver::session::Session;
16+
17+
struct ShowSpanVisitor {
18+
sess: Session
19+
}
20+
21+
impl Visitor<()> for ShowSpanVisitor {
22+
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
23+
self.sess.span_note(e.span, "expression");
24+
visit::walk_expr(self, e, ());
25+
}
26+
}
27+
28+
pub fn run(sess: Session, crate: &ast::Crate) {
29+
let mut v = ShowSpanVisitor { sess: sess };
30+
visit::walk_crate(&mut v, crate, ());
31+
}

branches/try2/src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub mod front {
9797
pub mod std_inject;
9898
pub mod assign_node_ids_and_map;
9999
pub mod feature_gate;
100+
pub mod show_span;
100101
}
101102

102103
pub mod back {

branches/try2/src/libsemver/lib.rs

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
use std::char;
3737
use std::cmp;
38-
use std::fmt;
3938
use std::option::{Option, Some, None};
4039
use std::to_str::ToStr;
4140

@@ -60,20 +59,13 @@ impl cmp::Ord for Identifier {
6059
}
6160
}
6261

63-
impl fmt::Show for Identifier {
64-
#[inline]
65-
fn fmt(version: &Identifier, f: &mut fmt::Formatter) -> fmt::Result {
66-
match *version {
67-
Numeric(ref n) => fmt::Show::fmt(n, f),
68-
AlphaNumeric(ref s) => fmt::Show::fmt(s, f)
69-
}
70-
}
71-
}
72-
7362
impl ToStr for Identifier {
7463
#[inline]
7564
fn to_str(&self) -> ~str {
76-
format!("{}", *self)
65+
match self {
66+
&Numeric(n) => n.to_str(),
67+
&AlphaNumeric(ref s) => s.to_str()
68+
}
7769
}
7870
}
7971

@@ -82,45 +74,33 @@ impl ToStr for Identifier {
8274
#[deriving(Clone, Eq)]
8375
pub struct Version {
8476
/// The major version, to be incremented on incompatible changes.
85-
major: uint,
77+
priv major: uint,
8678
/// The minor version, to be incremented when functionality is added in a
8779
/// backwards-compatible manner.
88-
minor: uint,
80+
priv minor: uint,
8981
/// The patch version, to be incremented when backwards-compatible bug
9082
/// fixes are made.
91-
patch: uint,
83+
priv patch: uint,
9284
/// The pre-release version identifier, if one exists.
93-
pre: ~[Identifier],
85+
priv pre: ~[Identifier],
9486
/// The build metadata, ignored when determining version precedence.
95-
build: ~[Identifier],
96-
}
97-
98-
impl fmt::Show for Version {
99-
#[inline]
100-
fn fmt(version: &Version, f: &mut fmt::Formatter) -> fmt::Result {
101-
if_ok!(write!(f.buf, "{}.{}.{}", version.major, version.minor, version.patch))
102-
if !version.pre.is_empty() {
103-
if_ok!(write!(f.buf, "-"));
104-
for (i, x) in version.pre.iter().enumerate() {
105-
if i != 0 { if_ok!(write!(f.buf, ".")) };
106-
if_ok!(fmt::Show::fmt(x, f));
107-
}
108-
}
109-
if !version.build.is_empty() {
110-
if_ok!(write!(f.buf, "+"));
111-
for (i, x) in version.build.iter().enumerate() {
112-
if i != 0 { if_ok!(write!(f.buf, ".")) };
113-
if_ok!(fmt::Show::fmt(x, f));
114-
}
115-
}
116-
Ok(())
117-
}
87+
priv build: ~[Identifier],
11888
}
11989

12090
impl ToStr for Version {
12191
#[inline]
12292
fn to_str(&self) -> ~str {
123-
format!("{}", *self)
93+
let s = format!("{}.{}.{}", self.major, self.minor, self.patch);
94+
let s = if self.pre.is_empty() {
95+
s
96+
} else {
97+
format!("{}-{}", s, self.pre.map(|i| i.to_str()).connect("."))
98+
};
99+
if self.build.is_empty() {
100+
s
101+
} else {
102+
format!("{}+{}", s, self.build.map(|i| i.to_str()).connect("."))
103+
}
124104
}
125105
}
126106

@@ -385,22 +365,6 @@ fn test_ne() {
385365
assert!(parse("1.2.3+23") != parse("1.2.3+42"));
386366
}
387367
388-
#[test]
389-
fn test_show() {
390-
assert_eq!(format!("{}", parse("1.2.3").unwrap()), ~"1.2.3");
391-
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), ~"1.2.3-alpha1");
392-
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), ~"1.2.3+build.42");
393-
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), ~"1.2.3-alpha1+42");
394-
}
395-
396-
#[test]
397-
fn test_to_str() {
398-
assert_eq!(parse("1.2.3").unwrap().to_str(), ~"1.2.3");
399-
assert_eq!(parse("1.2.3-alpha1").unwrap().to_str(), ~"1.2.3-alpha1");
400-
assert_eq!(parse("1.2.3+build.42").unwrap().to_str(), ~"1.2.3+build.42");
401-
assert_eq!(parse("1.2.3-alpha1+42").unwrap().to_str(), ~"1.2.3-alpha1+42");
402-
}
403-
404368
#[test]
405369
fn test_lt() {
406370
assert!(parse("0.0.0") < parse("1.2.3-alpha2"));

branches/try2/src/libstd/path/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ impl<'a, P: GenericPath> ToStr for Display<'a, P> {
508508
if self.filename {
509509
match self.path.filename() {
510510
None => ~"",
511-
Some(v) => str::from_utf8_lossy(v)
511+
Some(v) => from_utf8_with_replacement(v)
512512
}
513513
} else {
514-
str::from_utf8_lossy(self.path.as_vec())
514+
from_utf8_with_replacement(self.path.as_vec())
515515
}
516516
}
517517
}
@@ -596,6 +596,29 @@ fn contains_nul(v: &[u8]) -> bool {
596596
v.iter().any(|&x| x == 0)
597597
}
598598

599+
#[inline(always)]
600+
fn from_utf8_with_replacement(mut v: &[u8]) -> ~str {
601+
// FIXME (#9516): Don't decode utf-8 manually here once we have a good way to do it in str
602+
// This is a truly horrifically bad implementation, done as a functionality stopgap until
603+
// we have a proper utf-8 decoder. I don't really want to write one here.
604+
static REPLACEMENT_CHAR: char = '\uFFFD';
605+
606+
let mut s = str::with_capacity(v.len());
607+
while !v.is_empty() {
608+
let w = str::utf8_char_width(v[0]);
609+
if w == 0u {
610+
s.push_char(REPLACEMENT_CHAR);
611+
v = v.slice_from(1);
612+
} else if v.len() < w || !str::is_utf8(v.slice_to(w)) {
613+
s.push_char(REPLACEMENT_CHAR);
614+
v = v.slice_from(1);
615+
} else {
616+
s.push_str(unsafe { ::cast::transmute(v.slice_to(w)) });
617+
v = v.slice_from(w);
618+
}
619+
}
620+
s
621+
}
599622
#[cfg(test)]
600623
mod tests {
601624
use prelude::*;

0 commit comments

Comments
 (0)