Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Oct 15, 2021
1 parent c4b8702 commit 7dbee3c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ repository and compiled from source or installed from
of the nightly toolchain is supported at any given time.

<!-- NOTE: Keep in sync with nightly date on rust-toolchain. -->
It's recommended to use `nightly-2021-09-10` toolchain.
You can install it by using `rustup install nightly-2021-09-10` if you already have rustup.
It's recommended to use `nightly-2021-09-20` toolchain.
You can install it by using `rustup install nightly-2021-09-20` if you already have rustup.
Then you can do:

```sh
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-10
$ cargo +nightly-2021-09-10 install --git https://github.com/rust-lang/rust-semverver
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-20
$ cargo +nightly-2021-09-20 install --git https://github.com/rust-lang/rust-semverver
```

You'd also need `cmake` for some dependencies, and a few common libraries (if you hit
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: Keep in sync with nightly date on README
[toolchain]
channel = "nightly-2021-09-10"
channel = "nightly-2021-09-20"
components = ["llvm-tools-preview", "rustc-dev"]
24 changes: 12 additions & 12 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ pub mod tests {
use std::cmp::{max, min};

use rustc_span::hygiene::SyntaxContext;
use rustc_span::symbol::Interner;
use rustc_span::symbol::sym;
use rustc_span::BytePos;

/// A wrapper for `Span` that can be randomly generated.
Expand All @@ -1239,7 +1239,12 @@ pub mod tests {

impl Span_ {
pub fn inner(self) -> Span {
Span::new(BytePos(self.0), BytePos(self.1), SyntaxContext::root())
Span::new(
BytePos(self.0),
BytePos(self.1),
SyntaxContext::root(),
None,
)
}
}

Expand Down Expand Up @@ -1460,8 +1465,7 @@ pub mod tests {
output: bool,
changes: Vec<(ChangeType_, Option<Span_>)>,
) -> Change<'a> {
let mut interner = Interner::default();
let mut change = Change::new(Name::Symbol(RSymbol(interner.intern("test"))), s1, output);
let mut change = Change::new(Name::Symbol(RSymbol(sym::test)), s1, output);

for (type_, span) in changes {
change.insert(type_.inner(), span.map(|s| s.inner()));
Expand All @@ -1475,8 +1479,7 @@ pub mod tests {

/// Construct `PathChange`s from things that can be generated.
fn build_path_change(s1: Span, spans: Vec<(bool, Span)>) -> PathChange {
let mut interner = Interner::default();
let mut change = PathChange::new(interner.intern("test"), s1);
let mut change = PathChange::new(sym::test, s1);

for (add, span) in spans {
change.insert(span, add);
Expand Down Expand Up @@ -1546,8 +1549,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = changes
.iter()
Expand Down Expand Up @@ -1579,8 +1581,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = changes
.iter()
Expand Down Expand Up @@ -1614,8 +1615,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = pchanges
.iter()
Expand Down
12 changes: 5 additions & 7 deletions src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl IdMapping {
}

/// An export that could be missing from one of the crate versions.
type OptionalExport = Option<Export<HirId>>;
type OptionalExport = Option<Export>;

/// A mapping from names to pairs of old and new exports.
///
Expand All @@ -343,11 +343,11 @@ pub struct NameMapping {

impl NameMapping {
/// Insert a single export in the appropriate map, at the appropriate position.
fn insert(&mut self, item: Export<HirId>, old: bool) {
fn insert(&mut self, item: Export, old: bool) {
use rustc_hir::def::DefKind::*;
use rustc_hir::def::Res::*;

let map = match item.res {
let map = match item.res.expect_non_local::<HirId>() {
Def(kind, _) => match kind {
Mod |
Struct |
Expand Down Expand Up @@ -396,7 +396,7 @@ impl NameMapping {
}

/// Add all items from two vectors of old/new exports.
pub fn add(&mut self, old_items: Vec<Export<HirId>>, new_items: Vec<Export<HirId>>) {
pub fn add(&mut self, old_items: Vec<Export>, new_items: Vec<Export>) {
for item in old_items {
self.insert(item, true);
}
Expand All @@ -407,9 +407,7 @@ impl NameMapping {
}

/// Drain the item pairs being stored.
pub fn drain(
&mut self,
) -> impl Iterator<Item = (Option<Export<HirId>>, Option<Export<HirId>>)> + '_ {
pub fn drain(&mut self) -> impl Iterator<Item = (Option<Export>, Option<Export>)> + '_ {
self.type_map
.drain()
.chain(self.value_map.drain())
Expand Down
27 changes: 14 additions & 13 deletions src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn run_analysis(tcx: TyCtxt, old: DefId, new: DefId) -> ChangeSet {
}

// Get the visibility of the inner item, given the outer item's visibility.
fn get_vis(outer_vis: Visibility, def: Export<HirId>) -> Visibility {
fn get_vis(outer_vis: Visibility, def: Export) -> Visibility {
if outer_vis == Public {
def.vis
} else {
Expand Down Expand Up @@ -156,7 +156,8 @@ fn diff_structure<'tcx>(
match items {
// an item pair is found
(Some(o), Some(n)) => {
if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o.res, n.res) {
let (o_res, n_res) = (o.res.expect_non_local(), n.res.expect_non_local());
if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o_res, n_res) {
if visited.insert((o_def_id, n_def_id)) {
let o_vis = get_vis(old_vis, o);
let n_vis = get_vis(new_vis, n);
Expand All @@ -182,16 +183,16 @@ fn diff_structure<'tcx>(

mod_queue.push_back((o_def_id, n_def_id, o_vis, n_vis));
}
} else if id_mapping.add_export(o.res, n.res) {
} else if id_mapping.add_export(o_res, n_res) {
// struct constructors are weird/hard - let's go shopping!
if let (Def(Ctor(CtorOf::Struct, _), _), Def(Ctor(CtorOf::Struct, _), _)) =
(o.res, n.res)
(o_res, n_res)
{
continue;
}

let o_def_id = o.res.def_id();
let n_def_id = n.res.def_id();
let o_def_id = o_res.def_id();
let n_def_id = n_res.def_id();
let o_vis = get_vis(old_vis, o);
let n_vis = get_vis(new_vis, n);

Expand All @@ -211,7 +212,7 @@ fn diff_structure<'tcx>(
changes.add_change(ChangeType::ItemMadePublic, o_def_id, None);
}

let (o_kind, n_kind) = match (o.res, n.res) {
let (o_kind, n_kind) = match (o_res, n_res) {
(Res::Def(o_kind, _), Res::Def(n_kind, _)) => (o_kind, n_kind),
_ => {
// a non-matching item pair (seriously broken though) -
Expand Down Expand Up @@ -257,7 +258,7 @@ fn diff_structure<'tcx>(
// that need to be compared
(Fn, Fn) => {
diff_generics(changes, id_mapping, tcx, true, o_def_id, n_def_id);
diff_fn(changes, tcx, o.res, n.res);
diff_fn(changes, tcx, o_res, n_res);
}
// type aliases can declare generics, too
(TyAlias, TyAlias) => {
Expand All @@ -268,7 +269,7 @@ fn diff_structure<'tcx>(
// fields
(Struct, Struct) | (Union, Union) | (Enum, Enum) => {
diff_generics(changes, id_mapping, tcx, false, o_def_id, n_def_id);
diff_adts(changes, id_mapping, tcx, o.res, n.res);
diff_adts(changes, id_mapping, tcx, o_res, n_res);
}
// trait definitions can declare generics and require us to check
// for trait item addition and removal, as well as changes to their
Expand Down Expand Up @@ -298,7 +299,7 @@ fn diff_structure<'tcx>(
// only an old item is found
(Some(o), None) => {
// struct constructors are weird/hard - let's go shopping!
if let Def(Ctor(CtorOf::Struct, _), _) = o.res {
if let Def(Ctor(CtorOf::Struct, _), _) = o.res.expect_non_local::<HirId>() {
continue;
}

Expand All @@ -310,7 +311,7 @@ fn diff_structure<'tcx>(
// only a new item is found
(None, Some(n)) => {
// struct constructors are weird/hard - let's go shopping!
if let Def(Ctor(CtorOf::Struct, _), _) = n.res {
if let Def(Ctor(CtorOf::Struct, _), _) = n.res.expect_non_local::<HirId>() {
continue;
}

Expand All @@ -327,7 +328,7 @@ fn diff_structure<'tcx>(

// finally, process item additions and removals
for n in additions {
let n_def_id = n.res.def_id();
let n_def_id = n.res.expect_non_local::<HirId>().def_id();

if !id_mapping.contains_new_id(n_def_id) {
id_mapping.add_non_mapped(n_def_id);
Expand All @@ -338,7 +339,7 @@ fn diff_structure<'tcx>(
}

for o in removals {
let o_def_id = o.res.def_id();
let o_def_id = o.res.expect_non_local::<HirId>().def_id();

// reuse an already existing path change entry, if possible
if id_mapping.contains_old_id(o_def_id) {
Expand Down

0 comments on commit 7dbee3c

Please sign in to comment.