Skip to content

Rollup of 14 pull requests #145285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ba350ff
fix: re-enable self-assignment
notJoon Aug 10, 2025
de13718
test: Add rustdoc test for enum negative overflow
eval-exec Aug 10, 2025
20a134f
rustdoc: Use `discr`s `Display` impl to render the value with the cor…
eval-exec Aug 10, 2025
cd4676c
Turn _span into _trace as trace span name
Stypox Aug 11, 2025
6603fe1
Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2)
scrabsha Aug 3, 2025
d523b9f
Support using #[unstable_feature_bound] on trait
tiif Aug 11, 2025
9a8facb
Update rustc dev guide
tiif Aug 11, 2025
bcf87e4
Update error message
tiif Aug 11, 2025
0ccbe8f
std: sys: pal: uefi: Overhaul Time
Ayush1325 Apr 14, 2025
35906ea
std: sys: pal: uefi: tests: Add systemtime tests
Ayush1325 May 24, 2025
79a134a
Document compiler and stdlib in stage1 in `pr-check-2` CI job
Kobzol Aug 11, 2025
c022ed9
don't emit rustdoc::broken_intra_doc_links for stuff like [!NOTE]
lolbinarycat Aug 4, 2025
189f264
Allow attr entries to declare list of alternatives for `List` and `Na…
estebank Aug 11, 2025
625143b
Add link to docs on malformed attributes
estebank Aug 11, 2025
6bb29af
Add link to invalid `repr` error
estebank Aug 11, 2025
413ca5d
fix tests
estebank Aug 11, 2025
50d8b80
Update books
rustbot Aug 11, 2025
32ee26c
Add more docs to templates for attrs with incorrect arguments
estebank Aug 11, 2025
adccb8d
Rework `NameValueStr`
estebank Aug 11, 2025
1dc37df
Simplify `add_apple_sdk`
madsmtm Aug 11, 2025
928dd11
fix clippy test
estebank Aug 11, 2025
1cc44bf
Pass Apple SDK root to compiler driver via SDKROOT env var
madsmtm Aug 11, 2025
f4a9110
Only warn when invoking xcrun
madsmtm Aug 11, 2025
1d13162
Always attempt to invoke xcrun to get the Apple SDK
madsmtm Aug 11, 2025
86853b3
Account for new `assert!` desugaring in `!condition` suggestion
estebank Aug 11, 2025
39c5d6d
Factor out InherentImplCannotUnsafe
camsteffen Jul 30, 2025
fa73390
Move trait impl modifier errors to parsing
camsteffen Jul 30, 2025
3aa0ac0
Tweak trait modifier errors
camsteffen Jul 30, 2025
5bc23ce
Extract ast TraitImplHeader
camsteffen Jul 22, 2025
bf266dc
Propagate TraitImplHeader to hir
camsteffen Jul 24, 2025
25fe461
std: thread: Return error if setting thread stack size fails
Gelbpunkt Jul 20, 2025
5fbbbad
Rollup merge of #131477 - madsmtm:sdkroot-via-env-var, r=nnethercote
fmease Aug 12, 2025
e372be7
Rollup merge of #139806 - Ayush1325:uefi-systemtime, r=joboet
fmease Aug 12, 2025
2b06b3e
Rollup merge of #144210 - Gelbpunkt:thread-stack-size-musl, r=jhpratt
fmease Aug 12, 2025
c55f24c
Rollup merge of #144386 - camsteffen:imploftrait, r=fmease
fmease Aug 12, 2025
6fcd4bf
Rollup merge of #144921 - lolbinarycat:rustdoc-intra-doc-gfm-141866, …
fmease Aug 12, 2025
2a39cf1
Rollup merge of #145155 - scrabsha:push-tkvwkolzooyq, r=jdonszelmann
fmease Aug 12, 2025
e92800a
Rollup merge of #145214 - notJoon:fix/enable-self-assignment, r=petro…
fmease Aug 12, 2025
7c2f7a7
Rollup merge of #145216 - eval-exec:fix-145125-enum-rustdoc, r=fmease
fmease Aug 12, 2025
afe2fba
Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmann
fmease Aug 12, 2025
2caa3bb
Rollup merge of #145249 - Stypox:_span-to-_trace, r=joshtriplett
fmease Aug 12, 2025
556c571
Rollup merge of #145251 - tiif:support_trait, r=BoxyUwU
fmease Aug 12, 2025
716cfe8
Rollup merge of #145253 - Kobzol:pr-check-2-doc-stage-1, r=jieyouxu
fmease Aug 12, 2025
30bff95
Rollup merge of #145263 - rustbot:docs-update, r=ehuss
fmease Aug 12, 2025
84cce89
Rollup merge of #145273 - estebank:not-not, r=samueltardieu
fmease Aug 12, 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
21 changes: 13 additions & 8 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3661,15 +3661,19 @@ pub struct TyAlias {

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Impl {
pub generics: Generics,
pub of_trait: Option<Box<TraitImplHeader>>,
pub self_ty: Box<Ty>,
pub items: ThinVec<Box<AssocItem>>,
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct TraitImplHeader {
pub defaultness: Defaultness,
pub safety: Safety,
pub generics: Generics,
pub constness: Const,
pub polarity: ImplPolarity,
/// The trait being implemented, if any.
pub of_trait: Option<TraitRef>,
pub self_ty: Box<Ty>,
pub items: ThinVec<Box<AssocItem>>,
pub trait_ref: TraitRef,
}

#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)]
Expand Down Expand Up @@ -3793,7 +3797,7 @@ pub enum ItemKind {
/// An implementation.
///
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
Impl(Box<Impl>),
Impl(Impl),
/// A macro invocation.
///
/// E.g., `foo!(..)`.
Expand Down Expand Up @@ -3880,7 +3884,7 @@ impl ItemKind {
| Self::Union(_, generics, _)
| Self::Trait(box Trait { generics, .. })
| Self::TraitAlias(_, generics, _)
| Self::Impl(box Impl { generics, .. }) => Some(generics),
| Self::Impl(Impl { generics, .. }) => Some(generics),
_ => None,
}
}
Expand Down Expand Up @@ -4040,7 +4044,7 @@ mod size_asserts {
static_assert_size!(GenericArg, 24);
static_assert_size!(GenericBound, 88);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 136);
static_assert_size!(Impl, 64);
static_assert_size!(Item, 144);
static_assert_size!(ItemKind, 80);
static_assert_size!(LitKind, 24);
Expand All @@ -4053,6 +4057,7 @@ mod size_asserts {
static_assert_size!(PathSegment, 24);
static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16);
static_assert_size!(TraitImplHeader, 80);
static_assert_size!(Ty, 64);
static_assert_size!(TyKind, 40);
// tidy-alphabetical-end
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,13 @@ macro_rules! common_visitor_and_walkers {
}

impl_walkable!(|&$($mut)? $($lt)? self: Impl, vis: &mut V| {
let Impl { defaultness, safety, generics, constness, polarity, of_trait, self_ty, items } = self;
visit_visitable!($($mut)? vis, defaultness, safety, generics, constness, polarity, of_trait, self_ty);
let Impl { generics, of_trait, self_ty, items } = self;
try_visit!(vis.visit_generics(generics));
if let Some(box of_trait) = of_trait {
let TraitImplHeader { defaultness, safety, constness, polarity, trait_ref } = of_trait;
visit_visitable!($($mut)? vis, defaultness, safety, constness, polarity, trait_ref);
}
try_visit!(vis.visit_ty(self_ty));
visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() });
V::Result::output()
});
Expand Down
86 changes: 48 additions & 38 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::Union(ident, generics, vdata)
}
ItemKind::Impl(box Impl {
safety,
polarity,
defaultness,
constness,
ItemKind::Impl(Impl {
generics: ast_generics,
of_trait: trait_ref,
of_trait,
self_ty: ty,
items: impl_items,
}) => {
Expand All @@ -364,54 +360,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
// lifetime to be added, but rather a reference to a
// parent lifetime.
let itctx = ImplTraitContext::Universal;
let (generics, (trait_ref, lowered_ty)) =
let (generics, (of_trait, lowered_ty)) =
self.lower_generics(ast_generics, id, itctx, |this| {
let modifiers = TraitBoundModifiers {
constness: BoundConstness::Never,
asyncness: BoundAsyncness::Normal,
// we don't use this in bound lowering
polarity: BoundPolarity::Positive,
};

let trait_ref = trait_ref.as_ref().map(|trait_ref| {
this.lower_trait_ref(
modifiers,
trait_ref,
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
)
});
let of_trait = of_trait
.as_deref()
.map(|of_trait| this.lower_trait_impl_header(of_trait));

let lowered_ty = this.lower_ty(
ty,
ImplTraitContext::Disallowed(ImplTraitPosition::ImplSelf),
);

(trait_ref, lowered_ty)
(of_trait, lowered_ty)
});

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

// `defaultness.has_value()` is never called for an `impl`, always `true` in order
// to not cause an assertion failure inside the `lower_defaultness` function.
let has_val = true;
let (defaultness, defaultness_span) = self.lower_defaultness(*defaultness, has_val);
let polarity = match polarity {
ImplPolarity::Positive => ImplPolarity::Positive,
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)),
};
hir::ItemKind::Impl(self.arena.alloc(hir::Impl {
constness: self.lower_constness(*constness),
safety: self.lower_safety(*safety, hir::Safety::Safe),
polarity,
defaultness,
defaultness_span,
hir::ItemKind::Impl(hir::Impl {
generics,
of_trait: trait_ref,
of_trait,
self_ty: lowered_ty,
items: new_impl_items,
}))
})
}
ItemKind::Trait(box Trait {
constness,
Expand Down Expand Up @@ -982,6 +954,44 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.expr(span, hir::ExprKind::Err(guar))
}

fn lower_trait_impl_header(
&mut self,
trait_impl_header: &TraitImplHeader,
) -> &'hir hir::TraitImplHeader<'hir> {
let TraitImplHeader { constness, safety, polarity, defaultness, ref trait_ref } =
*trait_impl_header;
let constness = self.lower_constness(constness);
let safety = self.lower_safety(safety, hir::Safety::Safe);
let polarity = match polarity {
ImplPolarity::Positive => ImplPolarity::Positive,
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(s)),
};
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
// to not cause an assertion failure inside the `lower_defaultness` function.
let has_val = true;
let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
let modifiers = TraitBoundModifiers {
constness: BoundConstness::Never,
asyncness: BoundAsyncness::Normal,
// we don't use this in bound lowering
polarity: BoundPolarity::Positive,
};
let trait_ref = self.lower_trait_ref(
modifiers,
trait_ref,
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
);

self.arena.alloc(hir::TraitImplHeader {
constness,
safety,
polarity,
defaultness,
defaultness_span,
trait_ref,
})
}

fn lower_impl_item(
&mut self,
i: &AssocItem,
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ ast_passes_generic_default_trailing = generic parameters with a default must be
ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed
.help = remove one of these features
ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation}
.because = {$annotation} because of this
.type = inherent impl for this type
.only_trait = only trait implementations may be annotated with {$annotation}
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
.suggestion = remove safe from this item
Expand Down
51 changes: 10 additions & 41 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

match &item.kind {
ItemKind::Impl(box Impl {
safety,
polarity,
defaultness: _,
constness,
ItemKind::Impl(Impl {
generics,
of_trait: Some(t),
of_trait:
Some(box TraitImplHeader {
safety,
polarity,
defaultness: _,
constness,
trait_ref: t,
}),
self_ty,
items,
}) => {
Expand Down Expand Up @@ -992,46 +995,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl { of_trait: true });
});
}
ItemKind::Impl(box Impl {
safety,
polarity,
defaultness,
constness,
generics,
of_trait: None,
self_ty,
items,
}) => {
let error = |annotation_span, annotation, only_trait| errors::InherentImplCannot {
span: self_ty.span,
annotation_span,
annotation,
self_ty: self_ty.span,
only_trait,
};

ItemKind::Impl(Impl { generics, of_trait: None, self_ty, items }) => {
self.visit_attrs_vis(&item.attrs, &item.vis);
self.visibility_not_permitted(
&item.vis,
errors::VisibilityNotPermittedNote::IndividualImplItems,
);
if let &Safety::Unsafe(span) = safety {
self.dcx().emit_err(errors::InherentImplCannotUnsafe {
span: self_ty.span,
annotation_span: span,
annotation: "unsafe",
self_ty: self_ty.span,
});
}
if let &ImplPolarity::Negative(span) = polarity {
self.dcx().emit_err(error(span, "negative", false));
}
if let &Defaultness::Default(def_span) = defaultness {
self.dcx().emit_err(error(def_span, "`default`", true));
}
if let &Const::Yes(span) = constness {
self.dcx().emit_err(error(span, "`const`", true));
}

self.with_tilde_const(Some(TildeConstReason::Impl { span: item.span }), |this| {
this.visit_generics(generics)
Expand Down
26 changes: 0 additions & 26 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,32 +464,6 @@ pub(crate) struct UnsafeNegativeImpl {
pub r#unsafe: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_inherent_cannot_be)]
pub(crate) struct InherentImplCannot<'a> {
#[primary_span]
pub span: Span,
#[label(ast_passes_because)]
pub annotation_span: Span,
pub annotation: &'a str,
#[label(ast_passes_type)]
pub self_ty: Span,
#[note(ast_passes_only_trait)]
pub only_trait: bool,
}

#[derive(Diagnostic)]
#[diag(ast_passes_inherent_cannot_be, code = E0197)]
pub(crate) struct InherentImplCannotUnsafe<'a> {
#[primary_span]
pub span: Span,
#[label(ast_passes_because)]
pub annotation_span: Span,
pub annotation: &'a str,
#[label(ast_passes_type)]
pub self_ty: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_item)]
pub(crate) struct UnsafeItem {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

ast::ItemKind::Impl(box ast::Impl { polarity, defaultness, of_trait, .. }) => {
if let &ast::ImplPolarity::Negative(span) = polarity {
ast::ItemKind::Impl(ast::Impl { of_trait: Some(of_trait), .. }) => {
if let ast::ImplPolarity::Negative(span) = of_trait.polarity {
gate!(
&self,
negative_impls,
span.to(of_trait.as_ref().map_or(span, |t| t.path.span)),
span.to(of_trait.trait_ref.path.span),
"negative trait bounds are not fully implemented; \
use marker types for now"
);
}

if let ast::Defaultness::Default(_) = defaultness {
if let ast::Defaultness::Default(_) = of_trait.defaultness {
gate!(&self, specialization, i.span, "specialization is unstable");
}
}
Expand Down
Loading
Loading