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 5738fde

Browse files
committed
Auto merge of #144799 - GuillaumeGomez:rollup-uvbelp4, r=GuillaumeGomez
Rollup of 12 pull requests Successful merges: - #132748 (get rid of some false negatives in rustdoc::broken_intra_doc_links) - #135771 ([rustdoc] Add support for associated items in "jump to def" feature) - #143360 (loop match: error on `#[const_continue]` outside `#[loop_match]`) - #143662 ([rustdoc] Display unsafe attrs with edition 2024 `unsafe()` wrappers.) - #144478 (Improve formatting of doc code blocks) - #144703 ([test][AIX] ignore extern_weak linkage test) - #144747 (compiletest: Improve diagnostics for line annotation mismatches 2) - #144766 (Add human readable name "Cygwin") - #144782 (Properly pass path to staged `rustc` to `compiletest` self-tests) - #144786 (Cleanup the definition of `group_type`) - #144796 (Add my previous commit name to .mailmap) - #144797 (Update safety comment for new_unchecked in niche_types) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 63f6845 + 8df1c5d commit 5738fde

File tree

66 files changed

+819
-292
lines changed

Some content is hidden

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

66 files changed

+819
-292
lines changed

‎.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ Sam Radhakrishnan <sk09idm@gmail.com>
597597
Samuel Tardieu <sam@rfc1149.net>
598598
Santiago Pastorino <spastorino@gmail.com>
599599
Santiago Pastorino <spastorino@gmail.com> <santiago@wyeworks.com>
600+
Sasha Pourcelot <sasha.pourcelot@protonmail.com> Sasha <sasha.pourcelot@protonmail.com>
600601
Scott McMurray <scottmcm@users.noreply.github.com>
601602
Scott McMurray <scottmcm@users.noreply.github.com> <smcmurray@acm.org>
602603
Scott Olson <scott@solson.me> Scott Olson <scott@scott-olson.org>

‎compiler/rustc_attr_parsing/src/context.rs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
6262
use crate::parser::{ArgParser, MetaItemParser, PathParser};
6363
use crate::session_diagnostics::{AttributeParseError, AttributeParseErrorReason, UnknownMetaItem};
6464

65-
macro_rules! group_type {
66-
($stage: ty) => {
67-
LazyLock<(
68-
BTreeMap<&'static [Symbol], Vec<(AttributeTemplate, Box<dyn for<'sess, 'a> Fn(&mut AcceptContext<'_, 'sess, $stage>, &ArgParser<'a>) + Send + Sync>)>>,
69-
Vec<Box<dyn Send + Sync + Fn(&mut FinalizeContext<'_, '_, $stage>) -> Option<AttributeKind>>>
70-
)>
71-
};
65+
type GroupType<S> = LazyLock<GroupTypeInner<S>>;
66+
67+
struct GroupTypeInner<S: Stage> {
68+
accepters: BTreeMap<&'static [Symbol], Vec<GroupTypeInnerAccept<S>>>,
69+
finalizers: Vec<FinalizeFn<S>>,
70+
}
71+
72+
struct GroupTypeInnerAccept<S: Stage> {
73+
template: AttributeTemplate,
74+
accept_fn: AcceptFn<S>,
7275
}
7376

77+
type AcceptFn<S> =
78+
Box<dyn for<'sess, 'a> Fn(&mut AcceptContext<'_, 'sess, S>, &ArgParser<'a>) + Send + Sync>;
79+
type FinalizeFn<S> =
80+
Box<dyn Send + Sync + Fn(&mut FinalizeContext<'_, '_, S>) -> Option<AttributeKind>>;
81+
7482
macro_rules! attribute_parsers {
7583
(
7684
pub(crate) static $name: ident = [$($names: ty),* $(,)?];
@@ -93,23 +101,26 @@ macro_rules! attribute_parsers {
93101
}
94102
};
95103
(
96-
@[$ty: ty] pub(crate) static $name: ident = [$($names: ty),* $(,)?];
104+
@[$stage: ty] pub(crate) static $name: ident = [$($names: ty),* $(,)?];
97105
) => {
98-
pub(crate) static $name: group_type!($ty) = LazyLock::new(|| {
99-
let mut accepts = BTreeMap::<_, Vec<(AttributeTemplate,Box<dyn for<'sess,'a> Fn(&mutAcceptContext<'_,'sess, $ty>,&ArgParser<'a>) + Send + Sync>)>>::new();
100-
let mut finalizes = Vec::<Box<dyn Send + Sync + Fn(&mutFinalizeContext<'_,'_, $ty>) -> Option<AttributeKind>>>::new();
106+
pub(crate) static $name: GroupType<$stage> = LazyLock::new(|| {
107+
let mut accepts = BTreeMap::<_, Vec<GroupTypeInnerAccept<$stage>>>::new();
108+
let mut finalizes = Vec::<FinalizeFn<$stage>>::new();
101109
$(
102110
{
103111
thread_local! {
104112
static STATE_OBJECT: RefCell<$names> = RefCell::new(<$names>::default());
105113
};
106114

107115
for (path, template, accept_fn) in <$names>::ATTRIBUTES {
108-
accepts.entry(*path).or_default().push((*template, Box::new(|cx, args| {
109-
STATE_OBJECT.with_borrow_mut(|s| {
110-
accept_fn(s, cx, args)
116+
accepts.entry(*path).or_default().push(GroupTypeInnerAccept {
117+
template: *template,
118+
accept_fn: Box::new(|cx, args| {
119+
STATE_OBJECT.with_borrow_mut(|s| {
120+
accept_fn(s, cx, args)
121+
})
111122
})
112-
})));
123+
});
113124
}
114125

115126
finalizes.push(Box::new(|cx| {
@@ -119,7 +130,7 @@ macro_rules! attribute_parsers {
119130
}
120131
)*
121132

122-
(accepts, finalizes)
133+
GroupTypeInner{ accepters:accepts, finalizers:finalizes}
123134
});
124135
};
125136
}
@@ -215,7 +226,7 @@ pub trait Stage: Sized + 'static + Sealed {
215226
type Id: Copy;
216227
const SHOULD_EMIT_LINTS: bool;
217228

218-
fn parsers() -> &'static group_type!(Self);
229+
fn parsers() -> &'static GroupType<Self>;
219230

220231
fn emit_err<'sess>(
221232
&self,
@@ -230,7 +241,7 @@ impl Stage for Early {
230241
type Id = NodeId;
231242
const SHOULD_EMIT_LINTS: bool = false;
232243

233-
fn parsers() -> &'static group_type!(Self) {
244+
fn parsers() -> &'static GroupType<Self> {
234245
&early::ATTRIBUTE_PARSERS
235246
}
236247
fn emit_err<'sess>(
@@ -252,7 +263,7 @@ impl Stage for Late {
252263
type Id = HirId;
253264
const SHOULD_EMIT_LINTS: bool = true;
254265

255-
fn parsers() -> &'static group_type!(Self) {
266+
fn parsers() -> &'static GroupType<Self> {
256267
&late::ATTRIBUTE_PARSERS
257268
}
258269
fn emit_err<'sess>(
@@ -811,8 +822,8 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
811822
let args = parser.args();
812823
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
813824

814-
if let Some(accepts) = S::parsers().0.get(parts.as_slice()) {
815-
for (template,accept) in accepts {
825+
if let Some(accepts) = S::parsers().accepters.get(parts.as_slice()) {
826+
for accept in accepts {
816827
let mut cx: AcceptContext<'_, 'sess, S> = AcceptContext {
817828
shared: SharedContext {
818829
cx: self,
@@ -821,11 +832,11 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
821832
emit_lint: &mut emit_lint,
822833
},
823834
attr_span: lower_span(attr.span),
824-
template,
835+
template:&accept.template,
825836
attr_path: path.get_attribute_path(),
826837
};
827838

828-
accept(&mut cx, args)
839+
(accept.accept_fn)(&mut cx, args)
829840
}
830841
} else {
831842
// If we're here, we must be compiling a tool attribute... Or someone
@@ -856,7 +867,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
856867
}
857868

858869
let mut parsed_attributes = Vec::new();
859-
for f in &S::parsers().1 {
870+
for f in &S::parsers().finalizers {
860871
if let Some(attr) = f(&mut FinalizeContext {
861872
shared: SharedContext {
862873
cx: self,
@@ -877,7 +888,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
877888

878889
/// Returns whether there is a parser for an attribute with this name
879890
pub fn is_parsed_attribute(path: &[Symbol]) -> bool {
880-
Late::parsers().0.contains_key(path)
891+
Late::parsers().accepters.contains_key(path)
881892
}
882893

883894
fn lower_attr_args(&self, args: &ast::AttrArgs, lower_span: impl Fn(Span) -> Span) -> AttrArgs {

‎compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
417417
/// minimum values.
418418
///
419419
/// For example:
420-
/// ```
420+
/// ```ignore (illustrative)
421421
/// fn foo<'a, 'b>( /* ... */ ) where 'a: 'b { /* ... */ }
422422
/// ```
423423
/// would initialize two variables like so:

‎compiler/rustc_hir/src/def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl DefKind {
360360
/// For example, everything prefixed with `/* Res */` in this example has
361361
/// an associated `Res`:
362362
///
363-
/// ```
363+
/// ```ignore (illustrative)
364364
/// fn str_to_string(s: & /* Res */ str) -> /* Res */ String {
365365
/// /* Res */ String::from(/* Res */ s)
366366
/// }
@@ -421,7 +421,7 @@ pub enum Res<Id = hir::HirId> {
421421
/// }
422422
///
423423
/// impl Foo for Bar {
424-
/// fn foo() -> Box<Self> { // SelfTyAlias
424+
/// fn foo() -> Box<Self /* SelfTyAlias */> {
425425
/// let _: Self; // SelfTyAlias
426426
///
427427
/// todo!()

‎compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3016,7 +3016,7 @@ impl fmt::Display for LoopIdError {
30163016
}
30173017
}
30183018

3019-
#[derive(Copy, Clone, Debug, HashStable_Generic)]
3019+
#[derive(Copy, Clone, Debug, PartialEq,HashStable_Generic)]
30203020
pub struct Destination {
30213021
/// This is `Some(_)` iff there is an explicit user-specified 'label
30223022
pub label: Option<Label>,

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
425425
///
426426
/// trait Foo {
427427
/// fn bar() -> impl Deref<Target = impl Sized>;
428-
/// // ^- RPITIT #1 ^- RPITIT #2
428+
/// // ^- RPITIT #1 ^- RPITIT #2
429429
/// }
430430
///
431431
/// impl Foo for () {

‎compiler/rustc_hir_typeck/src/loops.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::BTreeMap;
22
use std::fmt;
33

44
use Context::*;
5-
use rustc_ast::Label;
65
use rustc_hir as hir;
76
use rustc_hir::attrs::AttributeKind;
87
use rustc_hir::def::DefKind;
@@ -42,8 +41,8 @@ enum Context {
4241
ConstBlock,
4342
/// E.g. `#[loop_match] loop { state = 'label: { /* ... */ } }`.
4443
LoopMatch {
45-
/// The label of the labeled block (not of the loop itself).
46-
labeled_block: Label,
44+
/// The destination pointing to the labeled block (not to the loop itself).
45+
labeled_block: Destination,
4746
},
4847
}
4948

@@ -186,18 +185,18 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
186185
{
187186
self.with_context(UnlabeledBlock(b.span.shrink_to_lo()), |v| v.visit_block(b));
188187
}
189-
hir::ExprKind::Break(break_label, ref opt_expr) => {
188+
hir::ExprKind::Break(break_destination, ref opt_expr) => {
190189
if let Some(e) = opt_expr {
191190
self.visit_expr(e);
192191
}
193192

194-
if self.require_label_in_labeled_block(e.span, &break_label, "break") {
193+
if self.require_label_in_labeled_block(e.span, &break_destination, "break") {
195194
// If we emitted an error about an unlabeled break in a labeled
196195
// block, we don't need any further checking for this break any more
197196
return;
198197
}
199198

200-
let loop_id = match break_label.target_id {
199+
let loop_id = match break_destination.target_id {
201200
Ok(loop_id) => Some(loop_id),
202201
Err(hir::LoopIdError::OutsideLoopScope) => None,
203202
Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
@@ -212,18 +211,25 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
212211

213212
// A `#[const_continue]` must break to a block in a `#[loop_match]`.
214213
if find_attr!(self.tcx.hir_attrs(e.hir_id), AttributeKind::ConstContinue(_)) {
215-
if let Some(break_label) = break_label.label {
216-
let is_target_label = |cx: &Context| match cx {
217-
Context::LoopMatch { labeled_block } => {
218-
break_label.ident.name == labeled_block.ident.name
219-
}
220-
_ => false,
221-
};
214+
let Some(label) = break_destination.label else {
215+
let span = e.span;
216+
self.tcx.dcx().emit_fatal(ConstContinueBadLabel { span });
217+
};
222218

223-
if !self.cx_stack.iter().rev().any(is_target_label) {
224-
let span = break_label.ident.span;
225-
self.tcx.dcx().emit_fatal(ConstContinueBadLabel { span });
219+
let is_target_label = |cx: &Context| match cx {
220+
Context::LoopMatch { labeled_block } => {
221+
// NOTE: with macro expansion, the label's span might be different here
222+
// even though it does still refer to the same HIR node. A block
223+
// can't have two labels, so the hir_id is a unique identifier.
224+
assert!(labeled_block.target_id.is_ok()); // see `is_loop_match`.
225+
break_destination.target_id == labeled_block.target_id
226226
}
227+
_ => false,
228+
};
229+
230+
if !self.cx_stack.iter().rev().any(is_target_label) {
231+
let span = label.ident.span;
232+
self.tcx.dcx().emit_fatal(ConstContinueBadLabel { span });
227233
}
228234
}
229235

@@ -249,7 +255,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
249255
Some(kind) => {
250256
let suggestion = format!(
251257
"break{}",
252-
break_label
258+
break_destination
253259
.label
254260
.map_or_else(String::new, |l| format!(" {}", l.ident))
255261
);
@@ -259,7 +265,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
259265
kind: kind.name(),
260266
suggestion,
261267
loop_label,
262-
break_label: break_label.label,
268+
break_label: break_destination.label,
263269
break_expr_kind: &break_expr.kind,
264270
break_expr_span: break_expr.span,
265271
});
@@ -268,7 +274,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
268274
}
269275

270276
let sp_lo = e.span.with_lo(e.span.lo() + BytePos("break".len() as u32));
271-
let label_sp = match break_label.label {
277+
let label_sp = match break_destination.label {
272278
Some(label) => sp_lo.with_hi(label.ident.span.hi()),
273279
None => sp_lo.shrink_to_lo(),
274280
};
@@ -416,7 +422,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
416422
&self,
417423
e: &'hir hir::Expr<'hir>,
418424
body: &'hir hir::Block<'hir>,
419-
) -> Option<Label> {
425+
) -> Option<Destination> {
420426
if !find_attr!(self.tcx.hir_attrs(e.hir_id), AttributeKind::LoopMatch(_)) {
421427
return None;
422428
}
@@ -438,8 +444,8 @@ impl<'hir> CheckLoopVisitor<'hir> {
438444

439445
let hir::ExprKind::Assign(_, rhs_expr, _) = loop_body_expr.kind else { return None };
440446

441-
let hir::ExprKind::Block(_, label) = rhs_expr.kind else { return None };
447+
let hir::ExprKind::Block(block, label) = rhs_expr.kind else { return None };
442448

443-
label
449+
Some(Destination{label,target_id:Ok(block.hir_id)})
444450
}
445451
}

‎compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,13 +2391,11 @@ fn migration_suggestion_for_2229(
23912391
/// let mut p = Point { x: 10, y: 10 };
23922392
///
23932393
/// let c = || {
2394-
/// p.x += 10;
2395-
/// // ^ E1 ^
2394+
/// p.x += 10; // E1
23962395
/// // ...
23972396
/// // More code
23982397
/// // ...
23992398
/// p.x += 10; // E2
2400-
/// // ^ E2 ^
24012399
/// };
24022400
/// ```
24032401
/// `CaptureKind` associated with both `E1` and `E2` will be ByRef(MutBorrow),

‎compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)) {}
3737
//! fn foo<T>(x: T) {
3838
//! bar(x, |y| { /* ... */})
39-
//! // ^ closure arg
39+
//! // ^ closure arg
4040
//! }
4141
//! ```
4242
//!

‎compiler/rustc_middle/src/hir/map.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,10 @@ impl<'tcx> TyCtxt<'tcx> {
533533
/// ```
534534
/// fn foo(x: usize) -> bool {
535535
/// if x == 1 {
536-
/// true // If `get_fn_id_for_return_block` gets passed the `id` corresponding
537-
/// } else { // to this, it will return `foo`'s `HirId`.
536+
/// // If `get_fn_id_for_return_block` gets passed the `id` corresponding to this, it
537+
/// // will return `foo`'s `HirId`.
538+
/// true
539+
/// } else {
538540
/// false
539541
/// }
540542
/// }
@@ -543,8 +545,10 @@ impl<'tcx> TyCtxt<'tcx> {
543545
/// ```compile_fail,E0308
544546
/// fn foo(x: usize) -> bool {
545547
/// loop {
546-
/// true // If `get_fn_id_for_return_block` gets passed the `id` corresponding
547-
/// } // to this, it will return `None`.
548+
/// // If `get_fn_id_for_return_block` gets passed the `id` corresponding to this, it
549+
/// // will return `None`.
550+
/// true
551+
/// }
548552
/// false
549553
/// }
550554
/// ```

0 commit comments

Comments
(0)

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