Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9dba3a

Browse files
committed
Auto merge of #145300 - Zalathar:rollup-0eqbt6a, r=Zalathar
Rollup of 17 pull requests Successful merges: - #131477 (Apple: Always pass SDK root when linking with `cc`, and pass it via `SDKROOT` env var) - #139806 (std: sys: pal: uefi: Overhaul Time) - #144386 (Extract TraitImplHeader in AST/HIR) - #144921 (Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`) - #145155 (Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2)) - #145214 (fix: re-enable self-assignment) - #145216 (rustdoc: correct negative-to-implicit discriminant display) - #145238 (Tweak invalid builtin attribute output) - #145249 (Rename entered trace span variables from `_span` to `_trace`) - #145251 (Support using #[unstable_feature_bound] on trait) - #145253 (Document compiler and stdlib in stage1 in `pr-check-2` CI job) - #145260 (Make explicit guarantees about `Vec`’s allocator) - #145263 (Update books) - #145273 (Account for new `assert!` desugaring in `!condition` suggestion) - #145283 (Make I-miscompile imply I-prioritize) - #145291 (bootstrap: Only warn about `rust.debug-assertions` if downloading rustc) - #145292 (Fix a typo in range docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a153133 + 7c4bedc commit d9dba3a

File tree

221 files changed

+2681
-1183
lines changed

Some content is hidden

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

221 files changed

+2681
-1183
lines changed

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,15 +3661,19 @@ pub struct TyAlias {
36613661

36623662
#[derive(Clone, Encodable, Decodable, Debug)]
36633663
pub struct Impl {
3664+
pub generics: Generics,
3665+
pub of_trait: Option<Box<TraitImplHeader>>,
3666+
pub self_ty: Box<Ty>,
3667+
pub items: ThinVec<Box<AssocItem>>,
3668+
}
3669+
3670+
#[derive(Clone, Encodable, Decodable, Debug)]
3671+
pub struct TraitImplHeader {
36643672
pub defaultness: Defaultness,
36653673
pub safety: Safety,
3666-
pub generics: Generics,
36673674
pub constness: Const,
36683675
pub polarity: ImplPolarity,
3669-
/// The trait being implemented, if any.
3670-
pub of_trait: Option<TraitRef>,
3671-
pub self_ty: Box<Ty>,
3672-
pub items: ThinVec<Box<AssocItem>>,
3676+
pub trait_ref: TraitRef,
36733677
}
36743678

36753679
#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)]
@@ -3793,7 +3797,7 @@ pub enum ItemKind {
37933797
/// An implementation.
37943798
///
37953799
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
3796-
Impl(Box<Impl>),
3800+
Impl(Impl),
37973801
/// A macro invocation.
37983802
///
37993803
/// E.g., `foo!(..)`.
@@ -3880,7 +3884,7 @@ impl ItemKind {
38803884
| Self::Union(_, generics, _)
38813885
| Self::Trait(box Trait { generics, .. })
38823886
| Self::TraitAlias(_, generics, _)
3883-
| Self::Impl(box Impl { generics, .. }) => Some(generics),
3887+
| Self::Impl(Impl { generics, .. }) => Some(generics),
38843888
_ => None,
38853889
}
38863890
}
@@ -4040,7 +4044,7 @@ mod size_asserts {
40404044
static_assert_size!(GenericArg, 24);
40414045
static_assert_size!(GenericBound, 88);
40424046
static_assert_size!(Generics, 40);
4043-
static_assert_size!(Impl, 136);
4047+
static_assert_size!(Impl, 64);
40444048
static_assert_size!(Item, 144);
40454049
static_assert_size!(ItemKind, 80);
40464050
static_assert_size!(LitKind, 24);
@@ -4053,6 +4057,7 @@ mod size_asserts {
40534057
static_assert_size!(PathSegment, 24);
40544058
static_assert_size!(Stmt, 32);
40554059
static_assert_size!(StmtKind, 16);
4060+
static_assert_size!(TraitImplHeader, 80);
40564061
static_assert_size!(Ty, 64);
40574062
static_assert_size!(TyKind, 40);
40584063
// tidy-alphabetical-end

‎compiler/rustc_ast/src/visit.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,13 @@ macro_rules! common_visitor_and_walkers {
929929
}
930930

931931
impl_walkable!(|&$($mut)? $($lt)? self: Impl, vis: &mut V| {
932-
let Impl { defaultness, safety, generics, constness, polarity, of_trait, self_ty, items } = self;
933-
visit_visitable!($($mut)? vis, defaultness, safety, generics, constness, polarity, of_trait, self_ty);
932+
let Impl { generics, of_trait, self_ty, items } = self;
933+
try_visit!(vis.visit_generics(generics));
934+
if let Some(box of_trait) = of_trait {
935+
let TraitImplHeader { defaultness, safety, constness, polarity, trait_ref } = of_trait;
936+
visit_visitable!($($mut)? vis, defaultness, safety, constness, polarity, trait_ref);
937+
}
938+
try_visit!(vis.visit_ty(self_ty));
934939
visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() });
935940
V::Result::output()
936941
});

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
340340
);
341341
hir::ItemKind::Union(ident, generics, vdata)
342342
}
343-
ItemKind::Impl(box Impl {
344-
safety,
345-
polarity,
346-
defaultness,
347-
constness,
343+
ItemKind::Impl(Impl {
348344
generics: ast_generics,
349-
of_trait: trait_ref,
345+
of_trait,
350346
self_ty: ty,
351347
items: impl_items,
352348
}) => {
@@ -364,54 +360,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
364360
// lifetime to be added, but rather a reference to a
365361
// parent lifetime.
366362
let itctx = ImplTraitContext::Universal;
367-
let (generics, (trait_ref, lowered_ty)) =
363+
let (generics, (of_trait, lowered_ty)) =
368364
self.lower_generics(ast_generics, id, itctx, |this| {
369-
let modifiers = TraitBoundModifiers {
370-
constness: BoundConstness::Never,
371-
asyncness: BoundAsyncness::Normal,
372-
// we don't use this in bound lowering
373-
polarity: BoundPolarity::Positive,
374-
};
375-
376-
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
377-
this.lower_trait_ref(
378-
modifiers,
379-
trait_ref,
380-
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
381-
)
382-
});
365+
let of_trait = of_trait
366+
.as_deref()
367+
.map(|of_trait| this.lower_trait_impl_header(of_trait));
383368

384369
let lowered_ty = this.lower_ty(
385370
ty,
386371
ImplTraitContext::Disallowed(ImplTraitPosition::ImplSelf),
387372
);
388373

389-
(trait_ref, lowered_ty)
374+
(of_trait, lowered_ty)
390375
});
391376

392377
let new_impl_items = self
393378
.arena
394379
.alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item)));
395380

396-
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
397-
// to not cause an assertion failure inside the `lower_defaultness` function.
398-
let has_val = true;
399-
let (defaultness, defaultness_span) = self.lower_defaultness(*defaultness, has_val);
400-
let polarity = match polarity {
401-
ImplPolarity::Positive => ImplPolarity::Positive,
402-
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)),
403-
};
404-
hir::ItemKind::Impl(self.arena.alloc(hir::Impl {
405-
constness: self.lower_constness(*constness),
406-
safety: self.lower_safety(*safety, hir::Safety::Safe),
407-
polarity,
408-
defaultness,
409-
defaultness_span,
381+
hir::ItemKind::Impl(hir::Impl {
410382
generics,
411-
of_trait: trait_ref,
383+
of_trait,
412384
self_ty: lowered_ty,
413385
items: new_impl_items,
414-
}))
386+
})
415387
}
416388
ItemKind::Trait(box Trait {
417389
constness,
@@ -982,6 +954,44 @@ impl<'hir> LoweringContext<'_, 'hir> {
982954
self.expr(span, hir::ExprKind::Err(guar))
983955
}
984956

957+
fn lower_trait_impl_header(
958+
&mut self,
959+
trait_impl_header: &TraitImplHeader,
960+
) -> &'hir hir::TraitImplHeader<'hir> {
961+
let TraitImplHeader { constness, safety, polarity, defaultness, ref trait_ref } =
962+
*trait_impl_header;
963+
let constness = self.lower_constness(constness);
964+
let safety = self.lower_safety(safety, hir::Safety::Safe);
965+
let polarity = match polarity {
966+
ImplPolarity::Positive => ImplPolarity::Positive,
967+
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(s)),
968+
};
969+
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
970+
// to not cause an assertion failure inside the `lower_defaultness` function.
971+
let has_val = true;
972+
let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
973+
let modifiers = TraitBoundModifiers {
974+
constness: BoundConstness::Never,
975+
asyncness: BoundAsyncness::Normal,
976+
// we don't use this in bound lowering
977+
polarity: BoundPolarity::Positive,
978+
};
979+
let trait_ref = self.lower_trait_ref(
980+
modifiers,
981+
trait_ref,
982+
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
983+
);
984+
985+
self.arena.alloc(hir::TraitImplHeader {
986+
constness,
987+
safety,
988+
polarity,
989+
defaultness,
990+
defaultness_span,
991+
trait_ref,
992+
})
993+
}
994+
985995
fn lower_impl_item(
986996
&mut self,
987997
i: &AssocItem,

‎compiler/rustc_ast_passes/messages.ftl‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ ast_passes_generic_default_trailing = generic parameters with a default must be
175175
ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed
176176
.help = remove one of these features
177177
178-
ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation}
179-
.because = {$annotation} because of this
180-
.type = inherent impl for this type
181-
.only_trait = only trait implementations may be annotated with {$annotation}
182-
183178
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
184179
.suggestion = remove safe from this item
185180

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
954954
}
955955

956956
match &item.kind {
957-
ItemKind::Impl(box Impl {
958-
safety,
959-
polarity,
960-
defaultness: _,
961-
constness,
957+
ItemKind::Impl(Impl {
962958
generics,
963-
of_trait: Some(t),
959+
of_trait:
960+
Some(box TraitImplHeader {
961+
safety,
962+
polarity,
963+
defaultness: _,
964+
constness,
965+
trait_ref: t,
966+
}),
964967
self_ty,
965968
items,
966969
}) => {
@@ -992,46 +995,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
992995
walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl { of_trait: true });
993996
});
994997
}
995-
ItemKind::Impl(box Impl {
996-
safety,
997-
polarity,
998-
defaultness,
999-
constness,
1000-
generics,
1001-
of_trait: None,
1002-
self_ty,
1003-
items,
1004-
}) => {
1005-
let error = |annotation_span, annotation, only_trait| errors::InherentImplCannot {
1006-
span: self_ty.span,
1007-
annotation_span,
1008-
annotation,
1009-
self_ty: self_ty.span,
1010-
only_trait,
1011-
};
1012-
998+
ItemKind::Impl(Impl { generics, of_trait: None, self_ty, items }) => {
1013999
self.visit_attrs_vis(&item.attrs, &item.vis);
10141000
self.visibility_not_permitted(
10151001
&item.vis,
10161002
errors::VisibilityNotPermittedNote::IndividualImplItems,
10171003
);
1018-
if let &Safety::Unsafe(span) = safety {
1019-
self.dcx().emit_err(errors::InherentImplCannotUnsafe {
1020-
span: self_ty.span,
1021-
annotation_span: span,
1022-
annotation: "unsafe",
1023-
self_ty: self_ty.span,
1024-
});
1025-
}
1026-
if let &ImplPolarity::Negative(span) = polarity {
1027-
self.dcx().emit_err(error(span, "negative", false));
1028-
}
1029-
if let &Defaultness::Default(def_span) = defaultness {
1030-
self.dcx().emit_err(error(def_span, "`default`", true));
1031-
}
1032-
if let &Const::Yes(span) = constness {
1033-
self.dcx().emit_err(error(span, "`const`", true));
1034-
}
10351004

10361005
self.with_tilde_const(Some(TildeConstReason::Impl { span: item.span }), |this| {
10371006
this.visit_generics(generics)

‎compiler/rustc_ast_passes/src/errors.rs‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -464,32 +464,6 @@ pub(crate) struct UnsafeNegativeImpl {
464464
pub r#unsafe: Span,
465465
}
466466

467-
#[derive(Diagnostic)]
468-
#[diag(ast_passes_inherent_cannot_be)]
469-
pub(crate) struct InherentImplCannot<'a> {
470-
#[primary_span]
471-
pub span: Span,
472-
#[label(ast_passes_because)]
473-
pub annotation_span: Span,
474-
pub annotation: &'a str,
475-
#[label(ast_passes_type)]
476-
pub self_ty: Span,
477-
#[note(ast_passes_only_trait)]
478-
pub only_trait: bool,
479-
}
480-
481-
#[derive(Diagnostic)]
482-
#[diag(ast_passes_inherent_cannot_be, code = E0197)]
483-
pub(crate) struct InherentImplCannotUnsafe<'a> {
484-
#[primary_span]
485-
pub span: Span,
486-
#[label(ast_passes_because)]
487-
pub annotation_span: Span,
488-
pub annotation: &'a str,
489-
#[label(ast_passes_type)]
490-
pub self_ty: Span,
491-
}
492-
493467
#[derive(Diagnostic)]
494468
#[diag(ast_passes_unsafe_item)]
495469
pub(crate) struct UnsafeItem {

‎compiler/rustc_ast_passes/src/feature_gate.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
217217
}
218218
}
219219

220-
ast::ItemKind::Impl(box ast::Impl { polarity, defaultness,of_trait, .. }) => {
221-
if let &ast::ImplPolarity::Negative(span) = polarity {
220+
ast::ItemKind::Impl(ast::Impl { of_trait:Some(of_trait), .. }) => {
221+
if let ast::ImplPolarity::Negative(span) = of_trait.polarity {
222222
gate!(
223223
&self,
224224
negative_impls,
225-
span.to(of_trait.as_ref().map_or(span, |t| t.path.span)),
225+
span.to(of_trait.trait_ref.path.span),
226226
"negative trait bounds are not fully implemented; \
227227
use marker types for now"
228228
);
229229
}
230230

231-
if let ast::Defaultness::Default(_) = defaultness {
231+
if let ast::Defaultness::Default(_) = of_trait.defaultness {
232232
gate!(&self, specialization, i.span, "specialization is unstable");
233233
}
234234
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /