Skip to content

Commit bcb42b1

Browse files
committed
Auto merge of #146662 - jhpratt:rollup-8pggsqv, r=jhpratt
Rollup of 9 pull requests Successful merges: - #144871 (Stabilize `btree_entry_insert` feature) - #145181 (remove FIXME block from `has_significant_drop`, it never encounters inference variables) - #145838 (don't apply temporary lifetime extension rules to non-extended `super let`) - #146259 (Suggest removing Box::new instead of unboxing it) - #146410 (Iterator repeat: no infinite loop for `last` and `count`) - #146460 (Add tidy readme) - #146581 (Detect attempt to use var-args in closure) - #146588 (tests/run-make: Update list of statically linked musl targets) - #146647 (Move `#[rustc_coherence_is_core]` to the `crate_level` file) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3f1552a + 0c77b06 commit bcb42b1

File tree

29 files changed

+541
-89
lines changed

29 files changed

+541
-89
lines changed

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoStdParser {
174174
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
175175
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
176176
}
177+
178+
pub(crate) struct RustcCoherenceIsCoreParser;
179+
180+
impl<S: Stage> NoArgsAttributeParser<S> for RustcCoherenceIsCoreParser {
181+
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
182+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
183+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
184+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
185+
}

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for AllowIncoherentImplParser {
149149
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AllowIncoherentImpl;
150150
}
151151

152-
pub(crate) struct CoherenceIsCoreParser;
153-
impl<S: Stage> NoArgsAttributeParser<S> for CoherenceIsCoreParser {
154-
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
155-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
156-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
157-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CoherenceIsCore;
158-
}
159-
160152
pub(crate) struct FundamentalParser;
161153
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
162154
const PATH: &[Symbol] = &[sym::fundamental];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::attributes::codegen_attrs::{
2626
use crate::attributes::confusables::ConfusablesParser;
2727
use crate::attributes::crate_level::{
2828
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoStdParser, PatternComplexityLimitParser,
29-
RecursionLimitParser, TypeLengthLimitParser,
29+
RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
3030
};
3131
use crate::attributes::deprecation::DeprecationParser;
3232
use crate::attributes::dummy::DummyParser;
@@ -61,10 +61,10 @@ use crate::attributes::stability::{
6161
};
6262
use crate::attributes::test_attrs::{IgnoreParser, ShouldPanicParser};
6363
use crate::attributes::traits::{
64-
AllowIncoherentImplParser, CoherenceIsCoreParser, CoinductiveParser, ConstTraitParser,
65-
DenyExplicitImplParser, DoNotImplementViaObjectParser, FundamentalParser, MarkerParser,
66-
ParenSugarParser, PointeeParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
67-
TypeConstParser, UnsafeSpecializationMarkerParser,
64+
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
65+
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
66+
PointeeParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
67+
UnsafeSpecializationMarkerParser,
6868
};
6969
use crate::attributes::transparency::TransparencyParser;
7070
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -204,7 +204,6 @@ attribute_parsers!(
204204
Single<WithoutArgs<AllowInternalUnsafeParser>>,
205205
Single<WithoutArgs<AsPtrParser>>,
206206
Single<WithoutArgs<AutomaticallyDerivedParser>>,
207-
Single<WithoutArgs<CoherenceIsCoreParser>>,
208207
Single<WithoutArgs<CoinductiveParser>>,
209208
Single<WithoutArgs<ColdParser>>,
210209
Single<WithoutArgs<ConstContinueParser>>,
@@ -232,6 +231,7 @@ attribute_parsers!(
232231
Single<WithoutArgs<ProcMacroAttributeParser>>,
233232
Single<WithoutArgs<ProcMacroParser>>,
234233
Single<WithoutArgs<PubTransparentParser>>,
234+
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
235235
Single<WithoutArgs<SpecializationTraitParser>>,
236236
Single<WithoutArgs<StdInternalSymbolParser>>,
237237
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,6 @@ pub enum AttributeKind {
444444
span: Span,
445445
},
446446

447-
/// Represents `#[rustc_coherence_is_core]`.
448-
CoherenceIsCore,
449-
450447
/// Represents `#[rustc_coinductive]`.
451448
Coinductive(Span),
452449

@@ -633,6 +630,9 @@ pub enum AttributeKind {
633630
/// Represents `#[rustc_builtin_macro]`.
634631
RustcBuiltinMacro { builtin_name: Option<Symbol>, helper_attrs: ThinVec<Symbol>, span: Span },
635632

633+
/// Represents `#[rustc_coherence_is_core]`
634+
RustcCoherenceIsCore(Span),
635+
636636
/// Represents `#[rustc_layout_scalar_valid_range_end]`.
637637
RustcLayoutScalarValidRangeEnd(Box<u128>, Span),
638638

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ impl AttributeKind {
2626
AsPtr(..) => Yes,
2727
AutomaticallyDerived(..) => Yes,
2828
BodyStability { .. } => No,
29-
CoherenceIsCore => No,
3029
Coinductive(..) => No,
3130
Cold(..) => No,
3231
Confusables { .. } => Yes,
@@ -82,6 +81,7 @@ impl AttributeKind {
8281
RecursionLimit { .. } => No,
8382
Repr { .. } => No,
8483
RustcBuiltinMacro { .. } => Yes,
84+
RustcCoherenceIsCore(..) => No,
8585
RustcLayoutScalarValidRangeEnd(..) => Yes,
8686
RustcLayoutScalarValidRangeStart(..) => Yes,
8787
RustcObjectLifetimeDefault => No,

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,12 @@ fn resolve_local<'tcx>(
467467
// A, but the inner rvalues `a()` and `b()` have an extended lifetime
468468
// due to rule C.
469469

470-
if let_kind == LetKind::Super {
471-
if let Some(scope) = visitor.extended_super_lets.remove(&pat.unwrap().hir_id.local_id) {
470+
let extend_initializer = match let_kind {
471+
LetKind::Regular => true,
472+
LetKind::Super
473+
if let Some(scope) =
474+
visitor.extended_super_lets.remove(&pat.unwrap().hir_id.local_id) =>
475+
{
472476
// This expression was lifetime-extended by a parent let binding. E.g.
473477
//
474478
// let a = {
@@ -481,7 +485,10 @@ fn resolve_local<'tcx>(
481485
// Processing of `let a` will have already decided to extend the lifetime of this
482486
// `super let` to its own var_scope. We use that scope.
483487
visitor.cx.var_parent = scope;
484-
} else {
488+
// Extend temporaries to live in the same scope as the parent `let`'s bindings.
489+
true
490+
}
491+
LetKind::Super => {
485492
// This `super let` is not subject to lifetime extension from a parent let binding. E.g.
486493
//
487494
// identity({ super let x = temp(); &x }).method();
@@ -493,10 +500,17 @@ fn resolve_local<'tcx>(
493500
if let Some(inner_scope) = visitor.cx.var_parent {
494501
(visitor.cx.var_parent, _) = visitor.scope_tree.default_temporary_scope(inner_scope)
495502
}
503+
// Don't lifetime-extend child `super let`s or block tail expressions' temporaries in
504+
// the initializer when this `super let` is not itself extended by a parent `let`
505+
// (#145784). Block tail expressions are temporary drop scopes in Editions 2024 and
506+
// later, their temps shouldn't outlive the block in e.g. `f(pin!({ &temp() }))`.
507+
false
496508
}
497-
}
509+
};
498510

499-
if let Some(expr) = init {
511+
if let Some(expr) = init
512+
&& extend_initializer
513+
{
500514
record_rvalue_scope_if_borrow_expr(visitor, expr, visitor.cx.var_parent);
501515

502516
if let Some(pat) = pat {

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30213021
)
30223022
{
30233023
let deref_kind = if checked_ty.is_box() {
3024+
// detect Box::new(..)
3025+
if let ExprKind::Call(box_new, [_]) = expr.kind
3026+
&& let ExprKind::Path(qpath) = &box_new.kind
3027+
&& let Res::Def(DefKind::AssocFn, fn_id) =
3028+
self.typeck_results.borrow().qpath_res(qpath, box_new.hir_id)
3029+
&& let Some(impl_id) = self.tcx.inherent_impl_of_assoc(fn_id)
3030+
&& self.tcx.type_of(impl_id).skip_binder().is_box()
3031+
&& self.tcx.item_name(fn_id) == sym::new
3032+
{
3033+
let l_paren = self.tcx.sess.source_map().next_point(box_new.span);
3034+
let r_paren = self.tcx.sess.source_map().end_point(expr.span);
3035+
return Some((
3036+
vec![
3037+
(box_new.span.to(l_paren), String::new()),
3038+
(r_paren, String::new()),
3039+
],
3040+
"consider removing the Box".to_string(),
3041+
Applicability::MachineApplicable,
3042+
false,
3043+
false,
3044+
));
3045+
}
30243046
"unboxing the value"
30253047
} else if checked_ty.is_ref() {
30263048
"dereferencing the borrow"

compiler/rustc_middle/src/hir/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'tcx> TyCtxt<'tcx> {
370370
}
371371

372372
pub fn hir_rustc_coherence_is_core(self) -> bool {
373-
find_attr!(self.hir_krate_attrs(), AttributeKind::CoherenceIsCore)
373+
find_attr!(self.hir_krate_attrs(), AttributeKind::RustcCoherenceIsCore(..))
374374
}
375375

376376
pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) {

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ impl<'tcx> Ty<'tcx> {
13591359
/// 2229 drop reorder migration analysis.
13601360
#[inline]
13611361
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
1362+
assert!(!self.has_non_region_infer());
13621363
// Avoid querying in simple cases.
13631364
match needs_drop_components(tcx, self) {
13641365
Err(AlwaysRequiresDrop) => true,
@@ -1371,14 +1372,6 @@ impl<'tcx> Ty<'tcx> {
13711372
_ => self,
13721373
};
13731374

1374-
// FIXME(#86868): We should be canonicalizing, or else moving this to a method of inference
1375-
// context, or *something* like that, but for now just avoid passing inference
1376-
// variables to queries that can't cope with them. Instead, conservatively
1377-
// return "true" (may change drop order).
1378-
if query_ty.has_infer() {
1379-
return true;
1380-
}
1381-
13821375
// This doesn't depend on regions, so try to minimize distinct
13831376
// query keys used.
13841377
let erased = tcx.normalize_erasing_regions(typing_env, query_ty);

compiler/rustc_parse/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ parse_dotdotdot = unexpected token: `...`
189189
parse_dotdotdot_rest_pattern = unexpected `...`
190190
.label = not a valid pattern
191191
.suggestion = for a rest pattern, use `..` instead of `...`
192+
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
193+
194+
parse_dotdotdot_rest_type = unexpected `...`
195+
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
192196
193197
parse_double_colon_in_bound = expected `:` followed by trait or lifetime
194198
.suggestion = use single colon

0 commit comments

Comments
 (0)