about summary refs log tree commit diff
path: root/src/librustc/hir
diff options
context:
space:
mode:
authorDan Robertson <dan@dlrobertson.com>2018-11-30 15:53:44 +0000
committerDan Robertson <dan@dlrobertson.com>2019-02-27 10:21:35 -0500
commit58147d486bc26eb59d18d8e0d83aa6fe0b467fb9 (patch)
tree3e25be958b33c7e5727b059511157ac9f1a22722 /src/librustc/hir
parentcd56472cc47981e62c684ceada7922ac3731b785 (diff)
downloadrust-58147d486bc26eb59d18d8e0d83aa6fe0b467fb9.tar.gz
rust-58147d486bc26eb59d18d8e0d83aa6fe0b467fb9.zip
Support defining C compatible variadic functions
Add support for defining C compatible variadic functions in unsafe rust
with extern "C".
Diffstat (limited to 'src/librustc/hir')
-rw-r--r--src/librustc/hir/intravisit.rs3
-rw-r--r--src/librustc/hir/lowering.rs6
-rw-r--r--src/librustc/hir/mod.rs3
-rw-r--r--src/librustc/hir/print.rs3
4 files changed, 15 insertions, 0 deletions
diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs
index 0bc40da7e4f..8e4b9a5e8e6 100644
--- a/src/librustc/hir/intravisit.rs
+++ b/src/librustc/hir/intravisit.rs
@@ -617,6 +617,9 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
         TyKind::Typeof(ref expression) => {
             visitor.visit_anon_const(expression)
         }
+        TyKind::CVarArgs(ref lt) => {
+            visitor.visit_lifetime(lt)
+        }
         TyKind::Infer | TyKind::Err => {}
     }
 }
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 0211dd72875..0e2b34d4fac 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -1345,6 +1345,12 @@ impl<'a> LoweringContext<'a> {
                 }
             }
             TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
+            TyKind::CVarArgs => {
+                // Create the implicit lifetime of the "spoofed" `VaList`.
+                let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
+                let lt = self.new_implicit_lifetime(span);
+                hir::TyKind::CVarArgs(lt)
+            },
         };
 
         let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id);
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index 38e6e61592b..205109d18fe 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -1829,6 +1829,9 @@ pub enum TyKind {
     Infer,
     /// Placeholder for a type that has failed to be defined.
     Err,
+    /// Placeholder for C-variadic arguments. We "spoof" the `VaList` created
+    /// from the variadic arguments. This type is only valid up to typeck.
+    CVarArgs(Lifetime),
 }
 
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs
index 17d37488413..8c252b0d027 100644
--- a/src/librustc/hir/print.rs
+++ b/src/librustc/hir/print.rs
@@ -434,6 +434,9 @@ impl<'a> State<'a> {
                 self.s.word("/*ERROR*/")?;
                 self.pclose()?;
             }
+            hir::TyKind::CVarArgs(_) => {
+                self.s.word("...")?;
+            }
         }
         self.end()
     }