Skip to content

Commit fec2c12

Browse files
committed
rustc_driver: use (expr: T) in --pretty=typed, instead of (expr as T), as the latter might compile some day.
1 parent 13d51f4 commit fec2c12

File tree

2 files changed

+30
-44
lines changed

2 files changed

+30
-44
lines changed

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ impl<'a, 'tcx> pprust::PpAnn for TypedAnnotation<'a, 'tcx> {
181181
node: pprust::AnnNode) -> old_io::IoResult<()> {
182182
match node {
183183
pprust::NodeExpr(expr) => {
184-
try!(pp::space(&mut s.s));
185-
try!(pp::word(&mut s.s, "as"));
186-
try!(pp::space(&mut s.s));
184+
try!(s.word_space(":"));
187185
try!(pp::word(&mut s.s,
188186
&ppaux::ty_to_string(
189187
self.tcx,

src/test/pretty/issue-4264.pp

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020

2121
// #4264 fixed-length vector types
2222

23-
pub fn foo(_: [i32; (3 as usize)]) { }
23+
pub fn foo(_: [i32; (3: usize)]) { }
2424

2525
pub fn bar() {
26-
const FOO: usize = ((5 as usize) - (4 as usize) as usize);
27-
let _: [(); (FOO as usize)] = ([(() as ())] as [(); 1]);
26+
const FOO: usize = ((5: usize) - (4: usize): usize);
27+
let _: [(); (FOO: usize)] = ([((): ())]: [(); 1]);
2828

29-
let _: [(); (1usize as usize)] = ([(() as ())] as [(); 1]);
29+
let _: [(); (1usize: usize)] = ([((): ())]: [(); 1]);
3030

3131
let _ =
32-
(((&((([(1 as i32), (2 as i32), (3 as i32)] as [i32; 3])) as [i32; 3])
33-
as &[i32; 3]) as *const _ as *const [i32; 3]) as
34-
*const [i32; (3usize as usize)] as *const [i32; 3]);
32+
(((&((([(1: i32), (2: i32), (3: i32)]: [i32; 3])): [i32; 3]):
33+
&[i32; 3]) as *const _: *const [i32; 3]) as
34+
*const [i32; (3usize: usize)]: *const [i32; 3]);
3535

3636

3737

@@ -41,56 +41,44 @@
4141

4242

4343

44-
((::std::fmt::format as
45-
fn(core::fmt::Arguments<'_>) -> collections::string::String {collections::fmt::format})(((::std::fmt::Arguments::new_v1
46-
as
44+
((::std::fmt::format:
45+
fn(core::fmt::Arguments<'_>) -> collections::string::String {collections::fmt::format})(((::std::fmt::Arguments::new_v1:
4746
fn(&[&str], &[core::fmt::ArgumentV1<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new_v1})(({
4847
static __STATIC_FMTSTR:
4948
&'static [&'static str]
5049
=
51-
(&([("test"
52-
as
53-
&'static str)]
54-
as
55-
[&'static str; 1])
56-
as
50+
(&([("test":
51+
&'static str)]:
52+
[&'static str; 1]):
5753
&'static [&'static str; 1]);
58-
(__STATIC_FMTSTR
59-
as
54+
(__STATIC_FMTSTR:
6055
&'static [&'static str])
61-
}
62-
as
56+
}:
6357
&[&str]),
64-
(&(match (()
65-
as
58+
(&(match (():
6659
())
6760
{
6861
()
6962
=>
70-
([]
71-
as
63+
([]:
7264
[core::fmt::ArgumentV1<'_>; 0]),
73-
}
74-
as
75-
[core::fmt::ArgumentV1<'_>; 0])
76-
as
77-
&[core::fmt::ArgumentV1<'_>; 0]))
78-
as
79-
core::fmt::Arguments<'_>))
80-
as collections::string::String);
65+
}:
66+
[core::fmt::ArgumentV1<'_>; 0]):
67+
&[core::fmt::ArgumentV1<'_>; 0])):
68+
core::fmt::Arguments<'_>)):
69+
collections::string::String);
8170
}
82-
pub type Foo = [i32; (3 as usize)];
71+
pub type Foo = [i32; (3: usize)];
8372
pub struct Bar {
84-
pub x: [i32; (3 as usize)],
73+
pub x: [i32; (3: usize)],
8574
}
86-
pub struct TupleBar([i32; (4 as usize)]);
87-
pub enum Baz { BazVariant([i32; (5 as usize)]), }
88-
pub fn id<T>(x: T) -> T { (x as T) }
75+
pub struct TupleBar([i32; (4: usize)]);
76+
pub enum Baz { BazVariant([i32; (5: usize)]), }
77+
pub fn id<T>(x: T) -> T { (x: T) }
8978
pub fn use_id() {
9079
let _ =
91-
((id::<[i32; (3 as usize)]> as
92-
fn([i32; 3]) -> [i32; 3] {id})(([(1 as i32), (2 as i32),
93-
(3 as i32)] as [i32; 3])) as
94-
[i32; 3]);
80+
((id::<[i32; (3: usize)]>:
81+
fn([i32; 3]) -> [i32; 3] {id})(([(1: i32), (2: i32), (3: i32)]:
82+
[i32; 3])): [i32; 3]);
9583
}
9684
fn main() { }

0 commit comments

Comments
 (0)