Skip to content

Commit 8a65ee0

Browse files
committed
Auto merge of #142697 - tgross35:rollup-xu4yuq6, r=tgross35
Rollup of 7 pull requests Successful merges: - #140247 (Don't build `ParamEnv` and do trait solving in `ItemCtxt`s when lowering IATs) - #142507 (use `#[align]` attribute for `fn_align`) - #142524 (Weekly `cargo update`) - #142606 (AsyncDrop trait without sync Drop generates an error) - #142639 (Add a missing colon at the end of the panic location details in location-detail-unwrap-multiline.rs) - #142654 (library: Increase timeout on mpmc test to reduce flakes) - #142692 (Assorted bootstrap cleanups (step 3)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1d8e38 + 986f8cd commit 8a65ee0

File tree

74 files changed

+1097
-655
lines changed

Some content is hidden

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

74 files changed

+1097
-655
lines changed

Cargo.lock

Lines changed: 124 additions & 116 deletions
Large diffs are not rendered by default.

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ impl Deprecation {
182182
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
183183
pub enum AttributeKind {
184184
// tidy-alphabetical-start
185+
/// Represents `#[align(N)]`.
186+
Align { align: Align, span: Span },
187+
185188
/// Represents `#[rustc_allow_const_fn_unstable]`.
186189
AllowConstFnUnstable(ThinVec<Symbol>),
187190

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ attr_parsing_incorrect_repr_format_packed_expect_integer =
4444
attr_parsing_incorrect_repr_format_packed_one_or_zero_arg =
4545
incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
4646
47+
attr_parsing_invalid_alignment_value =
48+
invalid alignment value: {$error_part}
49+
4750
attr_parsing_invalid_issue_string =
4851
`issue` must be a non-zero numeric string or "none"
4952
.must_not_be_zero = `issue` must not be "0", use "none" instead

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_attr_data_structures::{AttributeKind, IntType, ReprAttr};
44
use rustc_feature::{AttributeTemplate, template};
55
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
66

7-
use super::{CombineAttributeParser, ConvertFn};
7+
use super::{AcceptMapping, AttributeParser, CombineAttributeParser, ConvertFn, FinalizeContext};
88
use crate::context::{AcceptContext, Stage};
99
use crate::parser::{ArgParser, MetaItemListParser, MetaItemParser};
1010
use crate::session_diagnostics;
@@ -203,7 +203,7 @@ fn parse_repr_align<S: Stage>(
203203
});
204204
}
205205
Align => {
206-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
206+
cx.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
207207
span: param_span,
208208
});
209209
}
@@ -266,3 +266,57 @@ fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> {
266266
Err("not an unsuffixed integer")
267267
}
268268
}
269+
270+
/// Parse #[align(N)].
271+
#[derive(Default)]
272+
pub(crate) struct AlignParser(Option<(Align, Span)>);
273+
274+
impl AlignParser {
275+
const PATH: &'static [Symbol] = &[sym::align];
276+
const TEMPLATE: AttributeTemplate = template!(Word, List: "<alignment in bytes>");
277+
278+
fn parse<'c, S: Stage>(
279+
&mut self,
280+
cx: &'c mut AcceptContext<'_, '_, S>,
281+
args: &'c ArgParser<'_>,
282+
) {
283+
match args {
284+
ArgParser::NoArgs | ArgParser::NameValue(_) => {
285+
cx.expected_list(cx.attr_span);
286+
}
287+
ArgParser::List(list) => {
288+
let Some(align) = list.single() else {
289+
cx.expected_single_argument(list.span);
290+
return;
291+
};
292+
293+
let Some(lit) = align.lit() else {
294+
cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
295+
span: align.span(),
296+
});
297+
298+
return;
299+
};
300+
301+
match parse_alignment(&lit.kind) {
302+
Ok(literal) => self.0 = Ord::max(self.0, Some((literal, cx.attr_span))),
303+
Err(message) => {
304+
cx.emit_err(session_diagnostics::InvalidAlignmentValue {
305+
span: lit.span,
306+
error_part: message,
307+
});
308+
}
309+
}
310+
}
311+
}
312+
}
313+
}
314+
315+
impl<S: Stage> AttributeParser<S> for AlignParser {
316+
const ATTRIBUTES: AcceptMapping<Self, S> = &[(Self::PATH, Self::TEMPLATE, Self::parse)];
317+
318+
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
319+
let (align, span) = self.0?;
320+
Some(AttributeKind::Align { align, span })
321+
}
322+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::attributes::confusables::ConfusablesParser;
1919
use crate::attributes::deprecation::DeprecationParser;
2020
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2121
use crate::attributes::lint_helpers::AsPtrParser;
22-
use crate::attributes::repr::ReprParser;
22+
use crate::attributes::repr::{AlignParser, ReprParser};
2323
use crate::attributes::stability::{
2424
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
2525
};
@@ -90,6 +90,7 @@ macro_rules! attribute_parsers {
9090
attribute_parsers!(
9191
pub(crate) static ATTRIBUTE_PARSERS = [
9292
// tidy-alphabetical-start
93+
AlignParser,
9394
BodyStabilityParser,
9495
ConfusablesParser,
9596
ConstStabilityParser,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ pub(crate) struct EmptyConfusables {
450450
pub span: Span,
451451
}
452452

453+
#[derive(Diagnostic)]
454+
#[diag(attr_parsing_invalid_alignment_value, code = E0589)]
455+
pub(crate) struct InvalidAlignmentValue {
456+
#[primary_span]
457+
pub span: Span,
458+
pub error_part: &'static str,
459+
}
460+
453461
#[derive(Diagnostic)]
454462
#[diag(attr_parsing_repr_ident, code = E0565)]
455463
pub(crate) struct ReprIdent {

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::str::FromStr;
33
use rustc_abi::ExternAbi;
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
6-
use rustc_attr_data_structures::ReprAttr::ReprAlign;
76
use rustc_attr_data_structures::{
87
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, find_attr,
98
};
@@ -110,17 +109,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
110109
}
111110
};
112111

113-
if let hir::Attribute::Parsed(p) = attr {
114-
match p {
115-
AttributeKind::Repr(reprs) => {
116-
codegen_fn_attrs.alignment = reprs
117-
.iter()
118-
.filter_map(|(r, _)| if let ReprAlign(x) = r { Some(*x) } else { None })
119-
.max();
120-
}
121-
122-
_ => {}
123-
}
112+
if let hir::Attribute::Parsed(AttributeKind::Align { align, .. }) = attr {
113+
codegen_fn_attrs.alignment = Some(*align);
124114
}
125115

126116
let Some(Ident { name, .. }) = attr.ident() else {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
495495
),
496496
ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
497497
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No),
498+
gated!(align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(align)),
498499
ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
499500
ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No),
500501
ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ hir_analysis_associated_type_trait_uninferred_generic_params = cannot use the {$
4646
4747
hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion = use a fully qualified path with explicit lifetimes
4848
49+
hir_analysis_async_drop_without_sync_drop = `AsyncDrop` impl without `Drop` impl
50+
.help = type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds
51+
4952
hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
5053
.label = deref recursion limit reached
5154
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ pub fn provide(providers: &mut Providers) {
114114
}
115115

116116
fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Destructor> {
117-
tcx.calculate_dtor(def_id, always_applicable::check_drop_impl)
117+
let dtor = tcx.calculate_dtor(def_id, always_applicable::check_drop_impl);
118+
if dtor.is_none() && tcx.features().async_drop() {
119+
if let Some(async_dtor) = adt_async_destructor(tcx, def_id) {
120+
// When type has AsyncDrop impl, but doesn't have Drop impl, generate error
121+
let span = tcx.def_span(async_dtor.impl_did);
122+
tcx.dcx().emit_err(errors::AsyncDropWithoutSyncDrop { span });
123+
}
124+
}
125+
dtor
118126
}
119127

120128
fn adt_async_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::AsyncDestructor> {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
3434
use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause};
3535
use rustc_middle::query::Providers;
3636
use rustc_middle::ty::util::{Discr, IntTypeExt};
37-
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode, fold_regions};
37+
use rustc_middle::ty::{
38+
self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, TypingMode, fold_regions,
39+
};
3840
use rustc_middle::{bug, span_bug};
3941
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
4042
use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName;
4143
use rustc_trait_selection::infer::InferCtxtExt;
42-
use rustc_trait_selection::traits::{ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations};
44+
use rustc_trait_selection::traits::{
45+
FulfillmentError, ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations,
46+
};
4347
use tracing::{debug, instrument};
4448

4549
use crate::errors;
46-
use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer, RegionInferReason};
50+
use crate::hir_ty_lowering::{
51+
FeedConstTy, HirTyLowerer, InherentAssocCandidate, RegionInferReason,
52+
};
4753

4854
pub(crate) mod dump;
4955
mod generics_of;
@@ -364,6 +370,58 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
364370
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_ident))
365371
}
366372

373+
#[instrument(level = "debug", skip(self, _span), ret)]
374+
fn select_inherent_assoc_candidates(
375+
&self,
376+
_span: Span,
377+
self_ty: Ty<'tcx>,
378+
candidates: Vec<InherentAssocCandidate>,
379+
) -> (Vec<InherentAssocCandidate>, Vec<FulfillmentError<'tcx>>) {
380+
assert!(!self_ty.has_infer());
381+
382+
// We don't just call the normal normalization routine here as we can't provide the
383+
// correct `ParamEnv` and it would be wrong to invoke arbitrary trait solving under
384+
// the wrong `ParamEnv`. Expanding free aliases doesn't need a `ParamEnv` so we do
385+
// this just to make resolution a little bit smarter.
386+
let self_ty = self.tcx.expand_free_alias_tys(self_ty);
387+
debug!("select_inherent_assoc_candidates: self_ty={:?}", self_ty);
388+
389+
let candidates = candidates
390+
.into_iter()
391+
.filter(|&InherentAssocCandidate { impl_, .. }| {
392+
let impl_ty = self.tcx().type_of(impl_).instantiate_identity();
393+
394+
// See comment on doing this operation for `self_ty`
395+
let impl_ty = self.tcx.expand_free_alias_tys(impl_ty);
396+
debug!("select_inherent_assoc_candidates: impl_ty={:?}", impl_ty);
397+
398+
// We treat parameters in the self ty as rigid and parameters in the impl ty as infers
399+
// because it allows `impl<T> Foo<T>` to unify with `Foo<u8>::IAT`, while also disallowing
400+
// `Foo<T>::IAT` from unifying with `impl Foo<u8>`.
401+
//
402+
// We don't really care about a depth limit here because we're only working with user-written
403+
// types and if they wrote a type that would take hours to walk then that's kind of on them. On
404+
// the other hand the default depth limit is relatively low and could realistically be hit by
405+
// users in normal cases.
406+
//
407+
// `DeepRejectCtxt` leads to slightly worse IAT resolution than real type equality in cases
408+
// where the `impl_ty` has repeated uses of generic parameters. E.g. `impl<T> Foo<T, T>` would
409+
// be considered a valid candidate when resolving `Foo<u8, u16>::IAT`.
410+
//
411+
// Not replacing escaping bound vars in `self_ty` with placeholders also leads to slightly worse
412+
// resolution, but it probably won't come up in practice and it would be backwards compatible
413+
// to switch over to doing that.
414+
ty::DeepRejectCtxt::relate_rigid_infer(self.tcx).types_may_unify_with_depth(
415+
self_ty,
416+
impl_ty,
417+
usize::MAX,
418+
)
419+
})
420+
.collect();
421+
422+
(candidates, vec![])
423+
}
424+
367425
fn lower_assoc_item_path(
368426
&self,
369427
span: Span,

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,3 +1712,11 @@ pub(crate) struct AbiCustomClothedFunction {
17121712
)]
17131713
pub naked_span: Span,
17141714
}
1715+
1716+
#[derive(Diagnostic)]
1717+
#[diag(hir_analysis_async_drop_without_sync_drop)]
1718+
#[help]
1719+
pub(crate) struct AsyncDropWithoutSyncDrop {
1720+
#[primary_span]
1721+
pub span: Span,
1722+
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_trait_selection::traits::{
2626
use smallvec::SmallVec;
2727
use tracing::debug;
2828

29+
use super::InherentAssocCandidate;
2930
use crate::errors::{
3031
self, AssocItemConstraintsNotAllowedHere, ManualImplementation, MissingTypeParams,
3132
ParenthesizedFnTraitExpansion, TraitObjectDeclaredWithNoTraits,
@@ -793,7 +794,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
793794
&self,
794795
name: Ident,
795796
self_ty: Ty<'tcx>,
796-
candidates: Vec<(DefId, (DefId, DefId))>,
797+
candidates: Vec<InherentAssocCandidate>,
797798
fulfillment_errors: Vec<FulfillmentError<'tcx>>,
798799
span: Span,
799800
assoc_tag: ty::AssocTag,
@@ -827,8 +828,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
827828
let type_candidates = candidates
828829
.iter()
829830
.take(limit)
830-
.map(|&(impl_, _)| {
831-
format!("- `{}`", tcx.at(span).type_of(impl_).instantiate_identity())
831+
.map(|cand| {
832+
format!("- `{}`", tcx.at(span).type_of(cand.impl_).instantiate_identity())
832833
})
833834
.collect::<Vec<_>>()
834835
.join("\n");

0 commit comments

Comments
 (0)