Skip to content

Commit f295a41

Browse files
authored
Merge branch 'master' into rp-rename
2 parents 01dba83 + 8231065 commit f295a41

File tree

834 files changed

+13890
-7664
lines changed

Some content is hidden

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

834 files changed

+13890
-7664
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ jobs:
182182
- name: install MinGW
183183
run: src/ci/scripts/install-mingw.sh
184184

185+
# Workaround for spurious ci failures after mingw install
186+
# see https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/Spurious.20bors.20CI.20failures/near/528915775
187+
- name: ensure home dir exists
188+
run: mkdir -p ~
189+
185190
- name: install ninja
186191
run: src/ci/scripts/install-ninja.sh
187192

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,9 +3136,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
31363136

31373137
[[package]]
31383138
name = "rustc-literal-escaper"
3139-
version = "0.0.4"
3139+
version = "0.0.5"
31403140
source = "registry+https://github.com/rust-lang/crates.io-index"
3141-
checksum = "ab03008eb631b703dd16978282ae36c73282e7922fe101a4bd072a40ecea7b8b"
3141+
checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b"
31423142

31433143
[[package]]
31443144
name = "rustc-main"

compiler/rustc_ast/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
99
memchr = "2.7.4"
10-
rustc-literal-escaper = "0.0.4"
10+
rustc-literal-escaper = "0.0.5"
1111
rustc_ast_ir = { path = "../rustc_ast_ir" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_index = { path = "../rustc_index" }

compiler/rustc_ast/src/ast.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! - [`Attribute`]: Metadata associated with item.
1919
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
21-
use std::borrow::Cow;
21+
use std::borrow::{Borrow, Cow};
2222
use std::{cmp, fmt};
2323

2424
pub use GenericArgs::*;
@@ -155,6 +155,59 @@ impl Path {
155155
}
156156
}
157157

158+
/// Joins multiple symbols with "::" into a path, e.g. "a::b::c". If the first
159+
/// segment is `kw::PathRoot` it will be printed as empty, e.g. "::b::c".
160+
///
161+
/// The generics on the `path` argument mean it can accept many forms, such as:
162+
/// - `&[Symbol]`
163+
/// - `Vec<Symbol>`
164+
/// - `Vec<&Symbol>`
165+
/// - `impl Iterator<Item = Symbol>`
166+
/// - `impl Iterator<Item = &Symbol>`
167+
///
168+
/// Panics if `path` is empty or a segment after the first is `kw::PathRoot`.
169+
pub fn join_path_syms(path: impl IntoIterator<Item = impl Borrow<Symbol>>) -> String {
170+
// This is a guess at the needed capacity that works well in practice. It is slightly faster
171+
// than (a) starting with an empty string, or (b) computing the exact capacity required.
172+
// `8` works well because it's about the right size and jemalloc's size classes are all
173+
// multiples of 8.
174+
let mut iter = path.into_iter();
175+
let len_hint = iter.size_hint().1.unwrap_or(1);
176+
let mut s = String::with_capacity(len_hint * 8);
177+
178+
let first_sym = *iter.next().unwrap().borrow();
179+
if first_sym != kw::PathRoot {
180+
s.push_str(first_sym.as_str());
181+
}
182+
for sym in iter {
183+
let sym = *sym.borrow();
184+
debug_assert_ne!(sym, kw::PathRoot);
185+
s.push_str("::");
186+
s.push_str(sym.as_str());
187+
}
188+
s
189+
}
190+
191+
/// Like `join_path_syms`, but for `Ident`s. This function is necessary because
192+
/// `Ident::to_string` does more than just print the symbol in the `name` field.
193+
pub fn join_path_idents(path: impl IntoIterator<Item = impl Borrow<Ident>>) -> String {
194+
let mut iter = path.into_iter();
195+
let len_hint = iter.size_hint().1.unwrap_or(1);
196+
let mut s = String::with_capacity(len_hint * 8);
197+
198+
let first_ident = *iter.next().unwrap().borrow();
199+
if first_ident.name != kw::PathRoot {
200+
s.push_str(&first_ident.to_string());
201+
}
202+
for ident in iter {
203+
let ident = *ident.borrow();
204+
debug_assert_ne!(ident.name, kw::PathRoot);
205+
s.push_str("::");
206+
s.push_str(&ident.to_string());
207+
}
208+
s
209+
}
210+
158211
/// A segment of a path: an identifier, an optional lifetime, and a set of types.
159212
///
160213
/// E.g., `std`, `String` or `Box<T>`.
@@ -3637,6 +3690,7 @@ impl Default for FnHeader {
36373690

36383691
#[derive(Clone, Encodable, Decodable, Debug)]
36393692
pub struct Trait {
3693+
pub constness: Const,
36403694
pub safety: Safety,
36413695
pub is_auto: IsAuto,
36423696
pub ident: Ident,

compiler/rustc_ast/src/util/literal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ impl LitKind {
126126
token::CStr => {
127127
let s = symbol.as_str();
128128
let mut buf = Vec::with_capacity(s.len());
129-
unescape_c_str(s, |_span, c| match c {
129+
unescape_c_str(s, |_span, res| match res {
130130
Ok(MixedUnit::Char(c)) => {
131-
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
131+
buf.extend_from_slice(c.get().encode_utf8(&mut [0; 4]).as_bytes())
132132
}
133-
Ok(MixedUnit::HighByte(b)) => buf.push(b),
133+
Ok(MixedUnit::HighByte(b)) => buf.push(b.get()),
134134
Err(err) => {
135135
assert!(!err.is_fatal(), "failed to unescape C string literal")
136136
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ macro_rules! common_visitor_and_walkers {
738738
try_visit!(vis.visit_ty(self_ty));
739739
visit_assoc_items(vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() })
740740
}
741-
ItemKind::Trait(box Trait { safety, is_auto: _, ident, generics, bounds, items }) => {
741+
ItemKind::Trait(box Trait { constness, safety, is_auto: _, ident, generics, bounds, items }) => {
742+
try_visit!(visit_constness(vis, constness));
742743
try_visit!(visit_safety(vis, safety));
743744
try_visit!(vis.visit_ident(ident));
744745
try_visit!(vis.visit_generics(generics));

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
417417
items: new_impl_items,
418418
}))
419419
}
420-
ItemKind::Trait(box Trait { is_auto, safety, ident, generics, bounds, items }) => {
420+
ItemKind::Trait(box Trait {
421+
constness,
422+
is_auto,
423+
safety,
424+
ident,
425+
generics,
426+
bounds,
427+
items,
428+
}) => {
429+
let constness = self.lower_constness(*constness);
421430
let ident = self.lower_ident(*ident);
422431
let (generics, (safety, items, bounds)) = self.lower_generics(
423432
generics,
@@ -435,7 +444,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
435444
(safety, items, bounds)
436445
},
437446
);
438-
hir::ItemKind::Trait(*is_auto, safety, ident, generics, bounds, items)
447+
hir::ItemKind::Trait(constness, *is_auto, safety, ident, generics, bounds, items)
439448
}
440449
ItemKind::TraitAlias(ident, generics, bounds) => {
441450
let ident = self.lower_ident(*ident);

compiler/rustc_ast_passes/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ ast_passes_static_without_body =
240240
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241241
.closure = closures cannot have `[const]` trait bounds
242242
.function = this function is not `const`, so it cannot have `[const]` trait bounds
243-
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
243+
.trait = this trait is not `const`, so it cannot have `[const]` trait bounds
244244
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
245245
.impl = inherent impls cannot have `[const]` trait bounds
246-
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
246+
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
247247
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
248248
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
249249
.object = trait objects cannot have `[const]` trait bounds

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ enum SelfSemantic {
4949
}
5050

5151
enum TraitOrTraitImpl {
52-
Trait { span: Span, constness_span: Option<Span> },
52+
Trait { span: Span, constness: Const },
5353
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref_span: Span },
5454
}
5555

5656
impl TraitOrTraitImpl {
5757
fn constness(&self) -> Option<Span> {
5858
match self {
59-
Self::Trait { constness_span: Some(span), .. }
59+
Self::Trait { constness: Const::Yes(span), .. }
6060
| Self::TraitImpl { constness: Const::Yes(span), .. } => Some(*span),
6161
_ => None,
6262
}
@@ -110,15 +110,10 @@ impl<'a> AstValidator<'a> {
110110
self.outer_trait_or_trait_impl = old;
111111
}
112112

113-
fn with_in_trait(
114-
&mut self,
115-
span: Span,
116-
constness_span: Option<Span>,
117-
f: impl FnOnce(&mut Self),
118-
) {
113+
fn with_in_trait(&mut self, span: Span, constness: Const, f: impl FnOnce(&mut Self)) {
119114
let old = mem::replace(
120115
&mut self.outer_trait_or_trait_impl,
121-
Some(TraitOrTraitImpl::Trait { span, constness_span }),
116+
Some(TraitOrTraitImpl::Trait { span, constness }),
122117
);
123118
f(self);
124119
self.outer_trait_or_trait_impl = old;
@@ -273,7 +268,7 @@ impl<'a> AstValidator<'a> {
273268
};
274269

275270
let make_trait_const_sugg = if const_trait_impl
276-
&& let TraitOrTraitImpl::Trait { span, constness_span: None } = parent
271+
&& let TraitOrTraitImpl::Trait { span, constness: ast::Const::No } = parent
277272
{
278273
Some(span.shrink_to_lo())
279274
} else {
@@ -1131,10 +1126,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11311126
}
11321127
visit::walk_item(self, item)
11331128
}
1134-
ItemKind::Trait(box Trait { is_auto, generics, ident, bounds, items, .. }) => {
1129+
ItemKind::Trait(box Trait {
1130+
constness,
1131+
is_auto,
1132+
generics,
1133+
ident,
1134+
bounds,
1135+
items,
1136+
..
1137+
}) => {
11351138
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1136-
let is_const_trait =
1139+
// FIXME(const_trait_impl) remove this
1140+
let alt_const_trait_span =
11371141
attr::find_by_name(&item.attrs, sym::const_trait).map(|attr| attr.span);
1142+
let constness = match (*constness, alt_const_trait_span) {
1143+
(Const::Yes(span), _) | (Const::No, Some(span)) => Const::Yes(span),
1144+
(Const::No, None) => Const::No,
1145+
};
11381146
if *is_auto == IsAuto::Yes {
11391147
// Auto traits cannot have generics, super traits nor contain items.
11401148
self.deny_generic_params(generics, ident.span);
@@ -1145,13 +1153,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11451153

11461154
// Equivalent of `visit::walk_item` for `ItemKind::Trait` that inserts a bound
11471155
// context for the supertraits.
1148-
let disallowed =
1149-
is_const_trait.is_none().then(|| TildeConstReason::Trait { span: item.span });
1156+
let disallowed = matches!(constness, ast::Const::No)
1157+
.then(|| TildeConstReason::Trait { span: item.span });
11501158
self.with_tilde_const(disallowed, |this| {
11511159
this.visit_generics(generics);
11521160
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
11531161
});
1154-
self.with_in_trait(item.span, is_const_trait, |this| {
1162+
self.with_in_trait(item.span, constness, |this| {
11551163
walk_list!(this, visit_assoc_item, items, AssocCtxt::Trait);
11561164
});
11571165
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ pub(crate) struct ConstBoundTraitObject {
590590
}
591591

592592
// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.
593-
// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` / `#[const_trait]` here).
593+
// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).
594594
#[derive(Diagnostic)]
595595
#[diag(ast_passes_tilde_const_disallowed)]
596596
pub(crate) struct TildeConstDisallowed {

0 commit comments

Comments
 (0)