Skip to content

Commit 50b5954

Browse files
committed
Auto merge of #154378 - JonathanBrouwer:rollup-P5GqyDJ, r=<try>
Rollup of 21 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents 64d5cb6 + bf778fc commit 50b5954

197 files changed

Lines changed: 1746 additions & 1534 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ pub enum PatKind {
938938
Never,
939939

940940
/// A guard pattern (e.g., `x if guard(x)`).
941-
Guard(Box<Pat>, Box<Expr>),
941+
Guard(Box<Pat>, Box<Guard>),
942942

943943
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
944944
Paren(Box<Pat>),
@@ -1346,7 +1346,7 @@ pub struct Arm {
13461346
/// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`.
13471347
pub pat: Box<Pat>,
13481348
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`.
1349-
pub guard: Option<Box<Expr>>,
1349+
pub guard: Option<Box<Guard>>,
13501350
/// Match arm body. Omitted if the pattern is a never pattern.
13511351
pub body: Option<Box<Expr>>,
13521352
pub span: Span,
@@ -3954,6 +3954,18 @@ impl ConstBlockItem {
39543954
pub const IDENT: Ident = Ident { name: kw::Underscore, span: DUMMY_SP };
39553955
}
39563956

3957+
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
3958+
pub struct Guard {
3959+
pub cond: Expr,
3960+
pub span_with_leading_if: Span,
3961+
}
3962+
3963+
impl Guard {
3964+
pub fn span(&self) -> Span {
3965+
self.cond.span
3966+
}
3967+
}
3968+
39573969
// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
39583970
#[derive(Clone, Encodable, Decodable, Debug)]
39593971
pub enum ItemKind {

compiler/rustc_ast/src/token.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub enum MetaVarKind {
9494
},
9595
Path,
9696
Vis,
97+
Guard,
9798
TT,
9899
}
99100

@@ -114,6 +115,7 @@ impl fmt::Display for MetaVarKind {
114115
MetaVarKind::Meta { .. } => sym::meta,
115116
MetaVarKind::Path => sym::path,
116117
MetaVarKind::Vis => sym::vis,
118+
MetaVarKind::Guard => sym::guard,
117119
MetaVarKind::TT => sym::tt,
118120
};
119121
write!(f, "{sym}")
@@ -1124,6 +1126,7 @@ pub enum NonterminalKind {
11241126
Meta,
11251127
Path,
11261128
Vis,
1129+
Guard,
11271130
TT,
11281131
}
11291132

@@ -1161,6 +1164,7 @@ impl NonterminalKind {
11611164
sym::meta => NonterminalKind::Meta,
11621165
sym::path => NonterminalKind::Path,
11631166
sym::vis => NonterminalKind::Vis,
1167+
sym::guard => NonterminalKind::Guard,
11641168
sym::tt => NonterminalKind::TT,
11651169
_ => return None,
11661170
})
@@ -1182,6 +1186,7 @@ impl NonterminalKind {
11821186
NonterminalKind::Meta => sym::meta,
11831187
NonterminalKind::Path => sym::path,
11841188
NonterminalKind::Vis => sym::vis,
1189+
NonterminalKind::Guard => sym::guard,
11851190
NonterminalKind::TT => sym::tt,
11861191
}
11871192
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ macro_rules! common_visitor_and_walkers {
442442
FormatArguments,
443443
FormatPlaceholder,
444444
GenericParamKind,
445+
Guard,
445446
Impl,
446447
ImplPolarity,
447448
Inline,

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,17 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
432432
args.push(arg);
433433
}
434434

435+
// If we have no params in signature function but user still wrote some code in
436+
// delegation body, then add this code as first arg, eventually an error will be shown,
437+
// also nested delegations may need to access information about this code (#154332),
438+
// so it is better to leave this code as opposed to bodies of extern functions,
439+
// which are completely erased from existence.
440+
if param_count == 0
441+
&& let Some(block) = block
442+
{
443+
args.push(this.lower_target_expr(&block));
444+
}
445+
435446
let final_expr = this.finalize_body_lowering(delegation, args, generics, span);
436447

437448
(this.arena.alloc_from_iter(parameters), final_expr)

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
337337
// HACK: for now we generate predicates such that all lifetimes are early bound,
338338
// we can not not generate early-bound lifetimes, but we can't know which of them
339339
// are late-bound at this level of compilation.
340-
// FIXME(fn_delegation): proper support for late bound lifetimes.
341340
let predicates =
342341
self.arena.alloc_from_iter(params.iter().filter_map(|p| {
343342
p.is_lifetime().then(|| self.generate_lifetime_predicate(p, span))
@@ -391,7 +390,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
391390
self.arena.alloc(hir::GenericArgs {
392391
args: self.arena.alloc_from_iter(params.iter().filter_map(|p| {
393392
// Skip self generic arg, we do not need to propagate it.
394-
if p.name.ident().name == kw::SelfUpper {
393+
if p.name.ident().name == kw::SelfUpper || p.is_impl_trait() {
395394
return None;
396395
}
397396

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
640640

641641
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
642642
let pat = self.lower_pat(&arm.pat);
643-
let guard = arm.guard.as_ref().map(|cond| self.lower_expr(cond));
643+
let guard = arm.guard.as_ref().map(|guard| self.lower_expr(&guard.cond));
644644
let hir_id = self.next_id();
645645
let span = self.lower_span(arm.span);
646646
self.lower_attrs(hir_id, &arm.attrs, arm.span, Target::Arm);
@@ -663,7 +663,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
663663
} else if let Some(body) = &arm.body {
664664
self.dcx().emit_err(NeverPatternWithBody { span: body.span });
665665
} else if let Some(g) = &arm.guard {
666-
self.dcx().emit_err(NeverPatternWithGuard { span: g.span });
666+
self.dcx().emit_err(NeverPatternWithGuard { span: g.span() });
667667
}
668668

669669
// We add a fake `loop {}` arm body so that it typecks to `!`. The mir lowering of never

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
133133
self.lower_range_end(end, e2.is_some()),
134134
);
135135
}
136-
PatKind::Guard(inner, cond) => {
137-
break hir::PatKind::Guard(self.lower_pat(inner), self.lower_expr(cond));
136+
PatKind::Guard(inner, guard) => {
137+
break hir::PatKind::Guard(
138+
self.lower_pat(inner),
139+
self.lower_expr(&guard.cond),
140+
);
138141
}
139142
PatKind::Slice(pats) => break self.lower_pat_slice(pats),
140143
PatKind::Rest => {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,12 +1943,12 @@ impl<'a> State<'a> {
19431943
self.print_expr(e, FixupContext::default());
19441944
}
19451945
}
1946-
PatKind::Guard(subpat, condition) => {
1946+
PatKind::Guard(subpat, guard) => {
19471947
self.popen();
19481948
self.print_pat(subpat);
19491949
self.space();
19501950
self.word_space("if");
1951-
self.print_expr(condition, FixupContext::default());
1951+
self.print_expr(&guard.cond, FixupContext::default());
19521952
self.pclose();
19531953
}
19541954
PatKind::Slice(elts) => {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ impl<'a> State<'a> {
891891
self.print_outer_attributes(&arm.attrs);
892892
self.print_pat(&arm.pat);
893893
self.space();
894-
if let Some(e) = &arm.guard {
894+
if let Some(guard) = &arm.guard {
895895
self.word_space("if");
896-
self.print_expr(e, FixupContext::default());
896+
self.print_expr(&guard.cond, FixupContext::default());
897897
self.space();
898898
}
899899

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
582582
r#"kernel_address = "on|off""#,
583583
r#"cfi = "on|off""#,
584584
r#"hwaddress = "on|off""#,
585+
r#"kernel_hwaddress = "on|off""#,
585586
r#"kcfi = "on|off""#,
586587
r#"memory = "on|off""#,
587588
r#"memtag = "on|off""#,
@@ -648,7 +649,9 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
648649
Some(sym::memtag) => apply(SanitizerSet::MEMTAG),
649650
Some(sym::shadow_call_stack) => apply(SanitizerSet::SHADOWCALLSTACK),
650651
Some(sym::thread) => apply(SanitizerSet::THREAD),
651-
Some(sym::hwaddress) => apply(SanitizerSet::HWADDRESS),
652+
Some(sym::hwaddress) | Some(sym::kernel_hwaddress) => {
653+
apply(SanitizerSet::HWADDRESS | SanitizerSet::KERNELHWADDRESS)
654+
}
652655
Some(sym::realtime) => match value.value_as_str() {
653656
Some(sym::nonblocking) => rtsan = Some(RtsanSetting::Nonblocking),
654657
Some(sym::blocking) => rtsan = Some(RtsanSetting::Blocking),
@@ -673,6 +676,7 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
673676
sym::shadow_call_stack,
674677
sym::thread,
675678
sym::hwaddress,
679+
sym::kernel_hwaddress,
676680
sym::realtime,
677681
],
678682
);

0 commit comments

Comments
 (0)