1 use rustc::hir::itemlikevisit::ItemLikeVisitor;
4 use rustc_target::spec::abi::Abi;
6 pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<String> {
7 let mut collector = Collector {
10 tcx.hir().krate().visit_all_item_likes(&mut collector);
12 for attr in tcx.hir().krate().attrs.iter() {
13 if attr.path == "link_args" {
14 if let Some(linkarg) = attr.value_str() {
15 collector.add_link_args(&linkarg.as_str());
27 impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
28 fn visit_item(&mut self, it: &'tcx hir::Item) {
29 let fm = match it.node {
30 hir::ItemKind::ForeignMod(ref fm) => fm,
33 if fm.abi == Abi::Rust ||
34 fm.abi == Abi::RustIntrinsic ||
35 fm.abi == Abi::PlatformIntrinsic {
39 // First, add all of the custom #[link_args] attributes
40 for m in it.attrs.iter().filter(|a| a.check_name("link_args")) {
41 if let Some(linkarg) = m.value_str() {
42 self.add_link_args(&linkarg.as_str());
47 fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {}
48 fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {}
52 fn add_link_args(&mut self, args: &str) {
53 self.args.extend(args.split(' ').filter(|s| !s.is_empty()).map(|s| s.to_string()))