Skip to content

Commit 5f40394

Browse files
committed
Auto merge of #120877 - matthiaskrgr:rollup-j1b8mv6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #117614 (static mut: allow mutable reference to arbitrary types, not just slices and arrays) - #120719 (Remove support for `associated_type_bound` nested in `dyn` types) - #120764 (Add documentation on `str::starts_with`) - #120823 (Clarify that atomic and regular integers can differ in alignment) - #120859 (Loosen an assertion to account for stashed errors.) - #120865 (Turn the "no saved object file in work product" ICE into a translatable fatal error) - #120866 (Remove unnecessary `#![feature(min_specialization)]`) - #120870 (Allow restricted trait impls under `#[allow_internal_unstable(min_specialization)]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 232919c + 5591336 commit 5f40394

File tree

58 files changed

+225
-529
lines changed

Some content is hidden

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

58 files changed

+225
-529
lines changed

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(if_let_guard)]
1717
#![feature(let_chains)]
18-
#![feature(min_specialization)]
18+
#![cfg_attr(bootstrap, feature(min_specialization))]
1919
#![feature(negative_impls)]
2020
#![feature(stmt_expr_attributes)]
2121

compiler/rustc_ast_lowering/messages.ftl

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ ast_lowering_arbitrary_expression_in_pattern =
88
99
ast_lowering_argument = argument
1010
11+
ast_lowering_assoc_ty_binding_in_dyn =
12+
associated type bounds are not allowed in `dyn` types
13+
.suggestion = use `impl Trait` to introduce a type instead
14+
1115
ast_lowering_assoc_ty_parentheses =
1216
parenthesized generic arguments cannot be used in associated type constraints
1317
@@ -100,9 +104,6 @@ ast_lowering_match_arm_with_no_body =
100104
`match` arm with no body
101105
.suggestion = add a body after the pattern
102106
103-
ast_lowering_misplaced_assoc_ty_binding =
104-
associated type bounds are only allowed in where clauses and function signatures, not in {$position}
105-
106107
ast_lowering_misplaced_double_dot =
107108
`..` patterns are not allowed here
108109
.note = only allowed in tuple, tuple struct, and slice patterns

compiler/rustc_ast_lowering/src/errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ pub struct MisplacedImplTrait<'a> {
9494
}
9595

9696
#[derive(Diagnostic)]
97-
#[diag(ast_lowering_misplaced_assoc_ty_binding)]
98-
pub struct MisplacedAssocTyBinding<'a> {
97+
#[diag(ast_lowering_assoc_ty_binding_in_dyn)]
98+
pub struct MisplacedAssocTyBinding {
9999
#[primary_span]
100100
pub span: Span,
101-
pub position: DiagnosticArgFromDisplay<'a>,
101+
#[suggestion(code = " = impl", applicability = "maybe-incorrect", style = "verbose")]
102+
pub suggestion: Option<Span>,
102103
}
103104

104105
#[derive(Diagnostic, Clone, Copy)]

compiler/rustc_ast_lowering/src/lib.rs

+30-86
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ trait ResolverAstLoweringExt {
197197
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
198198
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
199199
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
200-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId);
201200
}
202201

203202
impl ResolverAstLoweringExt for ResolverAstLowering {
@@ -256,11 +255,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
256255
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
257256
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
258257
}
259-
260-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId) {
261-
let lifetimes = self.extra_lifetime_params_map.remove(&from).unwrap_or_default();
262-
self.extra_lifetime_params_map.insert(to, lifetimes);
263-
}
264258
}
265259

266260
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1084,88 +1078,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10841078
hir::TypeBindingKind::Equality { term }
10851079
}
10861080
AssocConstraintKind::Bound { bounds } => {
1087-
enum DesugarKind {
1088-
ImplTrait,
1089-
Error(ImplTraitPosition),
1090-
Bound,
1091-
}
1092-
1093-
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1094-
let desugar_kind = match itctx {
1095-
// in an argument, RPIT, or TAIT, if we are within a dyn type:
1096-
//
1097-
// fn foo(x: dyn Iterator<Item: Debug>)
1098-
//
1099-
// then desugar to:
1100-
//
1101-
// fn foo(x: dyn Iterator<Item = impl Debug>)
1102-
//
1103-
// This is because dyn traits must have all of their associated types specified.
1104-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1105-
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1106-
| ImplTraitContext::Universal
1107-
if self.is_in_dyn_type =>
1108-
{
1109-
DesugarKind::ImplTrait
1110-
}
1111-
1112-
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
1113-
DesugarKind::Error(position)
1114-
}
1115-
1116-
// We are in the parameter position, but not within a dyn type:
1117-
//
1118-
// fn foo(x: impl Iterator<Item: Debug>)
1119-
//
1120-
// so we leave it as is and this gets expanded in astconv to a bound like
1121-
// `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1122-
// `impl Iterator`.
1123-
_ => DesugarKind::Bound,
1124-
};
1125-
1126-
match desugar_kind {
1127-
DesugarKind::ImplTrait => {
1128-
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
1129-
// constructing the HIR for `impl bounds...` and then lowering that.
1130-
1131-
let impl_trait_node_id = self.next_node_id();
1132-
// Shift `impl Trait` lifetime captures from the associated type bound's
1133-
// node id to the opaque node id, so that the opaque can actually use
1134-
// these lifetime bounds.
1135-
self.resolver
1136-
.remap_extra_lifetime_params(constraint.id, impl_trait_node_id);
1137-
1138-
self.with_dyn_type_scope(false, |this| {
1139-
let node_id = this.next_node_id();
1140-
let ty = this.lower_ty(
1141-
&Ty {
1142-
id: node_id,
1143-
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1144-
span: this.lower_span(constraint.span),
1145-
tokens: None,
1146-
},
1147-
itctx,
1148-
);
1081+
// Disallow ATB in dyn types
1082+
if self.is_in_dyn_type {
1083+
let suggestion = match itctx {
1084+
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1085+
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1086+
| ImplTraitContext::Universal => {
1087+
let bound_end_span = constraint
1088+
.gen_args
1089+
.as_ref()
1090+
.map_or(constraint.ident.span, |args| args.span());
1091+
if bound_end_span.eq_ctxt(constraint.span) {
1092+
Some(self.tcx.sess.source_map().next_point(bound_end_span))
1093+
} else {
1094+
None
1095+
}
1096+
}
1097+
_ => None,
1098+
};
11491099

1150-
hir::TypeBindingKind::Equality { term: ty.into() }
1151-
})
1152-
}
1153-
DesugarKind::Bound => {
1154-
// Desugar `AssocTy: Bounds` into a type binding where the
1155-
// later desugars into a trait predicate.
1156-
let bounds = self.lower_param_bounds(bounds, itctx);
1100+
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1101+
span: constraint.span,
1102+
suggestion,
1103+
});
1104+
let err_ty =
1105+
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1106+
hir::TypeBindingKind::Equality { term: err_ty.into() }
1107+
} else {
1108+
// Desugar `AssocTy: Bounds` into a type binding where the
1109+
// later desugars into a trait predicate.
1110+
let bounds = self.lower_param_bounds(bounds, itctx);
11571111

1158-
hir::TypeBindingKind::Constraint { bounds }
1159-
}
1160-
DesugarKind::Error(position) => {
1161-
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1162-
span: constraint.span,
1163-
position: DiagnosticArgFromDisplay(&position),
1164-
});
1165-
let err_ty =
1166-
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1167-
hir::TypeBindingKind::Equality { term: err_ty.into() }
1168-
}
1112+
hir::TypeBindingKind::Constraint { bounds }
11691113
}
11701114
}
11711115
};

compiler/rustc_codegen_llvm/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(hash_raw_entry)]
1414
#![feature(iter_intersperse)]
1515
#![feature(let_chains)]
16-
#![feature(min_specialization)]
1716
#![feature(impl_trait_in_assoc_type)]
1817

1918
#[macro_use]

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ codegen_ssa_no_module_named =
190190
191191
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
192192
193+
codegen_ssa_no_saved_object_file = cached cgu {$cgu_name} should have an object file, but doesn't
194+
193195
codegen_ssa_processing_dymutil_failed = processing debug info with `dsymutil` failed: {$status}
194196
.note = {$output}
195197

compiler/rustc_codegen_ssa/src/back/write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
913913

914914
let object = load_from_incr_comp_dir(
915915
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
916-
module.source.saved_files.get("o").expect("no saved object file in work product"),
916+
module.source.saved_files.get("o").unwrap_or_else(|| {
917+
cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name })
918+
}),
917919
);
918920
let dwarf_object =
919921
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {

compiler/rustc_codegen_ssa/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ pub struct NoNatvisDirectory {
121121
pub error: Error,
122122
}
123123

124+
#[derive(Diagnostic)]
125+
#[diag(codegen_ssa_no_saved_object_file)]
126+
pub struct NoSavedObjectFile<'a> {
127+
pub cgu_name: &'a str,
128+
}
129+
124130
#[derive(Diagnostic)]
125131
#[diag(codegen_ssa_copy_path_buf)]
126132
pub struct CopyPathBuf {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -449,35 +449,27 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
449449
}
450450
}
451451

452-
Rvalue::Ref(_, BorrowKind::Mut { .. }, place) => {
453-
let ty = place.ty(self.body, self.tcx).ty;
454-
let is_allowed = match ty.kind() {
455-
// Inside a `static mut`, `&mut [...]` is allowed.
456-
ty::Array(..) | ty::Slice(_)
457-
if self.const_kind() == hir::ConstContext::Static(hir::Mutability::Mut) =>
458-
{
459-
true
460-
}
461-
462-
// FIXME(ecstaticmorse): We could allow `&mut []` inside a const context given
463-
// that this is merely a ZST and it is already eligible for promotion.
464-
// This may require an RFC?
465-
/*
466-
ty::Array(_, len) if len.try_eval_target_usize(cx.tcx, cx.param_env) == Some(0)
467-
=> true,
468-
*/
469-
_ => false,
470-
};
452+
Rvalue::Ref(_, BorrowKind::Mut { .. }, place)
453+
| Rvalue::AddressOf(Mutability::Mut, place) => {
454+
// Inside mutable statics, we allow arbitrary mutable references.
455+
// We've allowed `static mut FOO = &mut [elements];` for a long time (the exact
456+
// reasons why are lost to history), and there is no reason to restrict that to
457+
// arrays and slices.
458+
let is_allowed =
459+
self.const_kind() == hir::ConstContext::Static(hir::Mutability::Mut);
471460

472461
if !is_allowed {
473-
self.check_mut_borrow(place.local, hir::BorrowKind::Ref)
462+
self.check_mut_borrow(
463+
place.local,
464+
if matches!(rvalue, Rvalue::Ref(..)) {
465+
hir::BorrowKind::Ref
466+
} else {
467+
hir::BorrowKind::Raw
468+
},
469+
);
474470
}
475471
}
476472

477-
Rvalue::AddressOf(Mutability::Mut, place) => {
478-
self.check_mut_borrow(place.local, hir::BorrowKind::Raw)
479-
}
480-
481473
Rvalue::Ref(_, BorrowKind::Shared | BorrowKind::Fake, place)
482474
| Rvalue::AddressOf(Mutability::Not, place) => {
483475
let borrowed_place_has_mut_interior = qualifs::in_place::<HasMutInterior, _>(

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![allow(internal_features)]
88
#![allow(rustc::diagnostic_outside_of_impl)]
99
#![allow(rustc::untranslatable_diagnostic)]
10+
#![cfg_attr(bootstrap, feature(min_specialization))]
1011
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1112
#![doc(rust_logo)]
1213
#![feature(array_windows)]
@@ -16,7 +17,6 @@
1617
#![feature(error_reporter)]
1718
#![feature(extract_if)]
1819
#![feature(let_chains)]
19-
#![feature(min_specialization)]
2020
#![feature(negative_impls)]
2121
#![feature(never_type)]
2222
#![feature(rustc_attrs)]

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(associated_type_defaults)]
66
#![feature(closure_track_caller)]
77
#![feature(let_chains)]
8-
#![feature(min_specialization)]
8+
#![cfg_attr(bootstrap, feature(min_specialization))]
99
#![feature(never_type)]
1010
#![feature(rustc_attrs)]
1111
#![feature(variant_count)]

compiler/rustc_hir_analysis/src/check/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,8 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
12831283
let ty = tcx.type_of(def_id).instantiate_identity();
12841284
if ty.references_error() {
12851285
// If there is already another error, do not emit an error for not using a type parameter.
1286-
assert!(tcx.dcx().has_errors().is_some());
1286+
// Without the `stashed_err_count` part this can fail (#120856).
1287+
assert!(tcx.dcx().has_errors().is_some() || tcx.dcx().stashed_err_count() > 0);
12871288
return;
12881289
}
12891290

compiler/rustc_hir_analysis/src/coherence/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_errors::{codes::*, struct_span_code_err};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_middle::query::Providers;
1212
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
13-
use rustc_span::ErrorGuaranteed;
13+
use rustc_span::{sym, ErrorGuaranteed};
1414
use rustc_trait_selection::traits;
1515

1616
mod builtin;
@@ -70,7 +70,11 @@ fn enforce_trait_manually_implementable(
7070
if let ty::trait_def::TraitSpecializationKind::AlwaysApplicable =
7171
tcx.trait_def(trait_def_id).specialization_kind
7272
{
73-
if !tcx.features().specialization && !tcx.features().min_specialization {
73+
if !tcx.features().specialization
74+
&& !tcx.features().min_specialization
75+
&& !impl_header_span.allows_unstable(sym::specialization)
76+
&& !impl_header_span.allows_unstable(sym::min_specialization)
77+
{
7478
return Err(tcx.dcx().emit_err(errors::SpecializationTrait { span: impl_header_span }));
7579
}
7680
}

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
6767
#![feature(is_sorted)]
6868
#![feature(iter_intersperse)]
6969
#![feature(let_chains)]
70-
#![feature(min_specialization)]
70+
#![cfg_attr(bootstrap, feature(min_specialization))]
7171
#![feature(never_type)]
7272
#![feature(lazy_cell)]
7373
#![feature(slice_partition_dedup)]

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(try_blocks)]
66
#![feature(never_type)]
77
#![feature(box_patterns)]
8-
#![feature(min_specialization)]
8+
#![cfg_attr(bootstrap, feature(min_specialization))]
99
#![feature(control_flow_enum)]
1010

1111
#[macro_use]

compiler/rustc_infer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![feature(let_chains)]
2525
#![feature(if_let_guard)]
2626
#![feature(iterator_try_collect)]
27-
#![feature(min_specialization)]
27+
#![cfg_attr(bootstrap, feature(min_specialization))]
2828
#![feature(try_blocks)]
2929
#![recursion_limit = "512"] // For rustdoc
3030

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(iter_order_by)]
3636
#![feature(let_chains)]
3737
#![feature(trait_upcasting)]
38-
#![feature(min_specialization)]
3938
#![feature(rustc_attrs)]
4039
#![allow(internal_features)]
4140

compiler/rustc_lint_defs/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(min_specialization)]
2-
31
#[macro_use]
42
extern crate rustc_macros;
53

compiler/rustc_mir_build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![feature(box_patterns)]
1010
#![feature(if_let_guard)]
1111
#![feature(let_chains)]
12-
#![feature(min_specialization)]
12+
#![cfg_attr(bootstrap, feature(min_specialization))]
1313
#![feature(try_blocks)]
1414

1515
#[macro_use]

compiler/rustc_mir_dataflow/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(box_patterns)]
33
#![feature(exact_size_is_empty)]
44
#![feature(let_chains)]
5-
#![feature(min_specialization)]
5+
#![cfg_attr(bootstrap, feature(min_specialization))]
66
#![feature(try_blocks)]
77

88
#[macro_use]

0 commit comments

Comments
 (0)