Skip to content

Commit 6bcdcc7

Browse files
committed
Auto merge of #145020 - GuillaumeGomez:rollup-5prs9kw, r=GuillaumeGomez
Rollup of 15 pull requests Successful merges: - #144195 (Parser: Recover from attributes applied to types and generic args) - #144794 (Port `#[coroutine]` to the new attribute system) - #144835 (Anonymize binders in tail call sig) - #144861 (Stabilize `panic_payload_as_str` feature) - #144917 (Enforce tail call type is related to body return type in borrowck) - #144948 (we only merge candidates for trait and normalizes-to goals) - #144956 (Gate const trait syntax) - #144970 (rustdoc: fix caching of intra-doc links on reexports) - #144972 (add code example showing that file_prefix treats dotfiles as the name of a file, not an extension) - #144975 (`File::set_times`: Update documentation and example to support setting timestamps on directories) - #144977 (Fortify generic param default checks) - #144996 (simplifycfg: Mark as changed when start is modified in collapse goto chain) - #144998 (mir: Do not modify NonUse in `super_projection_elem`) - #145000 (Remove unneeded `stage` parameter when setting up stdlib Cargo) - #145008 (Fix rustdoc scrape examples crash) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7d82b83 + d369a1f commit 6bcdcc7

File tree

83 files changed

+1049
-497
lines changed

Some content is hidden

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

83 files changed

+1049
-497
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9898
}
9999

100100
let expr_hir_id = self.lower_node_id(e.id);
101-
self.lower_attrs(expr_hir_id, &e.attrs, e.span);
101+
let attrs = self.lower_attrs(expr_hir_id, &e.attrs, e.span);
102102

103103
let kind = match &e.kind {
104104
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
@@ -232,10 +232,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
232232
*fn_arg_span,
233233
),
234234
None => self.lower_expr_closure(
235+
attrs,
235236
binder,
236237
*capture_clause,
237238
e.id,
238-
expr_hir_id,
239239
*constness,
240240
*movability,
241241
fn_decl,
@@ -1052,10 +1052,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
10521052

10531053
fn lower_expr_closure(
10541054
&mut self,
1055+
attrs: &[rustc_hir::Attribute],
10551056
binder: &ClosureBinder,
10561057
capture_clause: CaptureBy,
10571058
closure_id: NodeId,
1058-
closure_hir_id: hir::HirId,
10591059
constness: Const,
10601060
movability: Movability,
10611061
decl: &FnDecl,
@@ -1067,15 +1067,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
10671067
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10681068

10691069
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
1070-
let mut coroutine_kind = if this
1071-
.attrs
1072-
.get(&closure_hir_id.local_id)
1073-
.is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine)))
1074-
{
1075-
Some(hir::CoroutineKind::Coroutine(Movability::Movable))
1076-
} else {
1077-
None
1078-
};
1070+
1071+
let mut coroutine_kind = find_attr!(attrs, AttributeKind::Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable));
1072+
10791073
// FIXME(contracts): Support contracts on closures?
10801074
let body_id = this.lower_fn_body(decl, None, |this| {
10811075
this.coroutine_kind = coroutine_kind;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Attributes that can be found in function body.
2+
3+
use rustc_hir::attrs::AttributeKind;
4+
use rustc_span::{Symbol, sym};
5+
6+
use super::{NoArgsAttributeParser, OnDuplicate};
7+
use crate::context::Stage;
8+
9+
pub(crate) struct CoroutineParser;
10+
11+
impl<S: Stage> NoArgsAttributeParser<S> for CoroutineParser {
12+
const PATH: &[Symbol] = &[sym::coroutine];
13+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
14+
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
15+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::parser::ArgParser;
2626
use crate::session_diagnostics::UnusedMultiple;
2727

2828
pub(crate) mod allow_unstable;
29+
pub(crate) mod body;
2930
pub(crate) mod cfg;
3031
pub(crate) mod cfg_old;
3132
pub(crate) mod codegen_attrs;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616
use crate::attributes::allow_unstable::{
1717
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
1818
};
19+
use crate::attributes::body::CoroutineParser;
1920
use crate::attributes::codegen_attrs::{
2021
ColdParser, CoverageParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser,
2122
TargetFeatureParser, TrackCallerParser, UsedParser,
@@ -184,6 +185,7 @@ attribute_parsers!(
184185
Single<WithoutArgs<ConstContinueParser>>,
185186
Single<WithoutArgs<ConstStabilityIndirectParser>>,
186187
Single<WithoutArgs<ConstTraitParser>>,
188+
Single<WithoutArgs<CoroutineParser>>,
187189
Single<WithoutArgs<DenyExplicitImplParser>>,
188190
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
189191
Single<WithoutArgs<ExportStableParser>>,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
769769
}
770770
TerminatorKind::Call { func, args, .. }
771771
| TerminatorKind::TailCall { func, args, .. } => {
772-
let call_source = match term.kind {
773-
TerminatorKind::Call { call_source, .. } => call_source,
774-
TerminatorKind::TailCall { .. } => CallSource::Normal,
772+
let (call_source, destination, is_diverging) = match term.kind {
773+
TerminatorKind::Call { call_source, destination, target, .. } => {
774+
(call_source, destination, target.is_none())
775+
}
776+
TerminatorKind::TailCall { .. } => {
777+
(CallSource::Normal, RETURN_PLACE.into(), false)
778+
}
775779
_ => unreachable!(),
776780
};
777781

@@ -845,9 +849,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
845849
);
846850
}
847851

848-
if let TerminatorKind::Call { destination, target, .. } = term.kind {
849-
self.check_call_dest(term, &sig, destination, target, term_location);
850-
}
852+
self.check_call_dest(term, &sig, destination, is_diverging, term_location);
851853

852854
// The ordinary liveness rules will ensure that all
853855
// regions in the type of the callee are live here. We
@@ -1874,65 +1876,61 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18741876
term: &Terminator<'tcx>,
18751877
sig: &ty::FnSig<'tcx>,
18761878
destination: Place<'tcx>,
1877-
target: Option<BasicBlock>,
1879+
is_diverging: bool,
18781880
term_location: Location,
18791881
) {
18801882
let tcx = self.tcx();
1881-
match target {
1882-
Some(_) => {
1883-
let dest_ty = destination.ty(self.body, tcx).ty;
1884-
let dest_ty = self.normalize(dest_ty, term_location);
1885-
let category = match destination.as_local() {
1886-
Some(RETURN_PLACE) => {
1887-
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1888-
self.universal_regions.defining_ty
1889-
{
1890-
if tcx.is_static(def_id) {
1891-
ConstraintCategory::UseAsStatic
1892-
} else {
1893-
ConstraintCategory::UseAsConst
1894-
}
1883+
if is_diverging {
1884+
// The signature in this call can reference region variables,
1885+
// so erase them before calling a query.
1886+
let output_ty = self.tcx().erase_regions(sig.output());
1887+
if !output_ty
1888+
.is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
1889+
{
1890+
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1891+
}
1892+
} else {
1893+
let dest_ty = destination.ty(self.body, tcx).ty;
1894+
let dest_ty = self.normalize(dest_ty, term_location);
1895+
let category = match destination.as_local() {
1896+
Some(RETURN_PLACE) => {
1897+
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1898+
self.universal_regions.defining_ty
1899+
{
1900+
if tcx.is_static(def_id) {
1901+
ConstraintCategory::UseAsStatic
18951902
} else {
1896-
ConstraintCategory::Return(ReturnConstraint::Normal)
1903+
ConstraintCategory::UseAsConst
18971904
}
1905+
} else {
1906+
ConstraintCategory::Return(ReturnConstraint::Normal)
18981907
}
1899-
Some(l) if !self.body.local_decls[l].is_user_variable() => {
1900-
ConstraintCategory::Boring
1901-
}
1902-
// The return type of a call is interesting for diagnostics.
1903-
_ => ConstraintCategory::Assignment,
1904-
};
1905-
1906-
let locations = term_location.to_locations();
1907-
1908-
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1909-
span_mirbug!(
1910-
self,
1911-
term,
1912-
"call dest mismatch ({:?} <- {:?}): {:?}",
1913-
dest_ty,
1914-
sig.output(),
1915-
terr
1916-
);
19171908
}
1918-
1919-
// When `unsized_fn_params` is not enabled,
1920-
// this check is done at `check_local`.
1921-
if self.unsized_feature_enabled() {
1922-
let span = term.source_info.span;
1923-
self.ensure_place_sized(dest_ty, span);
1909+
Some(l) if !self.body.local_decls[l].is_user_variable() => {
1910+
ConstraintCategory::Boring
19241911
}
1912+
// The return type of a call is interesting for diagnostics.
1913+
_ => ConstraintCategory::Assignment,
1914+
};
1915+
1916+
let locations = term_location.to_locations();
1917+
1918+
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1919+
span_mirbug!(
1920+
self,
1921+
term,
1922+
"call dest mismatch ({:?} <- {:?}): {:?}",
1923+
dest_ty,
1924+
sig.output(),
1925+
terr
1926+
);
19251927
}
1926-
None => {
1927-
// The signature in this call can reference region variables,
1928-
// so erase them before calling a query.
1929-
let output_ty = self.tcx().erase_regions(sig.output());
1930-
if !output_ty.is_privately_uninhabited(
1931-
self.tcx(),
1932-
self.infcx.typing_env(self.infcx.param_env),
1933-
) {
1934-
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1935-
}
1928+
1929+
// When `unsized_fn_params` is not enabled,
1930+
// this check is done at `check_local`.
1931+
if self.unsized_feature_enabled() {
1932+
let span = term.source_info.span;
1933+
self.ensure_place_sized(dest_ty, span);
19361934
}
19371935
}
19381936
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ pub enum AttributeKind {
297297
/// Represents `#[const_trait]`.
298298
ConstTrait(Span),
299299

300+
/// Represents `#[coroutine]`.
301+
Coroutine(Span),
302+
300303
/// Represents `#[coverage(..)]`.
301304
Coverage(Span, CoverageAttrKind),
302305

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl AttributeKind {
2828
ConstStability { .. } => Yes,
2929
ConstStabilityIndirect => No,
3030
ConstTrait(..) => No,
31+
Coroutine(..) => No,
3132
Coverage(..) => No,
3233
DenyExplicitImpl(..) => No,
3334
Deprecation { .. } => Yes,

0 commit comments

Comments
 (0)