Skip to content

Commit

Permalink
rustc: don't store a lifetime in hir::TyKind::CVarArgs.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 28, 2019
1 parent 8a9d775 commit 7683d1c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 30 deletions.
4 changes: 1 addition & 3 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -633,9 +633,7 @@ 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::CVarArgs |
TyKind::Infer | TyKind::Err => {}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1336,12 +1336,7 @@ impl<'a> LoweringContext<'a> {
}
}
TyKind::Mac(_) => bug!("`TyMac` should have been expanded by now"),
TyKind::CVarArgs => {
// Create the implicit lifetime of the "spoofed" `VaListImpl`.
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
let lt = self.new_implicit_lifetime(span);
hir::TyKind::CVarArgs(lt)
},
TyKind::CVarArgs => hir::TyKind::CVarArgs,
};

hir::Ty {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -2018,7 +2018,7 @@ pub enum TyKind {
Err,
/// Placeholder for C-variadic arguments. We "spoof" the `VaListImpl` created
/// from the variadic arguments. This type is only valid up to typeck.
CVarArgs(Lifetime),
CVarArgs,
}

#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Expand Up @@ -361,7 +361,7 @@ impl<'a> State<'a> {
self.s.word("/*ERROR*/");
self.pclose();
}
hir::TyKind::CVarArgs(_) => {
hir::TyKind::CVarArgs => {
self.s.word("...");
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -764,13 +764,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
});
}
}
hir::TyKind::CVarArgs(ref lt) => {
// Resolve the generated lifetime for the C-variadic arguments.
// The lifetime is generated in AST -> HIR lowering.
if lt.name.is_elided() {
self.resolve_elided_lifetimes(vec![lt])
}
}
_ => intravisit::walk_ty(self, ty),
}
}
Expand Down Expand Up @@ -2378,7 +2371,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
self.visit_lifetime(lifetime);
}
}
hir::TyKind::CVarArgs(_) => {}
_ => {
intravisit::walk_ty(self, ty);
}
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -2148,13 +2148,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// handled specially and will not descend into this routine.
self.ty_infer(None, ast_ty.span)
}
hir::TyKind::CVarArgs(lt) => {
hir::TyKind::CVarArgs => {
let va_list_did = match tcx.lang_items().va_list() {
Some(did) => did,
None => span_bug!(ast_ty.span,
"`va_list` lang item required for variadics"),
};
let region = self.ast_region_to_region(&lt, None);
// FIXME(eddyb) compute this in the body and don't let it reach the signature.
// HACK(eddyb) the `123` anon index is only temporary, to keep tests passing.
// Ideally this would use `ReScope` or similar.
let region = tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(123)));
tcx.type_of(va_list_did).subst(tcx, &[region.into()])
}
hir::TyKind::Err => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -3032,7 +3032,7 @@ impl Clean<Type> for hir::Ty {
TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
TyKind::Infer | TyKind::Err => Infer,
TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind),
TyKind::CVarArgs(_) => CVarArgs,
TyKind::CVarArgs => CVarArgs,
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/c-variadic/variadic-ffi-4.stderr
Expand Up @@ -47,7 +47,7 @@ LL | *ap0 = ap1;
|
= note: expected type `core::ffi::VaListImpl<'_>`
found type `core::ffi::VaListImpl<'_>`
note: the anonymous lifetime #3 defined on the function body at 19:1...
note: the anonymous lifetime #124 defined on the function body at 19:1...
--> $DIR/variadic-ffi-4.rs:19:1
|
LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
Expand Down Expand Up @@ -80,7 +80,7 @@ LL | | *ap0 = ap1;
LL | |
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 19:1
note: ...does not necessarily outlive the anonymous lifetime #124 defined on the function body at 19:1
--> $DIR/variadic-ffi-4.rs:19:1
|
LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
Expand All @@ -106,7 +106,7 @@ LL | |
LL | |
LL | | }
| |_^
note: but the borrow lasts for the anonymous lifetime #3 defined on the function body at 24:1
note: but the borrow lasts for the anonymous lifetime #124 defined on the function body at 24:1
--> $DIR/variadic-ffi-4.rs:24:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
Expand All @@ -126,7 +126,7 @@ LL | ap0 = &mut ap1;
|
= note: expected type `&mut core::ffi::VaListImpl<'_>`
found type `&mut core::ffi::VaListImpl<'_>`
note: the anonymous lifetime #3 defined on the function body at 24:1...
note: the anonymous lifetime #124 defined on the function body at 24:1...
--> $DIR/variadic-ffi-4.rs:24:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
Expand Down Expand Up @@ -168,7 +168,7 @@ LL | |
LL | |
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 24:1
note: ...does not necessarily outlive the anonymous lifetime #124 defined on the function body at 24:1
--> $DIR/variadic-ffi-4.rs:24:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
Expand All @@ -186,7 +186,7 @@ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to
LL | ap0 = &mut ap1;
| ^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 24:1...
note: first, the lifetime cannot outlive the anonymous lifetime #124 defined on the function body at 24:1...
--> $DIR/variadic-ffi-4.rs:24:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
Expand Down Expand Up @@ -227,7 +227,7 @@ LL | *ap0 = ap1.clone();
|
= note: expected type `core::ffi::VaListImpl<'_>`
found type `core::ffi::VaListImpl<'_>`
note: the anonymous lifetime #3 defined on the function body at 32:1...
note: the anonymous lifetime #124 defined on the function body at 32:1...
--> $DIR/variadic-ffi-4.rs:32:1
|
LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
Expand Down Expand Up @@ -260,7 +260,7 @@ LL | | *ap0 = ap1.clone();
LL | |
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 32:1
note: ...does not necessarily outlive the anonymous lifetime #124 defined on the function body at 32:1
--> $DIR/variadic-ffi-4.rs:32:1
|
LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
Expand Down

0 comments on commit 7683d1c

Please sign in to comment.