Skip to content

Commit 29e9248

Browse files
committedAug 5, 2024
Auto merge of #128672 - matthiaskrgr:rollup-txf7siy, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #127655 (turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps`) - #127907 (built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lint) - #127974 (force compiling std from source if modified) - #128309 (Implement cursors for `BTreeSet`) - #128500 (Add test for updating enum discriminant through pointer) - #128623 (Do not fire unhandled attribute assertion on multi-segment `AttributeType::Normal` attributes with builtin attribute as first segment) r? `@ghost` `@rustbot` modify labels: rollup
·
1.88.01.82.0
2 parents 176e545 + 2048007 commit 29e9248

File tree

26 files changed

+942
-343
lines changed

26 files changed

+942
-343
lines changed
 

‎compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,10 @@ use std::{iter, vec};
181181
use rustc_ast::ptr::P;
182182
use rustc_ast::{
183183
self as ast, BindingMode, ByRef, EnumDef, Expr, GenericArg, GenericParamKind, Generics,
184-
Mutability, PatKind, TyKind, VariantData,
184+
Mutability, PatKind, VariantData,
185185
};
186186
use rustc_attr as attr;
187187
use rustc_expand::base::{Annotatable, ExtCtxt};
188-
use rustc_session::lint::builtin::BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE;
189188
use rustc_span::symbol::{kw, sym, Ident, Symbol};
190189
use rustc_span::{Span, DUMMY_SP};
191190
use thin_vec::{thin_vec, ThinVec};
@@ -1599,52 +1598,11 @@ impl<'a> TraitDef<'a> {
15991598
),
16001599
);
16011600
if is_packed {
1602-
// In general, fields in packed structs are copied via a
1603-
// block, e.g. `&{self.0}`. The two exceptions are `[u8]`
1604-
// and `str` fields, which cannot be copied and also never
1605-
// cause unaligned references. These exceptions are allowed
1606-
// to handle the `FlexZeroSlice` type in the `zerovec`
1607-
// crate within `icu4x-0.9.0`.
1608-
//
1609-
// Once use of `icu4x-0.9.0` has dropped sufficiently, this
1610-
// exception should be removed.
1611-
let is_simple_path = |ty: &P<ast::Ty>, sym| {
1612-
if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind
1613-
&& let [seg] = segments.as_slice()
1614-
&& seg.ident.name == sym
1615-
&& seg.args.is_none()
1616-
{
1617-
true
1618-
} else {
1619-
false
1620-
}
1621-
};
1622-
1623-
let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind
1624-
&& is_simple_path(ty, sym::u8)
1625-
{
1626-
Some("byte")
1627-
} else if is_simple_path(&struct_field.ty, sym::str) {
1628-
Some("string")
1629-
} else {
1630-
None
1631-
};
1632-
1633-
if let Some(ty) = exception {
1634-
cx.sess.psess.buffer_lint(
1635-
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
1636-
sp,
1637-
ast::CRATE_NODE_ID,
1638-
rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive {
1639-
ty: ty.to_string(),
1640-
},
1641-
);
1642-
} else {
1643-
// Wrap the expression in `{...}`, causing a copy.
1644-
field_expr = cx.expr_block(
1645-
cx.block(struct_field.span, thin_vec![cx.stmt_expr(field_expr)]),
1646-
);
1647-
}
1601+
// Fields in packed structs are wrapped in a block, e.g. `&{self.0}`,
1602+
// causing a copy instead of a (potentially misaligned) reference.
1603+
field_expr = cx.expr_block(
1604+
cx.block(struct_field.span, thin_vec![cx.stmt_expr(field_expr)]),
1605+
);
16481606
}
16491607
cx.expr_addr_of(sp, field_expr)
16501608
})

‎compiler/rustc_feature/src/removed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ declare_features! (
8282
/// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
8383
(removed, custom_derive, "1.32.0", Some(29644),
8484
Some("subsumed by `#[proc_macro_derive]`")),
85+
/// Allows default type parameters to influence type inference.
86+
(removed, default_type_parameter_fallback, "CURRENT_RUSTC_VERSION", Some(27336),
87+
Some("never properly implemented; requires significant design work")),
8588
/// Allows using `#[doc(keyword = "...")]`.
8689
(removed, doc_keyword, "1.28.0", Some(51315),
8790
Some("merged into `#![feature(rustdoc_internals)]`")),

‎compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ declare_features! (
431431
(unstable, custom_test_frameworks, "1.30.0", Some(50297)),
432432
/// Allows declarative macros 2.0 (`macro`).
433433
(unstable, decl_macro, "1.17.0", Some(39412)),
434-
/// Allows default type parameters to influence type inference.
435-
(unstable, default_type_parameter_fallback, "1.3.0", Some(27336)),
436434
/// Allows using `#[deprecated_safe]` to deprecate the safeness of a function or trait
437435
(unstable, deprecated_safe, "1.61.0", Some(94978)),
438436
/// Allows having using `suggestion` in the `#[deprecated]` attribute.

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
338338
if default.is_some() {
339339
match allow_defaults {
340340
Defaults::Allowed => {}
341-
Defaults::FutureCompatDisallowed
342-
if tcx.features().default_type_parameter_fallback => {}
343341
Defaults::FutureCompatDisallowed => {
344342
tcx.node_span_lint(
345343
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,

‎compiler/rustc_lint/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fn register_builtins(store: &mut LintStore) {
543543
);
544544
store.register_removed(
545545
"suspicious_auto_trait_impls",
546-
"no longer needed, see #93367 \
546+
"no longer needed, see issue #93367 \
547547
<https://github.com/rust-lang/rust/issues/93367> for more information",
548548
);
549549
store.register_removed(
@@ -565,6 +565,11 @@ fn register_builtins(store: &mut LintStore) {
565565
"box_pointers",
566566
"it does not detect other kinds of allocations, and existed only for historical reasons",
567567
);
568+
store.register_removed(
569+
"byte_slice_in_packed_struct_with_derive",
570+
"converted into hard error, see issue #107457 \
571+
<https://github.com/rust-lang/rust/issues/107457> for more information",
572+
)
568573
}
569574

570575
fn register_internals(store: &mut LintStore) {

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ declare_lint_pass! {
2626
BARE_TRAIT_OBJECTS,
2727
BINDINGS_WITH_VARIANT_NAME,
2828
BREAK_WITH_LABEL_AND_LOOP,
29-
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
3029
CENUM_IMPL_DROP_CAST,
3130
COHERENCE_LEAK_CHECK,
3231
CONFLICTING_REPR_HINTS,
@@ -1267,7 +1266,7 @@ declare_lint! {
12671266
Deny,
12681267
"type parameter default erroneously allowed in invalid location",
12691268
@future_incompatible = FutureIncompatibleInfo {
1270-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1269+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
12711270
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
12721271
};
12731272
}
@@ -4315,39 +4314,6 @@ declare_lint! {
43154314
report_in_external_macro
43164315
}
43174316

4318-
declare_lint! {
4319-
/// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field
4320-
/// (`[u8]`) or string slice field (`str`) is used in a `packed` struct that derives one or
4321-
/// more built-in traits.
4322-
///
4323-
/// ### Example
4324-
///
4325-
/// ```rust
4326-
/// #[repr(packed)]
4327-
/// #[derive(Hash)]
4328-
/// struct FlexZeroSlice {
4329-
/// width: u8,
4330-
/// data: [u8],
4331-
/// }
4332-
/// ```
4333-
///
4334-
/// {{produces}}
4335-
///
4336-
/// ### Explanation
4337-
///
4338-
/// This was previously accepted but is being phased out, because fields in packed structs are
4339-
/// now required to implement `Copy` for `derive` to work. Byte slices and string slices are a
4340-
/// temporary exception because certain crates depended on them.
4341-
pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
4342-
Warn,
4343-
"`[u8]` or `str` used in a packed struct with `derive`",
4344-
@future_incompatible = FutureIncompatibleInfo {
4345-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
4346-
reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
4347-
};
4348-
report_in_external_macro
4349-
}
4350-
43514317
declare_lint! {
43524318
/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
43534319
///

‎compiler/rustc_passes/src/check_attr.rs

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -116,130 +116,130 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
116116
let attrs = self.tcx.hir().attrs(hir_id);
117117
for attr in attrs {
118118
match attr.path().as_slice() {
119-
[sym::diagnostic, sym::do_not_recommend] => {
119+
[sym::diagnostic, sym::do_not_recommend, ..] => {
120120
self.check_do_not_recommend(attr.span, hir_id, target)
121121
}
122-
[sym::diagnostic, sym::on_unimplemented] => {
122+
[sym::diagnostic, sym::on_unimplemented, ..] => {
123123
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
124124
}
125-
[sym::inline] => self.check_inline(hir_id, attr, span, target),
126-
[sym::coverage] => self.check_coverage(attr, span, target),
127-
[sym::optimize] => self.check_optimize(hir_id, attr, target),
128-
[sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target),
129-
[sym::marker] => self.check_marker(hir_id, attr, span, target),
130-
[sym::target_feature] => {
125+
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
126+
[sym::coverage, ..] => self.check_coverage(attr, span, target),
127+
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
128+
[sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target),
129+
[sym::marker, ..] => self.check_marker(hir_id, attr, span, target),
130+
[sym::target_feature, ..] => {
131131
self.check_target_feature(hir_id, attr, span, target, attrs)
132132
}
133-
[sym::thread_local] => self.check_thread_local(attr, span, target),
134-
[sym::track_caller] => {
133+
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
134+
[sym::track_caller, ..] => {
135135
self.check_track_caller(hir_id, attr.span, attrs, span, target)
136136
}
137-
[sym::doc] => self.check_doc_attrs(
137+
[sym::doc, ..] => self.check_doc_attrs(
138138
attr,
139139
hir_id,
140140
target,
141141
&mut specified_inline,
142142
&mut doc_aliases,
143143
),
144-
[sym::no_link] => self.check_no_link(hir_id, attr, span, target),
145-
[sym::export_name] => self.check_export_name(hir_id, attr, span, target),
146-
[sym::rustc_layout_scalar_valid_range_start]
147-
| [sym::rustc_layout_scalar_valid_range_end] => {
144+
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
145+
[sym::export_name, ..] => self.check_export_name(hir_id, attr, span, target),
146+
[sym::rustc_layout_scalar_valid_range_start, ..]
147+
| [sym::rustc_layout_scalar_valid_range_end, ..] => {
148148
self.check_rustc_layout_scalar_valid_range(attr, span, target)
149149
}
150-
[sym::allow_internal_unstable] => {
150+
[sym::allow_internal_unstable, ..] => {
151151
self.check_allow_internal_unstable(hir_id, attr, span, target, attrs)
152152
}
153-
[sym::debugger_visualizer] => self.check_debugger_visualizer(attr, target),
154-
[sym::rustc_allow_const_fn_unstable] => {
153+
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
154+
[sym::rustc_allow_const_fn_unstable, ..] => {
155155
self.check_rustc_allow_const_fn_unstable(hir_id, attr, span, target)
156156
}
157-
[sym::rustc_std_internal_symbol] => {
157+
[sym::rustc_std_internal_symbol, ..] => {
158158
self.check_rustc_std_internal_symbol(attr, span, target)
159159
}
160-
[sym::naked] => self.check_naked(hir_id, attr, span, target, attrs),
161-
[sym::rustc_never_returns_null_ptr] => {
160+
[sym::naked, ..] => self.check_naked(hir_id, attr, span, target, attrs),
161+
[sym::rustc_never_returns_null_ptr, ..] => {
162162
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
163163
}
164-
[sym::rustc_legacy_const_generics] => {
164+
[sym::rustc_legacy_const_generics, ..] => {
165165
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
166166
}
167-
[sym::rustc_lint_query_instability] => {
167+
[sym::rustc_lint_query_instability, ..] => {
168168
self.check_rustc_lint_query_instability(hir_id, attr, span, target)
169169
}
170-
[sym::rustc_lint_diagnostics] => {
170+
[sym::rustc_lint_diagnostics, ..] => {
171171
self.check_rustc_lint_diagnostics(hir_id, attr, span, target)
172172
}
173-
[sym::rustc_lint_opt_ty] => self.check_rustc_lint_opt_ty(attr, span, target),
174-
[sym::rustc_lint_opt_deny_field_access] => {
173+
[sym::rustc_lint_opt_ty, ..] => self.check_rustc_lint_opt_ty(attr, span, target),
174+
[sym::rustc_lint_opt_deny_field_access, ..] => {
175175
self.check_rustc_lint_opt_deny_field_access(attr, span, target)
176176
}
177-
[sym::rustc_clean]
178-
| [sym::rustc_dirty]
179-
| [sym::rustc_if_this_changed]
180-
| [sym::rustc_then_this_would_need] => self.check_rustc_dirty_clean(attr),
181-
[sym::rustc_coinductive]
182-
| [sym::rustc_must_implement_one_of]
183-
| [sym::rustc_deny_explicit_impl]
184-
| [sym::const_trait] => self.check_must_be_applied_to_trait(attr, span, target),
185-
[sym::cmse_nonsecure_entry] => {
177+
[sym::rustc_clean, ..]
178+
| [sym::rustc_dirty, ..]
179+
| [sym::rustc_if_this_changed, ..]
180+
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
181+
[sym::rustc_coinductive, ..]
182+
| [sym::rustc_must_implement_one_of, ..]
183+
| [sym::rustc_deny_explicit_impl, ..]
184+
| [sym::const_trait, ..] => self.check_must_be_applied_to_trait(attr, span, target),
185+
[sym::cmse_nonsecure_entry, ..] => {
186186
self.check_cmse_nonsecure_entry(hir_id, attr, span, target)
187187
}
188-
[sym::collapse_debuginfo] => self.check_collapse_debuginfo(attr, span, target),
189-
[sym::must_not_suspend] => self.check_must_not_suspend(attr, span, target),
190-
[sym::must_use] => self.check_must_use(hir_id, attr, target),
191-
[sym::rustc_pass_by_value] => self.check_pass_by_value(attr, span, target),
192-
[sym::rustc_allow_incoherent_impl] => {
188+
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
189+
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
190+
[sym::must_use, ..] => self.check_must_use(hir_id, attr, target),
191+
[sym::rustc_pass_by_value, ..] => self.check_pass_by_value(attr, span, target),
192+
[sym::rustc_allow_incoherent_impl, ..] => {
193193
self.check_allow_incoherent_impl(attr, span, target)
194194
}
195-
[sym::rustc_has_incoherent_inherent_impls] => {
195+
[sym::rustc_has_incoherent_inherent_impls, ..] => {
196196
self.check_has_incoherent_inherent_impls(attr, span, target)
197197
}
198-
[sym::ffi_pure] => self.check_ffi_pure(attr.span, attrs, target),
199-
[sym::ffi_const] => self.check_ffi_const(attr.span, target),
200-
[sym::rustc_const_unstable]
201-
| [sym::rustc_const_stable]
202-
| [sym::unstable]
203-
| [sym::stable]
204-
| [sym::rustc_allowed_through_unstable_modules]
205-
| [sym::rustc_promotable] => self.check_stability_promotable(attr, target),
206-
[sym::link_ordinal] => self.check_link_ordinal(attr, span, target),
207-
[sym::rustc_confusables] => self.check_confusables(attr, target),
208-
[sym::rustc_safe_intrinsic] => {
198+
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span, attrs, target),
199+
[sym::ffi_const, ..] => self.check_ffi_const(attr.span, target),
200+
[sym::rustc_const_unstable, ..]
201+
| [sym::rustc_const_stable, ..]
202+
| [sym::unstable, ..]
203+
| [sym::stable, ..]
204+
| [sym::rustc_allowed_through_unstable_modules, ..]
205+
| [sym::rustc_promotable, ..] => self.check_stability_promotable(attr, target),
206+
[sym::link_ordinal, ..] => self.check_link_ordinal(attr, span, target),
207+
[sym::rustc_confusables, ..] => self.check_confusables(attr, target),
208+
[sym::rustc_safe_intrinsic, ..] => {
209209
self.check_rustc_safe_intrinsic(hir_id, attr, span, target)
210210
}
211-
[sym::cold] => self.check_cold(hir_id, attr, span, target),
212-
[sym::link] => self.check_link(hir_id, attr, span, target),
213-
[sym::link_name] => self.check_link_name(hir_id, attr, span, target),
214-
[sym::link_section] => self.check_link_section(hir_id, attr, span, target),
215-
[sym::no_mangle] => self.check_no_mangle(hir_id, attr, span, target),
216-
[sym::deprecated] => self.check_deprecated(hir_id, attr, span, target),
217-
[sym::macro_use] | [sym::macro_escape] => {
211+
[sym::cold, ..] => self.check_cold(hir_id, attr, span, target),
212+
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
213+
[sym::link_name, ..] => self.check_link_name(hir_id, attr, span, target),
214+
[sym::link_section, ..] => self.check_link_section(hir_id, attr, span, target),
215+
[sym::no_mangle, ..] => self.check_no_mangle(hir_id, attr, span, target),
216+
[sym::deprecated, ..] => self.check_deprecated(hir_id, attr, span, target),
217+
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
218218
self.check_macro_use(hir_id, attr, target)
219219
}
220-
[sym::path] => self.check_generic_attr(hir_id, attr, target, Target::Mod),
221-
[sym::macro_export] => self.check_macro_export(hir_id, attr, target),
222-
[sym::ignore] | [sym::should_panic] => {
220+
[sym::path, ..] => self.check_generic_attr(hir_id, attr, target, Target::Mod),
221+
[sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target),
222+
[sym::ignore, ..] | [sym::should_panic, ..] => {
223223
self.check_generic_attr(hir_id, attr, target, Target::Fn)
224224
}
225-
[sym::automatically_derived] => {
225+
[sym::automatically_derived, ..] => {
226226
self.check_generic_attr(hir_id, attr, target, Target::Impl)
227227
}
228-
[sym::no_implicit_prelude] => {
228+
[sym::no_implicit_prelude, ..] => {
229229
self.check_generic_attr(hir_id, attr, target, Target::Mod)
230230
}
231-
[sym::rustc_object_lifetime_default] => self.check_object_lifetime_default(hir_id),
232-
[sym::proc_macro] => {
231+
[sym::rustc_object_lifetime_default, ..] => self.check_object_lifetime_default(hir_id),
232+
[sym::proc_macro, ..] => {
233233
self.check_proc_macro(hir_id, target, ProcMacroKind::FunctionLike)
234234
}
235-
[sym::proc_macro_attribute] => {
235+
[sym::proc_macro_attribute, ..] => {
236236
self.check_proc_macro(hir_id, target, ProcMacroKind::Attribute);
237237
}
238-
[sym::proc_macro_derive] => {
238+
[sym::proc_macro_derive, ..] => {
239239
self.check_generic_attr(hir_id, attr, target, Target::Fn);
240240
self.check_proc_macro(hir_id, target, ProcMacroKind::Derive)
241241
}
242-
[sym::coroutine] => {
242+
[sym::coroutine, ..] => {
243243
self.check_coroutine(attr, target);
244244
}
245245
[
@@ -273,14 +273,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
273273
| sym::default_lib_allocator
274274
| sym::start
275275
| sym::custom_mir,
276+
..
276277
] => {}
277278
[name, ..] => {
278279
match BUILTIN_ATTRIBUTE_MAP.get(name) {
279280
// checked below
280281
Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
281282
Some(_) => {
282-
// FIXME: differentiate between unstable and internal attributes just like we do with features instead
283-
// of just accepting `rustc_` attributes by name. That should allow trimming the above list, too.
283+
// FIXME: differentiate between unstable and internal attributes just
284+
// like we do with features instead of just accepting `rustc_`
285+
// attributes by name. That should allow trimming the above list, too.
284286
if !name.as_str().starts_with("rustc_") {
285287
span_bug!(
286288
attr.span,

‎config.example.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@
472472
# This is mostly useful for tools; if you have changes to `compiler/` or `library/` they will be ignored.
473473
#
474474
# Set this to "if-unchanged" to only download if the compiler and standard library have not been modified.
475-
# Set this to `true` to download unconditionally (useful if e.g. you are only changing doc-comments).
475+
# Set this to `true` to download unconditionally. This is useful if you are working on tools, doc-comments,
476+
# or library (you will be able to build the standard library without needing to build the compiler).
476477
#download-rustc = false
477478

478479
# Number of codegen units to use for each compiler invocation. A value of 0

‎library/alloc/src/collections/btree/set.rs

Lines changed: 582 additions & 1 deletion
Large diffs are not rendered by default.

‎src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use crate::core::builder::{
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
2727
use crate::utils::exec::command;
2828
use crate::utils::helpers::{
29-
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
29+
self, exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
30+
symlink_dir, t, up_to_date,
3031
};
3132
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
3233

@@ -114,21 +115,43 @@ impl Step for Std {
114115
const DEFAULT: bool = true;
115116

116117
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
117-
// When downloading stage1, the standard library has already been copied to the sysroot, so
118-
// there's no need to rebuild it.
119-
let builder = run.builder;
120-
run.crate_or_deps("sysroot")
121-
.path("library")
122-
.lazy_default_condition(Box::new(|| !builder.download_rustc()))
118+
run.crate_or_deps("sysroot").path("library")
123119
}
124120

125121
fn make_run(run: RunConfig<'_>) {
126122
let crates = std_crates_for_run_make(&run);
123+
let builder = run.builder;
124+
125+
// Force compilation of the standard library from source if the `library` is modified. This allows
126+
// library team to compile the standard library without needing to compile the compiler with
127+
// the `rust.download-rustc=true` option.
128+
let force_recompile =
129+
if builder.rust_info().is_managed_git_subrepository() && builder.download_rustc() {
130+
let closest_merge_commit = get_closest_merge_base_commit(
131+
Some(&builder.src),
132+
&builder.config.git_config(),
133+
&builder.config.stage0_metadata.config.git_merge_commit_email,
134+
&[],
135+
)
136+
.unwrap();
137+
138+
// Check if `library` has changes (returns false otherwise)
139+
!t!(helpers::git(Some(&builder.src))
140+
.args(["diff-index", "--quiet", &closest_merge_commit])
141+
.arg("--")
142+
.arg(builder.src.join("library"))
143+
.as_command_mut()
144+
.status())
145+
.success()
146+
} else {
147+
false
148+
};
149+
127150
run.builder.ensure(Std {
128151
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
129152
target: run.target,
130153
crates,
131-
force_recompile: false,
154+
force_recompile,
132155
extra_rust_args: &[],
133156
is_for_mir_opt_tests: false,
134157
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ compile-flags: -O
2+
//@ min-llvm-version: 19
3+
4+
#![crate_type = "lib"]
5+
6+
pub enum State {
7+
A([u8; 753]),
8+
B([u8; 753]),
9+
}
10+
11+
// CHECK-LABEL: @update
12+
#[no_mangle]
13+
pub unsafe fn update(s: *mut State) {
14+
// CHECK-NEXT: start:
15+
// CHECK-NEXT: store i8
16+
// CHECK-NEXT: ret
17+
let State::A(v) = s.read() else { std::hint::unreachable_unchecked() };
18+
s.write(State::B(v));
19+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//! Regression test for #128622.
2+
//!
3+
//! PR #128581 introduced an assertion that all builtin attributes are actually checked via
4+
//! `CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes.
5+
//! Unfortunately, the check had correctness problems.
6+
//!
7+
//! The match on attribute path segments looked like
8+
//!
9+
//! ```rs,ignore
10+
//! [sym::should_panic] => /* check is implemented */
11+
//! match BUILTIN_ATTRIBUTE_MAP.get(name) {
12+
//! // checked below
13+
//! Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
14+
//! Some(_) => {
15+
//! if !name.as_str().starts_with("rustc_") {
16+
//! span_bug!(
17+
//! attr.span,
18+
//! "builtin attribute {name:?} not handled by `CheckAttrVisitor`"
19+
//! )
20+
//! }
21+
//! }
22+
//! None => (),
23+
//! }
24+
//! ```
25+
//!
26+
//! However, it failed to account for edge cases such as an attribute whose:
27+
//!
28+
//! 1. path segments *starts* with a builtin attribute such as `should_panic`
29+
//! 2. which does not start with `rustc_`, and
30+
//! 3. is also an `AttributeType::Normal` attribute upon registration with the builtin attribute map
31+
//!
32+
//! These conditions when all satisfied cause the span bug to be issued for e.g.
33+
//! `#[should_panic::skip]` because the `[sym::should_panic]` arm is not matched (since it's
34+
//! `[sym::should_panic, sym::skip]`).
35+
//!
36+
//! This test checks that the span bug is not fired for such cases.
37+
//!
38+
//! issue: rust-lang/rust#128622
39+
40+
// Notably, `should_panic` is a `AttributeType::Normal` attribute that is checked separately.
41+
42+
struct Foo {
43+
#[should_panic::skip]
44+
//~^ ERROR failed to resolve
45+
pub field: u8,
46+
47+
#[should_panic::a::b::c]
48+
//~^ ERROR failed to resolve
49+
pub field2: u8,
50+
}
51+
52+
fn foo() {}
53+
54+
fn main() {
55+
#[deny::skip]
56+
//~^ ERROR failed to resolve
57+
foo();
58+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0433]: failed to resolve: use of undeclared crate or module `should_panic`
2+
--> $DIR/check-builtin-attr-ice.rs:43:7
3+
|
4+
LL | #[should_panic::skip]
5+
| ^^^^^^^^^^^^ use of undeclared crate or module `should_panic`
6+
7+
error[E0433]: failed to resolve: use of undeclared crate or module `should_panic`
8+
--> $DIR/check-builtin-attr-ice.rs:47:7
9+
|
10+
LL | #[should_panic::a::b::c]
11+
| ^^^^^^^^^^^^ use of undeclared crate or module `should_panic`
12+
13+
error[E0433]: failed to resolve: use of undeclared crate or module `deny`
14+
--> $DIR/check-builtin-attr-ice.rs:55:7
15+
|
16+
LL | #[deny::skip]
17+
| ^^^^ use of undeclared crate or module `deny`
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0433`.

‎tests/ui/derives/deriving-with-repr-packed.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@ struct Y(usize);
2222
struct X(Y);
2323
//~^ ERROR cannot move out of `self` which is behind a shared reference
2424

25-
// This is currently allowed, but will be phased out at some point. From
26-
// `zerovec` within icu4x-0.9.0.
2725
#[derive(Debug)]
2826
#[repr(packed)]
2927
struct FlexZeroSlice {
3028
width: u8,
3129
data: [u8],
32-
//~^ WARNING byte slice in a packed struct that derives a built-in trait
33-
//~^^ this was previously accepted
30+
//~^ ERROR cannot move
31+
//~| ERROR cannot move
3432
}
3533

36-
// Again, currently allowed, but will be phased out.
3734
#[derive(Debug)]
3835
#[repr(packed)]
3936
struct WithStr {
4037
width: u8,
4138
data: str,
42-
//~^ WARNING string slice in a packed struct that derives a built-in trait
43-
//~^^ this was previously accepted
39+
//~^ ERROR cannot move
40+
//~| ERROR cannot move
4441
}
4542

4643
fn main() {}
Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
warning: byte slice in a packed struct that derives a built-in trait
2-
--> $DIR/deriving-with-repr-packed.rs:31:5
3-
|
4-
LL | #[derive(Debug)]
5-
| ----- in this derive macro expansion
6-
...
7-
LL | data: [u8],
8-
| ^^^^^^^^^^
9-
|
10-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11-
= note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
12-
= help: consider implementing the trait by hand, or remove the `packed` attribute
13-
= note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
14-
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
15-
16-
warning: string slice in a packed struct that derives a built-in trait
17-
--> $DIR/deriving-with-repr-packed.rs:41:5
18-
|
19-
LL | #[derive(Debug)]
20-
| ----- in this derive macro expansion
21-
...
22-
LL | data: str,
23-
| ^^^^^^^^^
24-
|
25-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26-
= note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
27-
= help: consider implementing the trait by hand, or remove the `packed` attribute
28-
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
29-
301
error[E0507]: cannot move out of `self` which is behind a shared reference
312
--> $DIR/deriving-with-repr-packed.rs:22:10
323
|
@@ -47,38 +18,43 @@ LL | struct X(Y);
4718
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
4819
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
4920

50-
error: aborting due to 1 previous error; 2 warnings emitted
21+
error[E0161]: cannot move a value of type `[u8]`
22+
--> $DIR/deriving-with-repr-packed.rs:29:5
23+
|
24+
LL | data: [u8],
25+
| ^^^^^^^^^^ the size of `[u8]` cannot be statically determined
5126

52-
For more information about this error, try `rustc --explain E0507`.
53-
Future incompatibility report: Future breakage diagnostic:
54-
warning: byte slice in a packed struct that derives a built-in trait
55-
--> $DIR/deriving-with-repr-packed.rs:31:5
27+
error[E0507]: cannot move out of `self.data` which is behind a shared reference
28+
--> $DIR/deriving-with-repr-packed.rs:29:5
5629
|
5730
LL | #[derive(Debug)]
5831
| ----- in this derive macro expansion
5932
...
6033
LL | data: [u8],
61-
| ^^^^^^^^^^
34+
| ^^^^^^^^^^ move occurs because `self.data` has type `[u8]`, which does not implement the `Copy` trait
35+
|
36+
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
37+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
38+
39+
error[E0161]: cannot move a value of type `str`
40+
--> $DIR/deriving-with-repr-packed.rs:38:5
6241
|
63-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
64-
= note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
65-
= help: consider implementing the trait by hand, or remove the `packed` attribute
66-
= note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
67-
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
42+
LL | data: str,
43+
| ^^^^^^^^^ the size of `str` cannot be statically determined
6844

69-
Future breakage diagnostic:
70-
warning: string slice in a packed struct that derives a built-in trait
71-
--> $DIR/deriving-with-repr-packed.rs:41:5
45+
error[E0507]: cannot move out of `self.data` which is behind a shared reference
46+
--> $DIR/deriving-with-repr-packed.rs:38:5
7247
|
7348
LL | #[derive(Debug)]
7449
| ----- in this derive macro expansion
7550
...
7651
LL | data: str,
77-
| ^^^^^^^^^
52+
| ^^^^^^^^^ move occurs because `self.data` has type `str`, which does not implement the `Copy` trait
7853
|
79-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
80-
= note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
81-
= help: consider implementing the trait by hand, or remove the `packed` attribute
82-
= note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
83-
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
54+
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
55+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
56+
57+
error: aborting due to 5 previous errors
8458

59+
Some errors have detailed explanations: E0161, E0507.
60+
For more information about an error, try `rustc --explain E0161`.

‎tests/ui/deriving/deriving-all-codegen.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ impl Copy for PackedManualCopy {}
7373
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
7474
struct Unsized([u32]);
7575

76-
// A packed struct with an unsized `[u8]` field. This is currently allowed, but
77-
// causes a warning and will be phased out at some point.
78-
#[derive(Debug, Hash)]
79-
#[repr(packed)]
80-
struct PackedUnsizedU8([u8]);
81-
//~^ WARNING byte slice in a packed struct that derives a built-in trait
82-
//~^^ WARNING byte slice in a packed struct that derives a built-in trait
83-
//~^^^ this was previously accepted
84-
//~^^^^ this was previously accepted
85-
8676
trait Trait {
8777
type A;
8878
}

‎tests/ui/deriving/deriving-all-codegen.stderr

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

‎tests/ui/deriving/deriving-all-codegen.stdout

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -516,26 +516,6 @@ impl ::core::cmp::Ord for Unsized {
516516
}
517517
}
518518

519-
// A packed struct with an unsized `[u8]` field. This is currently allowed, but
520-
// causes a warning and will be phased out at some point.
521-
#[repr(packed)]
522-
struct PackedUnsizedU8([u8]);
523-
#[automatically_derived]
524-
impl ::core::fmt::Debug for PackedUnsizedU8 {
525-
#[inline]
526-
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
527-
::core::fmt::Formatter::debug_tuple_field1_finish(f,
528-
"PackedUnsizedU8", &&self.0)
529-
}
530-
}
531-
#[automatically_derived]
532-
impl ::core::hash::Hash for PackedUnsizedU8 {
533-
#[inline]
534-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
535-
::core::hash::Hash::hash(&self.0, state)
536-
}
537-
}
538-
539519
trait Trait {
540520
type A;
541521
}

‎tests/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr

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

‎tests/ui/impl-trait/where-allowed.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,25 @@ error: aborting due to 50 previous errors
433433

434434
Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0599, E0658, E0666.
435435
For more information about an error, try `rustc --explain E0053`.
436+
Future incompatibility report: Future breakage diagnostic:
437+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
438+
--> $DIR/where-allowed.rs:239:7
439+
|
440+
LL | impl <T = impl Debug> T {}
441+
| ^^^^^^^^^^^^^^
442+
|
443+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
444+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
445+
= note: `#[deny(invalid_type_param_default)]` on by default
446+
447+
Future breakage diagnostic:
448+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
449+
--> $DIR/where-allowed.rs:246:36
450+
|
451+
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
452+
| ^^^^^^^^^^^^^^
453+
|
454+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
455+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
456+
= note: `#[deny(invalid_type_param_default)]` on by default
457+

‎tests/ui/issues/issue-26812.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#![feature(default_type_parameter_fallback)]
2-
31
fn avg<T=T::Item>(_: T) {}
42
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
3+
//~| ERROR defaults for type parameters
4+
//~| WARN previously accepted
55

66
fn main() {}

‎tests/ui/issues/issue-26812.stderr

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
error[E0128]: generic parameters with a default cannot use forward declared identifiers
2-
--> $DIR/issue-26812.rs:3:10
2+
--> $DIR/issue-26812.rs:1:10
33
|
44
LL | fn avg<T=T::Item>(_: T) {}
55
| ^^^^^^^ defaulted generic parameters cannot be forward declared
66

7-
error: aborting due to 1 previous error
7+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
8+
--> $DIR/issue-26812.rs:1:8
9+
|
10+
LL | fn avg<T=T::Item>(_: T) {}
11+
| ^^^^^^^^^
12+
|
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
15+
= note: `#[deny(invalid_type_param_default)]` on by default
16+
17+
error: aborting due to 2 previous errors
818

919
For more information about this error, try `rustc --explain E0128`.
20+
Future incompatibility report: Future breakage diagnostic:
21+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
22+
--> $DIR/issue-26812.rs:1:8
23+
|
24+
LL | fn avg<T=T::Item>(_: T) {}
25+
| ^^^^^^^^^
26+
|
27+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
28+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
29+
= note: `#[deny(invalid_type_param_default)]` on by default
30+

‎tests/ui/lifetimes/unusual-rib-combinations.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ error: aborting due to 8 previous errors
7272

7373
Some errors have detailed explanations: E0106, E0214, E0308, E0770.
7474
For more information about an error, try `rustc --explain E0106`.
75+
Future incompatibility report: Future breakage diagnostic:
76+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
77+
--> $DIR/unusual-rib-combinations.rs:15:6
78+
|
79+
LL | fn c<T = u8()>() {}
80+
| ^^^^^^^^
81+
|
82+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
83+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
84+
= note: `#[deny(invalid_type_param_default)]` on by default
85+

‎tests/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ LL | foo::<T, U>();
1212
error: aborting due to 1 previous error
1313

1414
For more information about this error, try `rustc --explain E0282`.
15+
Future incompatibility report: Future breakage diagnostic:
16+
warning: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
17+
--> $DIR/unbounded-type-param-in-fn-with-assoc-type.rs:3:11
18+
|
19+
LL | fn foo<T, U = u64>() -> (T, U) {
20+
| ^^^^^^^
21+
|
22+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
24+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
2+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:3:8
3+
|
4+
LL | fn avg<T=i32>(_: T) {}
5+
| ^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
9+
= note: `#[deny(invalid_type_param_default)]` on by default
10+
11+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
12+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:8:6
13+
|
14+
LL | impl<T=i32> S<T> {}
15+
| ^^^^^
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
19+
20+
error: aborting due to 2 previous errors
21+
22+
Future incompatibility report: Future breakage diagnostic:
23+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
24+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:3:8
25+
|
26+
LL | fn avg<T=i32>(_: T) {}
27+
| ^^^^^
28+
|
29+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
31+
= note: `#[deny(invalid_type_param_default)]` on by default
32+
33+
Future breakage diagnostic:
34+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
35+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:8:6
36+
|
37+
LL | impl<T=i32> S<T> {}
38+
| ^^^^^
39+
|
40+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
41+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
42+
= note: `#[deny(invalid_type_param_default)]` on by default
43+

0 commit comments

Comments
 (0)
Please sign in to comment.