Skip to content

Commit 953cc43

Browse files
Swatinemc4rrao
authored andcommitted
Sync fork
Add a fast-path to `Debug` ASCII `&str` Instead of going through the `EscapeDebug` machinery, we can just skip over ASCII chars that don’t need any escaping. Introduce printable-ASCII fast-path for `impl Debug for str` Instead of having a single loop that works on utf-8 `char`s, this splits the implementation into a loop that quickly skips over printable ASCII, falling back to per-char iteration for other chunks. Switch to primarily using `&str` Surprisingly, benchmarks have shown that using `&str` instead of `&[u8]` with some `unsafe` code is actually faster. Process a single not-ASCII-printable `char` per iteration This avoids having to collect a non-ASCII-printable run before processing it. std: simplify key-based thread locals std: clean up the TLS implementation Make clamp inline Run rustfmt on files that need it. Somehow these files aren't properly formatted. By default `x fmt` and `x tidy` only check files that have changed against master, so if an ill-formatted file somehow slips in it can stay that way as long as it doesn't get modified(?) I found these when I ran `x fmt` explicitly on every `.rs` file in the repo, while working on rust-lang/compiler-team#750. Fix the dead link in the bootstrap README Notify kobzol after changes to `opt-dist` Revert "Rollup merge of rust-lang#123979 - oli-obk:define_opaque_types7, r=compiler-errors" This reverts commit f939d1f, reversing changes made to 183c706. Add regression tests Only suppress binop error in favor of semicolon suggestion if we're in an assignment statement compiler: const_eval/transform/validate.rs -> mir_transform/validate.rs compiler: unnest rustc_const_eval::check_consts clippy: unnest check_consts miri: receive the blessings of validate.rs Migrate `run-make/rustdoc-with-output-dir-option` to `rmake.rs` Fix some SIMD intrinsics documentation Actually just remove the special case altogether rustdoc-json: Add test for keywords with `--document-private-items` tag more stuff with `WG-trait-system-refactor` Warn/error on self ctor from outer item in inner item (Mostly) revert "Account for type param from other item in `note_and_explain`" This mostly reverts commit 7449478. It also removes an `opt_param_at` that really is unnecessary given our ICE policy for malformed intrinsics. Update cargo use posix_memalign on most Unix targets fix typo Co-authored-by: Jubilee <[email protected]> Fail relating constants of different types Use regular type equating instead of a custom query Bump bootstrap compiler to the latest beta compiler Remove now outdated comment since we bumped stage0 Stop using the avx512er and avx512pf x86 target features They are no longer supported by LLVM 19. Fixes rust-lang#125492 remove proof tree formatter, make em shallow Don't eagerly monomorphize drop for types that are impossible to instantiate Better ICE message for unresolved upvars Structurally resolve before builtin_index in EUV Add manual Sync impl for ReentrantLockGuard Fixes: rust-lang#125526
1 parent 8971f10 commit 953cc43

File tree

121 files changed

+1504
-1697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1504
-1697
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,7 @@ dependencies = [
42524252
"rustc_fluent_macro",
42534253
"rustc_hir",
42544254
"rustc_index",
4255+
"rustc_infer",
42554256
"rustc_macros",
42564257
"rustc_middle",
42574258
"rustc_mir_build",

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, Debugger
2929
use rustc_middle::middle::exported_symbols;
3030
use rustc_middle::middle::exported_symbols::SymbolExportKind;
3131
use rustc_middle::middle::lang_items;
32-
use rustc_middle::mir::BinOp;
3332
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
33+
use rustc_middle::mir::BinOp;
3434
use rustc_middle::query::Providers;
3535
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
3636
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ where
139139
ErrorHandled::TooGeneric(span)
140140
}
141141
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span),
142-
err_inval!(Layout(LayoutError::ReferencesError(guar))) => ErrorHandled::Reported(
143-
ReportedErrorInfo::tainted_by_errors(guar),
144-
span,
145-
),
142+
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
143+
ErrorHandled::Reported(ReportedErrorInfo::tainted_by_errors(guar), span)
144+
}
146145
// Report remaining errors.
147146
_ => {
148147
let (our_span, frames) = get_span_and_frames();

compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#![feature(yeet_expr)]
1515
#![feature(if_let_guard)]
1616

17+
pub mod check_consts;
1718
pub mod const_eval;
1819
mod errors;
1920
pub mod interpret;
20-
pub mod transform;
2121
pub mod util;
2222

2323
use std::sync::atomic::AtomicBool;

compiler/rustc_const_eval/src/transform/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ pub fn check_intrinsic_type(
164164
) {
165165
let generics = tcx.generics_of(intrinsic_id);
166166
let param = |n| {
167-
if let Some(&ty::GenericParamDef {
168-
name, kind: ty::GenericParamDefKind::Type { .. }, ..
169-
}) = generics.opt_param_at(n as usize, tcx)
167+
if let &ty::GenericParamDef { name, kind: ty::GenericParamDefKind::Type { .. }, .. } =
168+
generics.param_at(n as usize, tcx)
170169
{
171170
Ty::new_param(tcx, n, name)
172171
} else {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 47 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -461,83 +461,55 @@ pub(super) fn explicit_predicates_of<'tcx>(
461461
}
462462
}
463463
} else {
464-
if matches!(def_kind, DefKind::AnonConst) && tcx.features().generic_const_exprs {
465-
let hir_id = tcx.local_def_id_to_hir_id(def_id);
466-
let parent_def_id = tcx.hir().get_parent_item(hir_id);
467-
468-
if let Some(defaulted_param_def_id) =
469-
tcx.hir().opt_const_param_default_param_def_id(hir_id)
470-
{
471-
// In `generics_of` we set the generics' parent to be our parent's parent which means that
472-
// we lose out on the predicates of our actual parent if we dont return those predicates here.
473-
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
474-
//
475-
// struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait;
476-
// ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling
477-
// ^^^ explicit_predicates_of on
478-
// parent item we dont have set as the
479-
// parent of generics returned by `generics_of`
480-
//
481-
// In the above code we want the anon const to have predicates in its param env for `T: Trait`
482-
// and we would be calling `explicit_predicates_of(Foo)` here
483-
let parent_preds = tcx.explicit_predicates_of(parent_def_id);
484-
485-
// If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter
486-
// will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
487-
// to #106994 is implemented.
488-
let filtered_predicates = parent_preds
489-
.predicates
490-
.into_iter()
491-
.filter(|(pred, _)| {
492-
if let ty::ClauseKind::ConstArgHasType(ct, _) = pred.kind().skip_binder() {
493-
match ct.kind() {
494-
ty::ConstKind::Param(param_const) => {
495-
let defaulted_param_idx = tcx
496-
.generics_of(parent_def_id)
497-
.param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
498-
param_const.index < defaulted_param_idx
499-
}
500-
_ => bug!(
501-
"`ConstArgHasType` in `predicates_of`\
502-
that isn't a `Param` const"
503-
),
464+
if matches!(def_kind, DefKind::AnonConst)
465+
&& tcx.features().generic_const_exprs
466+
&& let Some(defaulted_param_def_id) =
467+
tcx.hir().opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
468+
{
469+
// In `generics_of` we set the generics' parent to be our parent's parent which means that
470+
// we lose out on the predicates of our actual parent if we dont return those predicates here.
471+
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
472+
//
473+
// struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait;
474+
// ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling
475+
// ^^^ explicit_predicates_of on
476+
// parent item we dont have set as the
477+
// parent of generics returned by `generics_of`
478+
//
479+
// In the above code we want the anon const to have predicates in its param env for `T: Trait`
480+
// and we would be calling `explicit_predicates_of(Foo)` here
481+
let parent_def_id = tcx.local_parent(def_id);
482+
let parent_preds = tcx.explicit_predicates_of(parent_def_id);
483+
484+
// If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter
485+
// will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
486+
// to #106994 is implemented.
487+
let filtered_predicates = parent_preds
488+
.predicates
489+
.into_iter()
490+
.filter(|(pred, _)| {
491+
if let ty::ClauseKind::ConstArgHasType(ct, _) = pred.kind().skip_binder() {
492+
match ct.kind() {
493+
ty::ConstKind::Param(param_const) => {
494+
let defaulted_param_idx = tcx
495+
.generics_of(parent_def_id)
496+
.param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
497+
param_const.index < defaulted_param_idx
504498
}
505-
} else {
506-
true
499+
_ => bug!(
500+
"`ConstArgHasType` in `predicates_of`\
501+
that isn't a `Param` const"
502+
),
507503
}
508-
})
509-
.cloned();
510-
return GenericPredicates {
511-
parent: parent_preds.parent,
512-
predicates: { tcx.arena.alloc_from_iter(filtered_predicates) },
513-
};
514-
}
515-
516-
let parent_def_kind = tcx.def_kind(parent_def_id);
517-
if matches!(parent_def_kind, DefKind::OpaqueTy) {
518-
// In `instantiate_identity` we inherit the predicates of our parent.
519-
// However, opaque types do not have a parent (see `gather_explicit_predicates_of`), which means
520-
// that we lose out on the predicates of our actual parent if we dont return those predicates here.
521-
//
522-
//
523-
// fn foo<T: Trait>() -> impl Iterator<Output = Another<{ <T as Trait>::ASSOC }> > { todo!() }
524-
// ^^^^^^^^^^^^^^^^^^^ the def id we are calling
525-
// explicit_predicates_of on
526-
//
527-
// In the above code we want the anon const to have predicates in its param env for `T: Trait`.
528-
// However, the anon const cannot inherit predicates from its parent since it's opaque.
529-
//
530-
// To fix this, we call `explicit_predicates_of` directly on `foo`, the parent's parent.
531-
532-
// In the above example this is `foo::{opaque#0}` or `impl Iterator`
533-
let parent_hir_id = tcx.local_def_id_to_hir_id(parent_def_id.def_id);
534-
535-
// In the above example this is the function `foo`
536-
let item_def_id = tcx.hir().get_parent_item(parent_hir_id);
537-
538-
// In the above code example we would be calling `explicit_predicates_of(foo)` here
539-
return tcx.explicit_predicates_of(item_def_id);
540-
}
504+
} else {
505+
true
506+
}
507+
})
508+
.cloned();
509+
return GenericPredicates {
510+
parent: parent_preds.parent,
511+
predicates: { tcx.arena.alloc_from_iter(filtered_predicates) },
512+
};
541513
}
542514
gather_explicit_predicates_of(tcx, def_id)
543515
}

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ hir_typeck_rpit_change_return_type = you could change the return type to be a bo
137137
hir_typeck_rustcall_incorrect_args =
138138
functions with the "rust-call" ABI must take a single non-self tuple argument
139139
140+
hir_typeck_self_ctor_from_outer_item = can't reference `Self` constructor from outer item
141+
.label = the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
142+
.suggestion = replace `Self` with the actual type
143+
140144
hir_typeck_struct_expr_non_exhaustive =
141145
cannot create non-exhaustive {$what} using struct expression
142146

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,31 @@ pub enum SuggestBoxingForReturnImplTrait {
651651
ends: Vec<Span>,
652652
},
653653
}
654+
655+
#[derive(Diagnostic)]
656+
#[diag(hir_typeck_self_ctor_from_outer_item, code = E0401)]
657+
pub struct SelfCtorFromOuterItem {
658+
#[primary_span]
659+
pub span: Span,
660+
#[label]
661+
pub impl_span: Span,
662+
#[subdiagnostic]
663+
pub sugg: Option<ReplaceWithName>,
664+
}
665+
666+
#[derive(LintDiagnostic)]
667+
#[diag(hir_typeck_self_ctor_from_outer_item)]
668+
pub struct SelfCtorFromOuterItemLint {
669+
#[label]
670+
pub impl_span: Span,
671+
#[subdiagnostic]
672+
pub sugg: Option<ReplaceWithName>,
673+
}
674+
675+
#[derive(Subdiagnostic)]
676+
#[suggestion(hir_typeck_suggestion, code = "{name}", applicability = "machine-applicable")]
677+
pub struct ReplaceWithName {
678+
#[primary_span]
679+
pub span: Span,
680+
pub name: String,
681+
}

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
17411741
}
17421742

17431743
PatKind::Slice(before, ref slice, after) => {
1744-
let Some(element_ty) = place_with_id.place.ty().builtin_index() else {
1744+
let Some(element_ty) = self
1745+
.cx
1746+
.try_structurally_resolve_type(pat.span, place_with_id.place.ty())
1747+
.builtin_index()
1748+
else {
17451749
debug!("explicit index of non-indexable type {:?}", place_with_id);
17461750
return Err(self
17471751
.cx

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::callee::{self, DeferredCallResolution};
2-
use crate::errors::CtorIsPrivate;
2+
use crate::errors::{self, CtorIsPrivate};
33
use crate::method::{self, MethodCallee, SelfSource};
44
use crate::rvalue_scopes;
55
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
@@ -21,6 +21,7 @@ use rustc_hir_analysis::hir_ty_lowering::{
2121
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
2222
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
2323
use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
24+
use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
2425
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2526
use rustc_middle::ty::error::TypeError;
2627
use rustc_middle::ty::fold::TypeFoldable;
@@ -1156,6 +1157,43 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11561157
span,
11571158
tcx.at(span).type_of(impl_def_id).instantiate_identity(),
11581159
);
1160+
1161+
// Firstly, check that this SelfCtor even comes from the item we're currently
1162+
// typechecking. This can happen because we never validated the resolution of
1163+
// SelfCtors, and when we started doing so, we noticed regressions. After
1164+
// sufficiently long time, we can remove this check and turn it into a hard
1165+
// error in `validate_res_from_ribs` -- it's just difficult to tell whether the
1166+
// self type has any generic types during rustc_resolve, which is what we use
1167+
// to determine if this is a hard error or warning.
1168+
if std::iter::successors(Some(self.body_id.to_def_id()), |def_id| {
1169+
self.tcx.generics_of(def_id).parent
1170+
})
1171+
.all(|def_id| def_id != impl_def_id)
1172+
{
1173+
let sugg = ty.normalized.ty_adt_def().map(|def| errors::ReplaceWithName {
1174+
span: path_span,
1175+
name: self.tcx.item_name(def.did()).to_ident_string(),
1176+
});
1177+
if ty.raw.has_param() {
1178+
let guar = self.tcx.dcx().emit_err(errors::SelfCtorFromOuterItem {
1179+
span: path_span,
1180+
impl_span: tcx.def_span(impl_def_id),
1181+
sugg,
1182+
});
1183+
return (Ty::new_error(self.tcx, guar), res);
1184+
} else {
1185+
self.tcx.emit_node_span_lint(
1186+
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
1187+
hir_id,
1188+
path_span,
1189+
errors::SelfCtorFromOuterItemLint {
1190+
impl_span: tcx.def_span(impl_def_id),
1191+
sugg,
1192+
},
1193+
);
1194+
}
1195+
}
1196+
11591197
match ty.normalized.ty_adt_def() {
11601198
Some(adt_def) if adt_def.has_ctor() => {
11611199
let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
381381
let maybe_missing_semi = self.check_for_missing_semi(expr, &mut err);
382382

383383
// We defer to the later error produced by `check_lhs_assignable`.
384-
// We only downgrade this if it's the LHS, though.
384+
// We only downgrade this if it's the LHS, though, and if this is a
385+
// valid assignment statement.
385386
if maybe_missing_semi
386387
&& let hir::Node::Expr(parent) = self.tcx.parent_hir_node(expr.hir_id)
387388
&& let hir::ExprKind::Assign(lhs, _, _) = parent.kind
389+
&& let hir::Node::Stmt(stmt) = self.tcx.parent_hir_node(parent.hir_id)
390+
&& let hir::StmtKind::Expr(_) | hir::StmtKind::Semi(_) = stmt.kind
388391
&& lhs.hir_id == expr.hir_id
389392
{
390393
err.downgrade_to_delayed_bug();

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
116116

117117
if let LoadResult::Ok { data: (work_products_data, start_pos) } = load_result {
118118
// Decode the list of work_products
119-
let Ok(mut work_product_decoder) =
120-
MemDecoder::new(&work_products_data[..], start_pos)
119+
let Ok(mut work_product_decoder) = MemDecoder::new(&work_products_data[..], start_pos)
121120
else {
122121
sess.dcx().emit_warn(errors::CorruptFile { path: &work_products_path });
123122
return LoadResult::DataOutOfDate;

0 commit comments

Comments
 (0)