From a30de6e7cb1458e271ead5e40e49dbe709275537 Mon Sep 17 00:00:00 2001 From: csmoe Date: Thu, 3 Nov 2022 22:34:24 +0800 Subject: [PATCH 01/14] record llvm cgu instruction stats --- Cargo.lock | 2 ++ compiler/rustc_codegen_llvm/Cargo.toml | 2 ++ compiler/rustc_codegen_llvm/src/back/write.rs | 21 +++++++++++++++++++ compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 ++ .../rustc_llvm/llvm-wrapper/LLVMWrapper.h | 1 + .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 13 ++++++++++++ 6 files changed, 41 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3ffa9e590f402..d74b0a9aa5675 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3801,6 +3801,8 @@ dependencies = [ "rustc_span", "rustc_symbol_mangling", "rustc_target", + "serde", + "serde_json", "smallvec", "tempfile", "tracing", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 773c0ebbe59db..a7ba2f8b69533 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -36,3 +36,5 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } tempfile = "3.2.0" +serde = { version = "1", features = [ "derive" ]} +serde_json = "1" diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 40f0594b40db3..a4ae1b01e869d 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -761,6 +761,7 @@ pub(crate) unsafe fn codegen( EmitObj::None => {} } + record_llvm_cgu_instructions_stats(&cgcx.prof, llmod); drop(handlers); } @@ -974,3 +975,23 @@ fn record_artifact_size( self_profiler_ref.artifact_size(artifact_kind, artifact_name.to_string_lossy(), file_size); } } + +fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Module) { + if !prof.enabled() { + return; + } + + let raw_stats = + llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(&llmod, s) }) + .expect("cannot get module instruction stats"); + + #[derive(serde::Deserialize)] + struct InstructionsStats { + module: String, + total: u64, + } + + let InstructionsStats { module, total } = + serde_json::from_str(&raw_stats).expect("cannot parse llvm cgu instructions stats"); + prof.artifact_size("cgu_instructions", module, total); +} diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 7aab666fc5e8c..1b3ce2e83a979 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2410,6 +2410,8 @@ extern "C" { pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize; pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer); pub fn LLVMRustModuleCost(M: &Module) -> u64; + #[allow(improper_ctypes)] + pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString); pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer; pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer); diff --git a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h index 9146a3739b2b1..0589062837866 100644 --- a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h +++ b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h @@ -14,6 +14,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/JSON.h" #include "llvm/Support/Host.h" #include "llvm/Support/Memory.h" #include "llvm/Support/SourceMgr.h" diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index b1e6534944db3..e3493caaaf74e 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -1751,6 +1751,19 @@ LLVMRustModuleCost(LLVMModuleRef M) { return std::distance(std::begin(f), std::end(f)); } +extern "C" void +LLVMRustModuleInstructionStats(LLVMModuleRef M, RustStringRef Str) +{ + RawRustStringOstream OS(Str); + llvm::json::OStream JOS(OS); + auto Module = unwrap(M); + + JOS.object([&] { + JOS.attribute("module", Module->getName()); + JOS.attribute("total", Module->getInstructionCount()); + }); +} + // Vector reductions: extern "C" LLVMValueRef LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { From 46ea12a499aecd655a5c954431466db0a66e8ec9 Mon Sep 17 00:00:00 2001 From: nx2k3 Date: Sun, 26 Feb 2023 16:17:23 +0000 Subject: [PATCH 02/14] fix #108495, postfix decrement and prefix decrement has no warning --- .../rustc_parse/src/parser/diagnostics.rs | 29 ++++- compiler/rustc_parse/src/parser/expr.rs | 33 +++++- tests/ui/parser/issue-108495-dec.rs | 52 +++++++++ tests/ui/parser/issue-108495-dec.stderr | 107 ++++++++++++++++++ 4 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 tests/ui/parser/issue-108495-dec.rs create mode 100644 tests/ui/parser/issue-108495-dec.stderr diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index d235b8a8176a8..e3dbe89b56c4e 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -166,7 +166,7 @@ enum IsStandalone { enum IncOrDec { Inc, // FIXME: `i--` recovery isn't implemented yet - #[allow(dead_code)] + // #[allow(dead_code)] Dec, } @@ -1331,7 +1331,7 @@ impl<'a> Parser<'a> { Ok(()) } - + #[allow(dead_code)] pub(super) fn recover_from_prefix_increment( &mut self, operand_expr: P, @@ -1342,7 +1342,7 @@ impl<'a> Parser<'a> { let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre }; self.recover_from_inc_dec(operand_expr, kind, op_span) } - + #[allow(dead_code)] pub(super) fn recover_from_postfix_increment( &mut self, operand_expr: P, @@ -1356,7 +1356,30 @@ impl<'a> Parser<'a> { }; self.recover_from_inc_dec(operand_expr, kind, op_span) } + pub(super) fn recover_from_prefix_decrement( + &mut self, + operand_expr: P, + op_span: Span, + start_stmt: bool, + ) -> PResult<'a, P> { + let standalone = if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }; + let kind = IncDecRecovery { standalone, op: IncOrDec::Dec, fixity: UnaryFixity::Pre }; + self.recover_from_inc_dec(operand_expr, kind, op_span) + } + pub(super) fn recover_from_postfix_decrement( + &mut self, + operand_expr: P, + op_span: Span, + start_stmt: bool, + ) -> PResult<'a, P> { + let kind = IncDecRecovery { + standalone: if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }, + op: IncOrDec::Dec, + fixity: UnaryFixity::Post, + }; + self.recover_from_inc_dec(operand_expr, kind, op_span) + } fn recover_from_inc_dec( &mut self, base: P, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 12f65a436e3be..2004d0a8fe7b6 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -281,6 +281,16 @@ impl<'a> Parser<'a> { lhs = self.recover_from_postfix_increment(lhs, op_span, starts_stmt)?; continue; } + if self.prev_token == token::BinOp(token::Minus) + && self.token == token::BinOp(token::Minus) + && self.prev_token.span.between(self.token.span).is_empty() + { + let op_span = self.prev_token.span.to(self.token.span); + // Eat the second `+` + self.bump(); + lhs = self.recover_from_postfix_decrement(lhs, op_span, starts_stmt)?; + continue; + } let op = op.node; // Special cases: @@ -550,10 +560,7 @@ impl<'a> Parser<'a> { token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), // `~expr` token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), - // `-expr` - token::BinOp(token::Minus) => { - make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) - } + // `*expr` token::BinOp(token::Star) => { make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref)) @@ -595,6 +602,24 @@ impl<'a> Parser<'a> { let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt) } + // Recover from `++x`: + token::BinOp(token::Minus) + if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) => + { + let starts_stmt = this.prev_token == token::Semi + || this.prev_token == token::CloseDelim(Delimiter::Brace); + let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); + // Eat both `+`s. + this.bump(); + this.bump(); + + let operand_expr = this.parse_dot_or_call_expr(Default::default())?; + this.recover_from_prefix_decrement(operand_expr, pre_span, starts_stmt) + } + // `-expr` + token::BinOp(token::Minus) => { + make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) + } token::Ident(..) if this.token.is_keyword(kw::Box) => { make_it!(this, attrs, |this, _| this.parse_box_expr(lo)) } diff --git a/tests/ui/parser/issue-108495-dec.rs b/tests/ui/parser/issue-108495-dec.rs new file mode 100644 index 0000000000000..165e6142b466c --- /dev/null +++ b/tests/ui/parser/issue-108495-dec.rs @@ -0,0 +1,52 @@ +fn test1() { + let mut i = 0; + let _ = i + --i; //~ ERROR Rust has no prefix decrement operator +} + +fn test2() { + let mut i = 0; + let _ = --i + i; //~ ERROR Rust has no prefix decrement operator +} + +fn test3() { + let mut i = 0; + let _ = --i + --i; //~ ERROR Rust has no prefix decrement operator +} + +fn test4() { + let mut i = 0; + let _ = i + i--; //~ ERROR Rust has no postfix decrement operator + // won't suggest since we can not handle the precedences +} + +fn test5() { + let mut i = 0; + let _ = i-- + i; //~ ERROR Rust has no postfix decrement operator +} + +fn test6() { + let mut i = 0; + let _ = i-- + i--; //~ ERROR Rust has no postfix decrement operator +} + +fn test7() { + let mut i = 0; + let _ = --i + i--; //~ ERROR Rust has no prefix decrement operator +} + +fn test8() { + let mut i = 0; + let _ = i-- + --i; //~ ERROR Rust has no postfix decrement operator +} + +fn test9() { + let mut i = 0; + let _ = (1 + 2 + i)--; //~ ERROR Rust has no postfix decrement operator +} + +fn test10() { + let mut i = 0; + let _ = (i-- + 1) + 2; //~ ERROR Rust has no postfix decrement operator +} + +fn main() { } diff --git a/tests/ui/parser/issue-108495-dec.stderr b/tests/ui/parser/issue-108495-dec.stderr new file mode 100644 index 0000000000000..078fec74c5545 --- /dev/null +++ b/tests/ui/parser/issue-108495-dec.stderr @@ -0,0 +1,107 @@ +error: Rust has no prefix decrement operator + --> $DIR/issue-dec.rs:3:17 + | +LL | let _ = i + --i; + | ^^ not a valid prefix operator + | +help: use `-= 1` instead + | +LL | let _ = i + { i -= 1; i }; + | ~ +++++++++ + +error: Rust has no prefix decrement operator + --> $DIR/issue-dec.rs:8:13 + | +LL | let _ = --i + i; + | ^^ not a valid prefix operator + | +help: use `-= 1` instead + | +LL | let _ = { i -= 1; i } + i; + | ~ +++++++++ + +error: Rust has no prefix decrement operator + --> $DIR/issue-dec.rs:13:13 + | +LL | let _ = --i + --i; + | ^^ not a valid prefix operator + | +help: use `-= 1` instead + | +LL | let _ = { i -= 1; i } + --i; + | ~ +++++++++ + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:18:18 + | +LL | let _ = i + i--; + | ^^ not a valid postfix operator + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:24:14 + | +LL | let _ = i-- + i; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | let _ = { let tmp = i; i -= 1; tmp } + i; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:29:14 + | +LL | let _ = i-- + i--; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | let _ = { let tmp = i; i -= 1; tmp } + i--; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no prefix decrement operator + --> $DIR/issue-dec.rs:34:13 + | +LL | let _ = --i + i--; + | ^^ not a valid prefix operator + | +help: use `-= 1` instead + | +LL | let _ = { i -= 1; i } + i--; + | ~ +++++++++ + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:39:14 + | +LL | let _ = i-- + --i; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | let _ = { let tmp = i; i -= 1; tmp } + --i; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:44:24 + | +LL | let _ = (1 + 2 + i)--; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | let _ = { let tmp = (1 + 2 + i); (1 + 2 + i) -= 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: Rust has no postfix decrement operator + --> $DIR/issue-dec.rs:49:15 + | +LL | let _ = (i-- + 1) + 2; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | let _ = ({ let tmp = i; i -= 1; tmp } + 1) + 2; + | +++++++++++ ~~~~~~~~~~~~~~~ + +error: aborting due to 10 previous errors + From 13a741afaccf03a4e98bedfc09e46c72e22810e0 Mon Sep 17 00:00:00 2001 From: nx2k3 Date: Sun, 26 Feb 2023 16:24:08 +0000 Subject: [PATCH 03/14] fix some comments --- compiler/rustc_parse/src/parser/diagnostics.rs | 6 ++---- compiler/rustc_parse/src/parser/expr.rs | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index e3dbe89b56c4e..134120532f87a 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -165,8 +165,6 @@ enum IsStandalone { #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum IncOrDec { Inc, - // FIXME: `i--` recovery isn't implemented yet - // #[allow(dead_code)] Dec, } @@ -1331,7 +1329,7 @@ impl<'a> Parser<'a> { Ok(()) } - #[allow(dead_code)] + pub(super) fn recover_from_prefix_increment( &mut self, operand_expr: P, @@ -1342,7 +1340,7 @@ impl<'a> Parser<'a> { let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre }; self.recover_from_inc_dec(operand_expr, kind, op_span) } - #[allow(dead_code)] + pub(super) fn recover_from_postfix_increment( &mut self, operand_expr: P, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2004d0a8fe7b6..a14f576eedce6 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -286,7 +286,7 @@ impl<'a> Parser<'a> { && self.prev_token.span.between(self.token.span).is_empty() { let op_span = self.prev_token.span.to(self.token.span); - // Eat the second `+` + // Eat the second `-` self.bump(); lhs = self.recover_from_postfix_decrement(lhs, op_span, starts_stmt)?; continue; @@ -602,14 +602,14 @@ impl<'a> Parser<'a> { let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt) } - // Recover from `++x`: + // Recover from `--x`: token::BinOp(token::Minus) if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) => { let starts_stmt = this.prev_token == token::Semi || this.prev_token == token::CloseDelim(Delimiter::Brace); let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); - // Eat both `+`s. + // Eat both `-`s. this.bump(); this.bump(); From ff336aa6f9cd3f7e3176bbc56c475e66b86bd377 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 26 Feb 2023 23:51:49 +0000 Subject: [PATCH 04/14] Small cleanup to one_bound_for_assoc_type --- .../rustc_hir_analysis/src/astconv/mod.rs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 43dd5b3621a6e..00a24fdf5fcd8 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -50,6 +50,7 @@ use rustc_trait_selection::traits::{self, astconv_object_safety_violations, Obli use smallvec::{smallvec, SmallVec}; use std::collections::BTreeSet; +use std::fmt::Display; use std::slice; #[derive(Debug)] @@ -1095,11 +1096,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // those that do. self.one_bound_for_assoc_type( || traits::supertraits(tcx, trait_ref), - || trait_ref.print_only_trait_path().to_string(), + trait_ref.print_only_trait_path(), binding.item_name, path_span, - || match binding.kind { - ConvertedBindingKind::Equality(ty) => Some(ty.to_string()), + match binding.kind { + ConvertedBindingKind::Equality(term) => Some(term), _ => None, }, )? @@ -1789,10 +1790,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assoc_name, ) }, - || param_name.to_string(), + param_name, assoc_name, span, - || None, + None, ) } @@ -1802,10 +1803,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { fn one_bound_for_assoc_type( &self, all_candidates: impl Fn() -> I, - ty_param_name: impl Fn() -> String, + ty_param_name: impl Display, assoc_name: Ident, span: Span, - is_equality: impl Fn() -> Option, + is_equality: Option>, ) -> Result, ErrorGuaranteed> where I: Iterator>, @@ -1821,7 +1822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (None, None) => { let reported = self.complain_about_assoc_type_not_found( all_candidates, - &ty_param_name(), + &ty_param_name.to_string(), assoc_name, span, ); @@ -1833,7 +1834,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(bound2) = next_cand { debug!(?bound2); - let is_equality = is_equality(); let bounds = IntoIterator::into_iter([bound, bound2]).chain(matching_candidates); let mut err = if is_equality.is_some() { // More specific Error Index entry. @@ -1843,7 +1843,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { E0222, "ambiguous associated type `{}` in bounds of `{}`", assoc_name, - ty_param_name() + ty_param_name ) } else { struct_span_err!( @@ -1852,7 +1852,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { E0221, "ambiguous associated type `{}` in bounds of `{}`", assoc_name, - ty_param_name() + ty_param_name ) }; err.span_label(span, format!("ambiguous associated type `{}`", assoc_name)); @@ -1886,18 +1886,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.span_suggestion_verbose( span.with_hi(assoc_name.span.lo()), "use fully qualified syntax to disambiguate", - format!( - "<{} as {}>::", - ty_param_name(), - bound.print_only_trait_path(), - ), + format!("<{} as {}>::", ty_param_name, bound.print_only_trait_path()), Applicability::MaybeIncorrect, ); } } else { err.note(&format!( "associated type `{}` could derive from `{}`", - ty_param_name(), + ty_param_name, bound.print_only_trait_path(), )); } @@ -1906,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.help(&format!( "consider introducing a new type parameter `T` and adding `where` constraints:\ \n where\n T: {},\n{}", - ty_param_name(), + ty_param_name, where_bounds.join(",\n"), )); } @@ -2070,10 +2066,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.one_bound_for_assoc_type( || traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())), - || "Self".to_string(), + kw::SelfUpper, assoc_ident, span, - || None, + None, )? } ( From 0883973d2a1a0346832e1d8556997f771c87e5d7 Mon Sep 17 00:00:00 2001 From: nx2k3 Date: Mon, 27 Feb 2023 13:25:03 +0000 Subject: [PATCH 05/14] check double negation --- compiler/rustc_parse/src/parser/expr.rs | 13 +++- tests/ui/parser/issue-108495-dec-pass.rs | 48 +++++++++++++++ tests/ui/parser/issue-108495-dec.rs | 35 ++++------- tests/ui/parser/issue-108495-dec.stderr | 78 ++++++------------------ 4 files changed, 90 insertions(+), 84 deletions(-) create mode 100644 tests/ui/parser/issue-108495-dec-pass.rs diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a14f576eedce6..d1dc4ce1e9919 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -284,6 +284,7 @@ impl<'a> Parser<'a> { if self.prev_token == token::BinOp(token::Minus) && self.token == token::BinOp(token::Minus) && self.prev_token.span.between(self.token.span).is_empty() + && !self.look_ahead(1, |tok| tok.can_begin_expr()) { let op_span = self.prev_token.span.to(self.token.span); // Eat the second `-` @@ -560,7 +561,10 @@ impl<'a> Parser<'a> { token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), // `~expr` token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), - + // // `-expr` + // token::BinOp(token::Minus) => { + // make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) + // } // `*expr` token::BinOp(token::Star) => { make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref)) @@ -604,17 +608,20 @@ impl<'a> Parser<'a> { } // Recover from `--x`: token::BinOp(token::Minus) - if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) => + if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) + && !this.token.can_begin_expr() => { let starts_stmt = this.prev_token == token::Semi || this.prev_token == token::CloseDelim(Delimiter::Brace); let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); + // if !this.token.can_begin_expr() { // Eat both `-`s. this.bump(); this.bump(); - let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_decrement(operand_expr, pre_span, starts_stmt) + + // } } // `-expr` token::BinOp(token::Minus) => { diff --git a/tests/ui/parser/issue-108495-dec-pass.rs b/tests/ui/parser/issue-108495-dec-pass.rs new file mode 100644 index 0000000000000..2e17a317b685c --- /dev/null +++ b/tests/ui/parser/issue-108495-dec-pass.rs @@ -0,0 +1,48 @@ +// run-pass +fn test1() { + let i = 0; + let c = i + --i; + println!("{c}"); +} +fn test2() { + let i = 9; + let c = -- i + --i; + println!("{c}"); +} + +fn test3(){ + let i=10; + println!("{}",i--i); +} +fn test4(){ + let i=10; + println!("{}",--i); + +} +struct Foo { + bar: Bar, +} + +struct Bar { + qux: i32, +} + +fn test5() { + let foo = Foo { bar: Bar { qux: 0 } }; + let c=--foo.bar.qux; + println!("{c}"); +} + +fn test6(){ + let x=2; + let y=--x; + println!("{y}"); +} +fn main(){ + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); +} diff --git a/tests/ui/parser/issue-108495-dec.rs b/tests/ui/parser/issue-108495-dec.rs index 165e6142b466c..db45577ec0189 100644 --- a/tests/ui/parser/issue-108495-dec.rs +++ b/tests/ui/parser/issue-108495-dec.rs @@ -1,18 +1,3 @@ -fn test1() { - let mut i = 0; - let _ = i + --i; //~ ERROR Rust has no prefix decrement operator -} - -fn test2() { - let mut i = 0; - let _ = --i + i; //~ ERROR Rust has no prefix decrement operator -} - -fn test3() { - let mut i = 0; - let _ = --i + --i; //~ ERROR Rust has no prefix decrement operator -} - fn test4() { let mut i = 0; let _ = i + i--; //~ ERROR Rust has no postfix decrement operator @@ -21,32 +6,36 @@ fn test4() { fn test5() { let mut i = 0; - let _ = i-- + i; //~ ERROR Rust has no postfix decrement operator + let _ = i-- + i--; //~ ERROR Rust has no postfix decrement operator } fn test6() { let mut i = 0; - let _ = i-- + i--; //~ ERROR Rust has no postfix decrement operator + let _ = --i + i--; //~ ERROR Rust has no postfix decrement operator } fn test7() { let mut i = 0; - let _ = --i + i--; //~ ERROR Rust has no prefix decrement operator + let _ = i-- + --i; //~ ERROR Rust has no postfix decrement operator } fn test8() { let mut i = 0; - let _ = i-- + --i; //~ ERROR Rust has no postfix decrement operator + let _ = (1 + 2 + i)--; //~ ERROR Rust has no postfix decrement operator } fn test9() { let mut i = 0; - let _ = (1 + 2 + i)--; //~ ERROR Rust has no postfix decrement operator + let _ = (i-- + 1) + 2; //~ ERROR Rust has no postfix decrement operator } -fn test10() { - let mut i = 0; - let _ = (i-- + 1) + 2; //~ ERROR Rust has no postfix decrement operator + + +fn test14(){ + let i=10; + while i!=0{ + i--; //~ ERROR Rust has no postfix decrement operator + } } fn main() { } diff --git a/tests/ui/parser/issue-108495-dec.stderr b/tests/ui/parser/issue-108495-dec.stderr index 078fec74c5545..90019e68f4460 100644 --- a/tests/ui/parser/issue-108495-dec.stderr +++ b/tests/ui/parser/issue-108495-dec.stderr @@ -1,55 +1,11 @@ -error: Rust has no prefix decrement operator - --> $DIR/issue-dec.rs:3:17 - | -LL | let _ = i + --i; - | ^^ not a valid prefix operator - | -help: use `-= 1` instead - | -LL | let _ = i + { i -= 1; i }; - | ~ +++++++++ - -error: Rust has no prefix decrement operator - --> $DIR/issue-dec.rs:8:13 - | -LL | let _ = --i + i; - | ^^ not a valid prefix operator - | -help: use `-= 1` instead - | -LL | let _ = { i -= 1; i } + i; - | ~ +++++++++ - -error: Rust has no prefix decrement operator - --> $DIR/issue-dec.rs:13:13 - | -LL | let _ = --i + --i; - | ^^ not a valid prefix operator - | -help: use `-= 1` instead - | -LL | let _ = { i -= 1; i } + --i; - | ~ +++++++++ - error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:18:18 + --> $DIR/issue-108495-dec.rs:3:18 | LL | let _ = i + i--; | ^^ not a valid postfix operator error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:24:14 - | -LL | let _ = i-- + i; - | ^^ not a valid postfix operator - | -help: use `-= 1` instead - | -LL | let _ = { let tmp = i; i -= 1; tmp } + i; - | +++++++++++ ~~~~~~~~~~~~~~~ - -error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:29:14 + --> $DIR/issue-108495-dec.rs:9:14 | LL | let _ = i-- + i--; | ^^ not a valid postfix operator @@ -59,19 +15,14 @@ help: use `-= 1` instead LL | let _ = { let tmp = i; i -= 1; tmp } + i--; | +++++++++++ ~~~~~~~~~~~~~~~ -error: Rust has no prefix decrement operator - --> $DIR/issue-dec.rs:34:13 +error: Rust has no postfix decrement operator + --> $DIR/issue-108495-dec.rs:14:20 | LL | let _ = --i + i--; - | ^^ not a valid prefix operator - | -help: use `-= 1` instead - | -LL | let _ = { i -= 1; i } + i--; - | ~ +++++++++ + | ^^ not a valid postfix operator error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:39:14 + --> $DIR/issue-108495-dec.rs:19:14 | LL | let _ = i-- + --i; | ^^ not a valid postfix operator @@ -82,7 +33,7 @@ LL | let _ = { let tmp = i; i -= 1; tmp } + --i; | +++++++++++ ~~~~~~~~~~~~~~~ error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:44:24 + --> $DIR/issue-108495-dec.rs:24:24 | LL | let _ = (1 + 2 + i)--; | ^^ not a valid postfix operator @@ -93,7 +44,7 @@ LL | let _ = { let tmp = (1 + 2 + i); (1 + 2 + i) -= 1; tmp }; | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ error: Rust has no postfix decrement operator - --> $DIR/issue-dec.rs:49:15 + --> $DIR/issue-108495-dec.rs:29:15 | LL | let _ = (i-- + 1) + 2; | ^^ not a valid postfix operator @@ -103,5 +54,16 @@ help: use `-= 1` instead LL | let _ = ({ let tmp = i; i -= 1; tmp } + 1) + 2; | +++++++++++ ~~~~~~~~~~~~~~~ -error: aborting due to 10 previous errors +error: Rust has no postfix decrement operator + --> $DIR/issue-108495-dec.rs:37:10 + | +LL | i--; + | ^^ not a valid postfix operator + | +help: use `-= 1` instead + | +LL | i -= 1; + | ~~~~ + +error: aborting due to 7 previous errors From 5f593da4e6976fe27f7cd31ce0fb9a9293b3a00b Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 26 Feb 2023 21:50:19 +0000 Subject: [PATCH 06/14] Unify all validity check intrinsics Also merges the inhabitedness check into the query to further unify the code paths. --- .../src/intrinsics/mod.rs | 80 +++++++------------ compiler/rustc_codegen_ssa/src/mir/block.rs | 42 +++------- .../src/interpret/intrinsics.rs | 74 ++++++----------- compiler/rustc_const_eval/src/lib.rs | 4 +- ..._init.rs => check_validity_requirement.rs} | 30 ++++--- compiler/rustc_const_eval/src/util/mod.rs | 4 +- compiler/rustc_middle/src/query/keys.rs | 4 +- compiler/rustc_middle/src/query/mod.rs | 4 +- compiler/rustc_middle/src/ty/layout.rs | 22 ++++- compiler/rustc_middle/src/ty/query.rs | 2 +- .../rustc_mir_transform/src/instcombine.rs | 16 +--- 11 files changed, 119 insertions(+), 163 deletions(-) rename compiler/rustc_const_eval/src/util/{might_permit_raw_init.rs => check_validity_requirement.rs} (86%) diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index f00e932107058..e74aabf2fcb0d 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -22,7 +22,7 @@ pub(crate) use cpuid::codegen_cpuid_call; pub(crate) use llvm::codegen_llvm_intrinsic_call; use rustc_middle::ty; -use rustc_middle::ty::layout::{HasParamEnv, InitKind}; +use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::SubstsRef; use rustc_span::symbol::{kw, sym, Symbol}; @@ -628,57 +628,39 @@ fn codegen_regular_intrinsic_call<'tcx>( intrinsic_args!(fx, args => (); intrinsic); let ty = substs.type_at(0); - let layout = fx.layout_of(ty); - if layout.abi.is_uninhabited() { - with_no_trimmed_paths!({ - crate::base::codegen_panic_nounwind( - fx, - &format!("attempted to instantiate uninhabited type `{}`", layout.ty), - source_info, - ) - }); - return; - } - if intrinsic == sym::assert_zero_valid - && !fx - .tcx - .check_validity_of_init((InitKind::Zero, fx.param_env().and(ty))) - .expect("expected to have layout during codegen") - { - with_no_trimmed_paths!({ - crate::base::codegen_panic_nounwind( - fx, - &format!( - "attempted to zero-initialize type `{}`, which is invalid", - layout.ty - ), - source_info, - ); - }); - return; - } + let requirement = ValidityRequirement::from_intrinsic(intrinsic); - if intrinsic == sym::assert_mem_uninitialized_valid - && !fx + if let Some(requirement) = requirement { + let do_panic = !fx .tcx - .check_validity_of_init(( - InitKind::UninitMitigated0x01Fill, - fx.param_env().and(ty), - )) - .expect("expected to have layout during codegen") - { - with_no_trimmed_paths!({ - crate::base::codegen_panic_nounwind( - fx, - &format!( - "attempted to leave type `{}` uninitialized, which is invalid", - layout.ty - ), - source_info, - ) - }); - return; + .check_validity_requirement((requirement, fx.param_env().and(ty))) + .expect("expect to have layout during codegen"); + + if do_panic { + let layout = fx.layout_of(ty); + + with_no_trimmed_paths!({ + crate::base::codegen_panic_nounwind( + fx, + &if layout.abi.is_uninhabited() { + format!("attempted to instantiate uninhabited type `{}`", layout.ty) + } else if requirement == ValidityRequirement::Zero { + format!( + "attempted to zero-initialize type `{}`, which is invalid", + layout.ty + ) + } else { + format!( + "attempted to leave type `{}` uninitialized, which is invalid", + layout.ty + ) + }, + source_info, + ) + }); + return; + } } } diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index b1abbd673a53a..57a19a4ab1eab 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -14,7 +14,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_hir::lang_items::LangItem; use rustc_index::vec::Idx; use rustc_middle::mir::{self, AssertKind, SwitchTargets}; -use rustc_middle::ty::layout::{HasTyCtxt, InitKind, LayoutOf}; +use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement}; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; use rustc_session::config::OptLevel; @@ -655,44 +655,24 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Emit a panic or a no-op for `assert_*` intrinsics. // These are intrinsics that compile to panics so that we can get a message // which mentions the offending type, even from a const context. - #[derive(Debug, PartialEq)] - enum AssertIntrinsic { - Inhabited, - ZeroValid, - MemUninitializedValid, - } - let panic_intrinsic = intrinsic.and_then(|i| match i { - sym::assert_inhabited => Some(AssertIntrinsic::Inhabited), - sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid), - sym::assert_mem_uninitialized_valid => Some(AssertIntrinsic::MemUninitializedValid), - _ => None, - }); - if let Some(intrinsic) = panic_intrinsic { - use AssertIntrinsic::*; - + let panic_intrinsic = intrinsic.and_then(|s| ValidityRequirement::from_intrinsic(s)); + if let Some(requirement) = panic_intrinsic { let ty = instance.unwrap().substs.type_at(0); + + let do_panic = !bx + .tcx() + .check_validity_requirement((requirement, bx.param_env().and(ty))) + .expect("expect to have layout during codegen"); + let layout = bx.layout_of(ty); - let do_panic = match intrinsic { - Inhabited => layout.abi.is_uninhabited(), - ZeroValid => !bx - .tcx() - .check_validity_of_init((InitKind::Zero, bx.param_env().and(ty))) - .expect("expected to have layout during codegen"), - MemUninitializedValid => !bx - .tcx() - .check_validity_of_init(( - InitKind::UninitMitigated0x01Fill, - bx.param_env().and(ty), - )) - .expect("expected to have layout during codegen"), - }; + Some(if do_panic { let msg_str = with_no_visible_paths!({ with_no_trimmed_paths!({ if layout.abi.is_uninhabited() { // Use this error even for the other intrinsics as it is more precise. format!("attempted to instantiate uninhabited type `{}`", ty) - } else if intrinsic == ZeroValid { + } else if requirement == ValidityRequirement::Zero { format!("attempted to zero-initialize type `{}`, which is invalid", ty) } else { format!( diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 26c84b4ce6127..c65d677e8ea75 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -11,7 +11,7 @@ use rustc_middle::mir::{ BinOp, NonDivergingIntrinsic, }; use rustc_middle::ty; -use rustc_middle::ty::layout::{InitKind, LayoutOf as _}; +use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; @@ -418,57 +418,35 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => { let ty = instance.substs.type_at(0); - let layout = self.layout_of(ty)?; - - // For *all* intrinsics we first check `is_uninhabited` to give a more specific - // error message. - if layout.abi.is_uninhabited() { - // The run-time intrinsic panics just to get a good backtrace; here we abort - // since there is no problem showing a backtrace even for aborts. - M::abort( - self, - format!( + let requirement = ValidityRequirement::from_intrinsic(intrinsic_name).unwrap(); + + let should_panic = !self + .tcx + .check_validity_requirement((requirement, self.param_env.and(ty))) + .map_err(|_| err_inval!(TooGeneric))?; + + if should_panic { + let layout = self.layout_of(ty)?; + + let msg = match requirement { + // For *all* intrinsics we first check `is_uninhabited` to give a more specific + // error message. + _ if layout.abi.is_uninhabited() => format!( "aborted execution: attempted to instantiate uninhabited type `{}`", ty ), - )?; - } - - if intrinsic_name == sym::assert_zero_valid { - let should_panic = !self - .tcx - .check_validity_of_init((InitKind::Zero, self.param_env.and(ty))) - .map_err(|_| err_inval!(TooGeneric))?; - - if should_panic { - M::abort( - self, - format!( - "aborted execution: attempted to zero-initialize type `{}`, which is invalid", - ty - ), - )?; - } - } + ValidityRequirement::Inhabited => bug!("handled earlier"), + ValidityRequirement::Zero => format!( + "aborted execution: attempted to zero-initialize type `{}`, which is invalid", + ty + ), + ValidityRequirement::UninitMitigated0x01Fill => format!( + "aborted execution: attempted to leave type `{}` uninitialized, which is invalid", + ty + ), + }; - if intrinsic_name == sym::assert_mem_uninitialized_valid { - let should_panic = !self - .tcx - .check_validity_of_init(( - InitKind::UninitMitigated0x01Fill, - self.param_env.and(ty), - )) - .map_err(|_| err_inval!(TooGeneric))?; - - if should_panic { - M::abort( - self, - format!( - "aborted execution: attempted to leave type `{}` uninitialized, which is invalid", - ty - ), - )?; - } + M::abort(self, msg)?; } } sym::simd_insert => { diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 092a7dc3d3b51..ed9efe568fb30 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -61,7 +61,7 @@ pub fn provide(providers: &mut Providers) { let (param_env, value) = param_env_and_value.into_parts(); const_eval::deref_mir_constant(tcx, param_env, value) }; - providers.check_validity_of_init = |tcx, (init_kind, param_env_and_ty)| { - util::might_permit_raw_init(tcx, init_kind, param_env_and_ty) + providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| { + util::check_validity_requirement(tcx, init_kind, param_env_and_ty) }; } diff --git a/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs b/compiler/rustc_const_eval/src/util/check_validity_requirement.rs similarity index 86% rename from compiler/rustc_const_eval/src/util/might_permit_raw_init.rs rename to compiler/rustc_const_eval/src/util/check_validity_requirement.rs index a78bf927ca1dc..dcd15b919f4e3 100644 --- a/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs +++ b/compiler/rustc_const_eval/src/util/check_validity_requirement.rs @@ -1,4 +1,4 @@ -use rustc_middle::ty::layout::{InitKind, LayoutCx, LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement}; use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt}; use rustc_session::Limit; use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants}; @@ -18,16 +18,23 @@ use crate::interpret::{InterpCx, MemoryKind, OpTy}; /// Rust UB as long as there is no risk of miscompilations. The `strict_init_checks` can be set to /// do a full check against Rust UB instead (in which case we will also ignore the 0x01-filling and /// to the full uninit check). -pub fn might_permit_raw_init<'tcx>( +pub fn check_validity_requirement<'tcx>( tcx: TyCtxt<'tcx>, - kind: InitKind, + kind: ValidityRequirement, param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>, ) -> Result> { + let layout = tcx.layout_of(param_env_and_ty)?; + + // There is nothing strict or lax about inhabitedness. + if kind == ValidityRequirement::Inhabited { + return Ok(!layout.abi.is_uninhabited()); + } + if tcx.sess.opts.unstable_opts.strict_init_checks { - might_permit_raw_init_strict(tcx.layout_of(param_env_and_ty)?, tcx, kind) + might_permit_raw_init_strict(layout, tcx, kind) } else { let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env }; - might_permit_raw_init_lax(tcx.layout_of(param_env_and_ty)?, &layout_cx, kind) + might_permit_raw_init_lax(layout, &layout_cx, kind) } } @@ -36,7 +43,7 @@ pub fn might_permit_raw_init<'tcx>( fn might_permit_raw_init_strict<'tcx>( ty: TyAndLayout<'tcx>, tcx: TyCtxt<'tcx>, - kind: InitKind, + kind: ValidityRequirement, ) -> Result> { let machine = CompileTimeInterpreter::new( Limit::new(0), @@ -50,7 +57,7 @@ fn might_permit_raw_init_strict<'tcx>( .allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap)) .expect("OOM: failed to allocate for uninit check"); - if kind == InitKind::Zero { + if kind == ValidityRequirement::Zero { cx.write_bytes_ptr( allocated.ptr, std::iter::repeat(0_u8).take(ty.layout.size().bytes_usize()), @@ -72,15 +79,18 @@ fn might_permit_raw_init_strict<'tcx>( fn might_permit_raw_init_lax<'tcx>( this: TyAndLayout<'tcx>, cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, - init_kind: InitKind, + init_kind: ValidityRequirement, ) -> Result> { let scalar_allows_raw_init = move |s: Scalar| -> bool { match init_kind { - InitKind::Zero => { + ValidityRequirement::Inhabited => { + bug!("ValidityRequirement::Inhabited should have been handled above") + } + ValidityRequirement::Zero => { // The range must contain 0. s.valid_range(cx).contains(0) } - InitKind::UninitMitigated0x01Fill => { + ValidityRequirement::UninitMitigated0x01Fill => { // The range must include an 0x01-filled buffer. let mut val: u128 = 0x01; for _ in 1..s.size(cx).bytes() { diff --git a/compiler/rustc_const_eval/src/util/mod.rs b/compiler/rustc_const_eval/src/util/mod.rs index 51735e33e0f71..c0aabd77ceead 100644 --- a/compiler/rustc_const_eval/src/util/mod.rs +++ b/compiler/rustc_const_eval/src/util/mod.rs @@ -1,14 +1,14 @@ mod alignment; mod call_kind; +mod check_validity_requirement; pub mod collect_writes; mod compare_types; mod find_self_call; -mod might_permit_raw_init; mod type_name; pub use self::alignment::is_disaligned; pub use self::call_kind::{call_kind, CallDesugaringKind, CallKind}; +pub use self::check_validity_requirement::check_validity_requirement; pub use self::compare_types::{is_equal_up_to_subtyping, is_subtype}; pub use self::find_self_call::find_self_call; -pub use self::might_permit_raw_init::might_permit_raw_init; pub use self::type_name::type_name; diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 111ea6b8cddc0..78ee8a6a8fd64 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -4,7 +4,7 @@ use crate::infer::canonical::Canonical; use crate::mir; use crate::traits; use crate::ty::fast_reject::SimplifiedType; -use crate::ty::layout::{InitKind, TyAndLayout}; +use crate::ty::layout::{TyAndLayout, ValidityRequirement}; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::{self, Ty, TyCtxt}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; @@ -698,7 +698,7 @@ impl Key for HirId { } } -impl<'tcx> Key for (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) { +impl<'tcx> Key for (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) { type CacheSelector = DefaultCacheSelector; // Just forward to `Ty<'tcx>` diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index d4435a54b4ab6..f4c1ad0f6c0b9 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -2173,8 +2173,8 @@ rustc_queries! { separate_provide_extern } - query check_validity_of_init(key: (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>)) -> Result> { - desc { "checking to see if `{}` permits being left {}", key.1.value, key.0 } + query check_validity_requirement(key: (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>)) -> Result> { + desc { "checking validity requirement for `{}`: {}", key.1.value, key.0 } } query compare_impl_const( diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index f0b52455889aa..090272a6fa6d9 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -7,6 +7,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_index::vec::Idx; use rustc_session::config::OptLevel; +use rustc_span::symbol::{sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::call::FnAbi; use rustc_target::abi::*; @@ -172,16 +173,29 @@ pub const MAX_SIMD_LANES: u64 = 1 << 0xF; /// Used in `might_permit_raw_init` to indicate the kind of initialisation /// that is checked to be valid #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] -pub enum InitKind { +pub enum ValidityRequirement { + Inhabited, Zero, UninitMitigated0x01Fill, } -impl fmt::Display for InitKind { +impl ValidityRequirement { + pub fn from_intrinsic(intrinsic: Symbol) -> Option { + match intrinsic { + sym::assert_inhabited => Some(Self::Inhabited), + sym::assert_zero_valid => Some(Self::Zero), + sym::assert_mem_uninitialized_valid => Some(Self::UninitMitigated0x01Fill), + _ => None, + } + } +} + +impl fmt::Display for ValidityRequirement { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Zero => f.write_str("zeroed"), - Self::UninitMitigated0x01Fill => f.write_str("filled with 0x01"), + Self::Inhabited => f.write_str("is inhabited"), + Self::Zero => f.write_str("allows being left zeroed"), + Self::UninitMitigated0x01Fill => f.write_str("allows being filled with 0x01"), } } } diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index d743c30684958..2bc51baf87905 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -32,7 +32,7 @@ use crate::traits::specialization_graph; use crate::traits::{self, ImplSource}; use crate::ty::context::TyCtxtFeed; use crate::ty::fast_reject::SimplifiedType; -use crate::ty::layout::InitKind; +use crate::ty::layout::ValidityRequirement; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::util::AlwaysRequiresDrop; use crate::ty::GeneratorDiagnosticData; diff --git a/compiler/rustc_mir_transform/src/instcombine.rs b/compiler/rustc_mir_transform/src/instcombine.rs index 05286b71d47e4..4182da1957e39 100644 --- a/compiler/rustc_mir_transform/src/instcombine.rs +++ b/compiler/rustc_mir_transform/src/instcombine.rs @@ -6,9 +6,9 @@ use rustc_middle::mir::{ BinOp, Body, Constant, ConstantKind, LocalDecls, Operand, Place, ProjectionElem, Rvalue, SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UnOp, }; -use rustc_middle::ty::layout::InitKind; +use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::{self, ParamEnv, SubstsRef, Ty, TyCtxt}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::Symbol; pub struct InstCombine; @@ -256,16 +256,8 @@ fn intrinsic_assert_panics<'tcx>( ty: Ty<'tcx>, intrinsic_name: Symbol, ) -> Option { - Some(match intrinsic_name { - sym::assert_inhabited => tcx.layout_of(param_env.and(ty)).ok()?.abi.is_uninhabited(), - sym::assert_zero_valid => { - !tcx.check_validity_of_init((InitKind::Zero, param_env.and(ty))).ok()? - } - sym::assert_mem_uninitialized_valid => !tcx - .check_validity_of_init((InitKind::UninitMitigated0x01Fill, param_env.and(ty))) - .ok()?, - _ => return None, - }) + let requirement = ValidityRequirement::from_intrinsic(intrinsic_name)?; + Some(!tcx.check_validity_requirement((requirement, param_env.and(ty))).ok()?) } fn resolve_rust_intrinsic<'tcx>( From a4830266b01465462aab352008b2720ac60f2213 Mon Sep 17 00:00:00 2001 From: nx2k3 Date: Mon, 27 Feb 2023 16:54:38 +0000 Subject: [PATCH 07/14] handle only postfix decrement --- .../rustc_parse/src/parser/diagnostics.rs | 10 ---- compiler/rustc_parse/src/parser/expr.rs | 28 ++--------- tests/ui/parser/issue-108495-dec-pass.rs | 48 ------------------- 3 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 tests/ui/parser/issue-108495-dec-pass.rs diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 134120532f87a..779fd90627bee 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1354,16 +1354,6 @@ impl<'a> Parser<'a> { }; self.recover_from_inc_dec(operand_expr, kind, op_span) } - pub(super) fn recover_from_prefix_decrement( - &mut self, - operand_expr: P, - op_span: Span, - start_stmt: bool, - ) -> PResult<'a, P> { - let standalone = if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }; - let kind = IncDecRecovery { standalone, op: IncOrDec::Dec, fixity: UnaryFixity::Pre }; - self.recover_from_inc_dec(operand_expr, kind, op_span) - } pub(super) fn recover_from_postfix_decrement( &mut self, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index d1dc4ce1e9919..ec50388cb46f3 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -561,10 +561,10 @@ impl<'a> Parser<'a> { token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), // `~expr` token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), - // // `-expr` - // token::BinOp(token::Minus) => { - // make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) - // } + // `-expr` + token::BinOp(token::Minus) => { + make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) + } // `*expr` token::BinOp(token::Star) => { make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref)) @@ -606,27 +606,7 @@ impl<'a> Parser<'a> { let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt) } - // Recover from `--x`: - token::BinOp(token::Minus) - if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) - && !this.token.can_begin_expr() => - { - let starts_stmt = this.prev_token == token::Semi - || this.prev_token == token::CloseDelim(Delimiter::Brace); - let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); - // if !this.token.can_begin_expr() { - // Eat both `-`s. - this.bump(); - this.bump(); - let operand_expr = this.parse_dot_or_call_expr(Default::default())?; - this.recover_from_prefix_decrement(operand_expr, pre_span, starts_stmt) - // } - } - // `-expr` - token::BinOp(token::Minus) => { - make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) - } token::Ident(..) if this.token.is_keyword(kw::Box) => { make_it!(this, attrs, |this, _| this.parse_box_expr(lo)) } diff --git a/tests/ui/parser/issue-108495-dec-pass.rs b/tests/ui/parser/issue-108495-dec-pass.rs deleted file mode 100644 index 2e17a317b685c..0000000000000 --- a/tests/ui/parser/issue-108495-dec-pass.rs +++ /dev/null @@ -1,48 +0,0 @@ -// run-pass -fn test1() { - let i = 0; - let c = i + --i; - println!("{c}"); -} -fn test2() { - let i = 9; - let c = -- i + --i; - println!("{c}"); -} - -fn test3(){ - let i=10; - println!("{}",i--i); -} -fn test4(){ - let i=10; - println!("{}",--i); - -} -struct Foo { - bar: Bar, -} - -struct Bar { - qux: i32, -} - -fn test5() { - let foo = Foo { bar: Bar { qux: 0 } }; - let c=--foo.bar.qux; - println!("{c}"); -} - -fn test6(){ - let x=2; - let y=--x; - println!("{y}"); -} -fn main(){ - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); -} From e326777ccaa8c710df327d4e9fa2e6aef5aa7631 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:49:05 +0000 Subject: [PATCH 08/14] Some `infer/mod.rs` cleanups --- compiler/rustc_infer/src/infer/mod.rs | 50 ++++++--------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index cf8007c964dc0..bd1f96635a681 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -156,7 +156,7 @@ pub struct InferCtxtInner<'tcx> { undo_log: InferCtxtUndoLogs<'tcx>, /// Caches for opaque type inference. - pub opaque_type_storage: OpaqueTypeStorage<'tcx>, + opaque_type_storage: OpaqueTypeStorage<'tcx>, } impl<'tcx> InferCtxtInner<'tcx> { @@ -195,41 +195,17 @@ impl<'tcx> InferCtxtInner<'tcx> { } #[inline] - fn int_unification_table( - &mut self, - ) -> ut::UnificationTable< - ut::InPlace< - ty::IntVid, - &mut ut::UnificationStorage, - &mut InferCtxtUndoLogs<'tcx>, - >, - > { + fn int_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ty::IntVid> { self.int_unification_storage.with_log(&mut self.undo_log) } #[inline] - fn float_unification_table( - &mut self, - ) -> ut::UnificationTable< - ut::InPlace< - ty::FloatVid, - &mut ut::UnificationStorage, - &mut InferCtxtUndoLogs<'tcx>, - >, - > { + fn float_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ty::FloatVid> { self.float_unification_storage.with_log(&mut self.undo_log) } #[inline] - fn const_unification_table( - &mut self, - ) -> ut::UnificationTable< - ut::InPlace< - ty::ConstVid<'tcx>, - &mut ut::UnificationStorage>, - &mut InferCtxtUndoLogs<'tcx>, - >, - > { + fn const_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ty::ConstVid<'tcx>> { self.const_unification_storage.with_log(&mut self.undo_log) } @@ -1429,17 +1405,14 @@ impl<'tcx> InferCtxt<'tcx> { } } + /// Attempts to resolve all type/region/const variables in + /// `value`. Region inference must have been run already (e.g., + /// by calling `resolve_regions_and_report_errors`). If some + /// variable was never unified, an `Err` results. + /// + /// This method is idempotent, but it not typically not invoked + /// except during the writeback phase. pub fn fully_resolve>>(&self, value: T) -> FixupResult<'tcx, T> { - /*! - * Attempts to resolve all type/region/const variables in - * `value`. Region inference must have been run already (e.g., - * by calling `resolve_regions_and_report_errors`). If some - * variable was never unified, an `Err` results. - * - * This method is idempotent, but it not typically not invoked - * except during the writeback phase. - */ - let value = resolve::fully_resolve(self, value); assert!( value.as_ref().map_or(true, |value| !value.needs_infer()), @@ -1754,7 +1727,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // in this case. The typechecker should only ever report type errors involving mismatched // types using one of these methods, and should not call span_err directly for such // errors. - pub fn type_error_struct_with_diag( &self, sp: Span, From b26371c21a51169412231d0ab5904d23d7300a0b Mon Sep 17 00:00:00 2001 From: Albert Larsan Date: Tue, 28 Feb 2023 15:25:09 +0100 Subject: [PATCH 09/14] Make mailmap more correct --- .mailmap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 726d4c3d1d262..715bc4d30855e 100644 --- a/.mailmap +++ b/.mailmap @@ -15,7 +15,7 @@ Adrien Tétar Ahmed Charles Alan Egerton Alan Stoate -Albert Larsan Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> +Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Alessandro Decina Alex Burka Alex Burka Alex Hansen From a321013f3e11d62eb29c34b885cb7cfe1c8194e3 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 28 Feb 2023 14:53:36 +0000 Subject: [PATCH 10/14] Fix `x clean` with specific paths --- src/bootstrap/clean.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/clean.rs b/src/bootstrap/clean.rs index 468efc1114c43..7ebd0a8f27069 100644 --- a/src/bootstrap/clean.rs +++ b/src/bootstrap/clean.rs @@ -62,6 +62,7 @@ macro_rules! clean_crate_tree { let target = compiler.host; let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean"); for krate in &*self.crates { + cargo.arg("-p"); cargo.arg(krate); } From 031206bc1d16edcc963a1d0987ad37448a4cc019 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 28 Feb 2023 19:28:14 +0400 Subject: [PATCH 11/14] micro fmt changes --- .../rustc_parse/src/parser/diagnostics.rs | 1 + compiler/rustc_parse/src/parser/expr.rs | 2 +- tests/ui/parser/issue-108495-dec.rs | 20 +++++++++---------- tests/ui/parser/issue-108495-dec.stderr | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 779fd90627bee..78e4f3581b9e1 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1368,6 +1368,7 @@ impl<'a> Parser<'a> { }; self.recover_from_inc_dec(operand_expr, kind, op_span) } + fn recover_from_inc_dec( &mut self, base: P, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index ec50388cb46f3..828c268b58888 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -281,6 +281,7 @@ impl<'a> Parser<'a> { lhs = self.recover_from_postfix_increment(lhs, op_span, starts_stmt)?; continue; } + if self.prev_token == token::BinOp(token::Minus) && self.token == token::BinOp(token::Minus) && self.prev_token.span.between(self.token.span).is_empty() @@ -606,7 +607,6 @@ impl<'a> Parser<'a> { let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt) } - token::Ident(..) if this.token.is_keyword(kw::Box) => { make_it!(this, attrs, |this, _| this.parse_box_expr(lo)) } diff --git a/tests/ui/parser/issue-108495-dec.rs b/tests/ui/parser/issue-108495-dec.rs index db45577ec0189..e0816f84e5c15 100644 --- a/tests/ui/parser/issue-108495-dec.rs +++ b/tests/ui/parser/issue-108495-dec.rs @@ -1,41 +1,39 @@ -fn test4() { +fn test0() { let mut i = 0; let _ = i + i--; //~ ERROR Rust has no postfix decrement operator // won't suggest since we can not handle the precedences } -fn test5() { +fn test1() { let mut i = 0; let _ = i-- + i--; //~ ERROR Rust has no postfix decrement operator } -fn test6() { +fn test2() { let mut i = 0; let _ = --i + i--; //~ ERROR Rust has no postfix decrement operator } -fn test7() { +fn test3() { let mut i = 0; let _ = i-- + --i; //~ ERROR Rust has no postfix decrement operator } -fn test8() { +fn test4() { let mut i = 0; let _ = (1 + 2 + i)--; //~ ERROR Rust has no postfix decrement operator } -fn test9() { +fn test5() { let mut i = 0; let _ = (i-- + 1) + 2; //~ ERROR Rust has no postfix decrement operator } - - -fn test14(){ +fn test6(){ let i=10; - while i!=0{ + while i != 0 { i--; //~ ERROR Rust has no postfix decrement operator } } -fn main() { } +fn main() {} diff --git a/tests/ui/parser/issue-108495-dec.stderr b/tests/ui/parser/issue-108495-dec.stderr index 90019e68f4460..85b29038f7c78 100644 --- a/tests/ui/parser/issue-108495-dec.stderr +++ b/tests/ui/parser/issue-108495-dec.stderr @@ -55,7 +55,7 @@ LL | let _ = ({ let tmp = i; i -= 1; tmp } + 1) + 2; | +++++++++++ ~~~~~~~~~~~~~~~ error: Rust has no postfix decrement operator - --> $DIR/issue-108495-dec.rs:37:10 + --> $DIR/issue-108495-dec.rs:35:10 | LL | i--; | ^^ not a valid postfix operator From edf053036f7db0839f54b8b05d159551f3eacc3b Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Tue, 28 Feb 2023 17:08:04 +0100 Subject: [PATCH 12/14] Add contains_key to SortedIndexMultiMap --- compiler/rustc_data_structures/src/sorted_map/index_map.rs | 5 +++++ compiler/rustc_data_structures/src/sorted_map/tests.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/compiler/rustc_data_structures/src/sorted_map/index_map.rs b/compiler/rustc_data_structures/src/sorted_map/index_map.rs index 814e7c7fb9ba6..7d23ff5194870 100644 --- a/compiler/rustc_data_structures/src/sorted_map/index_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map/index_map.rs @@ -100,6 +100,11 @@ impl SortedIndexMultiMap { (k == &key).then_some((i, v)) }) } + + #[inline] + pub fn contains_key(&self, key: K) -> bool { + self.get_by_key(key).next().is_some() + } } impl Eq for SortedIndexMultiMap {} diff --git a/compiler/rustc_data_structures/src/sorted_map/tests.rs b/compiler/rustc_data_structures/src/sorted_map/tests.rs index 3cc250862df42..def7a7112fb3f 100644 --- a/compiler/rustc_data_structures/src/sorted_map/tests.rs +++ b/compiler/rustc_data_structures/src/sorted_map/tests.rs @@ -17,6 +17,10 @@ fn test_sorted_index_multi_map() { assert_eq!(set.get_by_key(3).copied().collect::>(), vec![0]); assert!(set.get_by_key(4).next().is_none()); + // `contains_key` works + assert!(set.contains_key(3)); + assert!(!set.contains_key(4)); + // `get_by_key` returns items in insertion order. let twos: Vec<_> = set.get_by_key_enumerated(2).collect(); let idxs: Vec = twos.iter().map(|(i, _)| *i).collect(); From 2186358e5a124d486f55a20220f720fb8f9a0694 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Mon, 27 Feb 2023 13:31:35 -0700 Subject: [PATCH 13/14] compiler/rustc_session: fix sysroot detection logic ... ... on systems where /usr/lib contains a multi-arch structure --- compiler/rustc_session/src/filesearch.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 2075ed57a94db..f1fbf38217d64 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -182,7 +182,17 @@ pub fn get_or_default_sysroot() -> Result { if dir.ends_with(crate::config::host_triple()) { dir.parent() // chop off `$target` .and_then(|p| p.parent()) // chop off `rustlib` - .and_then(|p| p.parent()) // chop off `lib` + .and_then(|p| { + // chop off `lib` (this could be also $arch dir if the host sysroot uses a + // multi-arch layout like Debian or Ubuntu) + match p.parent() { + Some(p) => match p.file_name() { + Some(f) if f == "lib" => p.parent(), // first chop went for $arch, so chop again for `lib` + _ => Some(p), + }, + None => None, + } + }) .map(|s| s.to_owned()) .ok_or(format!( "Could not move 3 levels upper using `parent()` on {}", From 8c6c8b14b8709ab797921fabdf815bf3cea94a8b Mon Sep 17 00:00:00 2001 From: David Koloski Date: Tue, 28 Feb 2023 14:40:13 -0500 Subject: [PATCH 14/14] Update Fuchsia platform team members --- src/doc/rustc/src/platform-support/fuchsia.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/fuchsia.md b/src/doc/rustc/src/platform-support/fuchsia.md index 63dde2aaedd64..56322d0da4374 100644 --- a/src/doc/rustc/src/platform-support/fuchsia.md +++ b/src/doc/rustc/src/platform-support/fuchsia.md @@ -12,7 +12,6 @@ The [Fuchsia team]: - Tyler Mandry ([@tmandry](https://github.com/tmandry)) - Dan Johnson ([@computerdruid](https://github.com/computerdruid)) - David Koloski ([@djkoloski](https://github.com/djkoloski)) -- Andrew Pollack ([@andrewpollack](https://github.com/andrewpollack)) - Joseph Ryan ([@P1n3appl3](https://github.com/P1n3appl3)) As the team evolves over time, the specific members listed here may differ from