Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b5a4e5d
remove gates
Kivooeo Aug 3, 2025
9fd57df
add tests, some with incorrect lifetime extension behavior
dianne Aug 13, 2025
0976d6c
don't extend non-extended `super let` initializers' block tail temps
dianne Aug 25, 2025
d5b5a4a
additional tests
dianne Aug 25, 2025
9405e76
Detect attempt to use var-args in closure
estebank Sep 15, 2025
0e290e4
Silence inference error on `PatKind::Err`
estebank Sep 15, 2025
a84c8de
Fix existing test
estebank Sep 15, 2025
53b58b3
tests/run-make: Update list of statically linked musl targets
Gelbpunkt Sep 15, 2025
fa7e474
remove FIXME from `has_significant_drop`, replaced with checking non_…
tnuha Sep 15, 2025
d66fb49
Suggest removing Box::new
camsteffen Sep 6, 2025
c89b6a9
Iterator repeat: no infinite loop for `last` and `count`
hkBst Sep 10, 2025
dfbaf7e
port `#[rustc_coherence_is_core]` to the new attribute parsing infras…
jdonszelmann Aug 24, 2025
c916e88
fmt
estebank Sep 16, 2025
ed85f98
remove redundant test
estebank Sep 16, 2025
8306a2f
Reword note
estebank Sep 16, 2025
e9270e3
Detect top-level `...` in argument type
estebank Sep 16, 2025
d81872a
add Readme.md to tidy
simp4t7 Sep 12, 2025
24f2d3e
Rollup merge of #144871 - Kivooeo:btree_entry_insert-stabilize, r=jhp…
jhpratt Sep 17, 2025
06286ff
Rollup merge of #145181 - Borgerr:remove-fixme-from-has-sigdrop, r=lcnr
jhpratt Sep 17, 2025
ab7e386
Rollup merge of #145838 - dianne:non-extending-super-let, r=jackh726,…
jhpratt Sep 17, 2025
5c4cef6
Rollup merge of #146259 - camsteffen:remove-the-box, r=jackh726
jhpratt Sep 17, 2025
ef6730b
Rollup merge of #146410 - hkBst:repeat-1, r=jhpratt
jhpratt Sep 17, 2025
667da4e
Rollup merge of #146460 - simp4t7:add-tidy-readme, r=clubby789
jhpratt Sep 17, 2025
5177665
Rollup merge of #146581 - estebank:issue-146489, r=lcnr
jhpratt Sep 17, 2025
45da8f2
Rollup merge of #146588 - Gelbpunkt:musl-default-linking-test, r=jiey…
jhpratt Sep 17, 2025
0c77b06
Rollup merge of #146647 - jdonszelmann:move-coherence-is-core, r=Urgau
jhpratt Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoStdParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
}

pub(crate) struct RustcCoherenceIsCoreParser;

impl<S: Stage> NoArgsAttributeParser<S> for RustcCoherenceIsCoreParser {
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
}
8 changes: 0 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for AllowIncoherentImplParser {
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AllowIncoherentImpl;
}

pub(crate) struct CoherenceIsCoreParser;
impl<S: Stage> NoArgsAttributeParser<S> for CoherenceIsCoreParser {
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CoherenceIsCore;
}

pub(crate) struct FundamentalParser;
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
const PATH: &[Symbol] = &[sym::fundamental];
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::attributes::codegen_attrs::{
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::crate_level::{
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoStdParser, PatternComplexityLimitParser,
RecursionLimitParser, TypeLengthLimitParser,
RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
};
use crate::attributes::deprecation::DeprecationParser;
use crate::attributes::dummy::DummyParser;
Expand Down Expand Up @@ -61,10 +61,10 @@ use crate::attributes::stability::{
};
use crate::attributes::test_attrs::{IgnoreParser, ShouldPanicParser};
use crate::attributes::traits::{
AllowIncoherentImplParser, CoherenceIsCoreParser, CoinductiveParser, ConstTraitParser,
DenyExplicitImplParser, DoNotImplementViaObjectParser, FundamentalParser, MarkerParser,
ParenSugarParser, PointeeParser, SkipDuringMethodDispatchParser, SpecializationTraitParser,
TypeConstParser, UnsafeSpecializationMarkerParser,
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
PointeeParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
UnsafeSpecializationMarkerParser,
};
use crate::attributes::transparency::TransparencyParser;
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
Expand Down Expand Up @@ -204,7 +204,6 @@ attribute_parsers!(
Single<WithoutArgs<AllowInternalUnsafeParser>>,
Single<WithoutArgs<AsPtrParser>>,
Single<WithoutArgs<AutomaticallyDerivedParser>>,
Single<WithoutArgs<CoherenceIsCoreParser>>,
Single<WithoutArgs<CoinductiveParser>>,
Single<WithoutArgs<ColdParser>>,
Single<WithoutArgs<ConstContinueParser>>,
Expand Down Expand Up @@ -232,6 +231,7 @@ attribute_parsers!(
Single<WithoutArgs<ProcMacroAttributeParser>>,
Single<WithoutArgs<ProcMacroParser>>,
Single<WithoutArgs<PubTransparentParser>>,
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
Single<WithoutArgs<SpecializationTraitParser>>,
Single<WithoutArgs<StdInternalSymbolParser>>,
Single<WithoutArgs<TrackCallerParser>>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,6 @@ pub enum AttributeKind {
span: Span,
},

/// Represents `#[rustc_coherence_is_core]`.
CoherenceIsCore,

/// Represents `#[rustc_coinductive]`.
Coinductive(Span),

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

/// Represents `#[rustc_coherence_is_core]`
RustcCoherenceIsCore(Span),

/// Represents `#[rustc_layout_scalar_valid_range_end]`.
RustcLayoutScalarValidRangeEnd(Box<u128>, Span),

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl AttributeKind {
AsPtr(..) => Yes,
AutomaticallyDerived(..) => Yes,
BodyStability { .. } => No,
CoherenceIsCore => No,
Coinductive(..) => No,
Cold(..) => No,
Confusables { .. } => Yes,
Expand Down Expand Up @@ -82,6 +81,7 @@ impl AttributeKind {
RecursionLimit { .. } => No,
Repr { .. } => No,
RustcBuiltinMacro { .. } => Yes,
RustcCoherenceIsCore(..) => No,
RustcLayoutScalarValidRangeEnd(..) => Yes,
RustcLayoutScalarValidRangeStart(..) => Yes,
RustcObjectLifetimeDefault => No,
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,12 @@ fn resolve_local<'tcx>(
// A, but the inner rvalues `a()` and `b()` have an extended lifetime
// due to rule C.

if let_kind == LetKind::Super {
if let Some(scope) = visitor.extended_super_lets.remove(&pat.unwrap().hir_id.local_id) {
let extend_initializer = match let_kind {
LetKind::Regular => true,
LetKind::Super
if let Some(scope) =
visitor.extended_super_lets.remove(&pat.unwrap().hir_id.local_id) =>
{
// This expression was lifetime-extended by a parent let binding. E.g.
//
// let a = {
Expand All @@ -481,7 +485,10 @@ fn resolve_local<'tcx>(
// Processing of `let a` will have already decided to extend the lifetime of this
// `super let` to its own var_scope. We use that scope.
visitor.cx.var_parent = scope;
} else {
// Extend temporaries to live in the same scope as the parent `let`'s bindings.
true
}
LetKind::Super => {
// This `super let` is not subject to lifetime extension from a parent let binding. E.g.
//
// identity({ super let x = temp(); &x }).method();
Expand All @@ -493,10 +500,17 @@ fn resolve_local<'tcx>(
if let Some(inner_scope) = visitor.cx.var_parent {
(visitor.cx.var_parent, _) = visitor.scope_tree.default_temporary_scope(inner_scope)
}
// Don't lifetime-extend child `super let`s or block tail expressions' temporaries in
// the initializer when this `super let` is not itself extended by a parent `let`
// (#145784). Block tail expressions are temporary drop scopes in Editions 2024 and
// later, their temps shouldn't outlive the block in e.g. `f(pin!({ &temp() }))`.
false
}
}
};

if let Some(expr) = init {
if let Some(expr) = init
&& extend_initializer
{
record_rvalue_scope_if_borrow_expr(visitor, expr, visitor.cx.var_parent);

if let Some(pat) = pat {
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
{
let deref_kind = if checked_ty.is_box() {
// detect Box::new(..)
if let ExprKind::Call(box_new, [_]) = expr.kind
&& let ExprKind::Path(qpath) = &box_new.kind
&& let Res::Def(DefKind::AssocFn, fn_id) =
self.typeck_results.borrow().qpath_res(qpath, box_new.hir_id)
&& let Some(impl_id) = self.tcx.inherent_impl_of_assoc(fn_id)
&& self.tcx.type_of(impl_id).skip_binder().is_box()
&& self.tcx.item_name(fn_id) == sym::new
{
let l_paren = self.tcx.sess.source_map().next_point(box_new.span);
let r_paren = self.tcx.sess.source_map().end_point(expr.span);
return Some((
vec![
(box_new.span.to(l_paren), String::new()),
(r_paren, String::new()),
],
"consider removing the Box".to_string(),
Applicability::MachineApplicable,
false,
false,
));
}
"unboxing the value"
} else if checked_ty.is_ref() {
"dereferencing the borrow"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

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

pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) {
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ impl<'tcx> Ty<'tcx> {
/// 2229 drop reorder migration analysis.
#[inline]
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
assert!(!self.has_non_region_infer());
// Avoid querying in simple cases.
match needs_drop_components(tcx, self) {
Err(AlwaysRequiresDrop) => true,
Expand All @@ -1371,14 +1372,6 @@ impl<'tcx> Ty<'tcx> {
_ => self,
};

// FIXME(#86868): We should be canonicalizing, or else moving this to a method of inference
// context, or *something* like that, but for now just avoid passing inference
// variables to queries that can't cope with them. Instead, conservatively
// return "true" (may change drop order).
if query_ty.has_infer() {
return true;
}

// This doesn't depend on regions, so try to minimize distinct
// query keys used.
let erased = tcx.normalize_erasing_regions(typing_env, query_ty);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ parse_dotdotdot = unexpected token: `...`
parse_dotdotdot_rest_pattern = unexpected `...`
.label = not a valid pattern
.suggestion = for a rest pattern, use `..` instead of `...`
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list

parse_dotdotdot_rest_type = unexpected `...`
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list

parse_double_colon_in_bound = expected `:` followed by trait or lifetime
.suggestion = use single colon
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2723,7 +2723,9 @@ pub(crate) struct DotDotDotRestPattern {
#[label]
pub span: Span,
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
pub suggestion: Span,
pub suggestion: Option<Span>,
#[note]
pub var_args: Option<()>,
}

#[derive(Diagnostic)]
Expand Down Expand Up @@ -3030,6 +3032,14 @@ pub(crate) struct NestedCVariadicType {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_dotdotdot_rest_type)]
#[note]
pub(crate) struct InvalidCVariadicType {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_invalid_dyn_keyword)]
#[help]
Expand Down
27 changes: 19 additions & 8 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl<'a> Parser<'a> {
self.bump(); // `..`
PatKind::Rest
} else if self.check(exp!(DotDotDot)) && !self.is_pat_range_end_start(1) {
self.recover_dotdotdot_rest_pat(lo)
self.recover_dotdotdot_rest_pat(lo, expected)
} else if let Some(form) = self.parse_range_end() {
self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
} else if self.eat(exp!(Bang)) {
Expand Down Expand Up @@ -886,16 +886,27 @@ impl<'a> Parser<'a> {

/// Recover from a typoed `...` pattern that was encountered
/// Ref: Issue #70388
fn recover_dotdotdot_rest_pat(&mut self, lo: Span) -> PatKind {
fn recover_dotdotdot_rest_pat(&mut self, lo: Span, expected: Option<Expected>) -> PatKind {
// A typoed rest pattern `...`.
self.bump(); // `...`

// The user probably mistook `...` for a rest pattern `..`.
self.dcx().emit_err(DotDotDotRestPattern {
span: lo,
suggestion: lo.with_lo(lo.hi() - BytePos(1)),
});
PatKind::Rest
if let Some(Expected::ParameterName) = expected {
// We have `...` in a closure argument, likely meant to be var-arg, which aren't
// supported in closures (#146489).
PatKind::Err(self.dcx().emit_err(DotDotDotRestPattern {
span: lo,
suggestion: None,
var_args: Some(()),
}))
} else {
// The user probably mistook `...` for a rest pattern `..`.
self.dcx().emit_err(DotDotDotRestPattern {
span: lo,
suggestion: Some(lo.with_lo(lo.hi() - BytePos(1))),
var_args: None,
});
PatKind::Rest
}
}

/// Try to recover the more general form `intersect ::= $pat_lhs @ $pat_rhs`.
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use super::{Parser, PathStyle, SeqSep, TokenType, Trailing};
use crate::errors::{
self, AttributeOnEmptyType, AttributeOnType, DynAfterMut, ExpectedFnPathFoundFnKeyword,
ExpectedMutOrConstInRawPointerType, FnPtrWithGenerics, FnPtrWithGenericsSugg,
HelpUseLatestEdition, InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime,
NestedCVariadicType, ReturnTypesUseThinArrow,
HelpUseLatestEdition, InvalidCVariadicType, InvalidDynKeyword, LifetimeAfterMut,
NeedPlusAfterTraitObjectLifetime, NestedCVariadicType, ReturnTypesUseThinArrow,
};
use crate::parser::item::FrontMatterParsingMode;
use crate::parser::{FnContext, FnParseMode};
Expand Down Expand Up @@ -106,6 +106,15 @@ fn can_begin_dyn_bound_in_edition_2015(t: &Token) -> bool {
impl<'a> Parser<'a> {
/// Parses a type.
pub fn parse_ty(&mut self) -> PResult<'a, Box<Ty>> {
if self.token == token::DotDotDot {
// We special case this so that we don't talk about "nested C-variadics" in types.
// We still pass in `AllowCVariadic::No` so that `parse_ty_common` can complain about
// things like `Vec<...>`.
let span = self.token.span;
self.bump();
let kind = TyKind::Err(self.dcx().emit_err(InvalidCVariadicType { span }));
return Ok(self.mk_ty(span, kind));
}
// Make sure deeply nested types don't overflow the stack.
ensure_sufficient_stack(|| {
self.parse_ty_common(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::Repr { .. }
| AttributeKind::Cold(..)
| AttributeKind::ExportName { .. }
| AttributeKind::CoherenceIsCore
| AttributeKind::Fundamental
| AttributeKind::Optimize(..)
| AttributeKind::LinkSection { .. }
Expand Down Expand Up @@ -276,6 +275,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::PatternComplexityLimit { .. }
| AttributeKind::NoCore { .. }
| AttributeKind::NoStd { .. }
| AttributeKind::RustcCoherenceIsCore(..)
) => { /* do nothing */ }
Attribute::Unparsed(attr_item) => {
style = Some(attr_item.style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use std::path::PathBuf;

use rustc_errors::codes::*;
use rustc_errors::{Diag, IntoDiagArg};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
use rustc_hir::{
self as hir, Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource, PatKind,
};
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
Expand Down Expand Up @@ -512,7 +513,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
type_name: ty_to_string(self, ty, def_id),
});
}
InferSourceKind::ClosureArg { insert_span, ty } => {
InferSourceKind::ClosureArg { insert_span, ty, .. } => {
infer_subdiags.push(SourceKindSubdiag::LetLike {
span: insert_span,
name: String::new(),
Expand Down Expand Up @@ -652,6 +653,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}),
};
*err.long_ty_path() = long_ty_path;
if let InferSourceKind::ClosureArg { kind: PatKind::Err(_), .. } = kind {
// We will have already emitted an error about this pattern.
err.downgrade_to_delayed_bug();
}
err
}
}
Expand All @@ -673,6 +678,7 @@ enum InferSourceKind<'tcx> {
ClosureArg {
insert_span: Span,
ty: Ty<'tcx>,
kind: PatKind<'tcx>,
},
GenericArg {
insert_span: Span,
Expand Down Expand Up @@ -1197,6 +1203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
kind: InferSourceKind::ClosureArg {
insert_span: param.pat.span.shrink_to_hi(),
ty: param_ty,
kind: param.pat.kind,
},
})
}
Expand Down
Loading
Loading