Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #132548

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
720d618
unicode_data.rs: show command for generating file
RalfJung Nov 2, 2024
34432f7
const_with_hasher test: actually construct a usable HashMap
RalfJung Nov 2, 2024
5266623
remove const_hash feature leftovers
RalfJung Nov 2, 2024
8837fc7
make codegen help output more consistent
senekor Nov 2, 2024
19673db
stabilize const_arguments_as_str
RalfJung Nov 2, 2024
afe1902
coverage: Regression test for inlining into an uninstrumented crate
Zalathar Nov 1, 2024
f341a19
NFC add known bug nr to test
matthiaskrgr Nov 2, 2024
b919675
Added regression test for 117446
ranger-ross Nov 2, 2024
82f8b8f
Use opt functions to not ICE in fallback suggestion
compiler-errors Nov 2, 2024
ab5583e
PassWrapper: adapt for llvm/llvm-project@b01e2a8b5620466c3b80cc6f049e…
durin42 Oct 31, 2024
c7b07d5
Rustdoc: added brief colon explanation
zedddie16 Oct 31, 2024
c613122
PassWrapper: adapt for llvm/llvm-project@5445edb5d
durin42 Nov 2, 2024
16394e9
Do not format generic consts
compiler-errors Nov 2, 2024
c0ca280
Rollup merge of #132393 - zedddie16:issue-131865-fix, r=tgross35
workingjubilee Nov 3, 2024
740044c
Rollup merge of #132419 - durin42:llvm-20-type-test-thing, r=cuviper
workingjubilee Nov 3, 2024
6f7074b
Rollup merge of #132437 - Zalathar:inline-mixed-regression, r=jieyouxu
workingjubilee Nov 3, 2024
9787449
Rollup merge of #132499 - RalfJung:unicode_data.rs, r=tgross35
workingjubilee Nov 3, 2024
4ab4fd2
Rollup merge of #132503 - RalfJung:const-hash-map, r=Amanieu
workingjubilee Nov 3, 2024
d420d94
Rollup merge of #132511 - RalfJung:const_arguments_as_str, r=dtolnay
workingjubilee Nov 3, 2024
eef2321
Rollup merge of #132520 - matthiaskrgr:knobu, r=jieyouxu
workingjubilee Nov 3, 2024
6a68225
Rollup merge of #132522 - senekor:consistenst-codegen-help, r=compile…
workingjubilee Nov 3, 2024
de48ea4
Rollup merge of #132523 - ranger-ross:test-issue-117446, r=compiler-e…
workingjubilee Nov 3, 2024
8260901
Rollup merge of #132528 - compiler-errors:fallback-sugg-opt, r=jieyouxu
workingjubilee Nov 3, 2024
e862ec7
Rollup merge of #132537 - durin42:llvm-20-prelinklto, r=DianQK
workingjubilee Nov 3, 2024
e0df21d
Rollup merge of #132540 - compiler-errors:gc, r=calebcartwright
workingjubilee Nov 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ pub struct WhereClause {
pub span: Span,
}

impl WhereClause {
pub fn is_empty(&self) -> bool {
!self.has_where_token && self.predicates.is_empty()
}
}

impl Default for WhereClause {
fn default() -> WhereClause {
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result {
// Try to replace `_` with `()`.
if let hir::TyKind::Infer = hir_ty.kind
&& let ty = self.fcx.typeck_results.borrow().node_type(hir_ty.hir_id)
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
{
Expand Down Expand Up @@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let Res::Def(DefKind::AssocFn, def_id) = path.res
&& self.fcx.tcx.trait_of_item(def_id).is_some()
&& let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0)
&& let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id)
&& let self_ty = args.type_at(0)
&& let Some(vid) = self.fcx.root_vid(self_ty)
&& self.reachable_vids.contains(&vid)
&& let [.., trait_segment, _method_segment] = path.segments
Expand All @@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
// For a local, try suggest annotating the type if it's missing.
if let None = local.ty
&& let ty = self.fcx.typeck_results.borrow().node_type(local.hir_id)
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
{
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;

// FIXME: We may want to expose this as an option.
bool DebugPassManager = false;

StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
StandardInstrumentations SI(TheModule->getContext(),
/*DebugLogging=*/false);
SI.registerCallbacks(PIC, &MAM);

if (LLVMPluginsLen) {
Expand Down Expand Up @@ -825,9 +823,9 @@ extern "C" LLVMRustResult LLVMRustOptimize(
!NoPrepopulatePasses) {
PipelineStartEPCallbacks.push_back(
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
/*ImportSummary=*/nullptr,
/*DropTypeTests=*/false));
MPM.addPass(LowerTypeTestsPass(
/*ExportSummary=*/nullptr,
/*ImportSummary=*/nullptr));
});
}

Expand Down Expand Up @@ -932,8 +930,9 @@ extern "C" LLVMRustResult LLVMRustOptimize(
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);

// Pass false as we manually schedule ThinLTOBufferPasses below.
MPM = PB.buildO0DefaultPipeline(OptLevel, /* PreLinkLTO */ false);
// We manually schedule ThinLTOBufferPasses below, so don't pass the value
// to enable it here.
MPM = PB.buildO0DefaultPipeline(OptLevel);
} else {
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
Expand All @@ -942,7 +941,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(

switch (OptStage) {
case LLVMRustOptStage::PreLinkNoLTO:
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
MPM = PB.buildPerModuleDefaultPipeline(OptLevel);
break;
case LLVMRustOptStage::PreLinkThinLTO:
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ options! {
link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
"keep dead code at link time (useful for code coverage) (default: no)"),
link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED],
"control whether to link Rust provided C objects/libraries or rely
"control whether to link Rust provided C objects/libraries or rely \
on a C toolchain or linker installed in the system"),
linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
"system linker to link outputs with"),
Expand Down
10 changes: 10 additions & 0 deletions library/alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@
//! parameters (corresponding to `format_spec` in [the syntax](#syntax)). These
//! parameters affect the string representation of what's being formatted.
//!
//! The colon `:` in format syntax divides indentifier of the input data and
//! the formatting options, the colon itself does not change anything, only
//! introduces the options.
//!
//! ```
//! let a = 5;
//! let b = &a;
//! println!("{a:e} {b:p}"); // => 5e0 0x7ffe37b7273c
//! ```
//!
//! ## Width
//!
//! ```
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,9 @@ impl<'a> Arguments<'a> {
/// assert_eq!(format_args!("{:?}", std::env::current_dir()).as_str(), None);
/// ```
#[stable(feature = "fmt_as_str", since = "1.52.0")]
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "103900")]
#[rustc_const_stable(feature = "const_arguments_as_str", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
pub const fn as_str(&self) -> Option<&'static str> {
match (self.pieces, self.args) {
([], []) => Some(""),
Expand Down
12 changes: 4 additions & 8 deletions library/core/src/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,17 @@ impl SipHasher {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
#[must_use]
pub const fn new() -> SipHasher {
pub fn new() -> SipHasher {
SipHasher::new_with_keys(0, 0)
}

/// Creates a `SipHasher` that is keyed off the provided keys.
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
#[must_use]
pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
SipHasher(SipHasher24 { hasher: Hasher::new_with_keys(key0, key1) })
}
}
Expand All @@ -169,17 +167,15 @@ impl SipHasher13 {
#[inline]
#[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
pub const fn new() -> SipHasher13 {
pub fn new() -> SipHasher13 {
SipHasher13::new_with_keys(0, 0)
}

/// Creates a `SipHasher13` that is keyed off the provided keys.
#[inline]
#[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) }
}
}
Expand Down
2 changes: 0 additions & 2 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@
#![feature(const_align_of_val_raw)]
#![feature(const_align_offset)]
#![feature(const_alloc_layout)]
#![feature(const_arguments_as_str)]
#![feature(const_array_into_iter_constructors)]
#![feature(const_bigint_helper_methods)]
#![feature(const_black_box)]
#![feature(const_char_encode_utf16)]
#![feature(const_eval_select)]
#![feature(const_exact_div)]
#![feature(const_float_methods)]
#![feature(const_hash)]
#![feature(const_heap)]
#![feature(const_nonnull_new)]
#![feature(const_num_midpoint)]
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/panic/panic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ impl<'a> PanicMessage<'a> {
///
/// See [`fmt::Arguments::as_str`] for details.
#[stable(feature = "panic_info_message", since = "1.81.0")]
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "103900")]
#[rustc_const_stable(feature = "const_arguments_as_str", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
pub const fn as_str(&self) -> Option<&'static str> {
self.message.as_str()
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/unicode/unicode_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! This file is generated by src/tools/unicode-table-generator; do not edit manually!
///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually!

#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")]
#[inline(always)]
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![feature(const_bigint_helper_methods)]
#![feature(const_black_box)]
#![feature(const_eval_select)]
#![feature(const_hash)]
#![feature(const_heap)]
#![feature(const_nonnull_new)]
#![feature(const_num_midpoint)]
Expand Down
26 changes: 23 additions & 3 deletions library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::Entry::{Occupied, Vacant};
use super::HashMap;
use crate::assert_matches::assert_matches;
use crate::cell::RefCell;
use crate::hash::RandomState;
use crate::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, RandomState};
use crate::test_helpers::test_rng;

// https://github.com/rust-lang/rust/issues/62301
Expand Down Expand Up @@ -1124,6 +1124,26 @@ fn from_array() {

#[test]
fn const_with_hasher() {
const X: HashMap<(), (), ()> = HashMap::with_hasher(());
assert_eq!(X.len(), 0);
const X: HashMap<(), (), BuildHasherDefault<DefaultHasher>> =
HashMap::with_hasher(BuildHasherDefault::new());
let mut x = X;
assert_eq!(x.len(), 0);
x.insert((), ());
assert_eq!(x.len(), 1);

// It *is* possible to do this without using the `BuildHasherDefault` type.
struct MyBuildDefaultHasher;
impl BuildHasher for MyBuildDefaultHasher {
type Hasher = DefaultHasher;

fn build_hasher(&self) -> Self::Hasher {
DefaultHasher::new()
}
}

const Y: HashMap<(), (), MyBuildDefaultHasher> = HashMap::with_hasher(MyBuildDefaultHasher);
let mut y = Y;
assert_eq!(y.len(), 0);
y.insert((), ());
assert_eq!(y.len(), 1);
}
3 changes: 1 addition & 2 deletions library/std/src/hash/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ impl DefaultHasher {
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
#[inline]
#[allow(deprecated)]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
#[must_use]
pub const fn new() -> DefaultHasher {
pub fn new() -> DefaultHasher {
DefaultHasher(SipHasher13::new_with_keys(0, 0))
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
// Library features (core):
// tidy-alphabetical-start
#![feature(array_chunks)]
#![feature(build_hasher_default_const_new)]
#![feature(c_str_module)]
#![feature(char_internals)]
#![feature(clone_to_uninit)]
Expand Down Expand Up @@ -415,7 +416,6 @@
// Only for const-ness:
// tidy-alphabetical-start
#![feature(const_collections_with_hasher)]
#![feature(const_hash)]
#![feature(thread_local_internals)]
// tidy-alphabetical-end
//
Expand Down
27 changes: 21 additions & 6 deletions src/tools/rustfmt/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ pub(crate) struct StaticParts<'a> {
safety: ast::Safety,
vis: &'a ast::Visibility,
ident: symbol::Ident,
generics: Option<&'a ast::Generics>,
ty: &'a ast::Ty,
mutability: ast::Mutability,
expr_opt: Option<&'a ptr::P<ast::Expr>>,
Expand All @@ -2018,15 +2019,18 @@ pub(crate) struct StaticParts<'a> {

impl<'a> StaticParts<'a> {
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
let (defaultness, prefix, safety, ty, mutability, expr) = match &item.kind {
ast::ItemKind::Static(s) => (None, "static", s.safety, &s.ty, s.mutability, &s.expr),
let (defaultness, prefix, safety, ty, mutability, expr, generics) = match &item.kind {
ast::ItemKind::Static(s) => {
(None, "static", s.safety, &s.ty, s.mutability, &s.expr, None)
}
ast::ItemKind::Const(c) => (
Some(c.defaultness),
"const",
ast::Safety::Default,
&c.ty,
ast::Mutability::Not,
&c.expr,
Some(&c.generics),
),
_ => unreachable!(),
};
Expand All @@ -2035,6 +2039,7 @@ impl<'a> StaticParts<'a> {
safety,
vis: &item.vis,
ident: item.ident,
generics,
ty,
mutability,
expr_opt: expr.as_ref(),
Expand All @@ -2044,15 +2049,16 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr_opt) = match &ti.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
let (defaultness, ty, expr_opt, generics) = match &ti.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
_ => unreachable!(),
};
StaticParts {
prefix: "const",
safety: ast::Safety::Default,
vis: &ti.vis,
ident: ti.ident,
generics,
ty,
mutability: ast::Mutability::Not,
expr_opt: expr_opt.as_ref(),
Expand All @@ -2062,15 +2068,16 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr) = match &ii.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
let (defaultness, ty, expr, generics) = match &ii.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
_ => unreachable!(),
};
StaticParts {
prefix: "const",
safety: ast::Safety::Default,
vis: &ii.vis,
ident: ii.ident,
generics,
ty,
mutability: ast::Mutability::Not,
expr_opt: expr.as_ref(),
Expand All @@ -2085,6 +2092,14 @@ fn rewrite_static(
static_parts: &StaticParts<'_>,
offset: Indent,
) -> Option<String> {
// For now, if this static (or const) has generics, then bail.
if static_parts
.generics
.is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty())
{
return None;
}

let colon = colon_spaces(context.config);
let mut prefix = format!(
"{}{}{}{} {}{}{}",
Expand Down
25 changes: 25 additions & 0 deletions src/tools/rustfmt/tests/target/const-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Make sure we don't mess up the formatting of generic consts

#![feature(generic_const_items)]

const GENERIC<N, const M: usize>: i32 = 0;

const WHERECLAUSE: i32 = 0
where
i32:;

trait Foo {
const GENERIC<N, const M: usize>: i32;

const WHERECLAUSE: i32
where
i32:;
}

impl Foo for () {
const GENERIC<N, const M: usize>: i32 = 0;

const WHERECLAUSE: i32 = 0
where
i32:;
}
2 changes: 1 addition & 1 deletion src/tools/unicode-table-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn main() {
let mut table_file = String::new();

table_file.push_str(
"///! This file is generated by src/tools/unicode-table-generator; do not edit manually!\n",
"///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually!\n",
);

// Include the range search function
Expand Down
Loading
Loading