Skip to content

Commit 4a4a81a

Browse files
committed
Auto merge of rust-lang#3731 - rust-lang:rustup-2024-07-04, r=saethlin
Automatic Rustup
2 parents b0d791d + d24bfd4 commit 4a4a81a

File tree

302 files changed

+3729
-1843
lines changed

Some content is hidden

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

302 files changed

+3729
-1843
lines changed

Cargo.lock

+21-2
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,19 @@ dependencies = [
31413141
"bitflags 2.5.0",
31423142
"getopts",
31433143
"memchr",
3144-
"pulldown-cmark-escape",
3144+
"pulldown-cmark-escape 0.10.1",
3145+
"unicase",
3146+
]
3147+
3148+
[[package]]
3149+
name = "pulldown-cmark"
3150+
version = "0.11.0"
3151+
source = "registry+https://github.com/rust-lang/crates.io-index"
3152+
checksum = "8746739f11d39ce5ad5c2520a9b75285310dbfe78c541ccf832d38615765aec0"
3153+
dependencies = [
3154+
"bitflags 2.5.0",
3155+
"memchr",
3156+
"pulldown-cmark-escape 0.11.0",
31453157
"unicase",
31463158
]
31473159

@@ -3151,6 +3163,12 @@ version = "0.10.1"
31513163
source = "registry+https://github.com/rust-lang/crates.io-index"
31523164
checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3"
31533165

3166+
[[package]]
3167+
name = "pulldown-cmark-escape"
3168+
version = "0.11.0"
3169+
source = "registry+https://github.com/rust-lang/crates.io-index"
3170+
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
3171+
31543172
[[package]]
31553173
name = "pulldown-cmark-to-cmark"
31563174
version = "13.0.0"
@@ -4604,7 +4622,7 @@ name = "rustc_resolve"
46044622
version = "0.0.0"
46054623
dependencies = [
46064624
"bitflags 2.5.0",
4607-
"pulldown-cmark 0.9.6",
4625+
"pulldown-cmark 0.11.0",
46084626
"rustc_arena",
46094627
"rustc_ast",
46104628
"rustc_ast_pretty",
@@ -4883,6 +4901,7 @@ dependencies = [
48834901
"indexmap",
48844902
"itertools",
48854903
"minifier",
4904+
"pulldown-cmark 0.9.6",
48864905
"regex",
48874906
"rustdoc-json-types",
48884907
"serde",

compiler/rustc_ast/src/ast.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub enum GenericArgs {
176176
AngleBracketed(AngleBracketedArgs),
177177
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
178178
Parenthesized(ParenthesizedArgs),
179+
/// `(..)` in return type notation
180+
ParenthesizedElided(Span),
179181
}
180182

181183
impl GenericArgs {
@@ -187,6 +189,7 @@ impl GenericArgs {
187189
match self {
188190
AngleBracketed(data) => data.span,
189191
Parenthesized(data) => data.span,
192+
ParenthesizedElided(span) => *span,
190193
}
191194
}
192195
}
@@ -2051,7 +2054,7 @@ impl UintTy {
20512054
/// * the `A: Bound` in `Trait<A: Bound>`
20522055
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
20532056
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2054-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2057+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
20552058
#[derive(Clone, Encodable, Decodable, Debug)]
20562059
pub struct AssocItemConstraint {
20572060
pub id: NodeId,

compiler/rustc_ast/src/attr/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ impl Attribute {
204204

205205
pub fn tokens(&self) -> TokenStream {
206206
match &self.kind {
207-
AttrKind::Normal(normal) => normal
208-
.tokens
209-
.as_ref()
210-
.unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}"))
211-
.to_attr_token_stream()
212-
.to_tokenstream(),
207+
AttrKind::Normal(normal) => TokenStream::new(
208+
normal
209+
.tokens
210+
.as_ref()
211+
.unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}"))
212+
.to_attr_token_stream()
213+
.to_token_trees(),
214+
),
213215
&AttrKind::DocComment(comment_kind, data) => TokenStream::token_alone(
214216
token::DocComment(comment_kind, self.style, data),
215217
self.span,

compiler/rustc_ast/src/mut_visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ fn noop_visit_generic_args<T: MutVisitor>(generic_args: &mut GenericArgs, vis: &
582582
match generic_args {
583583
GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data),
584584
GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data),
585+
GenericArgs::ParenthesizedElided(span) => vis.visit_span(span),
585586
}
586587
}
587588

compiler/rustc_ast/src/tokenstream.rs

+18-31
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_data_structures::sync::{self, Lrc};
2323
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2424
use rustc_serialize::{Decodable, Encodable};
2525
use rustc_span::{sym, Span, SpanDecoder, SpanEncoder, Symbol, DUMMY_SP};
26-
use smallvec::{smallvec, SmallVec};
2726

2827
use std::borrow::Cow;
2928
use std::{cmp, fmt, iter};
@@ -180,42 +179,33 @@ impl AttrTokenStream {
180179
AttrTokenStream(Lrc::new(tokens))
181180
}
182181

183-
/// Converts this `AttrTokenStream` to a plain `TokenStream`.
182+
/// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`.
184183
/// During conversion, `AttrTokenTree::Attributes` get 'flattened'
185184
/// back to a `TokenStream` of the form `outer_attr attr_target`.
186185
/// If there are inner attributes, they are inserted into the proper
187186
/// place in the attribute target tokens.
188-
pub fn to_tokenstream(&self) -> TokenStream {
189-
let trees: Vec<_> = self
190-
.0
191-
.iter()
192-
.flat_map(|tree| match &tree {
187+
pub fn to_token_trees(&self) -> Vec<TokenTree> {
188+
let mut res = Vec::with_capacity(self.0.len());
189+
for tree in self.0.iter() {
190+
match tree {
193191
AttrTokenTree::Token(inner, spacing) => {
194-
smallvec![TokenTree::Token(inner.clone(), *spacing)].into_iter()
192+
res.push(TokenTree::Token(inner.clone(), *spacing));
195193
}
196194
AttrTokenTree::Delimited(span, spacing, delim, stream) => {
197-
smallvec![TokenTree::Delimited(
195+
res.push(TokenTree::Delimited(
198196
*span,
199197
*spacing,
200198
*delim,
201-
stream.to_tokenstream()
202-
),]
203-
.into_iter()
199+
TokenStream::new(stream.to_token_trees()),
200+
))
204201
}
205202
AttrTokenTree::Attributes(data) => {
206203
let idx = data
207204
.attrs
208205
.partition_point(|attr| matches!(attr.style, crate::AttrStyle::Outer));
209206
let (outer_attrs, inner_attrs) = data.attrs.split_at(idx);
210207

211-
let mut target_tokens: Vec<_> = data
212-
.tokens
213-
.to_attr_token_stream()
214-
.to_tokenstream()
215-
.0
216-
.iter()
217-
.cloned()
218-
.collect();
208+
let mut target_tokens = data.tokens.to_attr_token_stream().to_token_trees();
219209
if !inner_attrs.is_empty() {
220210
let mut found = false;
221211
// Check the last two trees (to account for a trailing semi)
@@ -251,17 +241,14 @@ impl AttrTokenStream {
251241
"Failed to find trailing delimited group in: {target_tokens:?}"
252242
);
253243
}
254-
let mut flat: SmallVec<[_; 1]> =
255-
SmallVec::with_capacity(target_tokens.len() + outer_attrs.len());
256244
for attr in outer_attrs {
257-
flat.extend(attr.tokens().0.iter().cloned());
245+
res.extend(attr.tokens().0.iter().cloned());
258246
}
259-
flat.extend(target_tokens);
260-
flat.into_iter()
247+
res.extend(target_tokens);
261248
}
262-
})
263-
.collect();
264-
TokenStream::new(trees)
249+
}
250+
}
251+
res
265252
}
266253
}
267254

@@ -409,8 +396,8 @@ impl PartialEq<TokenStream> for TokenStream {
409396
}
410397

411398
impl TokenStream {
412-
pub fn new(streams: Vec<TokenTree>) -> TokenStream {
413-
TokenStream(Lrc::new(streams))
399+
pub fn new(tts: Vec<TokenTree>) -> TokenStream {
400+
TokenStream(Lrc::new(tts))
414401
}
415402

416403
pub fn is_empty(&self) -> bool {
@@ -461,7 +448,7 @@ impl TokenStream {
461448
AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
462449
AttrTokenStream::new(vec![AttrTokenTree::Attributes(attr_data)])
463450
};
464-
attr_stream.to_tokenstream()
451+
TokenStream::new(attr_stream.to_token_trees())
465452
}
466453

467454
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {

compiler/rustc_ast/src/util/classify.rs

+79-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Routines the parser and pretty-printer use to classify AST nodes.
22
33
use crate::ast::ExprKind::*;
4-
use crate::{ast, token::Delimiter};
4+
use crate::ast::{self, MatchKind};
5+
use crate::token::Delimiter;
56

67
/// This classification determines whether various syntactic positions break out
78
/// of parsing the current expression (true) or continue parsing more of the
@@ -81,6 +82,82 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
8182
}
8283
}
8384

85+
/// Returns whether the leftmost token of the given expression is the label of a
86+
/// labeled loop or block, such as in `'inner: loop { break 'inner 1 } + 1`.
87+
///
88+
/// Such expressions are not allowed as the value of an unlabeled break.
89+
///
90+
/// ```ignore (illustrative)
91+
/// 'outer: {
92+
/// break 'inner: loop { break 'inner 1 } + 1; // invalid syntax
93+
///
94+
/// break 'outer 'inner: loop { break 'inner 1 } + 1; // okay
95+
///
96+
/// break ('inner: loop { break 'inner 1 } + 1); // okay
97+
///
98+
/// break ('inner: loop { break 'inner 1 }) + 1; // okay
99+
/// }
100+
/// ```
101+
pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
102+
loop {
103+
match &expr.kind {
104+
Block(_, label) | ForLoop { label, .. } | Loop(_, label, _) | While(_, _, label) => {
105+
return label.is_some();
106+
}
107+
108+
Assign(e, _, _)
109+
| AssignOp(_, e, _)
110+
| Await(e, _)
111+
| Binary(_, e, _)
112+
| Call(e, _)
113+
| Cast(e, _)
114+
| Field(e, _)
115+
| Index(e, _, _)
116+
| Match(e, _, MatchKind::Postfix)
117+
| Range(Some(e), _, _)
118+
| Try(e) => {
119+
expr = e;
120+
}
121+
MethodCall(method_call) => {
122+
expr = &method_call.receiver;
123+
}
124+
125+
AddrOf(..)
126+
| Array(..)
127+
| Become(..)
128+
| Break(..)
129+
| Closure(..)
130+
| ConstBlock(..)
131+
| Continue(..)
132+
| FormatArgs(..)
133+
| Gen(..)
134+
| If(..)
135+
| IncludedBytes(..)
136+
| InlineAsm(..)
137+
| Let(..)
138+
| Lit(..)
139+
| MacCall(..)
140+
| Match(_, _, MatchKind::Prefix)
141+
| OffsetOf(..)
142+
| Paren(..)
143+
| Path(..)
144+
| Range(None, _, _)
145+
| Repeat(..)
146+
| Ret(..)
147+
| Struct(..)
148+
| TryBlock(..)
149+
| Tup(..)
150+
| Type(..)
151+
| Unary(..)
152+
| Underscore
153+
| Yeet(..)
154+
| Yield(..)
155+
| Err(..)
156+
| Dummy => return false,
157+
}
158+
}
159+
}
160+
84161
pub enum TrailingBrace<'a> {
85162
/// Trailing brace in a macro call, like the one in `x as *const brace! {}`.
86163
/// We will suggest changing the macro call to a different delimiter.
@@ -234,6 +311,6 @@ fn path_return_type(path: &ast::Path) -> Option<&ast::Ty> {
234311
ast::FnRetTy::Default(_) => None,
235312
ast::FnRetTy::Ty(ret) => Some(ret),
236313
},
237-
ast::GenericArgs::AngleBracketed(_) => None,
314+
ast::GenericArgs::AngleBracketed(_) | ast::GenericArgs::ParenthesizedElided(_) => None,
238315
}
239316
}

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ where
609609
walk_list!(visitor, visit_ty, inputs);
610610
try_visit!(visitor.visit_fn_ret_ty(output));
611611
}
612+
GenericArgs::ParenthesizedElided(_span) => {}
612613
}
613614
V::Result::output()
614615
}

compiler/rustc_ast_lowering/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ ast_lowering_bad_return_type_notation_inputs =
3636
argument types not allowed with return type notation
3737
.suggestion = remove the input types
3838
39+
ast_lowering_bad_return_type_notation_needs_dots = return type notation arguments must be elided with `..`
40+
.suggestion = add `..`
41+
3942
ast_lowering_bad_return_type_notation_output =
4043
return type not allowed with return type notation
4144
.suggestion = remove the return type
4245
46+
ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet
47+
4348
ast_lowering_base_expression_double_dot =
4449
base expression required after `..`
4550
.suggestion = add a base expression here

compiler/rustc_ast_lowering/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ pub enum BadReturnTypeNotation {
393393
#[suggestion(code = "", applicability = "maybe-incorrect")]
394394
span: Span,
395395
},
396+
#[diag(ast_lowering_bad_return_type_notation_needs_dots)]
397+
NeedsDots {
398+
#[primary_span]
399+
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
400+
span: Span,
401+
},
402+
#[diag(ast_lowering_bad_return_type_notation_position)]
403+
Position {
404+
#[primary_span]
405+
span: Span,
406+
},
396407
}
397408

398409
#[derive(Diagnostic)]

compiler/rustc_ast_lowering/src/lib.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -985,20 +985,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
985985
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
986986
}
987987
GenericArgs::Parenthesized(data) => {
988-
if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) {
989-
let parenthesized = if self.tcx.features().return_type_notation {
990-
hir::GenericArgsParentheses::ReturnTypeNotation
991-
} else {
992-
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
993-
hir::GenericArgsParentheses::No
994-
};
995-
GenericArgsCtor {
996-
args: Default::default(),
997-
constraints: &[],
998-
parenthesized,
999-
span: data.inputs_span,
1000-
}
1001-
} else if let Some(first_char) = constraint.ident.as_str().chars().next()
988+
if let Some(first_char) = constraint.ident.as_str().chars().next()
1002989
&& first_char.is_ascii_lowercase()
1003990
{
1004991
let mut err = if !data.inputs.is_empty() {
@@ -1010,7 +997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1010997
span: data.inputs_span.shrink_to_hi().to(ty.span),
1011998
})
1012999
} else {
1013-
unreachable!("inputs are empty and return type is not provided")
1000+
self.dcx().create_err(errors::BadReturnTypeNotation::NeedsDots {
1001+
span: data.inputs_span,
1002+
})
10141003
};
10151004
if !self.tcx.features().return_type_notation
10161005
&& self.tcx.sess.is_nightly_build()
@@ -1040,6 +1029,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10401029
.0
10411030
}
10421031
}
1032+
GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1033+
args: Default::default(),
1034+
constraints: &[],
1035+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1036+
span: *span,
1037+
},
10431038
};
10441039
gen_args_ctor.into_generic_args(self)
10451040
} else {

0 commit comments

Comments
 (0)