From a15cb49362971a360c5fd0ad88e7add3bd9ac5d6 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Tue, 14 Dec 2021 21:49:49 +0000 Subject: [PATCH 01/15] #91836: Clarify error on casting larger integers to char --- compiler/rustc_error_codes/src/error_codes/E0604.md | 11 ++++++++--- compiler/rustc_typeck/src/check/cast.rs | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0604.md b/compiler/rustc_error_codes/src/error_codes/E0604.md index adbf76509ed48..806f0001c60fd 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0604.md +++ b/compiler/rustc_error_codes/src/error_codes/E0604.md @@ -6,11 +6,16 @@ Erroneous code example: 0u32 as char; // error: only `u8` can be cast as `char`, not `u32` ``` -As the error message indicates, only `u8` can be cast into `char`. Example: +`char` is a Unicode Scalar Value, an integer value from 0 to 0xD7FF and +0xE000 to 0x10FFFF. (The gap is for surrogate pairs.) Only `u8` always fits in +those ranges so only `u8` may be cast to `char`. + +To allow larger values, use `char::from_u32`, which checks the value is valid. ``` -let c = 86u8 as char; // ok! -assert_eq!(c, 'V'); +assert_eq!(86u8 as char, 'V'); // ok! +assert_eq!(char::from_u32(0x3B1), Some('α')); // ok! +assert_eq!(char::from_u32(0xD800), None); // not a USV. ``` For more information about casts, take a look at the Type cast section in diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index a397ee771af59..f6b5e0084d186 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -337,6 +337,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { self.expr_ty ) .span_label(self.span, "invalid cast") + .span_help(self.span, "try `char::from_u32` instead") .emit(); } CastError::NonScalar => { From badb81a6129b84a9f01223ab73a56ffe52bf33ce Mon Sep 17 00:00:00 2001 From: George Bateman Date: Tue, 25 Jan 2022 23:19:00 +0000 Subject: [PATCH 02/15] #91939: integer to char cast error, make more targeted --- compiler/rustc_typeck/src/check/cast.rs | 21 ++++++++++++++----- .../const-eval/const-eval-overflow-4b.stderr | 6 ++++++ src/test/ui/error-codes/E0604.stderr | 6 ++++++ src/test/ui/error-festival.stderr | 6 ++++++ .../ui/mismatched_types/cast-rfc0401.stderr | 6 ++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index f6b5e0084d186..be0b7733579b5 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -328,17 +328,28 @@ impl<'a, 'tcx> CastCheck<'tcx> { err.emit(); } CastError::CastToChar => { - type_error_struct!( + let mut err = type_error_struct!( fcx.tcx.sess, self.span, self.expr_ty, E0604, "only `u8` can be cast as `char`, not `{}`", self.expr_ty - ) - .span_label(self.span, "invalid cast") - .span_help(self.span, "try `char::from_u32` instead") - .emit(); + ); + err.span_label(self.span, "invalid cast"); + if self.expr_ty.is_numeric() { + err.span_help( + self.span, + if self.expr_ty == fcx.tcx.types.i8 { + "try casting from `u8` instead" + } else if self.expr_ty == fcx.tcx.types.u32 { + "try `char::from_u32` instead" + } else { + "try `char::from_u32` instead (via a `u32`)" + }, + ); + } + err.emit(); } CastError::NonScalar => { let mut err = type_error_struct!( diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr index 1e181c465dba7..f59ff329d18ac 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr @@ -17,6 +17,12 @@ error[E0604]: only `u8` can be cast as `char`, not `i8` | LL | : [u32; 5i8 as char as usize] | ^^^^^^^^^^^ invalid cast + | +help: try casting from `u8` instead + --> $DIR/const-eval-overflow-4b.rs:22:13 + | +LL | : [u32; 5i8 as char as usize] + | ^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/error-codes/E0604.stderr b/src/test/ui/error-codes/E0604.stderr index 18835310bd5e8..d715d28b73c01 100644 --- a/src/test/ui/error-codes/E0604.stderr +++ b/src/test/ui/error-codes/E0604.stderr @@ -3,6 +3,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32` | LL | 1u32 as char; | ^^^^^^^^^^^^ invalid cast + | +help: try `char::from_u32` instead + --> $DIR/E0604.rs:2:5 + | +LL | 1u32 as char; + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/error-festival.stderr b/src/test/ui/error-festival.stderr index b8cd7b7464ae3..0ddb6fc99b004 100644 --- a/src/test/ui/error-festival.stderr +++ b/src/test/ui/error-festival.stderr @@ -58,6 +58,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32` | LL | 0u32 as char; | ^^^^^^^^^^^^ invalid cast + | +help: try `char::from_u32` instead + --> $DIR/error-festival.rs:25:5 + | +LL | 0u32 as char; + | ^^^^^^^^^^^^ error[E0605]: non-primitive cast: `u8` as `Vec` --> $DIR/error-festival.rs:29:5 diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index 7f91d5ed42ce4..6dbf24baf2315 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -99,6 +99,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32` | LL | let _ = 0x61u32 as char; | ^^^^^^^^^^^^^^^ invalid cast + | +help: try `char::from_u32` instead + --> $DIR/cast-rfc0401.rs:41:13 + | +LL | let _ = 0x61u32 as char; + | ^^^^^^^^^^^^^^^ error[E0606]: casting `bool` as `f32` is invalid --> $DIR/cast-rfc0401.rs:43:13 From 91fcbfa2373ecbec6511b7fddca55a420288d8d5 Mon Sep 17 00:00:00 2001 From: Donald Hoskins Date: Mon, 31 Jan 2022 03:03:06 -0500 Subject: [PATCH 03/15] [mips64-openwrt-musl] Tier 3 tuple for Mips64 OpenWrt This incorporates rust-lang into the OpenWrt build system for Mips64 targets. Signed-off-by: Donald Hoskins --- .../src/spec/mips64_openwrt_linux_musl.rs | 26 +++++++++++++++++ compiler/rustc_target/src/spec/mod.rs | 2 ++ src/doc/rustc/src/platform-support.md | 1 + .../mips64-openwrt-linux-musl.md | 28 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs create mode 100644 src/doc/rustc/src/platform-support/mips64-openwrt-linux-musl.md diff --git a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs new file mode 100644 index 0000000000000..1199ed44202f9 --- /dev/null +++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs @@ -0,0 +1,26 @@ +/// A target tuple for OpenWrt MIPS64 targets +/// +use crate::abi::Endian; +use crate::spec::{Target, TargetOptions}; + +pub fn target() -> Target { + let mut base = super::linux_musl_base::opts(); + base.cpu = "mips64r2".to_string(); + base.features = "+mips64r2".to_string(); + base.max_atomic_width = Some(64); + base.crt_static_default = false; + + Target { + // LLVM doesn't recognize "muslabi64" yet. + llvm_target: "mips64-unknown-linux-musl".to_string(), + pointer_width: 64, + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), + arch: "mips64".to_string(), + options: TargetOptions { + abi: "abi64".to_string(), + endian: Endian::Big, + mcount: "_mcount".to_string(), + ..base + }, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4effb8bacf6d6..f17c0ec248d12 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1016,6 +1016,8 @@ supported_targets! { ("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf), ("x86_64-unknown-none", x86_64_unknown_none), + + ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl), } /// Warnings encountered when parsing the target `json`. diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index a31e08f0d12a6..bbcd6fb0998ea 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -244,6 +244,7 @@ target | std | host | notes `i686-wrs-vxworks` | ? | | `m68k-unknown-linux-gnu` | ? | | Motorola 680x0 Linux `mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc +`mips64-openwrt-linux-musl` | ? | | MIPS64 for OpenWrt Linux MUSL `mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP) `mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc `mipsel-unknown-none` | * | | Bare MIPS (LE) softfloat diff --git a/src/doc/rustc/src/platform-support/mips64-openwrt-linux-musl.md b/src/doc/rustc/src/platform-support/mips64-openwrt-linux-musl.md new file mode 100644 index 0000000000000..07470eef051d8 --- /dev/null +++ b/src/doc/rustc/src/platform-support/mips64-openwrt-linux-musl.md @@ -0,0 +1,28 @@ +# `mips64-openwrt-linux-musl` +**Tier: 3** + +## Target maintainers +- Donald Hoskins `grommish@gmail.com`, https://github.com/Itus-Shield + +## Requirements +This target is cross-compiled. There is no support for `std`. There is no +default allocator, but it's possible to use `alloc` by supplying an allocator. + +By default, Rust code generated for this target uses `-msoft-float` and is +dynamically linked. + +This target generated binaries in the ELF format. + +## Building the target +This target is built exclusively within the `OpenWrt` build system via +the `rust-lang` HOST package + +## 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). + +## Testing +As `mips64-openwrt-linux-musl` supports a variety of different environments and does +not support `std`, this target does not support running the Rust testsuite at this +time. From 73d0f7c7b68784f1db0a1f53855c20d118a7e8b0 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 7 Jan 2022 12:39:56 -0500 Subject: [PATCH 04/15] Remove "up here" arrow on item-infos Use spacing to distinguish what is related to a given heading. --- src/librustdoc/html/static/css/rustdoc.css | 44 ++++++++++--------- src/test/rustdoc-gui/hash-item-expansion.goml | 4 -- src/test/rustdoc-gui/item-info-width.goml | 3 +- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 76913a5c1c5b5..e2271ce32e025 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -175,11 +175,13 @@ h3.code-header { h4.code-header { font-size: 1rem; } -h3.code-header, h4.code-header { +.code-header { font-weight: 600; border-bottom-style: none; - padding: 0; margin: 0; + padding: 0; + margin-top: 0.6em; + margin-bottom: 0.4em; } .impl, .impl-items .method, @@ -192,8 +194,6 @@ h3.code-header, h4.code-header { .methods .associatedtype { flex-basis: 100%; font-weight: 600; - margin-top: 16px; - margin-bottom: 10px; position: relative; } @@ -744,21 +744,13 @@ nav.sub { .content .item-info { position: relative; - margin-left: 33px; + margin-left: 24px; } .sub-variant > div > .item-info { margin-top: initial; } -.content .item-info::before { - content: '⬑'; - font-size: 1.5625rem; - position: absolute; - top: -6px; - left: -19px; -} - .content .impl-items .docblock, .content .impl-items .item-info { margin-bottom: .6em; } @@ -777,6 +769,7 @@ nav.sub { #main-content > .item-info { margin-top: 0; + margin-left: 0; } nav.sub { @@ -1125,13 +1118,6 @@ body.blur > :not(#help) { float: right; } -.has-srclink { - font-size: 1rem; - margin-bottom: 12px; - /* Push the src link out to the right edge consistently */ - justify-content: space-between; -} - .variants_table { width: 100%; } @@ -2065,6 +2051,24 @@ details.rustdoc-toggle[open] > summary.hideme::after { } } +.method-toggle summary, +.implementors-toggle summary { + margin-bottom: 0.75em; +} + +.method-toggle[open] { + margin-bottom: 2em; +} + +.implementors-toggle[open] { + margin-bottom: 2em; +} + +#trait-implementations-list .method-toggle, +#synthetic-implementations-list .method-toggle, +#blanket-implementations-list .method-toggle { + margin-bottom: 1em; +} /* Begin: styles for --scrape-examples feature */ diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml index 42bc1c1002005..2885978ce1f21 100644 --- a/src/test/rustdoc-gui/hash-item-expansion.goml +++ b/src/test/rustdoc-gui/hash-item-expansion.goml @@ -4,10 +4,6 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow assert-attribute: ("#blanket-implementations-list > details:nth-child(2)", {"open": ""}) // We first check that the impl block is open by default. assert-attribute: ("#implementations + details", {"open": ""}) -// We collapse it. -click: "#implementations + details > summary" -// We check that it was collapsed as expected. -assert-attribute-false: ("#implementations + details", {"open": ""}) // To ensure that we will click on the currently hidden method. assert-text: (".sidebar-links > a", "must_use") click: ".sidebar-links > a" diff --git a/src/test/rustdoc-gui/item-info-width.goml b/src/test/rustdoc-gui/item-info-width.goml index acb30141ce577..1c4cf4ddf87f3 100644 --- a/src/test/rustdoc-gui/item-info-width.goml +++ b/src/test/rustdoc-gui/item-info-width.goml @@ -3,5 +3,6 @@ goto: file://|DOC_PATH|/lib2/struct.Foo.html // We set a fixed size so there is no chance of "random" resize. size: (1100, 800) // We check that ".item-info" is bigger than its content. -assert-css: (".item-info", {"width": "757px"}) +assert-css: (".item-info", {"width": "790px"}) assert-css: (".item-info .stab", {"width": "341px"}) +assert-position: (".item-info .stab", {"x": 295}) From 0b7e1baa58dea7cfb1170a361e12c3dec8e76840 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jan 2022 13:13:13 -0800 Subject: [PATCH 05/15] Add trailing comma support --- compiler/rustc_ast_pretty/src/pp.rs | 12 ++++++---- .../rustc_ast_pretty/src/pp/convenience.rs | 22 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index d567c8dae43a4..2433b8fb74fd0 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -148,7 +148,7 @@ pub enum Breaks { Inconsistent, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] enum IndentStyle { /// Vertically aligned under whatever column this block begins at. /// @@ -164,19 +164,20 @@ enum IndentStyle { Block { offset: isize }, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default, PartialEq)] pub struct BreakToken { offset: isize, blank_space: isize, + pre_break: Option, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub struct BeginToken { indent: IndentStyle, breaks: Breaks, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub enum Token { // In practice a string token contains either a `&'static str` or a // `String`. `Cow` is overkill for this because we never modify the data, @@ -415,6 +416,9 @@ impl Printer { self.pending_indentation += token.blank_space; self.space -= token.blank_space; } else { + if let Some(pre_break) = token.pre_break { + self.out.push(pre_break); + } self.out.push('\n'); let indent = self.indent as isize + token.offset; self.pending_indentation = indent; diff --git a/compiler/rustc_ast_pretty/src/pp/convenience.rs b/compiler/rustc_ast_pretty/src/pp/convenience.rs index 1b9ac705883af..b9bfafa52ae13 100644 --- a/compiler/rustc_ast_pretty/src/pp/convenience.rs +++ b/compiler/rustc_ast_pretty/src/pp/convenience.rs @@ -25,7 +25,11 @@ impl Printer { } pub fn break_offset(&mut self, n: usize, off: isize) { - self.scan_break(BreakToken { offset: off, blank_space: n as isize }) + self.scan_break(BreakToken { + offset: off, + blank_space: n as isize, + ..BreakToken::default() + }); } pub fn end(&mut self) { @@ -66,12 +70,24 @@ impl Printer { } pub fn hardbreak_tok_offset(off: isize) -> Token { - Token::Break(BreakToken { offset: off, blank_space: SIZE_INFINITY }) + Token::Break(BreakToken { + offset: off, + blank_space: SIZE_INFINITY, + ..BreakToken::default() + }) + } + + pub fn trailing_comma(&mut self) { + self.scan_break(BreakToken { + blank_space: 1, + pre_break: Some(','), + ..BreakToken::default() + }); } } impl Token { pub fn is_hardbreak_tok(&self) -> bool { - matches!(self, Token::Break(BreakToken { offset: 0, blank_space: SIZE_INFINITY })) + *self == Printer::hardbreak_tok_offset(0) } } From 8bdf08fbed2fba60e41dadb3be9714b4c0441f72 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jan 2022 14:15:14 -0800 Subject: [PATCH 06/15] Change pp indent to signed to allow negative indents --- compiler/rustc_ast_pretty/src/pp.rs | 4 +++- compiler/rustc_ast_pretty/src/pp/convenience.rs | 11 ++++------- compiler/rustc_ast_pretty/src/pprust/state.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index 2433b8fb74fd0..7f03f98f1a29e 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -392,7 +392,9 @@ impl Printer { if size > self.space { self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks }); self.indent = match token.indent { - IndentStyle::Block { offset } => (self.indent as isize + offset) as usize, + IndentStyle::Block { offset } => { + usize::try_from(self.indent as isize + offset).unwrap() + } IndentStyle::Visual => (MARGIN - self.space) as usize, }; } else { diff --git a/compiler/rustc_ast_pretty/src/pp/convenience.rs b/compiler/rustc_ast_pretty/src/pp/convenience.rs index b9bfafa52ae13..785e6886d8a38 100644 --- a/compiler/rustc_ast_pretty/src/pp/convenience.rs +++ b/compiler/rustc_ast_pretty/src/pp/convenience.rs @@ -3,20 +3,17 @@ use std::borrow::Cow; impl Printer { /// "raw box" - pub fn rbox(&mut self, indent: usize, breaks: Breaks) { - self.scan_begin(BeginToken { - indent: IndentStyle::Block { offset: indent as isize }, - breaks, - }) + pub fn rbox(&mut self, indent: isize, breaks: Breaks) { + self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks }) } /// Inconsistent breaking box - pub fn ibox(&mut self, indent: usize) { + pub fn ibox(&mut self, indent: isize) { self.rbox(indent, Breaks::Inconsistent) } /// Consistent breaking box - pub fn cbox(&mut self, indent: usize) { + pub fn cbox(&mut self, indent: isize) { self.rbox(indent, Breaks::Consistent) } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b575dc2196133..e88d37ec102dc 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -92,7 +92,7 @@ pub struct State<'a> { ann: &'a (dyn PpAnn + 'a), } -crate const INDENT_UNIT: usize = 4; +crate const INDENT_UNIT: isize = 4; /// Requires you to pass an input filename and reader so that /// it can scan the input text for comments to copy forward. diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index a47ebaf1237a1..13008a8337979 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -139,7 +139,7 @@ impl<'a> PrintState<'a> for State<'a> { } } -pub const INDENT_UNIT: usize = 4; +pub const INDENT_UNIT: isize = 4; /// Requires you to pass an input filename and reader so that /// it can scan the input text for comments to copy forward. From 63406ac771c08597c870cc7b01ca8d8098ea3a2b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jan 2022 14:20:17 -0800 Subject: [PATCH 07/15] Support offsetting the most recent break --- compiler/rustc_ast_pretty/src/pp.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index 7f03f98f1a29e..ddce86f216538 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -314,6 +314,12 @@ impl Printer { } } + pub fn offset(&mut self, offset: isize) { + if let Some(BufEntry { token: Token::Break(token), .. }) = &mut self.buf.last_mut() { + token.offset += offset; + } + } + fn check_stream(&mut self) { while self.right_total - self.left_total > self.space { if *self.scan_stack.front().unwrap() == self.buf.index_of_first() { From 40fcbbafa096944a60169fc8a2f65ba4ab6cadf8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jan 2022 13:36:08 -0800 Subject: [PATCH 08/15] Change struct expr pretty printing to match rustfmt style --- compiler/rustc_ast_pretty/src/pprust/state.rs | 3 + .../src/pprust/state/delimited.rs | 41 +++++++++++ .../rustc_ast_pretty/src/pprust/state/expr.rs | 70 +++++++++++-------- 3 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 compiler/rustc_ast_pretty/src/pprust/state/delimited.rs diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index e88d37ec102dc..b2c62383fb69a 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1,3 +1,4 @@ +mod delimited; mod expr; mod item; @@ -23,6 +24,8 @@ use rustc_span::{BytePos, FileName, Span}; use std::borrow::Cow; +pub use self::delimited::IterDelimited; + pub enum MacHeader<'a> { Path(&'a ast::Path), Keyword(&'static str), diff --git a/compiler/rustc_ast_pretty/src/pprust/state/delimited.rs b/compiler/rustc_ast_pretty/src/pprust/state/delimited.rs new file mode 100644 index 0000000000000..fe0640baaa1b0 --- /dev/null +++ b/compiler/rustc_ast_pretty/src/pprust/state/delimited.rs @@ -0,0 +1,41 @@ +use std::iter::Peekable; +use std::mem; +use std::ops::Deref; + +pub struct Delimited { + is_first: bool, + iter: Peekable, +} + +pub trait IterDelimited: Iterator + Sized { + fn delimited(self) -> Delimited { + Delimited { is_first: true, iter: self.peekable() } + } +} + +impl IterDelimited for I {} + +pub struct IteratorItem { + value: T, + pub is_first: bool, + pub is_last: bool, +} + +impl Iterator for Delimited { + type Item = IteratorItem; + + fn next(&mut self) -> Option { + let value = self.iter.next()?; + let is_first = mem::replace(&mut self.is_first, false); + let is_last = self.iter.peek().is_none(); + Some(IteratorItem { value, is_first, is_last }) + } +} + +impl Deref for IteratorItem { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.value + } +} diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 6a5bba30b8bca..44116fa76a0c1 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -1,5 +1,5 @@ -use crate::pp::Breaks::{Consistent, Inconsistent}; -use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT}; +use crate::pp::Breaks::Inconsistent; +use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT}; use rustc_ast::ptr::P; use rustc_ast::util::parser::{self, AssocOp, Fixity}; @@ -117,38 +117,46 @@ impl<'a> State<'a> { } else { self.print_path(path, true, 0); } + self.nbsp(); self.word("{"); - self.commasep_cmnt( - Consistent, - fields, - |s, field| { - s.print_outer_attributes(&field.attrs); - s.ibox(INDENT_UNIT); - if !field.is_shorthand { - s.print_ident(field.ident); - s.word_space(":"); - } - s.print_expr(&field.expr); - s.end(); - }, - |f| f.span, - ); - match rest { - ast::StructRest::Base(_) | ast::StructRest::Rest(_) => { - self.ibox(INDENT_UNIT); - if !fields.is_empty() { - self.word(","); - self.space(); - } - self.word(".."); - if let ast::StructRest::Base(ref expr) = *rest { - self.print_expr(expr); - } - self.end(); + let has_rest = match rest { + ast::StructRest::Base(_) | ast::StructRest::Rest(_) => true, + ast::StructRest::None => false, + }; + if fields.is_empty() && !has_rest { + self.word("}"); + return; + } + self.cbox(0); + for field in fields.iter().delimited() { + self.maybe_print_comment(field.span.hi()); + self.print_outer_attributes(&field.attrs); + if field.is_first { + self.space_if_not_bol(); + } + if !field.is_shorthand { + self.print_ident(field.ident); + self.word_nbsp(":"); + } + self.print_expr(&field.expr); + if !field.is_last || has_rest { + self.word_space(","); + } else { + self.trailing_comma(); } - ast::StructRest::None if !fields.is_empty() => self.word(","), - _ => {} } + if has_rest { + if fields.is_empty() { + self.space(); + } + self.word(".."); + if let ast::StructRest::Base(expr) = rest { + self.print_expr(expr); + } + self.space(); + } + self.offset(-INDENT_UNIT); + self.end(); self.word("}"); } From ca3057fd5595667d6eeb703b9ab80dbe73e8841c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jan 2022 18:10:12 -0800 Subject: [PATCH 09/15] Bless all pretty printer tests and ui tests --- src/test/pretty/ast-stmt-expr-attr.rs | 6 +++--- .../issue-68710-field-attr-proc-mac-lost.rs | 5 +++-- src/test/pretty/stmt_expr_attributes.rs | 12 +++++------ src/test/ui/macros/stringify.rs | 20 +++++++++---------- .../dbg-macro-expected-behavior.run.stderr | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/test/pretty/ast-stmt-expr-attr.rs b/src/test/pretty/ast-stmt-expr-attr.rs index 2404b32194289..27c86ec22b84e 100644 --- a/src/test/pretty/ast-stmt-expr-attr.rs +++ b/src/test/pretty/ast-stmt-expr-attr.rs @@ -119,9 +119,9 @@ fn syntax() { let _ = #[attr] foo![#! [attr]]; let _ = #[attr] foo! {}; let _ = #[attr] foo! { #! [attr] }; - let _ = #[attr] Foo{bar: baz,}; - let _ = #[attr] Foo{..foo}; - let _ = #[attr] Foo{bar: baz, ..foo}; + let _ = #[attr] Foo { bar: baz }; + let _ = #[attr] Foo { ..foo }; + let _ = #[attr] Foo { bar: baz, ..foo }; let _ = #[attr] (0); { diff --git a/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs b/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs index 87f525a6178e6..80f739f4f9e1a 100644 --- a/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs +++ b/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs @@ -8,9 +8,10 @@ struct C { #[allow()] const C: C = - C{ + C { #[cfg(debug_assertions)] field: 0, #[cfg(not(debug_assertions))] - field: 1,}; + field: 1, + }; diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs index 96bde96200af9..7ab22f1960c2d 100644 --- a/src/test/pretty/stmt_expr_attributes.rs +++ b/src/test/pretty/stmt_expr_attributes.rs @@ -90,9 +90,9 @@ struct Bar(()); fn _7() { #[rustc_dummy] - Foo{data: (),}; + Foo { data: () }; - let _ = #[rustc_dummy] Foo{data: (),}; + let _ = #[rustc_dummy] Foo { data: () }; } fn _8() { @@ -209,7 +209,7 @@ fn _11() { let mut x = 0; let _ = #[rustc_dummy] x = 15; let _ = #[rustc_dummy] x += 15; - let s = Foo{data: (),}; + let s = Foo { data: () }; let _ = #[rustc_dummy] s.data; let _ = (#[rustc_dummy] s).data; let t = Bar(()); @@ -235,9 +235,9 @@ fn _11() { let _ = #[rustc_dummy] expr_mac!(); let _ = #[rustc_dummy] expr_mac![]; let _ = #[rustc_dummy] expr_mac! {}; - let _ = #[rustc_dummy] Foo{data: (),}; - let _ = #[rustc_dummy] Foo{..s}; - let _ = #[rustc_dummy] Foo{data: (), ..s}; + let _ = #[rustc_dummy] Foo { data: () }; + let _ = #[rustc_dummy] Foo { ..s }; + let _ = #[rustc_dummy] Foo { data: (), ..s }; let _ = #[rustc_dummy] (0); } diff --git a/src/test/ui/macros/stringify.rs b/src/test/ui/macros/stringify.rs index 004ab386b3ff0..57e5ab42f79d3 100644 --- a/src/test/ui/macros/stringify.rs +++ b/src/test/ui/macros/stringify.rs @@ -315,17 +315,17 @@ fn test_expr() { assert_eq!(stringify_expr!(mac! { ... }), "mac! { ... }"); // ExprKind::Struct - assert_eq!(stringify_expr!(Struct {}), "Struct{}"); // FIXME + assert_eq!(stringify_expr!(Struct {}), "Struct {}"); #[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5151 - assert_eq!(stringify_expr!(::Type {}), "::Type{}"); - assert_eq!(stringify_expr!(Struct { .. }), "Struct{..}"); // FIXME - assert_eq!(stringify_expr!(Struct { ..base }), "Struct{..base}"); // FIXME - assert_eq!(stringify_expr!(Struct { x }), "Struct{x,}"); - assert_eq!(stringify_expr!(Struct { x, .. }), "Struct{x, ..}"); - assert_eq!(stringify_expr!(Struct { x, ..base }), "Struct{x, ..base}"); - assert_eq!(stringify_expr!(Struct { x: true }), "Struct{x: true,}"); - assert_eq!(stringify_expr!(Struct { x: true, .. }), "Struct{x: true, ..}"); - assert_eq!(stringify_expr!(Struct { x: true, ..base }), "Struct{x: true, ..base}"); + assert_eq!(stringify_expr!(::Type {}), "::Type {}"); + assert_eq!(stringify_expr!(Struct { .. }), "Struct { .. }"); + assert_eq!(stringify_expr!(Struct { ..base }), "Struct { ..base }"); + assert_eq!(stringify_expr!(Struct { x }), "Struct { x }"); + assert_eq!(stringify_expr!(Struct { x, .. }), "Struct { x, .. }"); + assert_eq!(stringify_expr!(Struct { x, ..base }), "Struct { x, ..base }"); + assert_eq!(stringify_expr!(Struct { x: true }), "Struct { x: true }"); + assert_eq!(stringify_expr!(Struct { x: true, .. }), "Struct { x: true, .. }"); + assert_eq!(stringify_expr!(Struct { x: true, ..base }), "Struct { x: true, ..base }"); // ExprKind::Repeat assert_eq!(stringify_expr!([(); 0]), "[(); 0]"); diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr index 707b38cf37af0..49d72158e92ba 100644 --- a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr @@ -1,6 +1,6 @@ [$DIR/dbg-macro-expected-behavior.rs:20] Unit = Unit [$DIR/dbg-macro-expected-behavior.rs:21] a = Unit -[$DIR/dbg-macro-expected-behavior.rs:27] Point{x: 42, y: 24,} = Point { +[$DIR/dbg-macro-expected-behavior.rs:27] Point { x: 42, y: 24 } = Point { x: 42, y: 24, } From 8e99d92f4ecaf7c6d8deae4461d4781c4194bf24 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 4 Feb 2022 17:11:51 +0300 Subject: [PATCH 10/15] Add regression tests for issue 80309 --- src/test/ui/ptr_ops/issue-80309-safe.rs | 16 ++++++++++++++++ src/test/ui/ptr_ops/issue-80309.rs | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/ui/ptr_ops/issue-80309-safe.rs create mode 100644 src/test/ui/ptr_ops/issue-80309.rs diff --git a/src/test/ui/ptr_ops/issue-80309-safe.rs b/src/test/ui/ptr_ops/issue-80309-safe.rs new file mode 100644 index 0000000000000..16c2580303776 --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309-safe.rs @@ -0,0 +1,16 @@ +// run-pass +// compiler-flags: -O + +// Regression test for issue #80309 + +pub fn zero(x: usize) -> usize { + std::ptr::null::().wrapping_add(x) as usize - x +} +pub fn qux(x: &[i8]) -> i8 { + x[zero(x.as_ptr() as usize)] +} + +fn main() { + let z = vec![42, 43]; + println!("{}", qux(&z)); +} diff --git a/src/test/ui/ptr_ops/issue-80309.rs b/src/test/ui/ptr_ops/issue-80309.rs new file mode 100644 index 0000000000000..191ae5f42d231 --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309.rs @@ -0,0 +1,13 @@ +// run-pass +// compiler-flags: -O + +// Regression test for issue #80309 + +pub unsafe fn foo(x: *const i8) -> i8 { + *x.wrapping_sub(x as _).wrapping_add(x as _) +} + +fn main() { + let x = 42; + println!("{}", unsafe { foo(&x) }); +} From a3b1bc13882197900f4a6858c465f67ffb75f1fe Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 4 Feb 2022 21:18:56 +0300 Subject: [PATCH 11/15] Specify min llvm version for issue 80309 regression tests --- src/test/ui/ptr_ops/issue-80309-safe.rs | 1 + src/test/ui/ptr_ops/issue-80309.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/test/ui/ptr_ops/issue-80309-safe.rs b/src/test/ui/ptr_ops/issue-80309-safe.rs index 16c2580303776..ca3778aab2da3 100644 --- a/src/test/ui/ptr_ops/issue-80309-safe.rs +++ b/src/test/ui/ptr_ops/issue-80309-safe.rs @@ -1,4 +1,5 @@ // run-pass +// min-llvm-version: 13.0 // compiler-flags: -O // Regression test for issue #80309 diff --git a/src/test/ui/ptr_ops/issue-80309.rs b/src/test/ui/ptr_ops/issue-80309.rs index 191ae5f42d231..bbec1012082c3 100644 --- a/src/test/ui/ptr_ops/issue-80309.rs +++ b/src/test/ui/ptr_ops/issue-80309.rs @@ -1,4 +1,5 @@ // run-pass +// min-llvm-version: 13.0 // compiler-flags: -O // Regression test for issue #80309 From 6756ff9316008f04c339a8b024656195534b6937 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 4 Feb 2022 13:44:24 -0500 Subject: [PATCH 12/15] Update CPU idle tracking for apple hosts The previous setup did not properly consider hyperthreads (at least in local testing), which likely skews CI results as well. The new code is both simpler and hopefully will produce more accurate results. --- src/ci/cpu-usage-over-time.py | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ci/cpu-usage-over-time.py b/src/ci/cpu-usage-over-time.py index 267c3964d0d69..adfd895ead04e 100644 --- a/src/ci/cpu-usage-over-time.py +++ b/src/ci/cpu-usage-over-time.py @@ -108,37 +108,37 @@ def idle_since(self, prev): from ctypes import * libc = cdll.LoadLibrary('/usr/lib/libc.dylib') - PROESSOR_CPU_LOAD_INFO = c_int(2) + class host_cpu_load_info_data_t(Structure): + _fields_ = [("cpu_ticks", c_uint * 4)] + + host_statistics = libc.host_statistics + host_statistics.argtypes = [ + c_uint, + c_int, + POINTER(host_cpu_load_info_data_t), + POINTER(c_int) + ] + host_statistics.restype = c_int + CPU_STATE_USER = 0 CPU_STATE_SYSTEM = 1 CPU_STATE_IDLE = 2 CPU_STATE_NICE = 3 - c_int_p = POINTER(c_int) - class State: def __init__(self): - num_cpus_u = c_uint(0) - cpu_info = c_int_p() - cpu_info_cnt = c_int(0) - err = libc.host_processor_info( + stats = host_cpu_load_info_data_t() + count = c_int(4) # HOST_CPU_LOAD_INFO_COUNT + err = libc.host_statistics( libc.mach_host_self(), - PROESSOR_CPU_LOAD_INFO, - byref(num_cpus_u), - byref(cpu_info), - byref(cpu_info_cnt), + c_int(3), # HOST_CPU_LOAD_INFO + byref(stats), + byref(count), ) assert err == 0 - self.user = 0 - self.system = 0 - self.idle = 0 - self.nice = 0 - cur = 0 - while cur < cpu_info_cnt.value: - self.user += cpu_info[cur + CPU_STATE_USER] - self.system += cpu_info[cur + CPU_STATE_SYSTEM] - self.idle += cpu_info[cur + CPU_STATE_IDLE] - self.nice += cpu_info[cur + CPU_STATE_NICE] - cur += num_cpus_u.value + self.system = stats.cpu_ticks[CPU_STATE_SYSTEM] + self.user = stats.cpu_ticks[CPU_STATE_USER] + self.idle = stats.cpu_ticks[CPU_STATE_IDLE] + self.nice = stats.cpu_ticks[CPU_STATE_NICE] def idle_since(self, prev): user = self.user - prev.user From 8c6f7fd5e1b6face1550249375743960cbde96f3 Mon Sep 17 00:00:00 2001 From: lancethepants Date: Tue, 1 Feb 2022 14:52:59 -0700 Subject: [PATCH 13/15] Add new target armv7-unknown-linux-uclibceabi (softfloat) --- .../spec/armv7_unknown_linux_uclibceabi.rs | 23 ++++ compiler/rustc_target/src/spec/mod.rs | 1 + src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 3 +- .../armv7-unknown-linux-uclibceabi.md | 121 ++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs create mode 100644 src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs new file mode 100644 index 0000000000000..7faa8ed7a800e --- /dev/null +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs @@ -0,0 +1,23 @@ +use crate::spec::{Target, TargetOptions}; + +// This target is for uclibc Linux on ARMv7 without NEON, +// thumb-mode or hardfloat. + +pub fn target() -> Target { + let base = super::linux_uclibc_base::opts(); + Target { + llvm_target: "armv7-unknown-linux-gnueabi".to_string(), + pointer_width: 32, + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + arch: "arm".to_string(), + + options: TargetOptions { + features: "+v7,+thumb2,+soft-float,-neon".to_string(), + cpu: "generic".to_string(), + max_atomic_width: Some(64), + mcount: "_mcount".to_string(), + abi: "eabi".to_string(), + ..base + }, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4effb8bacf6d6..83b78f5b416cc 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1013,6 +1013,7 @@ supported_targets! { ("armv6k-nintendo-3ds", armv6k_nintendo_3ds), + ("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi), ("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf), ("x86_64-unknown-none", x86_64_unknown_none), diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 146408900ab24..8e0913d8659db 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -15,6 +15,7 @@ - [Platform Support](platform-support.md) - [Template for target-specific documentation](platform-support/TEMPLATE.md) - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) + - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) - [*-unknown-openbsd](platform-support/openbsd.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index a31e08f0d12a6..df1ab24535710 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -220,7 +220,8 @@ target | std | host | notes `armv6-unknown-netbsd-eabihf` | ? | | `armv6k-nintendo-3ds` | * | | ARMv6K Nintendo 3DS, Horizon (Requires devkitARM toolchain) `armv7-apple-ios` | ✓ | | ARMv7 iOS, Cortex-a8 -[`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | ARMv7 Linux uClibc +[`armv7-unknown-linux-uclibceabi`](platform-support/armv7-unknown-linux-uclibceabi.md) | ✓ | ✓ | ARMv7 Linux with uClibc, softfloat +[`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | ARMv7 Linux with uClibc, hardfloat `armv7-unknown-freebsd` | ✓ | ✓ | ARMv7 FreeBSD `armv7-unknown-netbsd-eabihf` | ✓ | ✓ | `armv7-wrs-vxworks-eabihf` | ? | | diff --git a/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md new file mode 100644 index 0000000000000..d58b857059589 --- /dev/null +++ b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md @@ -0,0 +1,121 @@ +# `armv7-unknown-linux-uclibceabi` + +**Tier: 3** + +This target supports ARMv7 softfloat CPUs and uses the uclibc-ng standard library. This is a common configuration on many consumer routers (e.g., Netgear R7000, Asus RT-AC68U). + +## Target maintainers + +* [@lancethepants](https://github.com/lancethepants) + +## Requirements + +This target is cross compiled, and requires a cross toolchain. + +This target supports host tools and std. + +## Building the target + +You will need to download or build a `'C'` cross toolchain that targets ARMv7 softfloat and that uses the uclibc-ng standard library. If your target hardware is something like a router or an embedded device, keep in mind that manufacturer supplied SDKs for this class of CPU could be outdated and potentially unsuitable for bootstrapping rust. + +[Here](https://github.com/lancethepants/tomatoware-toolchain) is a sample toolchain that is built using [buildroot](https://buildroot.org/). It uses modern toolchain components, older thus universal kernel headers (2.6.36.4), and is used for a project called [Tomatoware](https://github.com/lancethepants/tomatoware). This toolchain is patched so that its sysroot is located at /mmc (e.g., /mmc/bin, /mmc/lib, /mmc/include). This is useful in scenarios where the root filesystem is read-only but you are able attach external storage loaded with user applications. Tomatoware is an example of this that even allows you to run various compilers and developer tools natively on the target device. + +Utilizing the Tomatoware toolchain this target can be built for cross compilation and native compilation (host tools) with project + +[rust-bootstrap-armv7-unknown-linux-uclibceabi](https://github.com/lancethepants/rust-bootstrap-armv7-unknown-linux-uclibceabi). + + +Here is a sample config if using your own toolchain. + +```toml +[build] +build-stage = 2 +target = ["armv7-unknown-linux-uclibceabi"] + +[target.armv7-unknown-linux-uclibceabi] +cc = "/path/to/arm-unknown-linux-uclibcgnueabi-gcc" +cxx = "/path/to/arm-unknown-linux-uclibcgnueabi-g++" +ar = "path/to/arm-unknown-linux-uclibcgnueabi-ar" +ranlib = "path/to/arm-unknown-linux-uclibcgnueabi-" +linker = "/path/to/arm-unknown-linux-uclibcgnueabi-" +``` + +## Building Rust programs + +The following assumes you are using the Tomatoware toolchain and environment. Adapt if you are using your own toolchain. + +### Native compilation + +Since this target supports host tools, you can natively build rust applications directly on your target device. This can be convenient because it removes the complexities of cross compiling and you can immediately test and deploy your binaries. One downside is that compiling on your ARMv7 CPU will probably be much slower than cross compilation on your x86 machine. + +To setup native compilation: + +* Download Tomatoware to your device using the latest nightly release found [here](https://files.lancethepants.com/Tomatoware/Nightly/). +* Extract `tar zxvf arm-soft-mmc.tgz -C /mmc` +* Add `/mmc/bin:/mmc:sbin/` to your PATH, or `source /mmc/etc/profile` +* `apt update && apt install rust` + +If you bootstrap rust on your own using the project above, it will create a .deb file that you then can install with +```text +dpkg -i rust_1.xx.x-x_arm.deb +``` + +After completing these steps you can use rust normally in a native environment. + +### Cross Compilation + +To cross compile, you'll need to: + +* Build the rust cross toochain using [rust-bootstrap-armv7-unknown-linux-uclibceabi](https://github.com/lancethepants/rust-bootstrap-armv7-unknown-linux-uclibceabi) or your own built toolchain. +* Link your built toolchain with + + ```text + rustup toolchain link stage2 \ + ${HOME}/rust-bootstrap-armv7-unknown-linux-uclibceabi/src/rust/rust/build/x86_64-unknown-linux-gnu/stage2 + ``` +* Build with: + ```text + CC=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \ + CXX=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-g++ \ + AR=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-ar \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_LINKER=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_RUSTFLAGS='-Clink-arg=-s -Clink-arg=-Wl,--dynamic-linker=/mmc/lib/ld-uClibc.so.1 -Clink-arg=-Wl,-rpath,/mmc/lib' \ + cargo +stage2 build --target armv7-unknown-linux-uclibceabi --release + ``` +* Copy the binary to your target device and run. + +We specify `CC`, `CXX`, and `AR` because somtimes a project or a subproject requires the use of your `'C'` cross toolchain. Since Tomatoware has a modified sysroot we also pass via RUSTFLAGS the location of the dynamic-linker and rpath. + +### Test with QEMU + +To test a cross-compiled binary on your build system follow the instructions for `Cross Compilation`, install `qemu-arm-static`, and run with the following. +```text +CC=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \ +CXX=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-g++ \ +AR=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-ar \ +CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_LINKER=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \ +CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_RUNNER="qemu-arm-static -L /opt/tomatoware/arm-soft-mmc/arm-tomatoware-linux-uclibcgnueabi/sysroot/" \ +cargo +stage2 run --target armv7-unknown-linux-uclibceabi --release +``` +### Run in a chroot + +It's also possible to build in a chroot environment. This is a convenient way to work without needing to access the target hardware. + +To build the chroot: + +* `sudo debootstrap --arch armel bullseye $HOME/debian` +* `sudo chroot $HOME/debian/ /bin/bash` +* `mount proc /proc -t proc` +* `mount -t sysfs /sys sys/` +* `export PATH=/mmc/bin:/mmc/sbin:$PATH` + +From here you can setup your environment (e.g., add user, install wget). + +* Download Tomatoware to the chroot environment using the latest nightly release found [here](https://files.lancethepants.com/Tomatoware/Nightly/). +* Extract `tar zxvf arm-soft-mmc.tgz -C /mmc` +* Add `/mmc/bin:/mmc:sbin/` to your PATH, or `source /mmc/etc/profile` +* `sudo /mmc/bin/apt update && sudo /mmc/bin/apt install rust` + +After completing these steps you can use rust normally in a chroot environment. + +Remember when using `sudo` the root user's PATH could differ from your user's PATH. From ca4296dcfee60b456b21fed4d619a6ff21f35442 Mon Sep 17 00:00:00 2001 From: Eliaz Bobadilla Date: Fri, 4 Feb 2022 14:59:22 -0500 Subject: [PATCH 14/15] Refactor conditional --- src/librustdoc/html/static/js/search.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 8c832a222b74d..0aaa3b7c17902 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -587,11 +587,8 @@ window.initSearch = function(rawSearchIndex) { } function typePassesFilter(filter, type) { - // No filter - if (filter <= NO_TYPE_FILTER) return true; - - // Exact match - if (filter === type) return true; + // No filter or Exact mach + if (filter <= NO_TYPE_FILTER || filter === type) return true; // Match related items var name = itemTypes[type]; From bcf98841d47b23dfc4cc85568fcd8dbb79748965 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 4 Feb 2022 20:56:32 -0800 Subject: [PATCH 15/15] resolve lifetimes for const generic defaults --- compiler/rustc_resolve/src/late/lifetimes.rs | 5 ++++- src/test/ui/const-generics/issue-93647.rs | 6 ++++++ src/test/ui/const-generics/issue-93647.stderr | 9 +++++++++ .../outer-lifetime-in-const-generic-default.rs | 10 ++++++++++ .../outer-lifetime-in-const-generic-default.stderr | 11 +++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/const-generics/issue-93647.rs create mode 100644 src/test/ui/const-generics/issue-93647.stderr create mode 100644 src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs create mode 100644 src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 6ef85c426be70..f3d57139e0817 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1339,11 +1339,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { this.visit_ty(&ty); } } - GenericParamKind::Const { ref ty, .. } => { + GenericParamKind::Const { ref ty, default } => { let was_in_const_generic = this.is_in_const_generic; this.is_in_const_generic = true; walk_list!(this, visit_param_bound, param.bounds); this.visit_ty(&ty); + if let Some(default) = default { + this.visit_body(this.tcx.hir().body(default.body)); + } this.is_in_const_generic = was_in_const_generic; } } diff --git a/src/test/ui/const-generics/issue-93647.rs b/src/test/ui/const-generics/issue-93647.rs new file mode 100644 index 0000000000000..6a8fe64d1875d --- /dev/null +++ b/src/test/ui/const-generics/issue-93647.rs @@ -0,0 +1,6 @@ +struct X; + +fn main() {} diff --git a/src/test/ui/const-generics/issue-93647.stderr b/src/test/ui/const-generics/issue-93647.stderr new file mode 100644 index 0000000000000..0fe54e7de41f0 --- /dev/null +++ b/src/test/ui/const-generics/issue-93647.stderr @@ -0,0 +1,9 @@ +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-93647.rs:2:5 + | +LL | (||1usize)() + | ^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs new file mode 100644 index 0000000000000..3018439afa717 --- /dev/null +++ b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs @@ -0,0 +1,10 @@ +struct Foo< + 'a, + const N: usize = { + let x: &'a (); + //~^ ERROR use of non-static lifetime `'a` in const generic + 3 + }, +>(&'a ()); + +fn main() {} diff --git a/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr new file mode 100644 index 0000000000000..9d9555d3f647f --- /dev/null +++ b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr @@ -0,0 +1,11 @@ +error[E0771]: use of non-static lifetime `'a` in const generic + --> $DIR/outer-lifetime-in-const-generic-default.rs:4:17 + | +LL | let x: &'a (); + | ^^ + | + = note: for more information, see issue #74052 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0771`.