Skip to content

Commit

Permalink
Fix ICE
Browse files Browse the repository at this point in the history
  • Loading branch information
scalexm committed Sep 20, 2017
1 parent f7964ae commit 3fa3fe0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ define_dep_nodes!( <'tcx>
[] MissingExternCrateItem(CrateNum),
[] UsedCrateSource(CrateNum),
[] PostorderCnums,
[] HasCloneClosures(CrateNum),
[] HasCopyClosures(CrateNum),

[] Freevars(DefId),
[] MaybeUnusedTraitImport(DefId),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,10 +2087,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
let trait_id = obligation.predicate.def_id();
let copy_closures =
Some(trait_id) == self.tcx().lang_items().copy_trait() &&
self.tcx().sess.features.borrow().copy_closures;
self.tcx().has_copy_closures(def_id.krate);
let clone_closures =
Some(trait_id) == self.tcx().lang_items().clone_trait() &&
self.tcx().sess.features.borrow().clone_closures;
self.tcx().has_clone_closures(def_id.krate);

if copy_closures || clone_closures {
Where(ty::Binder(substs.upvar_tys(def_id, self.tcx()).collect()))
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2247,4 +2247,12 @@ pub fn provide(providers: &mut ty::maps::Providers) {
assert_eq!(cnum, LOCAL_CRATE);
tcx.output_filenames.clone()
};
providers.has_copy_closures = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.sess.features.borrow().copy_closures
};
providers.has_clone_closures = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.sess.features.borrow().clone_closures
};
}
12 changes: 12 additions & 0 deletions src/librustc/ty/maps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,15 @@ impl<'tcx> QueryDescription for queries::output_filenames<'tcx> {
format!("output_filenames")
}
}

impl<'tcx> QueryDescription for queries::has_clone_closures<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
format!("seeing if the crate has enabled `Clone` closures")
}
}

impl<'tcx> QueryDescription for queries::has_copy_closures<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
format!("seeing if the crate has enabled `Copy` closures")
}
}
3 changes: 3 additions & 0 deletions src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ define_maps! { <'tcx>
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
[] fn output_filenames: output_filenames_node(CrateNum)
-> Arc<OutputFilenames>,

[] fn has_copy_closures: HasCopyClosures(CrateNum) -> bool,
[] fn has_clone_closures: HasCloneClosures(CrateNum) -> bool,
}

//////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ impl CrateMetadata {
attr::contains_name(&attrs, "no_builtins")
}

pub fn has_copy_closures(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_feature_attr(&attrs, "copy_closures")
}

pub fn has_clone_closures(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_feature_attr(&attrs, "clone_closures")
}

pub fn panic_strategy(&self) -> PanicStrategy {
self.root.panic_strategy.clone()
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
}

used_crate_source => { Rc::new(cdata.source.clone()) }

has_copy_closures => { cdata.has_copy_closures() }
has_clone_closures => { cdata.has_clone_closures() }
}

pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
Expand Down
14 changes: 14 additions & 0 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,20 @@ pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<S
.and_then(|at| at.value_str())
}

/// Check if `attrs` contains an attribute like `#![feature(feature_name)]`.
/// This will not perform any "sanity checks" on the form of the attributes.
pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool {
attrs.iter().any(|item| {
item.check_name("feature") &&
item.meta_item_list().map(|list| {
list.iter().any(|mi| {
mi.word().map(|w| w.name() == feature_name)
.unwrap_or(false)
})
}).unwrap_or(false)
})
}

/* Higher-level applications */

pub fn find_crate_name(attrs: &[Attribute]) -> Option<Symbol> {
Expand Down

0 comments on commit 3fa3fe0

Please sign in to comment.