#!/usr/bin/perl -w # # Copyright 2021 Ian Jackson and contributors # SPDX-License-Identifier: GPL-3.0-or-later # There is NO WARRANTY. # After running this, # TRYBUILD=overwrite nailing-cargo -E test --lib -- --nocapture reject # can help use strict; use POSIX; sub perm ($) { my ($i) = @_; $i eq 'no' ? '!' : $i; } sub type ($) { my ($i) = @_; $i eq 'whole' ? 'X' : sprintf "partial!(X %s a)", perm($i); } sub make_one ($$$) { my ($f,$e,$d) = @_; open F, "> reject/$f.new" or die $!; print F $d or die $!; close F or die $!; rename "reject/$f.new", "reject/$f.rs" or die $!; if (stat "reject/$f.stderr") { } elsif ($! != &ENOENT) { die $!; } else { open E, ">> reject/$f.stderr" or die $!; print E $e or die $!; close E or die $!; } } sub bad_dg { my ($i, $o) = @_; bad_dgi($i,$o); bad_dgi('whole',$o) if $i eq 'mut'; } sub bad_dgi ($$) { my ($i, $o) = @_; my $it = type($i); my $ot = type($o); make_one("autobad-dg-$i-$o", <` is not satisfied END // !!!!! Note - autogenerated file! - edit reject/make-rejects instead !!!!! // // Copyright 2021 Ian Jackson and contributors // SPDX-License-Identifier: GPL-3.0-or-later // There is NO WARRANTY. use partial_borrow::prelude::*; #[derive(PartialBorrow,Default)] struct X { a: usize } fn main(){ let mut x = X::default(); let d: &mut $it = x.as_mut(); let e: &mut $ot = d.as_mut(); } END } sub bad_split { my ($i,$d,$e) = @_; bad_spliti($i,$d,$e); bad_spliti('whole',$d,$e) if $i eq 'mut'; } sub bad_spliti ($$$) { my ($i,$d,$e) = @_; my $it = type($i); my $dt = type($d); my $et = type($e); make_one("autobad-split-$i-$d-$e", <` is not satisfied END // !!!!! Note - autogenerated file! - edit reject/make-rejects instead !!!!! // // Copyright 2021 Ian Jackson and contributors // SPDX-License-Identifier: GPL-3.0-or-later // There is NO WARRANTY. use partial_borrow::prelude::*; #[derive(PartialBorrow,Default)] struct X { a: usize } fn main(){ let mut x = X::default(); let i: &mut $it = x.as_mut(); let (d,e): (&mut $dt, &mut $et) = i.into(); } END } sub bad_deref { my ($i,$o) = @_; my $it = type($i); my $omut = $o eq 'mut' ? 'mut' : ''; make_one("autobad-deref-field-$i-$o", $i eq 'no' ? <` cannot be dereferenced END error[E0596]: cannot borrow data in a dereference of `F_a<\u$i, usize, X>` as mutable END // !!!!! Note - autogenerated file! - edit reject/make-rejects instead !!!!! // // Copyright 2021 Ian Jackson and contributors // SPDX-License-Identifier: GPL-3.0-or-later // There is NO WARRANTY. use partial_borrow::prelude::*; #[derive(PartialBorrow,Default)] struct X { a: usize } fn main(){ let mut x = X::default(); let d: &mut $it = x.as_mut(); let _f: &$omut usize = &$omut *d.a; } END make_one("autobad-deref-whole-$i-$o", $i eq 'no' ? <` cannot be dereferenced END error[E0596]: cannot borrow data in a dereference of `X__Partial<\u$i>` as mutable END // !!!!! Note - autogenerated file! - edit reject/make-rejects instead !!!!! // // Copyright 2021 Ian Jackson and contributors // SPDX-License-Identifier: GPL-3.0-or-later // There is NO WARRANTY. use partial_borrow::prelude::*; #[derive(PartialBorrow,Default)] struct X { a: usize } fn main(){ let mut x = X::default(); let d: &mut $it = x.as_mut(); let _o: &$omut X = &$omut **d; } END } bad_dg(qw( const mut )); bad_dg(qw( no mut )); bad_dg(qw( no const )); bad_deref(qw( const mut )); bad_deref(qw( no mut )); bad_deref(qw( no const )); bad_split(qw( mut mut mut )); bad_split(qw( mut mut const )); bad_split(qw( const mut mut )); bad_split(qw( const mut const )); bad_split(qw( const mut no )); bad_split(qw( no mut mut )); bad_split(qw( no mut const )); bad_split(qw( no mut no )); bad_split(qw( no const const )); bad_split(qw( no const no ));