From 61c8c0a0a18d08f656c3a34b16590deee80472fd Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 1 Aug 2022 18:12:07 -0400 Subject: [PATCH 1/9] Document the `no-std` target option in config.toml.example --- config.toml.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.toml.example b/config.toml.example index b3284050f0530..b320cdcc109dd 100644 --- a/config.toml.example +++ b/config.toml.example @@ -721,6 +721,10 @@ changelog-seen = 2 # probably don't want to use this. #qemu-rootfs = (path) +# Skip building the `std` library for this target. Enabled by default for +# target triples containing `-none`, `nvptx`, `switch`, or `-uefi`. +#no-std = (bool) + # ============================================================================= # Distribution options # From 0a03825f764fde56c37b2dcaa02cb9833ca72382 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 7 Jul 2022 04:36:10 +0200 Subject: [PATCH 2/9] Remove even more box syntax uses from src/test Prior work, notably 6550021124451628b1efc60c59284465b109e3aa from #88316 has removed box syntax from most of the testsuite. However, some tests were left out. This commit removes box_syntax uses from more locations in src/test. Some tests that are very box syntax specific are not being migrated. --- src/test/mir-opt/simplify-locals.rs | 2 +- .../save-analysis-fail/foo.rs | 15 +++++----- .../run-make-fulldeps/save-analysis/foo.rs | 15 +++++----- .../cleanup-auto-borrow-obj.rs | 4 +-- src/test/run-pass-valgrind/coerce-match.rs | 15 ++++++---- src/test/rustdoc-ui/rustc-check-passes.rs | 4 +-- src/test/rustdoc-ui/rustc-check-passes.stderr | 6 ++-- src/test/ui/closures/issue-10398.rs | 4 +-- src/test/ui/closures/issue-10398.stderr | 2 +- src/test/ui/closures/issue-6801.rs | 4 +-- src/test/ui/dst/dst-rvalue.rs | 6 ++-- src/test/ui/dst/dst-rvalue.stderr | 28 +++++++++++++------ .../ui/dynamically-sized-types/dst-struct.rs | 3 +- .../ui/dynamically-sized-types/dst-trait.rs | 1 - src/test/ui/issues/auxiliary/issue-2380.rs | 4 +-- src/test/ui/issues/issue-10682.rs | 4 +-- src/test/ui/issues/issue-10767.rs | 4 +-- src/test/ui/issues/issue-10802.rs | 9 +++--- src/test/ui/issues/issue-11192.rs | 8 +++--- src/test/ui/issues/issue-11192.stderr | 2 +- src/test/ui/issues/issue-11515.rs | 6 ++-- src/test/ui/issues/issue-11515.stderr | 6 ++-- src/test/ui/issues/issue-11552.rs | 6 ++-- src/test/ui/issues/issue-11844.rs | 4 +-- src/test/ui/issues/issue-11844.stderr | 2 +- src/test/ui/issues/issue-12127.rs | 4 +-- src/test/ui/issues/issue-13323.rs | 3 +- src/test/ui/issues/issue-14399.rs | 4 +-- src/test/ui/issues/issue-14915.rs | 4 +-- src/test/ui/issues/issue-14915.stderr | 2 +- src/test/ui/issues/issue-15571.rs | 7 ++--- src/test/ui/issues/issue-15763.rs | 9 +++--- src/test/ui/issues/issue-16739.rs | 7 ++--- src/test/ui/issues/issue-16774.rs | 3 +- src/test/ui/issues/issue-17322.rs | 4 +-- src/test/ui/issues/issue-21033.rs | 5 ++-- src/test/ui/issues/issue-2288.rs | 4 +-- src/test/ui/issues/issue-23024.rs | 3 +- src/test/ui/issues/issue-23024.stderr | 6 ++-- src/test/ui/issues/issue-23491.rs | 3 +- src/test/ui/issues/issue-2708.rs | 4 +-- src/test/ui/issues/issue-2734.rs | 8 ++---- src/test/ui/issues/issue-2735.rs | 8 ++---- src/test/ui/issues/issue-2935.rs | 3 +- src/test/ui/issues/issue-3026.rs | 4 +-- src/test/ui/issues/issue-3121.rs | 3 +- src/test/ui/issues/issue-3290.rs | 3 +- src/test/ui/issues/issue-3447.rs | 3 +- src/test/ui/issues/issue-3794.rs | 3 +- src/test/ui/issues/issue-3878.rs | 3 +- src/test/ui/issues/issue-4759.rs | 4 +-- src/test/ui/issues/issue-4972.rs | 1 - src/test/ui/issues/issue-4972.stderr | 2 +- src/test/ui/issues/issue-5100.rs | 2 +- src/test/ui/issues/issue-5192.rs | 4 +-- src/test/ui/issues/issue-5439.rs | 4 +-- src/test/ui/issues/issue-5439.stderr | 6 ++-- src/test/ui/issues/issue-5666.rs | 5 ++-- src/test/ui/issues/issue-5718.rs | 4 +-- src/test/ui/issues/issue-5884.rs | 4 +-- src/test/ui/issues/issue-6318.rs | 4 +-- src/test/ui/issues/issue-6557.rs | 1 - src/test/ui/issues/issue-7013.rs | 4 +-- src/test/ui/issues/issue-7013.stderr | 8 +++--- src/test/ui/issues/issue-7364.rs | 4 +-- src/test/ui/issues/issue-7364.stderr | 4 +-- ...7673-cast-generically-implemented-trait.rs | 4 +-- src/test/ui/issues/issue-9129.rs | 4 +-- src/test/ui/issues/issue-9382.rs | 5 ++-- src/test/ui/limits/issue-17913.rs | 6 ++-- src/test/ui/match/issue-42679.rs | 7 ++--- src/test/ui/structs-enums/align-struct.rs | 5 ++-- 72 files changed, 154 insertions(+), 212 deletions(-) diff --git a/src/test/mir-opt/simplify-locals.rs b/src/test/mir-opt/simplify-locals.rs index f6bf396cd0515..89d9391f832dc 100644 --- a/src/test/mir-opt/simplify-locals.rs +++ b/src/test/mir-opt/simplify-locals.rs @@ -1,6 +1,6 @@ // unit-test: SimplifyLocals -#![feature(box_syntax)] + #![feature(thread_local)] #[derive(Copy, Clone)] diff --git a/src/test/run-make-fulldeps/save-analysis-fail/foo.rs b/src/test/run-make-fulldeps/save-analysis-fail/foo.rs index 94879c2a6ed66..c5a70605e04cb 100644 --- a/src/test/run-make-fulldeps/save-analysis-fail/foo.rs +++ b/src/test/run-make-fulldeps/save-analysis-fail/foo.rs @@ -1,5 +1,4 @@ #![crate_name = "test"] -#![feature(box_syntax)] #![feature(rustc_private)] extern crate rustc_graphviz; @@ -261,9 +260,9 @@ fn hello((z, a): (u32, String), ex: X) { let x = 32.0f32; let _ = (x + ((x * x) + 1.0).sqrt()).ln(); - let s: Box = box some_fields { field1: 43 }; - let s2: Box = box some_fields { field1: 43 }; - let s3 = box nofields; + let s: Box = Box::new(some_fields { field1: 43 }); + let s2: Box = Box::new(some_fields { field1: 43 }); + let s3 = Box::new(nofields); s.Method(43); s3.Method(43); @@ -317,7 +316,7 @@ mod macro_use_test { fn main() { // foo - let s = box some_fields { field1: 43 }; + let s = Box::new(some_fields { field1: 43 }); hello((43, "a".to_string()), *s); sub::sub2::hello(); sub2::sub3::hello(); @@ -345,17 +344,17 @@ fn main() { let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 }; let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 }; println(&s2.field1.to_string()); - let s5: MyType = box some_fields { field1: 55 }; + let s5: MyType = Box::new(some_fields { field1: 55 }); let s = SameDir::SameStruct { name: "Bob".to_string() }; let s = SubDir::SubStruct { name: "Bob".to_string() }; - let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5); + let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5); let s7: SomeEnum = SomeEnum::Strings("one", "two", "three"); matchSomeEnum(s6); matchSomeEnum(s7); let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2; matchSomeOtherEnum(s8); let s9: SomeStructEnum = - SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 }; + SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) }; matchSomeStructEnum(s9); for x in &vec![1, 2, 3] { diff --git a/src/test/run-make-fulldeps/save-analysis/foo.rs b/src/test/run-make-fulldeps/save-analysis/foo.rs index dd70675032f77..74aaabfbf1b4b 100644 --- a/src/test/run-make-fulldeps/save-analysis/foo.rs +++ b/src/test/run-make-fulldeps/save-analysis/foo.rs @@ -1,5 +1,4 @@ #![crate_name = "test"] -#![feature(box_syntax)] #![feature(rustc_private)] #![feature(associated_type_defaults)] @@ -255,9 +254,9 @@ fn hello((z, a): (u32, String), ex: X) { let x = 32.0f32; let _ = (x + ((x * x) + 1.0).sqrt()).ln(); - let s: Box = box some_fields { field1: 43 }; - let s2: Box = box some_fields { field1: 43 }; - let s3 = box nofields; + let s: Box = Box::new(some_fields { field1: 43 }); + let s2: Box = Box::new(some_fields { field1: 43 }); + let s3 = Box::new(nofields); s.Method(43); s3.Method(43); @@ -311,7 +310,7 @@ mod macro_use_test { fn main() { // foo - let s = box some_fields { field1: 43 }; + let s = Box::new(some_fields { field1: 43 }); hello((43, "a".to_string()), *s); sub::sub2::hello(); sub2::sub3::hello(); @@ -339,17 +338,17 @@ fn main() { let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 }; let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 }; println(&s2.field1.to_string()); - let s5: MyType = box some_fields { field1: 55 }; + let s5: MyType = Box::new(some_fields { field1: 55 }); let s = SameDir::SameStruct { name: "Bob".to_string() }; let s = SubDir::SubStruct { name: "Bob".to_string() }; - let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5); + let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5); let s7: SomeEnum = SomeEnum::Strings("one", "two", "three"); matchSomeEnum(s6); matchSomeEnum(s7); let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2; matchSomeOtherEnum(s8); let s9: SomeStructEnum = - SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 }; + SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) }; matchSomeStructEnum(s9); for x in &vec![1, 2, 3] { diff --git a/src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs b/src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs index fb2b4d476355e..dfc094abeb9b4 100644 --- a/src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs +++ b/src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs @@ -2,8 +2,6 @@ // schedule cleanups when auto borrowing trait objects. // This program should be valgrind clean. -#![feature(box_syntax)] - static mut DROP_RAN: bool = false; struct Foo; @@ -19,7 +17,7 @@ impl Trait for Foo {} pub fn main() { { - let _x: &Trait = &*(box Foo as Box); + let _x: &Trait = &*(Box::new(Foo) as Box); } unsafe { assert!(DROP_RAN); diff --git a/src/test/run-pass-valgrind/coerce-match.rs b/src/test/run-pass-valgrind/coerce-match.rs index a4ba5427d4b04..5b78f1ec77c54 100644 --- a/src/test/run-pass-valgrind/coerce-match.rs +++ b/src/test/run-pass-valgrind/coerce-match.rs @@ -2,15 +2,18 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - pub fn main() { - let _: Box<[isize]> = - if true { let b: Box<_> = box [1, 2, 3]; b } else { let b: Box<_> = box [1]; b }; + let _: Box<[isize]> = if true { + let b: Box<_> = Box::new([1, 2, 3]); + b + } else { + let b: Box<_> = Box::new([1]); + b + }; let _: Box<[isize]> = match true { - true => { let b: Box<_> = box [1, 2, 3]; b } - false => { let b: Box<_> = box [1]; b } + true => { let b: Box<_> = Box::new([1, 2, 3]); b } + false => { let b: Box<_> = Box::new([1]); b } }; // Check we don't get over-keen at propagating coercions in the case of casts. diff --git a/src/test/rustdoc-ui/rustc-check-passes.rs b/src/test/rustdoc-ui/rustc-check-passes.rs index 731cc8ba61750..56d59164d68f1 100644 --- a/src/test/rustdoc-ui/rustc-check-passes.rs +++ b/src/test/rustdoc-ui/rustc-check-passes.rs @@ -1,4 +1,4 @@ -#![feature(box_syntax)] -#![feature(box_syntax)] //~ ERROR +#![feature(rustdoc_internals)] +#![feature(rustdoc_internals)] //~ ERROR pub fn foo() {} diff --git a/src/test/rustdoc-ui/rustc-check-passes.stderr b/src/test/rustdoc-ui/rustc-check-passes.stderr index 9707895ff3dfe..83f4e87c6edeb 100644 --- a/src/test/rustdoc-ui/rustc-check-passes.stderr +++ b/src/test/rustdoc-ui/rustc-check-passes.stderr @@ -1,8 +1,8 @@ -error[E0636]: the feature `box_syntax` has already been declared +error[E0636]: the feature `rustdoc_internals` has already been declared --> $DIR/rustc-check-passes.rs:2:12 | -LL | #![feature(box_syntax)] - | ^^^^^^^^^^ +LL | #![feature(rustdoc_internals)] + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/closures/issue-10398.rs b/src/test/ui/closures/issue-10398.rs index 0405b2d01e2cc..f76d09cd0b2ae 100644 --- a/src/test/ui/closures/issue-10398.rs +++ b/src/test/ui/closures/issue-10398.rs @@ -1,7 +1,5 @@ -#![feature(box_syntax)] - fn main() { - let x: Box<_> = box 1; + let x: Box<_> = Box::new(1); let f = move|| { let _a = x; drop(x); diff --git a/src/test/ui/closures/issue-10398.stderr b/src/test/ui/closures/issue-10398.stderr index 8d9faf324e82a..423b79dafcc97 100644 --- a/src/test/ui/closures/issue-10398.stderr +++ b/src/test/ui/closures/issue-10398.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/issue-10398.rs:7:14 + --> $DIR/issue-10398.rs:5:14 | LL | let _a = x; | - value moved here diff --git a/src/test/ui/closures/issue-6801.rs b/src/test/ui/closures/issue-6801.rs index 694d86feb5a34..cecb08f006fde 100644 --- a/src/test/ui/closures/issue-6801.rs +++ b/src/test/ui/closures/issue-6801.rs @@ -2,7 +2,7 @@ // transferring ownership of the box before invoking the stack // closure results in a crash. -#![feature(box_syntax)] + fn twice(x: Box) -> usize { *x * 2 @@ -13,7 +13,7 @@ fn invoke(f: F) where F: FnOnce() -> usize { } fn main() { - let x : Box = box 9; + let x : Box = Box::new(9); let sq = || { *x * *x }; twice(x); //~ ERROR: cannot move out of diff --git a/src/test/ui/dst/dst-rvalue.rs b/src/test/ui/dst/dst-rvalue.rs index b52a95a701f54..fbb32cac1284d 100644 --- a/src/test/ui/dst/dst-rvalue.rs +++ b/src/test/ui/dst/dst-rvalue.rs @@ -1,12 +1,10 @@ // Check that dynamically sized rvalues are forbidden -#![feature(box_syntax)] - pub fn main() { - let _x: Box = box *"hello world"; + let _x: Box = Box::new(*"hello world"); //~^ ERROR E0277 let array: &[isize] = &[1, 2, 3]; - let _x: Box<[isize]> = box *array; + let _x: Box<[isize]> = Box::new(*array); //~^ ERROR E0277 } diff --git a/src/test/ui/dst/dst-rvalue.stderr b/src/test/ui/dst/dst-rvalue.stderr index 15830636b51fe..727f4d843033f 100644 --- a/src/test/ui/dst/dst-rvalue.stderr +++ b/src/test/ui/dst/dst-rvalue.stderr @@ -1,20 +1,32 @@ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/dst-rvalue.rs:6:28 + --> $DIR/dst-rvalue.rs:4:33 | -LL | let _x: Box = box *"hello world"; - | ^^^^^^^^^^^^^^ doesn't have a size known at compile-time +LL | let _x: Box = Box::new(*"hello world"); + | -------- ^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `str` - = note: the type of a box expression must have a statically known size +note: required by a bound in `Box::::new` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + | +LL | impl Box { + | ^ required by this bound in `Box::::new` error[E0277]: the size for values of type `[isize]` cannot be known at compilation time - --> $DIR/dst-rvalue.rs:10:32 + --> $DIR/dst-rvalue.rs:8:37 | -LL | let _x: Box<[isize]> = box *array; - | ^^^^^^ doesn't have a size known at compile-time +LL | let _x: Box<[isize]> = Box::new(*array); + | -------- ^^^^^^ doesn't have a size known at compile-time + | | + | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `[isize]` - = note: the type of a box expression must have a statically known size +note: required by a bound in `Box::::new` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + | +LL | impl Box { + | ^ required by this bound in `Box::::new` error: aborting due to 2 previous errors diff --git a/src/test/ui/dynamically-sized-types/dst-struct.rs b/src/test/ui/dynamically-sized-types/dst-struct.rs index 25ec07b88a665..5da9381f83783 100644 --- a/src/test/ui/dynamically-sized-types/dst-struct.rs +++ b/src/test/ui/dynamically-sized-types/dst-struct.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] struct Fat { f1: isize, @@ -111,7 +110,7 @@ pub fn main() { assert_eq!((*f2)[1], 2); // Nested Box. - let f1 : Box> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }; + let f1 : Box> = Box::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }); foo(&*f1); let f2 : Box> = f1; foo(&*f2); diff --git a/src/test/ui/dynamically-sized-types/dst-trait.rs b/src/test/ui/dynamically-sized-types/dst-trait.rs index ec6bc72192d4f..7ac6f03925bb1 100644 --- a/src/test/ui/dynamically-sized-types/dst-trait.rs +++ b/src/test/ui/dynamically-sized-types/dst-trait.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] struct Fat { f1: isize, diff --git a/src/test/ui/issues/auxiliary/issue-2380.rs b/src/test/ui/issues/auxiliary/issue-2380.rs index 9a51a73c9a37b..79fd62d16332f 100644 --- a/src/test/ui/issues/auxiliary/issue-2380.rs +++ b/src/test/ui/issues/auxiliary/issue-2380.rs @@ -1,8 +1,6 @@ #![crate_name="a"] #![crate_type = "lib"] -#![feature(box_syntax)] - pub trait i { fn dummy(&self, t: T) -> T { panic!() } @@ -11,5 +9,5 @@ pub trait i pub fn f() -> Box+'static> { impl i for () { } - box () as Box+'static> + Box::new(()) as Box+'static> } diff --git a/src/test/ui/issues/issue-10682.rs b/src/test/ui/issues/issue-10682.rs index afaa90f05caa1..72e4559d31a79 100644 --- a/src/test/ui/issues/issue-10682.rs +++ b/src/test/ui/issues/issue-10682.rs @@ -4,12 +4,10 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - fn work(_: Box) {} fn foo(_: F) {} pub fn main() { - let a = box 1; + let a = Box::new(1); foo(move|| { foo(move|| { work(a) }) }) } diff --git a/src/test/ui/issues/issue-10767.rs b/src/test/ui/issues/issue-10767.rs index f40815fdbdbc5..5670cd458f394 100644 --- a/src/test/ui/issues/issue-10767.rs +++ b/src/test/ui/issues/issue-10767.rs @@ -1,10 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - pub fn main() { fn f() { } - let _: Box = box (f as fn()); + let _: Box = Box::new(f as fn()); } diff --git a/src/test/ui/issues/issue-10802.rs b/src/test/ui/issues/issue-10802.rs index f1d6b37a6843f..99e1a92dfcc29 100644 --- a/src/test/ui/issues/issue-10802.rs +++ b/src/test/ui/issues/issue-10802.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code)] -#![feature(box_syntax)] struct DroppableStruct; enum DroppableEnum { @@ -33,14 +32,14 @@ impl Whatever { fn main() { { - let f: Box<_> = box DroppableStruct; - let _a = Whatever::new(box f as Box); + let f: Box<_> = Box::new(DroppableStruct); + let _a = Whatever::new(Box::new(f) as Box); } assert!(unsafe { DROPPED }); unsafe { DROPPED = false; } { - let f: Box<_> = box DroppableEnum::DroppableVariant1; - let _a = Whatever::new(box f as Box); + let f: Box<_> = Box::new(DroppableEnum::DroppableVariant1); + let _a = Whatever::new(Box::new(f) as Box); } assert!(unsafe { DROPPED }); } diff --git a/src/test/ui/issues/issue-11192.rs b/src/test/ui/issues/issue-11192.rs index 3bf91675ec3bb..1a3d8c9fe5869 100644 --- a/src/test/ui/issues/issue-11192.rs +++ b/src/test/ui/issues/issue-11192.rs @@ -1,20 +1,20 @@ -#![feature(box_syntax)] - struct Foo { x: isize } + impl Drop for Foo { fn drop(&mut self) { println!("drop {}", self.x); } } + fn main() { - let mut ptr: Box<_> = box Foo { x: 0 }; + let mut ptr: Box<_> = Box::new(Foo { x: 0 }); let mut test = |foo: &Foo| { println!("access {}", foo.x); - ptr = box Foo { x: ptr.x + 1 }; + ptr = Box::new(Foo { x: ptr.x + 1 }); println!("access {}", foo.x); }; test(&*ptr); diff --git a/src/test/ui/issues/issue-11192.stderr b/src/test/ui/issues/issue-11192.stderr index 2a9d913171c3e..fc15480134056 100644 --- a/src/test/ui/issues/issue-11192.stderr +++ b/src/test/ui/issues/issue-11192.stderr @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `*ptr` as immutable because it is also borrowed as m LL | let mut test = |foo: &Foo| { | ----------- mutable borrow occurs here LL | println!("access {}", foo.x); -LL | ptr = box Foo { x: ptr.x + 1 }; +LL | ptr = Box::new(Foo { x: ptr.x + 1 }); | --- first borrow occurs due to use of `ptr` in closure ... LL | test(&*ptr); diff --git a/src/test/ui/issues/issue-11515.rs b/src/test/ui/issues/issue-11515.rs index 2072f9c47e2a6..b5c942f96a702 100644 --- a/src/test/ui/issues/issue-11515.rs +++ b/src/test/ui/issues/issue-11515.rs @@ -1,10 +1,10 @@ -#![feature(box_syntax)] - struct Test { func: Box, } + + fn main() { let closure: Box = Box::new(|| ()); - let test = box Test { func: closure }; //~ ERROR trait upcasting coercion is experimental [E0658] + let test = Box::new(Test { func: closure }); //~ ERROR trait upcasting coercion is experimental [E0658] } diff --git a/src/test/ui/issues/issue-11515.stderr b/src/test/ui/issues/issue-11515.stderr index 17bfae2a4e46b..accd47f0f5fbc 100644 --- a/src/test/ui/issues/issue-11515.stderr +++ b/src/test/ui/issues/issue-11515.stderr @@ -1,8 +1,8 @@ error[E0658]: cannot cast `dyn Fn()` to `dyn FnMut()`, trait upcasting coercion is experimental - --> $DIR/issue-11515.rs:9:33 + --> $DIR/issue-11515.rs:9:38 | -LL | let test = box Test { func: closure }; - | ^^^^^^^ +LL | let test = Box::new(Test { func: closure }); + | ^^^^^^^ | = note: see issue #65991 for more information = help: add `#![feature(trait_upcasting)]` to the crate attributes to enable diff --git a/src/test/ui/issues/issue-11552.rs b/src/test/ui/issues/issue-11552.rs index bae12375da124..9fb9f3d2e3f34 100644 --- a/src/test/ui/issues/issue-11552.rs +++ b/src/test/ui/issues/issue-11552.rs @@ -1,6 +1,5 @@ // run-pass #![feature(box_patterns)] -#![feature(box_syntax)] #[derive(Clone)] enum Noun @@ -18,5 +17,8 @@ fn fas(n: &Noun) -> Noun } pub fn main() { - fas(&Noun::Cell(box Noun::Atom(2), box Noun::Cell(box Noun::Atom(2), box Noun::Atom(3)))); + fas( + &Noun::Cell(Box::new(Noun::Atom(2)), + Box::new(Noun::Cell(Box::new(Noun::Atom(2)), Box::new(Noun::Atom(3))))) + ); } diff --git a/src/test/ui/issues/issue-11844.rs b/src/test/ui/issues/issue-11844.rs index bb06f00d5cf2d..f974a4702960a 100644 --- a/src/test/ui/issues/issue-11844.rs +++ b/src/test/ui/issues/issue-11844.rs @@ -1,7 +1,5 @@ -#![feature(box_syntax)] - fn main() { - let a = Some(box 1); + let a = Some(Box::new(1)); match a { Ok(a) => //~ ERROR: mismatched types println!("{}",a), diff --git a/src/test/ui/issues/issue-11844.stderr b/src/test/ui/issues/issue-11844.stderr index 9d7470e7af9aa..81cf918a1030b 100644 --- a/src/test/ui/issues/issue-11844.stderr +++ b/src/test/ui/issues/issue-11844.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-11844.rs:6:9 + --> $DIR/issue-11844.rs:4:9 | LL | match a { | - this expression has type `Option>` diff --git a/src/test/ui/issues/issue-12127.rs b/src/test/ui/issues/issue-12127.rs index bb2c2734583eb..8b30ddc2de67e 100644 --- a/src/test/ui/issues/issue-12127.rs +++ b/src/test/ui/issues/issue-12127.rs @@ -1,10 +1,10 @@ -#![feature(box_syntax, unboxed_closures)] +#![feature(unboxed_closures)] fn to_fn_once>(f: F) -> F { f } fn do_it(x: &isize) { } fn main() { - let x: Box<_> = box 22; + let x: Box<_> = Box::new(22); let f = to_fn_once(move|| do_it(&*x)); to_fn_once(move|| { f(); diff --git a/src/test/ui/issues/issue-13323.rs b/src/test/ui/issues/issue-13323.rs index 26847ee7a0839..71e14d4dab5a6 100644 --- a/src/test/ui/issues/issue-13323.rs +++ b/src/test/ui/issues/issue-13323.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] struct StrWrap { s: String @@ -48,7 +47,7 @@ impl Matcher for EqualTo { } fn equal_to(expected: T) -> Box> { - box EqualTo { expected: expected } + Box::new(EqualTo { expected: expected }) } pub fn main() { diff --git a/src/test/ui/issues/issue-14399.rs b/src/test/ui/issues/issue-14399.rs index 6bf8a589959c5..7b32bf8e4cbb7 100644 --- a/src/test/ui/issues/issue-14399.rs +++ b/src/test/ui/issues/issue-14399.rs @@ -6,8 +6,6 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - #[derive(Clone)] struct B1; @@ -15,6 +13,6 @@ trait A { fn foo(&self) {} } impl A for B1 {} fn main() { - let v: Box<_> = box B1; + let v: Box<_> = Box::new(B1); let _c: Box = v.clone(); } diff --git a/src/test/ui/issues/issue-14915.rs b/src/test/ui/issues/issue-14915.rs index 909540355ed89..127b909dd63eb 100644 --- a/src/test/ui/issues/issue-14915.rs +++ b/src/test/ui/issues/issue-14915.rs @@ -1,7 +1,5 @@ -#![feature(box_syntax)] - fn main() { - let x: Box = box 0; + let x: Box = Box::new(0); println!("{}", x + 1); //~^ ERROR cannot add `{integer}` to `Box` diff --git a/src/test/ui/issues/issue-14915.stderr b/src/test/ui/issues/issue-14915.stderr index bd0b1d39a538a..6e63269293b75 100644 --- a/src/test/ui/issues/issue-14915.stderr +++ b/src/test/ui/issues/issue-14915.stderr @@ -1,5 +1,5 @@ error[E0369]: cannot add `{integer}` to `Box` - --> $DIR/issue-14915.rs:6:22 + --> $DIR/issue-14915.rs:4:22 | LL | println!("{}", x + 1); | - ^ - {integer} diff --git a/src/test/ui/issues/issue-15571.rs b/src/test/ui/issues/issue-15571.rs index 5381d65232f12..5f228b2863e46 100644 --- a/src/test/ui/issues/issue-15571.rs +++ b/src/test/ui/issues/issue-15571.rs @@ -1,8 +1,7 @@ // run-pass -#![feature(box_syntax)] fn match_on_local() { - let mut foo: Option> = Some(box 5); + let mut foo: Option> = Some(Box::new(5)); match foo { None => {}, Some(x) => { @@ -37,7 +36,7 @@ fn match_on_binding() { } fn match_on_upvar() { - let mut foo: Option> = Some(box 8); + let mut foo: Option> = Some(Box::new(8)); let f = move|| { match foo { None => {}, @@ -52,7 +51,7 @@ fn match_on_upvar() { fn main() { match_on_local(); - match_on_arg(Some(box 6)); + match_on_arg(Some(Box::new(6))); match_on_binding(); match_on_upvar(); } diff --git a/src/test/ui/issues/issue-15763.rs b/src/test/ui/issues/issue-15763.rs index 9ceffff2e3806..ae0863615e2c7 100644 --- a/src/test/ui/issues/issue-15763.rs +++ b/src/test/ui/issues/issue-15763.rs @@ -1,6 +1,5 @@ // run-pass #![allow(unreachable_code)] -#![feature(box_syntax)] #[derive(PartialEq, Debug)] struct Bar { @@ -78,12 +77,12 @@ fn main() { assert_eq!(cc().unwrap(), 3); assert_eq!(dd().unwrap(), 3); - let i = box 32isize as Box; + let i = Box::new(32isize) as Box; assert_eq!(i.aaa(), 3); - let i = box 32isize as Box; + let i = Box::new(32isize) as Box; assert_eq!(i.bbb(), 3); - let i = box 32isize as Box; + let i = Box::new(32isize) as Box; assert_eq!(i.ccc().unwrap(), 3); - let i = box 32isize as Box; + let i = Box::new(32isize) as Box; assert_eq!(i.ddd().unwrap(), 3); } diff --git a/src/test/ui/issues/issue-16739.rs b/src/test/ui/issues/issue-16739.rs index 94da2ca5cab81..b21ea4bcd7869 100644 --- a/src/test/ui/issues/issue-16739.rs +++ b/src/test/ui/issues/issue-16739.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] #![feature(unboxed_closures, fn_traits)] // Test that unboxing shim for calling rust-call ABI methods through a @@ -35,12 +34,12 @@ impl FnOnce<(u32,u32)> for Foo { } fn main() { - let mut f = box Foo { foo: 42 } as Box u32>; + let mut f = Box::new(Foo { foo: 42 }) as Box u32>; assert_eq!(f.call_mut(()), 42); - let mut f = box Foo { foo: 40 } as Box u32>; + let mut f = Box::new(Foo { foo: 40 }) as Box u32>; assert_eq!(f.call_mut((2,)), 42); - let mut f = box Foo { foo: 40 } as Box u32>; + let mut f = Box::new(Foo { foo: 40 }) as Box u32>; assert_eq!(f.call_mut((1, 1)), 42); } diff --git a/src/test/ui/issues/issue-16774.rs b/src/test/ui/issues/issue-16774.rs index 9e9b84034dbd8..2b308ef76e43d 100644 --- a/src/test/ui/issues/issue-16774.rs +++ b/src/test/ui/issues/issue-16774.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] #![feature(box_patterns)] use std::ops::{Deref, DerefMut}; @@ -35,7 +34,7 @@ impl DerefMut for X { fn main() { { - let mut test = X(box 5); + let mut test = X(Box::new(5)); { let mut change = || { *test = 10 }; change(); diff --git a/src/test/ui/issues/issue-17322.rs b/src/test/ui/issues/issue-17322.rs index 20a8d13612469..b4fc40c3f2b7c 100644 --- a/src/test/ui/issues/issue-17322.rs +++ b/src/test/ui/issues/issue-17322.rs @@ -1,8 +1,6 @@ // run-pass // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - use std::io::{self, Write}; fn f(wr: &mut dyn Write) { @@ -10,6 +8,6 @@ fn f(wr: &mut dyn Write) { } fn main() { - let mut wr = box io::stdout() as Box; + let mut wr = Box::new(io::stdout()) as Box; f(&mut wr); } diff --git a/src/test/ui/issues/issue-21033.rs b/src/test/ui/issues/issue-21033.rs index 86cc7707e50f9..91f72eb369bca 100644 --- a/src/test/ui/issues/issue-21033.rs +++ b/src/test/ui/issues/issue-21033.rs @@ -4,7 +4,6 @@ // pretty-expanded FIXME #23616 #![feature(box_patterns)] -#![feature(box_syntax)] enum E { StructVar { boxed: Box } @@ -13,7 +12,7 @@ enum E { fn main() { // Test matching each shorthand notation for field patterns. - let mut a = E::StructVar { boxed: box 3 }; + let mut a = E::StructVar { boxed: Box::new(3) }; match a { E::StructVar { box boxed } => { } } @@ -38,7 +37,7 @@ fn main() { // Test matching non shorthand notation. Recreate a since last test // moved `boxed` - let mut a = E::StructVar { boxed: box 3 }; + let mut a = E::StructVar { boxed: Box::new(3) }; match a { E::StructVar { boxed: box ref mut num } => { } } diff --git a/src/test/ui/issues/issue-2288.rs b/src/test/ui/issues/issue-2288.rs index c74e53fca60fd..6fd690a4d956a 100644 --- a/src/test/ui/issues/issue-2288.rs +++ b/src/test/ui/issues/issue-2288.rs @@ -1,8 +1,6 @@ // run-pass #![allow(non_camel_case_types)] -#![feature(box_syntax)] - trait clam { fn chowder(&self, y: A); } @@ -30,6 +28,6 @@ fn f(x: Box>, a: A) { pub fn main() { let c = foo(42); - let d: Box> = box c as Box>; + let d: Box> = Box::new(c) as Box>; f(d, c.x); } diff --git a/src/test/ui/issues/issue-23024.rs b/src/test/ui/issues/issue-23024.rs index e92273bd40914..010281ee371cd 100644 --- a/src/test/ui/issues/issue-23024.rs +++ b/src/test/ui/issues/issue-23024.rs @@ -1,11 +1,10 @@ -#![feature(box_syntax)] use std::any::Any; fn main() { fn h(x:i32) -> i32 {3*x} let mut vfnfer:Vec> = vec![]; - vfnfer.push(box h); + vfnfer.push(Box::new(h)); println!("{:?}",(vfnfer[0] as dyn Fn)(3)); //~^ ERROR the precise format of `Fn`-family traits' //~| ERROR missing generics for trait `Fn` diff --git a/src/test/ui/issues/issue-23024.stderr b/src/test/ui/issues/issue-23024.stderr index 7a4d90b4412f9..73f93c51d34e8 100644 --- a/src/test/ui/issues/issue-23024.stderr +++ b/src/test/ui/issues/issue-23024.stderr @@ -1,5 +1,5 @@ error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change - --> $DIR/issue-23024.rs:9:39 + --> $DIR/issue-23024.rs:8:39 | LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3)); | ^^ help: use parenthetical notation instead: `Fn() -> ()` @@ -8,7 +8,7 @@ LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3)); = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0107]: missing generics for trait `Fn` - --> $DIR/issue-23024.rs:9:39 + --> $DIR/issue-23024.rs:8:39 | LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3)); | ^^ expected 1 generic argument @@ -24,7 +24,7 @@ LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3)); | ~~~~~~~~ error[E0191]: the value of the associated type `Output` (from trait `FnOnce`) must be specified - --> $DIR/issue-23024.rs:9:39 + --> $DIR/issue-23024.rs:8:39 | LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3)); | ^^ help: specify the associated type: `Fn` diff --git a/src/test/ui/issues/issue-23491.rs b/src/test/ui/issues/issue-23491.rs index 1cb969731e29c..e5f9dd3efbd2a 100644 --- a/src/test/ui/issues/issue-23491.rs +++ b/src/test/ui/issues/issue-23491.rs @@ -1,9 +1,8 @@ // run-pass #![allow(unused_variables)] -#![feature(box_syntax)] struct Node(#[allow(unused_tuple_struct_fields)] T); fn main() { - let x: Box> = box Node([]); + let x: Box> = Box::new(Node([])); } diff --git a/src/test/ui/issues/issue-2708.rs b/src/test/ui/issues/issue-2708.rs index abd5e9507f8ee..4e53b9d145f0b 100644 --- a/src/test/ui/issues/issue-2708.rs +++ b/src/test/ui/issues/issue-2708.rs @@ -4,7 +4,7 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] + struct Font { fontbuf: usize, @@ -26,5 +26,5 @@ fn Font() -> Font { } pub fn main() { - let _f: Box<_> = box Font(); + let _f: Box<_> = Box::new(Font()); } diff --git a/src/test/ui/issues/issue-2734.rs b/src/test/ui/issues/issue-2734.rs index d449f6449aa09..df4f394dc373f 100644 --- a/src/test/ui/issues/issue-2734.rs +++ b/src/test/ui/issues/issue-2734.rs @@ -4,21 +4,19 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - trait hax { fn dummy(&self) { } } impl hax for A { } fn perform_hax(x: Box) -> Box { - box x as Box + Box::new(x) as Box } fn deadcode() { - perform_hax(box "deadcode".to_string()); + perform_hax(Box::new("deadcode".to_string())); } pub fn main() { - let _ = perform_hax(box 42); + let _ = perform_hax(Box::new(42)); } diff --git a/src/test/ui/issues/issue-2735.rs b/src/test/ui/issues/issue-2735.rs index 794c7d4edaa11..20d3949a9f998 100644 --- a/src/test/ui/issues/issue-2735.rs +++ b/src/test/ui/issues/issue-2735.rs @@ -4,21 +4,19 @@ // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - trait hax { fn dummy(&self) { } } impl hax for A { } fn perform_hax(x: Box) -> Box { - box x as Box + Box::new(x) as Box } fn deadcode() { - perform_hax(box "deadcode".to_string()); + perform_hax(Box::new("deadcode".to_string())); } pub fn main() { - perform_hax(box 42); + perform_hax(Box::new(42)); } diff --git a/src/test/ui/issues/issue-2935.rs b/src/test/ui/issues/issue-2935.rs index 11641ca738018..37f8181991c40 100644 --- a/src/test/ui/issues/issue-2935.rs +++ b/src/test/ui/issues/issue-2935.rs @@ -1,7 +1,6 @@ // run-pass #![allow(dead_code)] #![allow(non_camel_case_types)] -#![feature(box_syntax)] //type t = { a: isize }; // type t = { a: bool }; @@ -20,7 +19,7 @@ pub fn main() { // let y = box ({a: 4}); // let z = box ({a: 4} as it); // let z = box ({a: true} as it); - let z: Box<_> = box (box true as Box); + let z: Box<_> = Box::new(Box::new(true) as Box); // x.f(); // y.f(); // (*z).f(); diff --git a/src/test/ui/issues/issue-3026.rs b/src/test/ui/issues/issue-3026.rs index 1dea8134fba2f..4619a3fe78718 100644 --- a/src/test/ui/issues/issue-3026.rs +++ b/src/test/ui/issues/issue-3026.rs @@ -1,13 +1,11 @@ // run-pass // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - use std::collections::HashMap; pub fn main() { let x: Box<_>; let mut buggy_map: HashMap = HashMap::new(); - x = box 1; + x = Box::new(1); buggy_map.insert(42, &*x); } diff --git a/src/test/ui/issues/issue-3121.rs b/src/test/ui/issues/issue-3121.rs index f7bbfa9f6f4bd..4bf5b9b60a804 100644 --- a/src/test/ui/issues/issue-3121.rs +++ b/src/test/ui/issues/issue-3121.rs @@ -1,7 +1,6 @@ // run-pass #![allow(dead_code)] #![allow(non_camel_case_types)] -#![feature(box_syntax)] #[derive(Copy, Clone)] enum side { mayo, catsup, vinegar } @@ -21,5 +20,5 @@ fn foo(m: Box, cond: bool) { } pub fn main() { - foo(box meal::for_here(order::hamburger), true) + foo(Box::new(meal::for_here(order::hamburger)), true) } diff --git a/src/test/ui/issues/issue-3290.rs b/src/test/ui/issues/issue-3290.rs index 840c7ff8355d0..7014d517f181e 100644 --- a/src/test/ui/issues/issue-3290.rs +++ b/src/test/ui/issues/issue-3290.rs @@ -1,9 +1,8 @@ // run-pass -#![feature(box_syntax)] #![allow(dead_code)] pub fn main() { - let mut x: Box<_> = box 3; + let mut x: Box<_> = Box::new(3); x = x; assert_eq!(*x, 3); } diff --git a/src/test/ui/issues/issue-3447.rs b/src/test/ui/issues/issue-3447.rs index 1e329d1522af4..ee5b22778117e 100644 --- a/src/test/ui/issues/issue-3447.rs +++ b/src/test/ui/issues/issue-3447.rs @@ -2,7 +2,6 @@ #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_camel_case_types)] -#![feature(box_syntax)] use std::cell::RefCell; @@ -20,7 +19,7 @@ impl list { next: None }; - self.next = Some(box RefCell::new(newList)); + self.next = Some(Box::new(RefCell::new(newList))); } } diff --git a/src/test/ui/issues/issue-3794.rs b/src/test/ui/issues/issue-3794.rs index 1809e822c5421..b1f028fbccb9d 100644 --- a/src/test/ui/issues/issue-3794.rs +++ b/src/test/ui/issues/issue-3794.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] #![allow(dead_code)] trait T { @@ -26,7 +25,7 @@ fn print_s(s: &S) { } pub fn main() { - let s: Box = box S { s: 5 }; + let s: Box = Box::new(S { s: 5 }); print_s(&*s); let t: Box = s as Box; print_t(&*t); diff --git a/src/test/ui/issues/issue-3878.rs b/src/test/ui/issues/issue-3878.rs index a121f0ba878ef..6de3405af0d95 100644 --- a/src/test/ui/issues/issue-3878.rs +++ b/src/test/ui/issues/issue-3878.rs @@ -2,9 +2,8 @@ // pretty-expanded FIXME #23616 #![allow(path_statements)] -#![feature(box_syntax)] pub fn main() { - let y: Box<_> = box 1; + let y: Box<_> = Box::new(1); y; } diff --git a/src/test/ui/issues/issue-4759.rs b/src/test/ui/issues/issue-4759.rs index 53785af09626a..e5b9e2ed57438 100644 --- a/src/test/ui/issues/issue-4759.rs +++ b/src/test/ui/issues/issue-4759.rs @@ -2,8 +2,6 @@ // pretty-expanded FIXME #23616 #![allow(non_shorthand_field_patterns)] -#![feature(box_syntax)] - struct T { a: Box } trait U { @@ -15,6 +13,6 @@ impl U for Box { } pub fn main() { - let T { a: a } = T { a: box 0 }; + let T { a: a } = T { a: Box::new(0) }; a.f(); } diff --git a/src/test/ui/issues/issue-4972.rs b/src/test/ui/issues/issue-4972.rs index fab258f137e68..3f1c6f855007c 100644 --- a/src/test/ui/issues/issue-4972.rs +++ b/src/test/ui/issues/issue-4972.rs @@ -1,5 +1,4 @@ #![feature(box_patterns)] -#![feature(box_syntax)] trait MyTrait { fn dummy(&self) {} diff --git a/src/test/ui/issues/issue-4972.stderr b/src/test/ui/issues/issue-4972.stderr index 40db50278ca76..83daded7e093e 100644 --- a/src/test/ui/issues/issue-4972.stderr +++ b/src/test/ui/issues/issue-4972.stderr @@ -1,5 +1,5 @@ error[E0033]: type `Box<(dyn MyTrait + 'static)>` cannot be dereferenced - --> $DIR/issue-4972.rs:14:25 + --> $DIR/issue-4972.rs:13:25 | LL | TraitWrapper::A(box ref map) => map, | ^^^^^^^^^^^ type `Box<(dyn MyTrait + 'static)>` cannot be dereferenced diff --git a/src/test/ui/issues/issue-5100.rs b/src/test/ui/issues/issue-5100.rs index 5e926fabe2118..69ed4b0e4328b 100644 --- a/src/test/ui/issues/issue-5100.rs +++ b/src/test/ui/issues/issue-5100.rs @@ -1,5 +1,5 @@ #![feature(box_patterns)] -#![feature(box_syntax)] + enum A { B, C } diff --git a/src/test/ui/issues/issue-5192.rs b/src/test/ui/issues/issue-5192.rs index 5a83d1c2ff9fd..e2f835c199738 100644 --- a/src/test/ui/issues/issue-5192.rs +++ b/src/test/ui/issues/issue-5192.rs @@ -2,8 +2,6 @@ #![allow(dead_code)] // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - pub trait EventLoop { fn dummy(&self) { } } @@ -37,5 +35,5 @@ impl Scheduler { } pub fn main() { - let _sched = Scheduler::new(box UvEventLoop::new() as Box); + let _sched = Scheduler::new(Box::new(UvEventLoop::new()) as Box); } diff --git a/src/test/ui/issues/issue-5439.rs b/src/test/ui/issues/issue-5439.rs index cd039506f3816..852b264dc5dbf 100644 --- a/src/test/ui/issues/issue-5439.rs +++ b/src/test/ui/issues/issue-5439.rs @@ -1,5 +1,3 @@ -#![feature(box_syntax)] - struct Foo { foo: isize, } @@ -10,7 +8,7 @@ struct Bar { impl Bar { fn make_foo (&self, i: isize) -> Box { - return box Foo { nonexistent: self, foo: i }; //~ ERROR: no field named + return Box::new(Foo { nonexistent: self, foo: i }); //~ ERROR: no field named } } diff --git a/src/test/ui/issues/issue-5439.stderr b/src/test/ui/issues/issue-5439.stderr index bd0cb670bc210..dc8f8b878d730 100644 --- a/src/test/ui/issues/issue-5439.stderr +++ b/src/test/ui/issues/issue-5439.stderr @@ -1,8 +1,8 @@ error[E0560]: struct `Foo` has no field named `nonexistent` - --> $DIR/issue-5439.rs:13:26 + --> $DIR/issue-5439.rs:11:31 | -LL | return box Foo { nonexistent: self, foo: i }; - | ^^^^^^^^^^^ `Foo` does not have this field +LL | return Box::new(Foo { nonexistent: self, foo: i }); + | ^^^^^^^^^^^ `Foo` does not have this field | = note: available fields are: `foo` diff --git a/src/test/ui/issues/issue-5666.rs b/src/test/ui/issues/issue-5666.rs index aa51327783012..810895b1b1bc4 100644 --- a/src/test/ui/issues/issue-5666.rs +++ b/src/test/ui/issues/issue-5666.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] struct Dog { name : String @@ -17,8 +16,8 @@ impl Barks for Dog { pub fn main() { - let snoopy = box Dog{name: "snoopy".to_string()}; - let bubbles = box Dog{name: "bubbles".to_string()}; + let snoopy = Box::new(Dog{name: "snoopy".to_string()}); + let bubbles = Box::new(Dog{name: "bubbles".to_string()}); let barker = [snoopy as Box, bubbles as Box]; for pup in &barker { diff --git a/src/test/ui/issues/issue-5718.rs b/src/test/ui/issues/issue-5718.rs index 63efec953118a..f29a1e2a060d2 100644 --- a/src/test/ui/issues/issue-5718.rs +++ b/src/test/ui/issues/issue-5718.rs @@ -1,14 +1,12 @@ // run-pass // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - struct Element; macro_rules! foo { ($tag: expr, $string: expr) => { if $tag == $string { - let element: Box<_> = box Element; + let element: Box<_> = Box::new(Element); unsafe { return std::mem::transmute::<_, usize>(element); } diff --git a/src/test/ui/issues/issue-5884.rs b/src/test/ui/issues/issue-5884.rs index 2f64342a6dd82..991c52321bfeb 100644 --- a/src/test/ui/issues/issue-5884.rs +++ b/src/test/ui/issues/issue-5884.rs @@ -2,8 +2,6 @@ #![allow(dead_code)] // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - pub struct Foo { a: isize, } @@ -14,7 +12,7 @@ struct Bar<'a> { } fn check(a: Box) { - let _ic = Bar{ b: &*a, a: box None }; + let _ic = Bar{ b: &*a, a: Box::new(None) }; } pub fn main(){} diff --git a/src/test/ui/issues/issue-6318.rs b/src/test/ui/issues/issue-6318.rs index d8bd83f0dc6ad..e5f245f6fb80f 100644 --- a/src/test/ui/issues/issue-6318.rs +++ b/src/test/ui/issues/issue-6318.rs @@ -1,8 +1,6 @@ // run-pass // pretty-expanded FIXME #23616 -#![feature(box_syntax)] - pub enum Thing { A(Box) } @@ -16,7 +14,7 @@ pub struct Struct; impl Foo for Struct {} pub fn main() { - match Thing::A(box Struct as Box) { + match Thing::A(Box::new(Struct) as Box) { Thing::A(_a) => 0, }; } diff --git a/src/test/ui/issues/issue-6557.rs b/src/test/ui/issues/issue-6557.rs index e066aa52923b9..757e9608f1a1f 100644 --- a/src/test/ui/issues/issue-6557.rs +++ b/src/test/ui/issues/issue-6557.rs @@ -3,7 +3,6 @@ // pretty-expanded FIXME #23616 #![feature(box_patterns)] -#![feature(box_syntax)] fn foo(box (_x, _y): Box<(isize, isize)>) {} diff --git a/src/test/ui/issues/issue-7013.rs b/src/test/ui/issues/issue-7013.rs index c1f400b33049f..1fb01303c7836 100644 --- a/src/test/ui/issues/issue-7013.rs +++ b/src/test/ui/issues/issue-7013.rs @@ -1,5 +1,3 @@ -#![feature(box_syntax)] - use std::cell::RefCell; use std::rc::Rc; @@ -23,6 +21,6 @@ struct A { } fn main() { - let a = A {v: box B{v: None} as Box}; + let a = A {v: Box::new(B{v: None}) as Box}; //~^ ERROR `Rc>` cannot be sent between threads safely } diff --git a/src/test/ui/issues/issue-7013.stderr b/src/test/ui/issues/issue-7013.stderr index f6cb1cbdc11c6..4575f4dbae62d 100644 --- a/src/test/ui/issues/issue-7013.stderr +++ b/src/test/ui/issues/issue-7013.stderr @@ -1,13 +1,13 @@ error[E0277]: `Rc>` cannot be sent between threads safely - --> $DIR/issue-7013.rs:26:19 + --> $DIR/issue-7013.rs:24:19 | -LL | let a = A {v: box B{v: None} as Box}; - | ^^^^^^^^^^^^^^ `Rc>` cannot be sent between threads safely +LL | let a = A {v: Box::new(B{v: None}) as Box}; + | ^^^^^^^^^^^^^^^^^^^^ `Rc>` cannot be sent between threads safely | = help: within `B`, the trait `Send` is not implemented for `Rc>` = note: required because it appears within the type `Option>>` note: required because it appears within the type `B` - --> $DIR/issue-7013.rs:10:8 + --> $DIR/issue-7013.rs:8:8 | LL | struct B { | ^ diff --git a/src/test/ui/issues/issue-7364.rs b/src/test/ui/issues/issue-7364.rs index 83c52d286a199..79642bd411b38 100644 --- a/src/test/ui/issues/issue-7364.rs +++ b/src/test/ui/issues/issue-7364.rs @@ -1,9 +1,7 @@ -#![feature(box_syntax)] - use std::cell::RefCell; // Regression test for issue 7364 -static boxed: Box> = box RefCell::new(0); +static boxed: Box> = Box::new(RefCell::new(0)); //~^ ERROR `RefCell` cannot be shared between threads safely [E0277] fn main() { } diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr index f2e80f451695a..1018a92f64dfc 100644 --- a/src/test/ui/issues/issue-7364.stderr +++ b/src/test/ui/issues/issue-7364.stderr @@ -1,7 +1,7 @@ error[E0277]: `RefCell` cannot be shared between threads safely - --> $DIR/issue-7364.rs:6:15 + --> $DIR/issue-7364.rs:4:15 | -LL | static boxed: Box> = box RefCell::new(0); +LL | static boxed: Box> = Box::new(RefCell::new(0)); | ^^^^^^^^^^^^^^^^^^^ `RefCell` cannot be shared between threads safely | = help: the trait `Sync` is not implemented for `RefCell` diff --git a/src/test/ui/issues/issue-7673-cast-generically-implemented-trait.rs b/src/test/ui/issues/issue-7673-cast-generically-implemented-trait.rs index 2961dc79f10ef..c089c33083984 100644 --- a/src/test/ui/issues/issue-7673-cast-generically-implemented-trait.rs +++ b/src/test/ui/issues/issue-7673-cast-generically-implemented-trait.rs @@ -8,8 +8,6 @@ */ -#![feature(box_syntax)] - pub fn main() {} trait A { @@ -19,4 +17,4 @@ trait A { impl A for T {} fn owned2(a: Box) { a as Box; } -fn owned3(a: Box) { box a as Box; } +fn owned3(a: Box) { Box::new(a) as Box; } diff --git a/src/test/ui/issues/issue-9129.rs b/src/test/ui/issues/issue-9129.rs index 780a6419c5f30..04110b3ae8959 100644 --- a/src/test/ui/issues/issue-9129.rs +++ b/src/test/ui/issues/issue-9129.rs @@ -4,8 +4,6 @@ #![allow(non_snake_case)] // ignore-pretty unreported -#![feature(box_syntax)] - pub trait bomb { fn boom(&self, _: Ident); } pub struct S; impl bomb for S { fn boom(&self, _: Ident) { } } @@ -29,6 +27,6 @@ pub fn light_fuse(fld: Box) { } pub fn main() { - let b = box S as Box; + let b = Box::new(S) as Box; light_fuse(b); } diff --git a/src/test/ui/issues/issue-9382.rs b/src/test/ui/issues/issue-9382.rs index dbb0fa524ef51..65718343fc6a9 100644 --- a/src/test/ui/issues/issue-9382.rs +++ b/src/test/ui/issues/issue-9382.rs @@ -3,7 +3,6 @@ // run-pass #![allow(dead_code)] -#![feature(box_syntax)] // Tests for a previous bug that occurred due to an interaction // between struct field initialization and the auto-coercion @@ -24,11 +23,11 @@ struct Thing2<'a> { pub fn main() { let _t1_fixed = Thing1 { baz: &[], - bar: box 32, + bar: Box::new(32), }; Thing1 { baz: &Vec::new(), - bar: box 32, + bar: Box::new(32), }; let _t2_fixed = Thing2 { baz: &[], diff --git a/src/test/ui/limits/issue-17913.rs b/src/test/ui/limits/issue-17913.rs index ca13b9bd6ae7b..8d4cbe2018461 100644 --- a/src/test/ui/limits/issue-17913.rs +++ b/src/test/ui/limits/issue-17913.rs @@ -6,18 +6,16 @@ // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -#![feature(box_syntax)] - #[cfg(target_pointer_width = "64")] fn main() { let n = 0_usize; - let a: Box<_> = box [&n; 0xF000000000000000_usize]; + let a: Box<_> = Box::new([&n; 0xF000000000000000_usize]); println!("{}", a[0xFFFFFF_usize]); } #[cfg(target_pointer_width = "32")] fn main() { let n = 0_usize; - let a: Box<_> = box [&n; 0xFFFFFFFF_usize]; + let a: Box<_> = Box::new([&n; 0xFFFFFFFF_usize]); println!("{}", a[0xFFFFFF_usize]); } diff --git a/src/test/ui/match/issue-42679.rs b/src/test/ui/match/issue-42679.rs index 596309f256833..46a0bd35d6ada 100644 --- a/src/test/ui/match/issue-42679.rs +++ b/src/test/ui/match/issue-42679.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(box_syntax)] #![feature(box_patterns)] #[derive(Debug, PartialEq)] @@ -9,13 +8,13 @@ enum Test { } fn main() { - let a = box Test::Foo(10); - let b = box Test::Bar(-20); + let a = Box::new(Test::Foo(10)); + let b = Box::new(Test::Bar(-20)); match (a, b) { (_, box Test::Foo(_)) => unreachable!(), (box Test::Foo(x), b) => { assert_eq!(x, 10); - assert_eq!(b, box Test::Bar(-20)); + assert_eq!(b, Box::new(Test::Bar(-20))); }, _ => unreachable!(), } diff --git a/src/test/ui/structs-enums/align-struct.rs b/src/test/ui/structs-enums/align-struct.rs index 27ef990aa90df..f5418e754b239 100644 --- a/src/test/ui/structs-enums/align-struct.rs +++ b/src/test/ui/structs-enums/align-struct.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code)] -#![feature(box_syntax)] use std::mem; @@ -232,9 +231,9 @@ pub fn main() { assert_eq!(mem::size_of_val(&a), 32); assert!(is_aligned_to(&a, 16)); - let mut large = box AlignLarge { + let mut large = Box::new(AlignLarge { stuff: [0; 0x10000], - }; + }); large.stuff[0] = 132; *large.stuff.last_mut().unwrap() = 102; assert_eq!(large.stuff[0], 132); From fc43bd60c08eed7a714bb4726c8c511c1e6b3332 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 1 Aug 2022 18:42:16 +0900 Subject: [PATCH 3/9] revive suggestions for boxed trait objects instead of impl Trait --- compiler/rustc_typeck/src/check/_match.rs | 4 +-- ...type-err-cause-on-impl-trait-return.stderr | 29 +++++++++++++++++++ ...-trait-objects-instead-of-impl-trait.fixed | 21 ++++++++++++++ ...xed-trait-objects-instead-of-impl-trait.rs | 21 ++++++++++++++ ...trait-objects-instead-of-impl-trait.stderr | 26 +++++++++++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed create mode 100644 src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs create mode 100644 src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 1b13c98e4c3fa..9c6896dbad708 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -4,7 +4,7 @@ use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::{self as hir, ExprKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::Obligation; -use rustc_middle::ty::{self, ToPredicate, Ty, TypeVisitable}; +use rustc_middle::ty::{self, ToPredicate, Ty}; use rustc_span::Span; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::{ @@ -479,7 +479,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match orig_expected { Expectation::ExpectHasType(expected) if self.in_tail_expr - && self.ret_coercion.as_ref()?.borrow().merged_ty().has_opaque_types() + && self.return_type_has_opaque && self.can_coerce(outer_ty, expected) => { let obligations = self.fulfillment_cx.borrow().pending_obligations(); diff --git a/src/test/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr b/src/test/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr index 11c1072f02ccc..3c65fd998c5af 100644 --- a/src/test/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr +++ b/src/test/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr @@ -52,6 +52,16 @@ LL | | 1u32 LL | | } | |_____- `if` and `else` have incompatible types | +help: you could change the return type to be a boxed trait object + | +LL | fn qux() -> Box { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ Box::new(0i32) +LL | } else { +LL ~ Box::new(1u32) + | help: change the type of the numeric literal from `u32` to `i32` | LL | 1i32 @@ -114,6 +124,15 @@ LL | | _ => 2u32, LL | | } | |_____- `match` arms have incompatible types | +help: you could change the return type to be a boxed trait object + | +LL | fn dog() -> Box { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ 0 => Box::new(0i32), +LL ~ 1 => Box::new(1u32), + | help: change the type of the numeric literal from `u32` to `i32` | LL | 1 => 1i32, @@ -131,6 +150,16 @@ LL | | 1u32 LL | | } | |_____- `if` and `else` have incompatible types | +help: you could change the return type to be a boxed trait object + | +LL | fn apt() -> Box { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ Box::new(0i32) +LL | } else { +LL ~ Box::new(1u32) + | help: change the type of the numeric literal from `u32` to `i32` | LL | 1i32 diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed new file mode 100644 index 0000000000000..bc4ccbf503c12 --- /dev/null +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed @@ -0,0 +1,21 @@ +// run-rustfix + +#![allow(dead_code)] + +struct S; +struct Y; + +trait Trait {} + +impl Trait for S {} +impl Trait for Y {} + +fn baz() -> Box { + if true { + Box::new(S) + } else { + Box::new(Y) //~ ERROR `if` and `else` have incompatible types + } +} + +fn main() {} diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs new file mode 100644 index 0000000000000..0f60966500517 --- /dev/null +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs @@ -0,0 +1,21 @@ +// run-rustfix + +#![allow(dead_code)] + +struct S; +struct Y; + +trait Trait {} + +impl Trait for S {} +impl Trait for Y {} + +fn baz() -> impl Trait { + if true { + S + } else { + Y //~ ERROR `if` and `else` have incompatible types + } +} + +fn main() {} diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr new file mode 100644 index 0000000000000..72b5e25ea46d1 --- /dev/null +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr @@ -0,0 +1,26 @@ +error[E0308]: `if` and `else` have incompatible types + --> $DIR/suggest-boxed-trait-objects-instead-of-impl-trait.rs:17:9 + | +LL | / if true { +LL | | S + | | - expected because of this +LL | | } else { +LL | | Y + | | ^ expected struct `S`, found struct `Y` +LL | | } + | |_____- `if` and `else` have incompatible types + | +help: you could change the return type to be a boxed trait object + | +LL | fn baz() -> Box { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ Box::new(S) +LL | } else { +LL ~ Box::new(Y) + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 82f2c08200dabfecf82ad7eecd3bc6ff246bda5c Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 1 Aug 2022 20:22:50 +0900 Subject: [PATCH 4/9] fix wrong suggestions for boxed trait objects instead of impl trait --- compiler/rustc_typeck/src/check/_match.rs | 59 +++++++++++-------- compiler/rustc_typeck/src/check/expr.rs | 2 +- ...xed-trait-objects-instead-of-impl-trait.rs | 23 ++++++++ ...trait-objects-instead-of-impl-trait.stderr | 26 ++++++++ ...-trait-objects-instead-of-impl-trait.fixed | 9 ++- ...xed-trait-objects-instead-of-impl-trait.rs | 9 ++- ...trait-objects-instead-of-impl-trait.stderr | 25 +++++++- 7 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs create mode 100644 src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.stderr diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 9c6896dbad708..2d50412007d90 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -94,7 +94,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let arm_ty = self.check_expr_with_expectation(&arm.body, expected); all_arms_diverge &= self.diverges.get(); - let opt_suggest_box_span = self.opt_suggest_box_span(arm_ty, orig_expected); + let opt_suggest_box_span = prior_arm.and_then(|(_, prior_arm_ty, _)| { + self.opt_suggest_box_span(prior_arm_ty, arm_ty, orig_expected) + }); let (arm_block_id, arm_span) = if let hir::ExprKind::Block(blk, _) = arm.body.kind { (Some(blk.hir_id), self.find_block_span(blk)) @@ -473,43 +475,48 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // provide a structured suggestion in that case. pub(crate) fn opt_suggest_box_span( &self, - outer_ty: Ty<'tcx>, + first_ty: Ty<'tcx>, + second_ty: Ty<'tcx>, orig_expected: Expectation<'tcx>, ) -> Option { match orig_expected { Expectation::ExpectHasType(expected) if self.in_tail_expr && self.return_type_has_opaque - && self.can_coerce(outer_ty, expected) => + && self.can_coerce(first_ty, expected) + && self.can_coerce(second_ty, expected) => { let obligations = self.fulfillment_cx.borrow().pending_obligations(); let mut suggest_box = !obligations.is_empty(); - for o in obligations { - match o.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(t) => { - let pred = - ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate { - trait_ref: ty::TraitRef { - def_id: t.def_id(), - substs: self.tcx.mk_substs_trait(outer_ty, &[]), + 'outer: for o in obligations { + for outer_ty in &[first_ty, second_ty] { + match o.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(t) => { + let pred = ty::Binder::dummy(ty::PredicateKind::Trait( + ty::TraitPredicate { + trait_ref: ty::TraitRef { + def_id: t.def_id(), + substs: self.tcx.mk_substs_trait(*outer_ty, &[]), + }, + constness: t.constness, + polarity: t.polarity, }, - constness: t.constness, - polarity: t.polarity, - })); - let obl = Obligation::new( - o.cause.clone(), - self.param_env, - pred.to_predicate(self.tcx), - ); - suggest_box &= self.predicate_must_hold_modulo_regions(&obl); - if !suggest_box { - // We've encountered some obligation that didn't hold, so the - // return expression can't just be boxed. We don't need to - // evaluate the rest of the obligations. - break; + )); + let obl = Obligation::new( + o.cause.clone(), + self.param_env, + pred.to_predicate(self.tcx), + ); + suggest_box &= self.predicate_must_hold_modulo_regions(&obl); + if !suggest_box { + // We've encountered some obligation that didn't hold, so the + // return expression can't just be boxed. We don't need to + // evaluate the rest of the obligations. + break 'outer; + } } + _ => {} } - _ => {} } } // If all the obligations hold (or there are no obligations) the tail expression diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 6e97b0bf2ab7d..6d61f3dbb41c5 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1002,7 +1002,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let else_ty = self.check_expr_with_expectation(else_expr, expected); let else_diverges = self.diverges.get(); - let opt_suggest_box_span = self.opt_suggest_box_span(else_ty, orig_expected); + let opt_suggest_box_span = self.opt_suggest_box_span(then_ty, else_ty, orig_expected); let if_cause = self.if_cause( sp, cond_expr.span, diff --git a/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs b/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs new file mode 100644 index 0000000000000..d302dc99bd8aa --- /dev/null +++ b/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs @@ -0,0 +1,23 @@ +struct S; +struct Y; + +trait Trait {} + +impl Trait for Y {} + +fn foo() -> impl Trait { + if true { + S + } else { + Y //~ ERROR `if` and `else` have incompatible types + } +} + +fn bar() -> impl Trait { + match true { + true => S, + false => Y, //~ ERROR `match` arms have incompatible types + } +} + +fn main() {} diff --git a/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.stderr b/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.stderr new file mode 100644 index 0000000000000..2f814445bbadf --- /dev/null +++ b/src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.stderr @@ -0,0 +1,26 @@ +error[E0308]: `if` and `else` have incompatible types + --> $DIR/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs:12:9 + | +LL | / if true { +LL | | S + | | - expected because of this +LL | | } else { +LL | | Y + | | ^ expected struct `S`, found struct `Y` +LL | | } + | |_____- `if` and `else` have incompatible types + +error[E0308]: `match` arms have incompatible types + --> $DIR/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs:19:18 + | +LL | / match true { +LL | | true => S, + | | - this is found to be of type `S` +LL | | false => Y, + | | ^ expected struct `S`, found struct `Y` +LL | | } + | |_____- `match` arms have incompatible types + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed index bc4ccbf503c12..f30feaed05574 100644 --- a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.fixed @@ -10,7 +10,7 @@ trait Trait {} impl Trait for S {} impl Trait for Y {} -fn baz() -> Box { +fn foo() -> Box { if true { Box::new(S) } else { @@ -18,4 +18,11 @@ fn baz() -> Box { } } +fn bar() -> Box { + match true { + true => Box::new(S), + false => Box::new(Y), //~ ERROR `match` arms have incompatible types + } +} + fn main() {} diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs index 0f60966500517..2bd8146e289d9 100644 --- a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.rs @@ -10,7 +10,7 @@ trait Trait {} impl Trait for S {} impl Trait for Y {} -fn baz() -> impl Trait { +fn foo() -> impl Trait { if true { S } else { @@ -18,4 +18,11 @@ fn baz() -> impl Trait { } } +fn bar() -> impl Trait { + match true { + true => S, + false => Y, //~ ERROR `match` arms have incompatible types + } +} + fn main() {} diff --git a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr index 72b5e25ea46d1..f58b9c3ec16de 100644 --- a/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr +++ b/src/test/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr @@ -12,7 +12,7 @@ LL | | } | help: you could change the return type to be a boxed trait object | -LL | fn baz() -> Box { +LL | fn foo() -> Box { | ~~~~~~~ + help: if you change the return type to expect trait objects, box the returned expressions | @@ -21,6 +21,27 @@ LL | } else { LL ~ Box::new(Y) | -error: aborting due to previous error +error[E0308]: `match` arms have incompatible types + --> $DIR/suggest-boxed-trait-objects-instead-of-impl-trait.rs:24:18 + | +LL | / match true { +LL | | true => S, + | | - this is found to be of type `S` +LL | | false => Y, + | | ^ expected struct `S`, found struct `Y` +LL | | } + | |_____- `match` arms have incompatible types + | +help: you could change the return type to be a boxed trait object + | +LL | fn bar() -> Box { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ true => Box::new(S), +LL ~ false => Box::new(Y), + | + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. From f6af4efec579edc8d10f8c2ba5d3c43331130b39 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 7 Aug 2022 14:35:11 +0200 Subject: [PATCH 5/9] Use start_point instead of next_point to point to elided lifetime ampersand. --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_resolve/src/late.rs | 2 +- src/test/ui/lifetimes/fullwidth-ampersand.rs | 7 +++++ .../ui/lifetimes/fullwidth-ampersand.stderr | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lifetimes/fullwidth-ampersand.rs create mode 100644 src/test/ui/lifetimes/fullwidth-ampersand.stderr diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a5b089b032d8b..0562f7b88a3b0 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1228,7 +1228,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } else { self.next_node_id() }; - let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo()); + let span = self.tcx.sess.source_map().start_point(t.span); Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id } }); let lifetime = self.lower_lifetime(®ion); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index dea3eaecda6e7..ac8d26fb0724a 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -629,7 +629,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // Elided lifetime in reference: we resolve as if there was some lifetime `'_` with // NodeId `ty.id`. // This span will be used in case of elision failure. - let span = self.r.session.source_map().next_point(ty.span.shrink_to_lo()); + let span = self.r.session.source_map().start_point(ty.span); self.resolve_elided_lifetime(ty.id, span); visit::walk_ty(self, ty); } diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.rs b/src/test/ui/lifetimes/fullwidth-ampersand.rs new file mode 100644 index 0000000000000..7d8948bd844cf --- /dev/null +++ b/src/test/ui/lifetimes/fullwidth-ampersand.rs @@ -0,0 +1,7 @@ +// Verify that we do not ICE when the user uses a multubyte ampersand. + +fn f(_: &&()) -> &() { todo!() } +//~^ ERROR unknown start of token: \u{ff06} +//~| ERROR missing lifetime specifier [E0106] + +fn main() {} diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.stderr b/src/test/ui/lifetimes/fullwidth-ampersand.stderr new file mode 100644 index 0000000000000..4645254f4b70d --- /dev/null +++ b/src/test/ui/lifetimes/fullwidth-ampersand.stderr @@ -0,0 +1,26 @@ +error: unknown start of token: \u{ff06} + --> $DIR/fullwidth-ampersand.rs:3:10 + | +LL | fn f(_: &&()) -> &() { todo!() } + | ^^ + | +help: Unicode character '&' (Fullwidth Ampersand) looks like '&' (Ampersand), but it is not + | +LL | fn f(_: &&()) -> &() { todo!() } + | ~ + +error[E0106]: missing lifetime specifier + --> $DIR/fullwidth-ampersand.rs:3:18 + | +LL | fn f(_: &&()) -> &() { todo!() } + | ----- ^ expected named lifetime parameter + | + = help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from +help: consider introducing a named lifetime parameter + | +LL | fn f<'a>(_: &'a &'a ()) -> &'a () { todo!() } + | ++++ ++ ++ ++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0106`. From 5076c902a4b8f328d6a3ecf83fc86a1d0be09de4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 6 Aug 2022 14:17:40 -0400 Subject: [PATCH 6/9] test: skip terminfo parsing in Miri --- library/test/src/term/terminfo/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/test/src/term/terminfo/mod.rs b/library/test/src/term/terminfo/mod.rs index 694473f52c1a7..355859019714b 100644 --- a/library/test/src/term/terminfo/mod.rs +++ b/library/test/src/term/terminfo/mod.rs @@ -80,6 +80,17 @@ impl TermInfo { /// Creates a TermInfo for the named terminal. pub(crate) fn from_name(name: &str) -> Result { + if cfg!(miri) { + // Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just + // assume that the standard color codes work (like e.g. the 'colored' crate). + return Ok(TermInfo { + names: Default::default(), + bools: Default::default(), + numbers: Default::default(), + strings: Default::default(), + }); + } + get_dbpath_for_term(name) .ok_or_else(|| { Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found")) @@ -119,6 +130,12 @@ pub(crate) struct TerminfoTerminal { impl Terminal for TerminfoTerminal { fn fg(&mut self, color: color::Color) -> io::Result { let color = self.dim_if_necessary(color); + if cfg!(miri) && color < 8 { + // The Miri logic for this only works for the most basic 8 colors, which we just assume + // the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will + // just fail. But libtest doesn't use any higher colors anyway.) + return write!(self.out, "\x1B[3{color}m").and(Ok(true)); + } if self.num_colors > color { return self.apply_cap("setaf", &[Param::Number(color as i32)]); } @@ -126,6 +143,9 @@ impl Terminal for TerminfoTerminal { } fn reset(&mut self) -> io::Result { + if cfg!(miri) { + return write!(self.out, "\x1B[0m").and(Ok(true)); + } // are there any terminals that have color/attrs and not sgr0? // Try falling back to sgr, then op let cmd = match ["sgr0", "sgr", "op"].iter().find_map(|cap| self.ti.strings.get(*cap)) { From a8b445404769fab8c4497e13a00e03c55e5928ef Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:40:41 -0600 Subject: [PATCH 7/9] Create armv4t_none_eabi.rs --- .../rustc_target/src/spec/armv4t_none_eabi.rs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 compiler/rustc_target/src/spec/armv4t_none_eabi.rs diff --git a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs new file mode 100644 index 0000000000000..a76ffe808c3b2 --- /dev/null +++ b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs @@ -0,0 +1,54 @@ +//! Targets the ARMv4T, with code as `a32` code by default. +//! +//! Primarily of use for the GBA, but usable with other devices too. +//! +//! Please ping @Lokathor if changes are needed. +//! +//! This target profile assumes that you have the ARM binutils in your path +//! (specifically the linker, `arm-none-eabi-ld`). They can be obtained for free +//! for all major OSes from the ARM developer's website, and they may also be +//! available in your system's package manager. Unfortunately, the standard +//! linker that Rust uses (`lld`) only supports as far back as `ARMv5TE`, so we +//! must use the GNU `ld` linker. +//! +//! **Important:** This target profile **does not** specify a linker script. You +//! just get the default link script when you build a binary for this target. +//! The default link script is very likely wrong, so you should use +//! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script. + +use crate::spec::{cvs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "armv4t-none-eabi".into(), + pointer_width: 32, + arch: "arm".into(), + /* Data layout args are '-' separated: + * little endian + * stack is 64-bit aligned (EABI) + * pointers are 32-bit + * i64 must be 64-bit aligned (EABI) + * mangle names with ELF style + * native integers are 32-bit + * All other elements are default + */ + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + options: TargetOptions { + abi: "eabi".into(), + linker_flavor: LinkerFlavor::Ld, + linker: Some("arm-none-eabi-ld".into()), + asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",], + features: "+soft-float,+strict-align".into(), + main_needs_argc_argv: false, + atomic_cas: false, + has_thumb_interworking: true, + relocation_model: RelocModel::Static, + panic_strategy: PanicStrategy::Abort, + // from thumb_base, rust-lang/rust#44993. + emit_debug_gdb_scripts: false, + // from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets + c_enum_min_bits: 8, + ..Default::default() + }, + } +} From 008ce49944897225537b2f45e0a8d3a39c5dccf5 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:41:38 -0600 Subject: [PATCH 8/9] Create armv4t_none_eabi.md --- .../src/platform-support/armv4t_none_eabi.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/doc/rustc/src/platform-support/armv4t_none_eabi.md diff --git a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md new file mode 100644 index 0000000000000..cf831e1595e40 --- /dev/null +++ b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md @@ -0,0 +1,70 @@ +# armv4t-none-eabi + +Tier 3 + +Bare-metal target for any cpu in the ARMv4T architecture family, supporting +ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code +generation. + +In particular this supports the Gameboy Advance (GBA), but there's nothing GBA +specific with this target, so any ARMv4T device should work fine. + +## Target Maintainers + +* [@Lokathor](https://github.com/lokathor) + +## Requirements + +The target is cross-compiled, and uses static linking. + +The linker that comes with rustc cannot link for this platform (the platform is +too old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils +targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM +Developer Website][arm-dev], or possibly from your OS's package manager. + +[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain + +This target doesn't provide a linker script, you'll need to bring your own +according to the specific device you want to target. Pass +`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use +`your_script.ld` during linking. + +## Building Rust Programs + +Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target. + +Just use the `build-std` nightly cargo feature to build the `core` library. You +can pass this as a command line argument to cargo, or your `.cargo/config.toml` +file might include the following lines: + +```toml +[unstable] +build-std = ["core"] +``` + +Most of `core` should work as expected, with the following notes: +* the target is "soft float", so `f32` and `f64` operations are emulated in + software. +* integer division is also emulated in software. +* the target is old enough that it doesn't have atomic instructions. + +Rust programs are output as ELF files. + +For running on hardware, you'll generally need to extract the "raw" program code +out of the ELF and into a file of its own. The `objcopy` program provided as +part of the GNU Binutils can do this: + +```shell +arm-none-eabi-objcopy --output-target binary [in_file] [out_file] +``` + +## Testing + +This is a cross-compiled target that you will need to emulate during testing. + +Because this is a device-agnostic target, and the exact emulator that you'll +need depends on the specific device you want to run your code on. + +For example, when programming for the Gameboy Advance, the +[mgba-test-runner](https://github.com/agbrs/agb) program could be used to make a +normal set of rust tests be run within the `mgba` emulator. From b4a82998e5c0a35b9ccf935a86cc300a8f29bdd3 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:42:25 -0600 Subject: [PATCH 9/9] Update SUMMARY.md --- src/doc/rustc/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index d168af60c2df0..4e6bc41daa712 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -18,6 +18,7 @@ - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [\*-apple-watchos\*](platform-support/apple-watchos.md) - [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md) + - [armv4t-none-eabi](platform-support/armv4t-none-eabi.md) - [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)