Skip to content

Commit eb5facc

Browse files
committed
Now it works again :)
Fixes rust-lang#64.
1 parent 7381d71 commit eb5facc

File tree

3 files changed

+130
-127
lines changed

3 files changed

+130
-127
lines changed

src/bin/cargo_semver.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
247247
.map_err(|e| Error(format!("could not spawn rustc: {}", e)))?;
248248

249249
if let Some(ref mut stdin) = child.stdin {
250+
// The order of the `extern crate` declaration is important here: it will later
251+
// be used to select the `old` and `new` crates.
250252
stdin.write_fmt(format_args!("#[allow(unused_extern_crates)] \
251-
extern crate new; \
253+
extern crate old; \
252254
#[allow(unused_extern_crates)] \
253-
extern crate old;"))?;
255+
extern crate new;"))?;
254256
} else {
255257
return Err(Error("could not pipe to rustc (wtf?)".to_owned()).into());
256258
}

src/bin/rust_semverver.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc::hir::def_id::*;
1919
use rustc_metadata::cstore::CStore;
2020
use rustc::session::{config, Session};
2121
use rustc::session::config::{Input, ErrorOutputType};
22+
use rustc::middle::cstore::ExternCrate;
2223

2324
use rustc_driver::{driver, CompilerCalls, RustcDefaultCalls, Compilation};
2425

@@ -28,46 +29,46 @@ use std::path::PathBuf;
2829
use std::process::Command;
2930

3031
use syntax::ast;
32+
use syntax::source_map::Pos;
3133

3234
/// After the typechecker has finished it's work, perform our checks.
33-
///
34-
/// To compare the two well-typed crates, first find the aptly named crates `new` and `old`,
35-
/// find their root modules and then proceed to walk their module trees.
3635
fn callback(state: &driver::CompileState, version: &str, verbose: bool) {
3736
let tcx = state.tcx.unwrap();
3837

39-
let cnums = tcx
38+
// To select the old and new crates we look at the position of the declaration in the
39+
// source file. The first one will be the `old` and the other will be `new`. This is
40+
// unfortunately a bit hacky... See issue #64 for details.
41+
42+
let mut crates: Vec<_> = tcx
4043
.crates()
4144
.iter()
42-
.fold((None, None), |(o, n), crate_num| {
43-
let name = tcx.crate_name(*crate_num);
44-
if name == "old" {
45-
(Some(*crate_num), n)
46-
} else if name == "new" {
47-
(o, Some(*crate_num))
48-
} else {
49-
(o, n)
45+
.flat_map(|crate_num| {
46+
let def_id = DefId {
47+
krate: *crate_num,
48+
index: CRATE_DEF_INDEX,
49+
};
50+
51+
match *tcx.extern_crate(def_id) {
52+
Some(ExternCrate { span, direct: true, ..}) if span.data().lo.to_usize() > 0 =>
53+
Some((span.data().lo.to_usize(), def_id)),
54+
_ => None,
5055
}
51-
});
52-
53-
let (old_def_id, new_def_id) = if let (Some(c0), Some(c1)) = cnums {
54-
(DefId {
55-
krate: c0,
56-
index: CRATE_DEF_INDEX,
57-
},
58-
DefId {
59-
krate: c1,
60-
index: CRATE_DEF_INDEX,
61-
})
62-
} else {
63-
tcx.sess.err("could not find crate `old` and/or `new`");
64-
return;
65-
};
56+
})
57+
.collect();
58+
59+
crates.sort_by_key(|&(span_lo, _)| span_lo);
6660

67-
debug!("running semver analysis");
68-
let changes = run_analysis(tcx, old_def_id, new_def_id);
61+
match crates.as_slice() {
62+
&[(_, old_def_id), (_, new_def_id)] => {
63+
debug!("running semver analysis");
64+
let changes = run_analysis(tcx, old_def_id, new_def_id);
6965

70-
changes.output(tcx.sess, version, verbose);
66+
changes.output(tcx.sess, version, verbose);
67+
}
68+
_ => {
69+
tcx.sess.err("could not find crate old and new crates");
70+
}
71+
}
7172
}
7273

7374
/// A wrapper to control compilation.

tests/full_cases/libc-0.2.28-0.2.31

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,99 @@
11
version bump: 0.2.28 -> (breaking) -> 0.2.29
2+
error: path changes to `forkpty`
3+
--> libc-0.2.28/src/unix/notbsd/mod.rs:1035:5
4+
|
5+
1035 | / pub fn forkpty(amaster: *mut ::c_int,
6+
1036 | | name: *mut ::c_char,
7+
1037 | | termp: *const termios,
8+
1038 | | winp: *const ::winsize) -> ::pid_t;
9+
| |___________________________________________________^
10+
|
11+
warning: removed path (breaking)
12+
--> libc-0.2.28/src/lib.rs:275:17
13+
|
14+
275 | pub use unix::*;
15+
| ^^^^^^^
16+
17+
error: breaking changes in `PTRACE_O_EXITKILL`
18+
--> libc-0.2.31/src/unix/notbsd/mod.rs:738:1
19+
|
20+
738 | pub const PTRACE_O_EXITKILL: ::c_int = 0x00100000;
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= warning: type error: expected u32, found i32 (breaking)
24+
25+
error: breaking changes in `PTRACE_O_TRACECLONE`
26+
--> libc-0.2.31/src/unix/notbsd/mod.rs:733:1
27+
|
28+
733 | pub const PTRACE_O_TRACECLONE: ::c_int = 0x00000008;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= warning: type error: expected u32, found i32 (breaking)
32+
33+
error: breaking changes in `PTRACE_O_TRACEEXEC`
34+
--> libc-0.2.31/src/unix/notbsd/mod.rs:734:1
35+
|
36+
734 | pub const PTRACE_O_TRACEEXEC: ::c_int = 0x00000010;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
= warning: type error: expected u32, found i32 (breaking)
40+
41+
error: breaking changes in `PTRACE_O_TRACEEXIT`
42+
--> libc-0.2.31/src/unix/notbsd/mod.rs:736:1
43+
|
44+
736 | pub const PTRACE_O_TRACEEXIT: ::c_int = 0x00000040;
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
|
47+
= warning: type error: expected u32, found i32 (breaking)
48+
49+
error: breaking changes in `PTRACE_O_TRACEFORK`
50+
--> libc-0.2.31/src/unix/notbsd/mod.rs:731:1
51+
|
52+
731 | pub const PTRACE_O_TRACEFORK: ::c_int = 0x00000002;
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
|
55+
= warning: type error: expected u32, found i32 (breaking)
56+
57+
error: breaking changes in `PTRACE_O_TRACESYSGOOD`
58+
--> libc-0.2.31/src/unix/notbsd/mod.rs:730:1
59+
|
60+
730 | pub const PTRACE_O_TRACESYSGOOD: ::c_int = 0x00000001;
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62+
|
63+
= warning: type error: expected u32, found i32 (breaking)
64+
65+
error: breaking changes in `PTRACE_O_TRACEVFORK`
66+
--> libc-0.2.31/src/unix/notbsd/mod.rs:732:1
67+
|
68+
732 | pub const PTRACE_O_TRACEVFORK: ::c_int = 0x00000004;
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
|
71+
= warning: type error: expected u32, found i32 (breaking)
72+
73+
error: breaking changes in `PTRACE_O_TRACEVFORKDONE`
74+
--> libc-0.2.31/src/unix/notbsd/mod.rs:735:1
75+
|
76+
735 | pub const PTRACE_O_TRACEVFORKDONE: ::c_int = 0x00000020;
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78+
|
79+
= warning: type error: expected u32, found i32 (breaking)
80+
81+
error: breaking changes in `PTRACE_O_TRACESECCOMP`
82+
--> libc-0.2.31/src/unix/notbsd/mod.rs:737:1
83+
|
84+
737 | pub const PTRACE_O_TRACESECCOMP: ::c_int = 0x00000080;
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
|
87+
= warning: type error: expected u32, found i32 (breaking)
88+
89+
error: breaking changes in `PTRACE_O_SUSPEND_SECCOMP`
90+
--> libc-0.2.31/src/unix/notbsd/mod.rs:739:1
91+
|
92+
739 | pub const PTRACE_O_SUSPEND_SECCOMP: ::c_int = 0x00200000;
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
|
95+
= warning: type error: expected u32, found i32 (breaking)
96+
297
warning: path changes to `INADDR_LOOPBACK`
398
--> libc-0.2.31/src/unix/mod.rs:227:1
499
|
@@ -770,100 +865,5 @@ note: added path (technically breaking)
770865
284 | pub use unix::*;
771866
| ^^^^^^^
772867

773-
error: path changes to `forkpty`
774-
--> libc-0.2.28/src/unix/notbsd/mod.rs:1035:5
775-
|
776-
1035 | / pub fn forkpty(amaster: *mut ::c_int,
777-
1036 | | name: *mut ::c_char,
778-
1037 | | termp: *const termios,
779-
1038 | | winp: *const ::winsize) -> ::pid_t;
780-
| |___________________________________________________^
781-
|
782-
warning: removed path (breaking)
783-
--> libc-0.2.28/src/lib.rs:275:17
784-
|
785-
275 | pub use unix::*;
786-
| ^^^^^^^
787-
788-
error: breaking changes in `PTRACE_O_EXITKILL`
789-
--> libc-0.2.31/src/unix/notbsd/mod.rs:738:1
790-
|
791-
738 | pub const PTRACE_O_EXITKILL: ::c_int = 0x00100000;
792-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
793-
|
794-
= warning: type error: expected u32, found i32 (breaking)
795-
796-
error: breaking changes in `PTRACE_O_TRACECLONE`
797-
--> libc-0.2.31/src/unix/notbsd/mod.rs:733:1
798-
|
799-
733 | pub const PTRACE_O_TRACECLONE: ::c_int = 0x00000008;
800-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
801-
|
802-
= warning: type error: expected u32, found i32 (breaking)
803-
804-
error: breaking changes in `PTRACE_O_TRACEEXEC`
805-
--> libc-0.2.31/src/unix/notbsd/mod.rs:734:1
806-
|
807-
734 | pub const PTRACE_O_TRACEEXEC: ::c_int = 0x00000010;
808-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
809-
|
810-
= warning: type error: expected u32, found i32 (breaking)
811-
812-
error: breaking changes in `PTRACE_O_TRACEEXIT`
813-
--> libc-0.2.31/src/unix/notbsd/mod.rs:736:1
814-
|
815-
736 | pub const PTRACE_O_TRACEEXIT: ::c_int = 0x00000040;
816-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
817-
|
818-
= warning: type error: expected u32, found i32 (breaking)
819-
820-
error: breaking changes in `PTRACE_O_TRACEFORK`
821-
--> libc-0.2.31/src/unix/notbsd/mod.rs:731:1
822-
|
823-
731 | pub const PTRACE_O_TRACEFORK: ::c_int = 0x00000002;
824-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
825-
|
826-
= warning: type error: expected u32, found i32 (breaking)
827-
828-
error: breaking changes in `PTRACE_O_TRACESYSGOOD`
829-
--> libc-0.2.31/src/unix/notbsd/mod.rs:730:1
830-
|
831-
730 | pub const PTRACE_O_TRACESYSGOOD: ::c_int = 0x00000001;
832-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
833-
|
834-
= warning: type error: expected u32, found i32 (breaking)
835-
836-
error: breaking changes in `PTRACE_O_TRACEVFORK`
837-
--> libc-0.2.31/src/unix/notbsd/mod.rs:732:1
838-
|
839-
732 | pub const PTRACE_O_TRACEVFORK: ::c_int = 0x00000004;
840-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
841-
|
842-
= warning: type error: expected u32, found i32 (breaking)
843-
844-
error: breaking changes in `PTRACE_O_TRACEVFORKDONE`
845-
--> libc-0.2.31/src/unix/notbsd/mod.rs:735:1
846-
|
847-
735 | pub const PTRACE_O_TRACEVFORKDONE: ::c_int = 0x00000020;
848-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
849-
|
850-
= warning: type error: expected u32, found i32 (breaking)
851-
852-
error: breaking changes in `PTRACE_O_TRACESECCOMP`
853-
--> libc-0.2.31/src/unix/notbsd/mod.rs:737:1
854-
|
855-
737 | pub const PTRACE_O_TRACESECCOMP: ::c_int = 0x00000080;
856-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
857-
|
858-
= warning: type error: expected u32, found i32 (breaking)
859-
860-
error: breaking changes in `PTRACE_O_SUSPEND_SECCOMP`
861-
--> libc-0.2.31/src/unix/notbsd/mod.rs:739:1
862-
|
863-
739 | pub const PTRACE_O_SUSPEND_SECCOMP: ::c_int = 0x00200000;
864-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
865-
|
866-
= warning: type error: expected u32, found i32 (breaking)
867-
868868
error: aborting due to 11 previous errors
869869

0 commit comments

Comments
 (0)