Skip to content

Commit 05227a7

Browse files
authored
Merge pull request #4762 from rust-lang/rustup-2025-12-13
Automatic Rustup
2 parents bc81d84 + 96f2d59 commit 05227a7

File tree

417 files changed

+6578
-5257
lines changed

Some content is hidden

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

417 files changed

+6578
-5257
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ Lzu Tao <taolzu@gmail.com>
431431
Maik Klein <maikklein@googlemail.com>
432432
Maja Kądziołka <maya@compilercrim.es> <github@compilercrim.es>
433433
Maja Kądziołka <maya@compilercrim.es> <kuba@kadziolka.net>
434+
Makai <m4kai410@gmail.com>
434435
Malo Jaffré <jaffre.malo@gmail.com>
435436
Manish Goregaokar <manishsmail@gmail.com>
436437
Mara Bos <m-ou.se@m-ou.se>

Cargo.lock

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,7 +4011,6 @@ dependencies = [
40114011
"itertools",
40124012
"rustc_abi",
40134013
"rustc_ast",
4014-
"rustc_attr_parsing",
40154014
"rustc_data_structures",
40164015
"rustc_errors",
40174016
"rustc_fluent_macro",
@@ -4433,7 +4432,6 @@ dependencies = [
44334432
"rustc_abi",
44344433
"rustc_ast",
44354434
"rustc_ast_lowering",
4436-
"rustc_ast_pretty",
44374435
"rustc_attr_parsing",
44384436
"rustc_data_structures",
44394437
"rustc_errors",
@@ -4870,6 +4868,7 @@ dependencies = [
48704868
"indexmap",
48714869
"itertools",
48724870
"minifier",
4871+
"proc-macro2",
48734872
"pulldown-cmark-escape",
48744873
"regex",
48754874
"rustdoc-json-types",

compiler/rustc_ast/src/ast.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,11 @@ impl Path {
141141
/// Check if this path is potentially a trivial const arg, i.e., one that can _potentially_
142142
/// be represented without an anon const in the HIR.
143143
///
144-
/// If `allow_mgca_arg` is true (as should be the case in most situations when
145-
/// `#![feature(min_generic_const_args)]` is enabled), then this always returns true
146-
/// because all paths are valid.
147-
///
148-
/// Otherwise, it returns true iff the path has exactly one segment, and it has no generic args
144+
/// Returns true iff the path has exactly one segment, and it has no generic args
149145
/// (i.e., it is _potentially_ a const parameter).
150146
#[tracing::instrument(level = "debug", ret)]
151-
pub fn is_potential_trivial_const_arg(&self, allow_mgca_arg: bool) -> bool {
152-
allow_mgca_arg
153-
|| self.segments.len() == 1 && self.segments.iter().all(|seg| seg.args.is_none())
147+
pub fn is_potential_trivial_const_arg(&self) -> bool {
148+
self.segments.len() == 1 && self.segments.iter().all(|seg| seg.args.is_none())
154149
}
155150
}
156151

@@ -1385,6 +1380,15 @@ pub enum UnsafeSource {
13851380
UserProvided,
13861381
}
13871382

1383+
/// Track whether under `feature(min_generic_const_args)` this anon const
1384+
/// was explicitly disambiguated as an anon const or not through the use of
1385+
/// `const { ... }` syntax.
1386+
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, Walkable)]
1387+
pub enum MgcaDisambiguation {
1388+
AnonConst,
1389+
Direct,
1390+
}
1391+
13881392
/// A constant (expression) that's not an item or associated item,
13891393
/// but needs its own `DefId` for type-checking, const-eval, etc.
13901394
/// These are usually found nested inside types (e.g., array lengths)
@@ -1394,6 +1398,7 @@ pub enum UnsafeSource {
13941398
pub struct AnonConst {
13951399
pub id: NodeId,
13961400
pub value: Box<Expr>,
1401+
pub mgca_disambiguation: MgcaDisambiguation,
13971402
}
13981403

13991404
/// An expression.
@@ -1412,26 +1417,20 @@ impl Expr {
14121417
///
14131418
/// This will unwrap at most one block level (curly braces). After that, if the expression
14141419
/// is a path, it mostly dispatches to [`Path::is_potential_trivial_const_arg`].
1415-
/// See there for more info about `allow_mgca_arg`.
14161420
///
1417-
/// The only additional thing to note is that when `allow_mgca_arg` is false, this function
1418-
/// will only allow paths with no qself, before dispatching to the `Path` function of
1419-
/// the same name.
1421+
/// This function will only allow paths with no qself, before dispatching to the `Path`
1422+
/// function of the same name.
14201423
///
14211424
/// Does not ensure that the path resolves to a const param/item, the caller should check this.
14221425
/// This also does not consider macros, so it's only correct after macro-expansion.
1423-
pub fn is_potential_trivial_const_arg(&self, allow_mgca_arg: bool) -> bool {
1426+
pub fn is_potential_trivial_const_arg(&self) -> bool {
14241427
let this = self.maybe_unwrap_block();
1425-
if allow_mgca_arg {
1426-
matches!(this.kind, ExprKind::Path(..))
1428+
if let ExprKind::Path(None, path) = &this.kind
1429+
&& path.is_potential_trivial_const_arg()
1430+
{
1431+
true
14271432
} else {
1428-
if let ExprKind::Path(None, path) = &this.kind
1429-
&& path.is_potential_trivial_const_arg(allow_mgca_arg)
1430-
{
1431-
true
1432-
} else {
1433-
false
1434-
}
1433+
false
14351434
}
14361435
}
14371436

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use crate::ast::{
1313
Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NormalAttr, Path,
1414
PathSegment, Safety,
1515
};
16-
use crate::token::{self, CommentKind, Delimiter, InvisibleOrigin, MetaVarKind, Token};
16+
use crate::token::{
17+
self, CommentKind, Delimiter, DocFragmentKind, InvisibleOrigin, MetaVarKind, Token,
18+
};
1719
use crate::tokenstream::{
1820
DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenStreamIter, TokenTree,
1921
};
@@ -179,15 +181,21 @@ impl AttributeExt for Attribute {
179181
}
180182

181183
/// Returns the documentation and its kind if this is a doc comment or a sugared doc comment.
182-
/// * `///doc` returns `Some(("doc", CommentKind::Line))`.
183-
/// * `/** doc */` returns `Some(("doc", CommentKind::Block))`.
184-
/// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`.
184+
/// * `///doc` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Line)))`.
185+
/// * `/** doc */` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Block)))`.
186+
/// * `#[doc = "doc"]` returns `Some(("doc", DocFragmentKind::Raw))`.
185187
/// * `#[doc(...)]` returns `None`.
186-
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
188+
fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind)> {
187189
match &self.kind {
188-
AttrKind::DocComment(kind, data) => Some((*data, *kind)),
190+
AttrKind::DocComment(kind, data) => Some((*data, DocFragmentKind::Sugared(*kind))),
189191
AttrKind::Normal(normal) if normal.item.path == sym::doc => {
190-
normal.item.value_str().map(|s| (s, CommentKind::Line))
192+
if let Some(value) = normal.item.value_str()
193+
&& let Some(value_span) = normal.item.value_span()
194+
{
195+
Some((value, DocFragmentKind::Raw(value_span)))
196+
} else {
197+
None
198+
}
191199
}
192200
_ => None,
193201
}
@@ -220,6 +228,24 @@ impl AttributeExt for Attribute {
220228
fn is_automatically_derived_attr(&self) -> bool {
221229
self.has_name(sym::automatically_derived)
222230
}
231+
232+
fn is_doc_hidden(&self) -> bool {
233+
self.has_name(sym::doc)
234+
&& self.meta_item_list().is_some_and(|l| list_contains_name(&l, sym::hidden))
235+
}
236+
237+
fn is_doc_keyword_or_attribute(&self) -> bool {
238+
if self.has_name(sym::doc)
239+
&& let Some(items) = self.meta_item_list()
240+
{
241+
for item in items {
242+
if item.has_name(sym::keyword) || item.has_name(sym::attribute) {
243+
return true;
244+
}
245+
}
246+
}
247+
false
248+
}
223249
}
224250

225251
impl Attribute {
@@ -300,6 +326,25 @@ impl AttrItem {
300326
}
301327
}
302328

329+
/// Returns the span in:
330+
///
331+
/// ```text
332+
/// #[attribute = "value"]
333+
/// ^^^^^^^
334+
/// ```
335+
///
336+
/// It returns `None` in any other cases like:
337+
///
338+
/// ```text
339+
/// #[attr("value")]
340+
/// ```
341+
fn value_span(&self) -> Option<Span> {
342+
match &self.args {
343+
AttrArgs::Eq { expr, .. } => Some(expr.span),
344+
AttrArgs::Delimited(_) | AttrArgs::Empty => None,
345+
}
346+
}
347+
303348
pub fn meta(&self, span: Span) -> Option<MetaItem> {
304349
Some(MetaItem {
305350
unsafety: Safety::Default,
@@ -820,7 +865,7 @@ pub trait AttributeExt: Debug {
820865
/// * `/** doc */` returns `Some(("doc", CommentKind::Block))`.
821866
/// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`.
822867
/// * `#[doc(...)]` returns `None`.
823-
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
868+
fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind)>;
824869

825870
/// Returns outer or inner if this is a doc attribute or a sugared doc
826871
/// comment, otherwise None.
@@ -830,6 +875,12 @@ pub trait AttributeExt: Debug {
830875
/// commented module (for inner doc) vs within its parent module (for outer
831876
/// doc).
832877
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
878+
879+
/// Returns `true` if this attribute contains `doc(hidden)`.
880+
fn is_doc_hidden(&self) -> bool;
881+
882+
/// Returns `true` is this attribute contains `doc(keyword)` or `doc(attribute)`.
883+
fn is_doc_keyword_or_attribute(&self) -> bool;
833884
}
834885

835886
// FIXME(fn_delegation): use function delegation instead of manually forwarding
@@ -902,7 +953,7 @@ impl Attribute {
902953
AttributeExt::is_proc_macro_attr(self)
903954
}
904955

905-
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
906-
AttributeExt::doc_str_and_comment_kind(self)
956+
pub fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind)> {
957+
AttributeExt::doc_str_and_fragment_kind(self)
907958
}
908959
}

compiler/rustc_ast/src/token.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,31 @@ use rustc_span::{Ident, Symbol};
1616
use crate::ast;
1717
use crate::util::case::Case;
1818

19-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
19+
/// Represents the kind of doc comment it is, ie `///` or `#[doc = ""]`.
20+
#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
21+
pub enum DocFragmentKind {
22+
/// A sugared doc comment: `///` or `//!` or `/**` or `/*!`.
23+
Sugared(CommentKind),
24+
/// A "raw" doc comment: `#[doc = ""]`. The `Span` represents the string literal.
25+
Raw(Span),
26+
}
27+
28+
impl DocFragmentKind {
29+
pub fn is_sugared(self) -> bool {
30+
matches!(self, Self::Sugared(_))
31+
}
32+
33+
/// If it is `Sugared`, it will return its associated `CommentKind`, otherwise it will return
34+
/// `CommentKind::Line`.
35+
pub fn comment_kind(self) -> CommentKind {
36+
match self {
37+
Self::Sugared(kind) => kind,
38+
Self::Raw(_) => CommentKind::Line,
39+
}
40+
}
41+
}
42+
43+
#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
2044
pub enum CommentKind {
2145
Line,
2246
Block,

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ macro_rules! common_visitor_and_walkers {
415415
UnsafeBinderCastKind,
416416
BinOpKind,
417417
BlockCheckMode,
418+
MgcaDisambiguation,
418419
BorrowKind,
419420
BoundAsyncness,
420421
BoundConstness,

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
489489
arg
490490
};
491491

492-
let anon_const = AnonConst { id: node_id, value: const_value };
492+
let anon_const = AnonConst {
493+
id: node_id,
494+
value: const_value,
495+
mgca_disambiguation: MgcaDisambiguation::AnonConst,
496+
};
493497
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));
494498
} else {
495499
real_args.push(arg);

0 commit comments

Comments
 (0)