From d5a32d870120109012daaa348ed97992d0e99ebc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 18 Mar 2022 19:51:26 -0700 Subject: [PATCH 1/7] Add known-bug for #94034 --- src/test/ui/hrtb/issue-94034.rs | 96 +++++++++++++++++++++++++++++ src/test/ui/hrtb/issue-94034.stderr | 1 + 2 files changed, 97 insertions(+) create mode 100644 src/test/ui/hrtb/issue-94034.rs create mode 100644 src/test/ui/hrtb/issue-94034.stderr diff --git a/src/test/ui/hrtb/issue-94034.rs b/src/test/ui/hrtb/issue-94034.rs new file mode 100644 index 0000000000000..5239e5db11c96 --- /dev/null +++ b/src/test/ui/hrtb/issue-94034.rs @@ -0,0 +1,96 @@ +// known-bug +// failure-status: 101 +// compile-flags: --edition=2021 --crate-type=lib +// rustc-env:RUST_BACKTRACE=0 + +// normalize-stderr-test "thread 'rustc' panicked.*" -> "thread 'rustc' panicked" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> "" +// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> "" +// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> "" +// normalize-stderr-test "note: compiler flags.*\n\n" -> "" +// normalize-stderr-test "note: rustc.*running on.*\n\n" -> "" +// normalize-stderr-test "query stack during panic:\n" -> "" +// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> "" +// normalize-stderr-test "end of query stack\n" -> "" +// normalize-stderr-test "#.*\n" -> "" + +// This should not ICE. + +use std::{ + future::Future, + marker::PhantomData, + pin::Pin, + task::{Context, Poll}, +}; + +mod object { + use super::*; + + pub trait Object<'a> { + type Error; + type Future: Future; + fn create() -> Self::Future; + } + + impl<'a> Object<'a> for u8 { + type Error = (); + type Future = Pin>>; + fn create() -> Self::Future { + unimplemented!() + } + } + + impl<'a, E, A: Object<'a, Error = E>> Object<'a> for (A,) { + type Error = (); + type Future = CustomFut<'a, E, A>; + fn create() -> Self::Future { + unimplemented!() + } + } + + pub struct CustomFut<'f, E, A: Object<'f, Error = E>> { + ph: PhantomData<(A::Future,)>, + } + + impl<'f, E, A: Object<'f, Error = E>> Future for CustomFut<'f, E, A> { + type Output = (A,); + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + unimplemented!() + } + } +} + +mod async_fn { + use super::*; + + pub trait AsyncFn { + type Future: Future; + fn call(&self) -> Self::Future; + } + + impl AsyncFn for F + where + F: Fn() -> Fut, + Fut: Future, + { + type Future = Fut; + fn call(&self) -> Self::Future { + (self)() + } + } +} + +pub async fn test() { + use self::{async_fn::AsyncFn, object::Object}; + + async fn create>() { + T::create().await; + } + + async fn call_async_fn(inner: impl AsyncFn) { + inner.call().await; + } + + call_async_fn(create::<(u8,)>).await; +} diff --git a/src/test/ui/hrtb/issue-94034.stderr b/src/test/ui/hrtb/issue-94034.stderr new file mode 100644 index 0000000000000..1d8329142fc5c --- /dev/null +++ b/src/test/ui/hrtb/issue-94034.stderr @@ -0,0 +1 @@ +thread 'rustc' panicked From 05a467e4ce0000dd5372cbca74c18c001382341a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 3 Apr 2022 19:38:25 -0700 Subject: [PATCH 2/7] Mailmap update --- .mailmap | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 246 insertions(+), 4 deletions(-) diff --git a/.mailmap b/.mailmap index d72e6ebcb65fa..30c3212810cf9 100644 --- a/.mailmap +++ b/.mailmap @@ -7,51 +7,98 @@ Aaron Todd Abhishek Chanda Abhishek Chanda +Abhijeet Bhagat +Abroskin Alexander Adolfo Ochagavía +Adrian Heine né Lang Adrien Tétar Ahmed Charles +Alan Egerton +Alan Stoate +Alessandro Decina Alex Burka Alex Burka +Alex Hansen Alex Lyon Alex Newman Alex HotShot Newman Alex Rønne Petersen +Alex Vlasov +Alex von Gluck IV Alexander Light Alexander Light +Alexander Ronald Altman +Alexandre Martin Alexis Beingessner Alfie John Alfie John +Amos Onn +Ana-Maria Mihalache Anatoly Ikorsky Andre Bogus +Andrea Ciliberti Andreas Gal +Andreas Jonson +Andrew Gauger Andrew Kuchev <0coming.soon@gmail.com> Andrew <0coming.soon@gmail.com> +Andrew Lamb Andrew Poelstra +Anhad Singh +Antoine Plaskowski Anton Löfgren +Araam Borhanian +Araam Borhanian Areski Belaid areski Ariel Ben-Yehuda Ariel Ben-Yehuda Ariel Ben-Yehuda arielb1 +Artem Chernyak +Arthur Cohen +Arthur Silva +Arthur Woimbée +Artyom Pavlov Austin Seipp +Ayaz Hafiz Aydin Kim aydin.kim +Ayush Mishra +asrar +BaoshanPang Barosl Lee Barosl LEE +Bastian Kersting +Bastien Orivel Ben Alpert -Ben Sago Ben S -Ben Sago Ben S +Ben Lewis +Ben Sago +Ben Sago +Ben Striegel Benjamin Jackman +Benoît Cortier Bheesham Persaud Bheesham Persaud Björn Steinbrink blake2-ppc +boolean_coercion Boris Egorov +Braden Nelson Brandon Sanderson Brandon Sanderson Brett Cannon Brett Cannon Brian Anderson Brian Anderson +Brian Bowman +Brian Cain Brian Dawn Brian Leibig Brian Leibig +Caleb Cartwright +Caleb Jones Noah Lev Noah Lev <37223377+camelid@users.noreply.github.com> +cameron1024 +Camille Gillot Carl-Anton Ingmarsson +Carlo Teubner Carol (Nichols || Goulding) <193874+carols10cents@users.noreply.github.com> Carol (Nichols || Goulding) Carol (Nichols || Goulding) Carol Willing +Chandler Deng Charles Lew CrLF0710 Chris C Cerami Chris C Cerami +Chris Gregory +Chris Pardy Chris Pressey Chris Thorn Chris Thorn Chris Vittal Christopher Vittal @@ -62,29 +109,53 @@ Christian Poveda Christian Poveda Christian Poveda Christian Poveda +Christian Vallentin +Christoffer Buchholz +Christopher Durham Clark Gaebel +Clement Miao +Clément Renault +Cliff Dyer Clinton Ryan Corey Richardson Elaine "See More" Nemo +Crazycolorz5 +csmoe <35686186+csmoe@users.noreply.github.com> Cyryl Płotnicki Damien Schoof +Dan Robertson +Daniel Campoverde Daniel J Rollins +Daniel Mueller Daniel Ramos +Daniele D'Orazio +Dante Broggi <34220985+Dante-Broggi@users.noreply.github.com> +David Carlier David Klein David Manescu David Ross David Wood +Deadbeef Deadbeef Derek Chiang Derek Chiang (Enchi Jiang) +DeveloperC +Devin Ragotzy +Dharma Saputra Wijaya Diggory Hardy Diggory Hardy +Dileep Bapat Donough Liu Donough Liu DingMing Liu Dustin Bensing +DutchGhost Dylan Braithwaite +Dylan DPC +Dylan MacKenzie Dzmitry Malyshau E. Dunham edunham +Ed Barnard Eduard-Mihai Burtescu Eduardo Bautista <=> Eduardo Bautista +Eduardo Broto Elliott Slaughter Elly Fong-Jones Eric Holk @@ -92,46 +163,82 @@ Eric Holk Eric Holmes Eric Reed Erick Tryzelaar +Erik Desjardins +Erik Jensen +Erin Power Erin Power Erin Power +Esteban Küber Esteban Küber Esteban Küber Esteban Küber +Ethan Dagner Evgeny Sologubov +F001 +Fabian Kössel Falco Hirschenberger Felix S. Klock II Felix S Klock II +Félix Saparelli Flaper Fesp +Florian Berger Florian Wilkens Florian Wilkens +François Mockers Frank Steffahn +Fridtjof Stoldt +fukatani +Fuqiao Xue Gareth Daniel Smith gareth Gareth Daniel Smith Gareth Smith +Gauri Kholkar Georges Dubus +Giles Cope +Glen De Cauwsemaecker Graham Fawcett Graham Fawcett Graydon Hoare Graydon Hoare +Greg V +Gregor Peach +Grzegorz Bartoszek +Guanqun Lu Guillaume Gomez Guillaume Gomez ggomez Guillaume Gomez Guillaume Gomez Guillaume Gomez Guillaume Gomez +hamidreza kalbasi Hanna Kruppe Heather Heather Herman J. Radtke III Herman J. Radtke III Hirochika Matsumoto +Hrvoje Nikšić +Hsiang-Cheng Yang Ian Jackson Ian Jackson Ian Jackson +Ibraheem Ahmed Ilyong Cho inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> +Irina Popa Ivan Ivaschenko +ivan tkachenko J. J. Weber +Jack Huey +Jacob +Jacob Greenfield Jacob Pratt +Jake Vossen +Jakob Degen +Jakob Lautrup Nysom +Jakub Adam Wieczorek Jakub Adam Wieczorek Jakub Adam Wieczorek Jakub Adam Wieczorek +James [Undefined] James Deng James Hinshelwood James Miller James Perry +James Sanderson +Jaro Fietz Jason Fager Jason Liquorish Jason Orendorff @@ -140,33 +247,60 @@ Jason Toffaletti Jason Toffaletti Jauhien Piatlicki Jauhien Piatlicki Jay True Jeremy Letang +Jeremy Sorensen Jeremy Stucki Jeremy Stucki Jeremy Stucki +Jerry Hardee +Jesús Rubio Jethro Beekman +Jian Zeng Jihyun Yu Jihyun Yu jihyun Jihyun Yu Jihyun Yu João Oliveira joaoxsouls +joboet Johann Hofmann Johann John Clements John Hodge John Hodge +John Hörnvall John Kåre Alsaker John Talling +John Van Enk +Jonas Tepe Jonathan Bailey +Jonathan Chan Kwan Yin +Jonathan L Jonathan S Jonathan S +Jonathan Sieber Jonathan Turner Jorge Aparicio +Josef Reinhard Brandl +Joseph Dunne Joseph Martin +Joseph Richey +Joseph T. Lyons Joseph T. Lyons Joseph T. Lyons +Josh Cotton +Josh Driver +Josh Holmer Joshua Nelson +Julian Knodt jumbatm <30644300+jumbatm@users.noreply.github.com> Junyoung Cho Jyun-Yan You +Kalita Alexey +Kampfkarren Kang Seonghoon +Karim Snj +Katze Keegan McAllister +Kerem Kat Kevin Butler +Kevin Jiang +Kornel Lesiński +Krishna Sai Veera Reddy Kyeongwoon Lee Kyle J Strand Kyle J Strand @@ -176,57 +310,102 @@ Laurențiu Nicola lcnr Lee Jeffery Lee Jeffery Lee Wondong +lengyijun Lennart Kudling Léo Lanteri Thauvin Léo Lanteri Thauvin <38361244+LeSeulArtichaut@users.noreply.github.com> Léo Testard +Leonardo Yvens +Liigo Zhuang Lily Ballard Lindsey Kuper Lindsey Kuper +Liu Dingming +Loo Maclin +Loïc BRANSTETT +Lucy +Lukas H. +Lukas Lueg Luke Metz Luqman Aden Luqman Aden +Lzu Tao +Maik Klein +Malo Jaffré Manish Goregaokar +Mara Bos Marcell Pardavi +Marcus Klaas de Vries Margaret Meyerhofer +Mark Mansi Mark Rousskov Mark Sinclair Mark Sinclair =Mark Sinclair <=125axel125@gmail.com> +Markus Legner Markus Westerlind Markus +Martin Carton +Martin Habovštiak Martin Hafskjold Thoresen Matej Lach Matej Ľach +Mateusz Mikuła Mateusz Mikuła Mateusz Mikuła Matt Brubeck Matthew Auld +Matthew Jasper Matthew Kraai Matthew Kraai Matthew Kraai Matthew McPherrin +Matthew Tran <0e4ef622@gmail.com> Matthijs Hofstra +Max Sharnoff +Max Wase +Mazdak Farrokhzad +Meade Kincke Melody Horn +Mendes +mental +mibac138 <5672750+mibac138@users.noreply.github.com> Michael Williams Michael Woerister Michael Woerister Michael Woerister +Michael Zhang +Michał Krasnoborski +Michiel De Muynck Mickaël Raybaud-Roig m-r-r +Mikhail Babenko +Milan Landaverde +mjptree Ms2ger +msizanoen1 Mukilan Thiagarajan +Nadrieril Feneanar NAKASHIMA, Makoto NAKASHIMA, Makoto +Nathan Ringo Nathan West +Nathan Whitaker Nathan Wilson +Nathaniel Hamovitz <18648574+nhamovitz@users.noreply.github.com> Nathaniel Herman Nathaniel Herman Neil Pankey +Ngo Iok Ui (Wu Yu Wei) +Nicholas Baron Nick Platt +Niclas Schwarzlose <15schnic@gmail.com> +Nicolas Abram Nicole Mazzuca Nif Ward Nika Layzell +Nixon Enraght-Moony +NODA Kai +oliver <16816606+o752d@users.noreply.github.com> Oliver Middleton Oliver Scherer Oliver Scherer Oliver Scherer -Oliver Scherer Oliver Scherer Oliver Scherer Oliver Scherer @@ -236,76 +415,139 @@ Oliver Scherer Oliver Scherer Oliver Scherer Oliver Scherer +Ömer Sinan Ağacan +Ophir LOJKINE Ožbolt Menegatti gareins +Pankaj Chaudhary Paul Faria Paul Faria Peer Aramillo Irizar parir Peter Elmers Peter Liniker Phil Dawes Phil Dawes +Phil Hansch Philipp Brüschweiler Philipp Brüschweiler -Philipp Krones flip1995 +Philipp Krones +Philipp Krones <9744647+flip1995@users.noreply.github.com> Philipp Krones +Philipp Krones Philipp Matthias Schäfer +phosphorus +Pierre Krieger pierwill <19642016+pierwill@users.noreply.github.com> +Pradyumna Rahul Przemysław Wesołek Przemek Wesołek +r00ster Rafael Ávila de Espíndola Rafael Avila de Espindola +rail <12975677+rail-rain@users.noreply.github.com> Ralph Giles Ralph Giles Ramkumar Ramachandra +Raphaël Huchet +rChaser53 +Rémy Rakic +Rémy Rakic Renato Riccieri Santos Zannon Richard Diamond +Ricky Hosfelt +Ritiek Malhotra Rob Arnold Rob Arnold Rob Arnold Robert Foss robertfoss Robert Gawdzik Robert Gawdzik ☢ +Robert Habermeier Robert Millar +Roc Yu Rohit Joshi Rohit Joshi +Roxane Fruytier +Rui Russell Johnston +Rustin-Liu +Rusty Blitzerr +RustyYato Ruud van Asseldonk Ruud van Asseldonk +Ryan Leung Ryan Scheel +Ryan Sullivant +Ryan Wiedemann S Pradeep Kumar +Sam Radhakrishnan +Scott McMurray Scott Olson Scott Olson Sean Gillespie swgillespie +Seiichi Uchida Seonghyun Kim +Shohei Wada +Shotaro Yamada +Shotaro Yamada Shyam Sundar B Simon Barber-Dueck Simon BD Simon Sapin Simonas Kazlauskas Simonas Kazlauskas +Siva Prasad +Smittyvb +Srinivas Reddy Thatiparthy +Stanislav Tkach startling Stepan Koltsov Stepan Koltsov Steve Klabnik Steven Fackler +Steven Malis Steven Stewart-Gallus Stuart Pernsteiner Stuart Pernsteiner +Suyash458 +Sébastien Marie +Takashi Idobe +Takayuki Maeda Tamir Duberstein Tamir Duberstein +Tatsuyuki Ishi Tero Hänninen Tero Hänninen +The8472 Theo Belaire Theo Belaire +Theodore Luo Wang Thiago Pontes thiagopnts Thomas Bracht Laumann Jespersen +Tibo Delor Ticki Ticki <@> Tim Brooks Tim Brooks Tim Chevalier +Tim Diekmann +Tim Hutt Tim JIANG Tim Joseph Dumol +Timothy Maloney +Tomas Koutsky +Torsten Weber Torsten Weber Trevor Spiteri Ty Overby Tyler Mandry +Tyler Ruckinger Ulrik Sverdrup bluss Ulrik Sverdrup bluss Ulrik Sverdrup Ulrik Sverdrup Vadim Petrochenkov Vadim Petrochenkov petrochenkov +Val Markovic +Valerii Lashmanov Vitali Haravy Vitali Haravy +Vitaly Shukela +Waffle Maybe Wesley Wiser whitequark William Ting +Wim Looman +Without Boats +Without Boats +Xinye Tao Xuefeng Wu Xuefeng Wu Xuefeng Wu XuefengWu York Xiang Youngsoo Son +Youngsuk Kim +Yuki Okushi Yuki Okushi Yuki Okushi +Yuning Zhang Zach Pomerantz Zack Corr Zack Slayton From 3191d27f48d1434877303357ab1ae5b5128d0f6a Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 7 Apr 2022 08:13:41 -0300 Subject: [PATCH 3/7] Kickstart the inner usage of macro_metavar_expr --- compiler/rustc_expand/src/expand.rs | 4 +- compiler/rustc_expand/src/lib.rs | 3 +- library/core/src/lib.rs | 1 + library/core/src/tuple.rs | 140 +++++----------------------- 4 files changed, 28 insertions(+), 120 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index c3f7f4f27e54c..9b224a733568b 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -83,9 +83,7 @@ macro_rules! ast_fragments { } match self { $($(AstFragment::$Kind(ast) => ast.extend(placeholders.iter().flat_map(|id| { - // We are repeating through arguments with `many`, to do that we have to - // mention some macro variable from those arguments even if it's not used. - macro _repeating($flat_map_ast_elt) {} + ${ignore(flat_map_ast_elt)} placeholder(AstFragmentKind::$Kind, *id, None).$make_ast() })),)?)* _ => panic!("unexpected AST fragment kind") diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index cd5bb93de65bd..21078f79f634a 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(rustc::potential_query_instability)] #![feature(associated_type_bounds)] #![feature(associated_type_defaults)] #![feature(crate_visibility_modifier)] @@ -5,12 +6,12 @@ #![feature(if_let_guard)] #![feature(let_chains)] #![feature(let_else)] +#![feature(macro_metavar_expr)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] #![feature(proc_macro_span)] #![feature(try_blocks)] #![recursion_limit = "256"] -#![allow(rustc::potential_query_instability)] #[macro_use] extern crate rustc_macros; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 660f6d92fe184..6546a5244fd03 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -181,6 +181,7 @@ #![feature(intrinsics)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] +#![feature(macro_metavar_expr)] #![feature(min_specialization)] #![feature(mixed_integer_ops)] #![feature(must_not_suspend)] diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 9f8a3a1de4201..fdf58c50e4863 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -5,21 +5,17 @@ use crate::cmp::*; // macro for implementing n-ary tuple functions and operations macro_rules! tuple_impls { - ($( - $Tuple:ident { - $(($idx:tt) -> $T:ident)+ - } - )+) => { + ( $( $Tuple:ident( $( $T:ident )+ ) )+ ) => { $( #[stable(feature = "rust1", since = "1.0.0")] impl<$($T:PartialEq),+> PartialEq for ($($T,)+) where last_type!($($T,)+): ?Sized { #[inline] fn eq(&self, other: &($($T,)+)) -> bool { - $(self.$idx == other.$idx)&&+ + $( ${ignore(T)} self.${index()} == other.${index()} )&&+ } #[inline] fn ne(&self, other: &($($T,)+)) -> bool { - $(self.$idx != other.$idx)||+ + $( ${ignore(T)} self.${index()} != other.${index()} )||+ } } @@ -28,26 +24,28 @@ macro_rules! tuple_impls { #[stable(feature = "rust1", since = "1.0.0")] impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+) - where last_type!($($T,)+): ?Sized { + where + last_type!($($T,)+): ?Sized + { #[inline] fn partial_cmp(&self, other: &($($T,)+)) -> Option { - lexical_partial_cmp!($(self.$idx, other.$idx),+) + lexical_partial_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+) } #[inline] fn lt(&self, other: &($($T,)+)) -> bool { - lexical_ord!(lt, $(self.$idx, other.$idx),+) + lexical_ord!(lt, $( ${ignore(T)} self.${index()}, other.${index()} ),+) } #[inline] fn le(&self, other: &($($T,)+)) -> bool { - lexical_ord!(le, $(self.$idx, other.$idx),+) + lexical_ord!(le, $( ${ignore(T)} self.${index()}, other.${index()} ),+) } #[inline] fn ge(&self, other: &($($T,)+)) -> bool { - lexical_ord!(ge, $(self.$idx, other.$idx),+) + lexical_ord!(ge, $( ${ignore(T)} self.${index()}, other.${index()} ),+) } #[inline] fn gt(&self, other: &($($T,)+)) -> bool { - lexical_ord!(gt, $(self.$idx, other.$idx),+) + lexical_ord!(gt, $( ${ignore(T)} self.${index()}, other.${index()} ),+) } } @@ -55,7 +53,7 @@ macro_rules! tuple_impls { impl<$($T:Ord),+> Ord for ($($T,)+) where last_type!($($T,)+): ?Sized { #[inline] fn cmp(&self, other: &($($T,)+)) -> Ordering { - lexical_cmp!($(self.$idx, other.$idx),+) + lexical_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+) } } @@ -108,106 +106,16 @@ macro_rules! last_type { } tuple_impls! { - Tuple1 { - (0) -> A - } - Tuple2 { - (0) -> A - (1) -> B - } - Tuple3 { - (0) -> A - (1) -> B - (2) -> C - } - Tuple4 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - } - Tuple5 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - } - Tuple6 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - } - Tuple7 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - } - Tuple8 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - (7) -> H - } - Tuple9 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - (7) -> H - (8) -> I - } - Tuple10 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - (7) -> H - (8) -> I - (9) -> J - } - Tuple11 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - (7) -> H - (8) -> I - (9) -> J - (10) -> K - } - Tuple12 { - (0) -> A - (1) -> B - (2) -> C - (3) -> D - (4) -> E - (5) -> F - (6) -> G - (7) -> H - (8) -> I - (9) -> J - (10) -> K - (11) -> L - } + Tuple1(A) + Tuple2(A B) + Tuple3(A B C) + Tuple4(A B C D) + Tuple5(A B C D E) + Tuple6(A B C D E F) + Tuple7(A B C D E F G) + Tuple8(A B C D E F G H) + Tuple9(A B C D E F G H I) + Tuple10(A B C D E F G H I J) + Tuple11(A B C D E F G H I J K) + Tuple12(A B C D E F G H I J K L) } From 6a4b44426b7fd04592e618a93378510963ceda11 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 7 Apr 2022 20:15:16 +0100 Subject: [PATCH 4/7] Windows: Increase a pipe's buffer capacity to 64kb This brings it inline with typical Linux defaults: https://www.man7.org/linux/man-pages/man7/pipe.7.html --- library/std/src/sys/windows/pipe.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/pipe.rs b/library/std/src/sys/windows/pipe.rs index df4f1b24eec26..09d1dd55989e1 100644 --- a/library/std/src/sys/windows/pipe.rs +++ b/library/std/src/sys/windows/pipe.rs @@ -53,6 +53,9 @@ pub struct Pipes { /// with `OVERLAPPED` instances, but also works out ok if it's only ever used /// once at a time (which we do indeed guarantee). pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Result { + // A 64kb pipe capacity is the same as a typical Linux default. + const PIPE_BUFFER_CAPACITY: u32 = 64 * 1024; + // Note that we specifically do *not* use `CreatePipe` here because // unfortunately the anonymous pipes returned do not support overlapped // operations. Instead, we create a "hopefully unique" name and create a @@ -91,8 +94,8 @@ pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Res | c::PIPE_WAIT | reject_remote_clients_flag, 1, - 4096, - 4096, + PIPE_BUFFER_CAPACITY, + PIPE_BUFFER_CAPACITY, 0, ptr::null_mut(), ); From e0e64a89304de2b34dbafbc6cb354d2be9e67835 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Thu, 7 Apr 2022 17:56:06 -0700 Subject: [PATCH 5/7] hide an #[allow] directive from the Arc::new_cyclic doc example --- library/alloc/src/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index f8b4d46ac105d..a19999cd72580 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -369,7 +369,7 @@ impl Arc { /// /// # Example /// ``` - /// #![allow(dead_code)] + /// # #![allow(dead_code)] /// use std::sync::{Arc, Weak}; /// /// struct Gadget { From 66b3ca0b7f66621e09c88f94f6c1151cc1aed845 Mon Sep 17 00:00:00 2001 From: bstrie <865233+bstrie@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:47:40 -0400 Subject: [PATCH 6/7] Promote x86_64-unknown-none to Tier 2 --- .../host-x86_64/dist-various-2/Dockerfile | 1 + src/doc/rustc/src/platform-support.md | 2 +- .../platform-support/x86_64-unknown-none.md | 18 +++++++++++------- src/tools/build-manifest/src/main.rs | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index e363c4f79f9cf..a045666ca8aa5 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -111,6 +111,7 @@ ENV TARGETS=$TARGETS,nvptx64-nvidia-cuda ENV TARGETS=$TARGETS,armv7-unknown-linux-gnueabi ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi ENV TARGETS=$TARGETS,i686-unknown-freebsd +ENV TARGETS=$TARGETS,x86_64-unknown-none # As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211 # we need asm in the search path for gcc-8 (for gnux32) but not in the search path of the diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 8fc5a0d312b06..32def67ed65e3 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -177,6 +177,7 @@ target | std | notes `x86_64-linux-android` | ✓ | 64-bit x86 Android `x86_64-pc-solaris` | ✓ | 64-bit Solaris 10/11, illumos `x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15, glibc 2.27) +[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat `x86_64-unknown-redox` | ✓ | Redox OS [Fortanix ABI]: https://edp.fortanix.com/ @@ -291,7 +292,6 @@ target | std | host | notes `x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku `x86_64-unknown-hermit` | ✓ | | HermitCore `x86_64-unknown-l4re-uclibc` | ? | | -[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat `x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules [`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD `x86_64-unknown-uefi` | * | | 64-bit UEFI diff --git a/src/doc/rustc/src/platform-support/x86_64-unknown-none.md b/src/doc/rustc/src/platform-support/x86_64-unknown-none.md index afcc48003b936..bd5fd1d050230 100644 --- a/src/doc/rustc/src/platform-support/x86_64-unknown-none.md +++ b/src/doc/rustc/src/platform-support/x86_64-unknown-none.md @@ -1,6 +1,6 @@ # `x86_64-unknown-none` -**Tier: 3** +**Tier: 2** Freestanding/bare-metal x86-64 binaries in ELF format: firmware, kernels, etc. @@ -32,7 +32,7 @@ You can change this using the `-C code-model=` option to rustc. On `x86_64-unknown-none`, `extern "C"` uses the [standard System V calling convention](https://gitlab.com/x86-psABIs/x86-64-ABI), without red zones. -This target generated binaries in the ELF format. Any alternate formats or +This target generates binaries in the ELF format. Any alternate formats or special considerations for binary layout will require linker options or linker scripts. @@ -49,15 +49,19 @@ target = ["x86_64-unknown-none"] ## Building Rust programs -Rust does not yet ship pre-compiled artifacts for this target. To compile for -this target, you will either need to build Rust with the target enabled (see -"Building the target" above), or build your own copy of `core` by using -`build-std` or similar. +Starting with Rust 1.62, precompiled artifacts are provided via `rustup`: + +```text +# install cross-compile toolchain +rustup target add x86_64-unknown-none +# target flag may be used with any cargo or rustc command +cargo build --target x86_64-unknown-none +``` ## Testing As `x86_64-unknown-none` supports a variety of different environments and does -not support `std`, this target does not support running the Rust testsuite. +not support `std`, this target does not support running the Rust test suite. ## Cross-compilation toolchains and C code diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index c682879e32330..a1dfbef0601ad 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -152,6 +152,7 @@ static TARGETS: &[&str] = &[ "x86_64-unknown-linux-gnux32", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", + "x86_64-unknown-none", "x86_64-unknown-redox", "x86_64-unknown-hermit", ]; From 06788fd7a4c89479dfe28c1e42410778adf41eab Mon Sep 17 00:00:00 2001 From: Cyborus04 <87248184+Cyborus04@users.noreply.github.com> Date: Fri, 1 Apr 2022 20:07:28 -0400 Subject: [PATCH 7/7] add `<[[T; N]]>::flatten`, `<[[T; N]]>::flatten_mut`, and `Vec::<[T; N]>::into_flattened` --- library/alloc/src/lib.rs | 1 + library/alloc/src/vec/mod.rs | 45 +++++++++++++++++++ library/alloc/tests/lib.rs | 1 + library/alloc/tests/vec.rs | 7 +++ library/core/src/slice/mod.rs | 82 +++++++++++++++++++++++++++++++++++ library/core/tests/lib.rs | 1 + library/core/tests/slice.rs | 16 +++++++ 7 files changed, 153 insertions(+) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 065d071a2e360..69ca33cfc2265 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -131,6 +131,7 @@ #![feature(trusted_len)] #![feature(trusted_random_access)] #![feature(try_trait_v2)] +#![feature(unchecked_math)] #![feature(unicode_internals)] #![feature(unsize)] // diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 0b62622de819e..74bcac2b5414d 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2274,6 +2274,51 @@ impl Vec { } } +impl Vec<[T; N], A> { + /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. + /// + /// # Panics + /// + /// Panics if the length of the resulting vector would overflow a `usize`. + /// + /// This is only possible when flattening a vector of arrays of zero-sized + /// types, and thus tends to be irrelevant in practice. If + /// `size_of::() > 0`, this will never panic. + /// + /// # Examples + /// + /// ``` + /// #![feature(slice_flatten)] + /// + /// let mut vec = vec![[1, 2, 3], [4, 5, 6], [7, 8, 9]]; + /// assert_eq!(vec.pop(), Some([7, 8, 9])); + /// + /// let mut flattened = vec.into_flattened(); + /// assert_eq!(flattened.pop(), Some(6)); + /// ``` + #[unstable(feature = "slice_flatten", issue = "95629")] + pub fn into_flattened(self) -> Vec { + let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc(); + let (new_len, new_cap) = if mem::size_of::() == 0 { + (len.checked_mul(N).expect("vec len overflow"), usize::MAX) + } else { + // SAFETY: + // - `cap * N` cannot overflow because the allocation is already in + // the address space. + // - Each `[T; N]` has `N` valid elements, so there are `len * N` + // valid elements in the allocation. + unsafe { (len.unchecked_mul(N), cap.unchecked_mul(N)) } + }; + // SAFETY: + // - `ptr` was allocated by `self` + // - `ptr` is well-aligned because `[T; N]` has the same alignment as `T`. + // - `new_cap` refers to the same sized allocation as `cap` because + // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` + // - `len` <= `cap`, so `len * N` <= `cap * N`. + unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } + } +} + // This code generalizes `extend_with_{element,default}`. trait ExtendWith { fn next(&mut self) -> T; diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index abce47e5afe1a..16ceb8e373dcb 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -38,6 +38,7 @@ #![feature(const_str_from_utf8)] #![feature(nonnull_slice_from_raw_parts)] #![feature(panic_update_hook)] +#![feature(slice_flatten)] use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 19e39ebf910b5..bc1397146dda9 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -2408,3 +2408,10 @@ fn test_extend_from_within_panicing_clone() { assert_eq!(count.load(Ordering::SeqCst), 4); } + +#[test] +#[should_panic = "vec len overflow"] +fn test_into_flattened_size_overflow() { + let v = vec![[(); usize::MAX]; 2]; + let _ = v.into_flattened(); +} diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 77bf5f9dc34e3..e76c31635eae5 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3994,6 +3994,88 @@ impl [T] { } } +#[cfg(not(bootstrap))] +impl [[T; N]] { + /// Takes a `&[[T; N]]`, and flattens it to a `&[T]`. + /// + /// # Panics + /// + /// This panics if the length of the resulting slice would overflow a `usize`. + /// + /// This is only possible when flattening a slice of arrays of zero-sized + /// types, and thus tends to be irrelevant in practice. If + /// `size_of::() > 0`, this will never panic. + /// + /// # Examples + /// + /// ``` + /// #![feature(slice_flatten)] + /// + /// assert_eq!([[1, 2, 3], [4, 5, 6]].flatten(), &[1, 2, 3, 4, 5, 6]); + /// + /// assert_eq!( + /// [[1, 2, 3], [4, 5, 6]].flatten(), + /// [[1, 2], [3, 4], [5, 6]].flatten(), + /// ); + /// + /// let slice_of_empty_arrays: &[[i32; 0]] = &[[], [], [], [], []]; + /// assert!(slice_of_empty_arrays.flatten().is_empty()); + /// + /// let empty_slice_of_arrays: &[[u32; 10]] = &[]; + /// assert!(empty_slice_of_arrays.flatten().is_empty()); + /// ``` + #[unstable(feature = "slice_flatten", issue = "95629")] + pub fn flatten(&self) -> &[T] { + let len = if crate::mem::size_of::() == 0 { + self.len().checked_mul(N).expect("slice len overflow") + } else { + // SAFETY: `self.len() * N` cannot overflow because `self` is + // already in the address space. + unsafe { self.len().unchecked_mul(N) } + }; + // SAFETY: `[T]` is layout-identical to `[T; N]` + unsafe { from_raw_parts(self.as_ptr().cast(), len) } + } + + /// Takes a `&mut [[T; N]]`, and flattens it to a `&mut [T]`. + /// + /// # Panics + /// + /// This panics if the length of the resulting slice would overflow a `usize`. + /// + /// This is only possible when flattening a slice of arrays of zero-sized + /// types, and thus tends to be irrelevant in practice. If + /// `size_of::() > 0`, this will never panic. + /// + /// # Examples + /// + /// ``` + /// #![feature(slice_flatten)] + /// + /// fn add_5_to_all(slice: &mut [i32]) { + /// for i in slice { + /// *i += 5; + /// } + /// } + /// + /// let mut array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; + /// add_5_to_all(array.flatten_mut()); + /// assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]); + /// ``` + #[unstable(feature = "slice_flatten", issue = "95629")] + pub fn flatten_mut(&mut self) -> &mut [T] { + let len = if crate::mem::size_of::() == 0 { + self.len().checked_mul(N).expect("slice len overflow") + } else { + // SAFETY: `self.len() * N` cannot overflow because `self` is + // already in the address space. + unsafe { self.len().unchecked_mul(N) } + }; + // SAFETY: `[T]` is layout-identical to `[T; N]` + unsafe { from_raw_parts_mut(self.as_mut_ptr().cast(), len) } + } +} + trait CloneFromSpec { fn spec_clone_from(&mut self, src: &[T]); } diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 5f90a76ab74ee..e995565529584 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -93,6 +93,7 @@ #![feature(const_array_from_ref)] #![feature(const_slice_from_ref)] #![feature(waker_getters)] +#![feature(slice_flatten)] #![deny(unsafe_op_in_unsafe_fn)] extern crate test; diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 798fcc3dfde97..ada479147db95 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -2504,3 +2504,19 @@ fn test_slice_from_ptr_range() { assert_eq!(slice::from_ptr_range(range), &arr); } } + +#[test] +#[cfg(not(bootstrap))] +#[should_panic = "slice len overflow"] +fn test_flatten_size_overflow() { + let x = &[[(); usize::MAX]; 2][..]; + let _ = x.flatten(); +} + +#[test] +#[cfg(not(bootstrap))] +#[should_panic = "slice len overflow"] +fn test_flatten_mut_size_overflow() { + let x = &mut [[(); usize::MAX]; 2][..]; + let _ = x.flatten_mut(); +}