Skip to content

Commit 0e95a0f

Browse files
committed
Auto merge of #154637 - JonathanBrouwer:rollup-fGsU36o, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - #154419 (Take first task group for further execution) - #154569 (Fix type alias where clause suggestion spacing issue) - #154617 (Update flate2 users to use zlib-rs) - #154618 (Fix AtomicPtr::update's cfg gate) - #154620 (stabilize new Range type and iterator) - #151932 (refactor: remove `Adjust::ReborrowPin`) - #153980 (refactor: move doc(rust_logo) check to parser) - #154134 (fix: guard paren-sugar pretty-printing on short trait args) - #154270 (Create `Ty` type alias in `rustc_type_ir`) - #154580 (Split AttributeParserError Diagnostic implementation into subfunctions) - #154606 (misc test cleanups) - #154612 (Add a test for a now fixed ICE with `offset_of!()`)
2 parents ba11b1e + bbeec42 commit 0e95a0f

90 files changed

Lines changed: 740 additions & 627 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.

Cargo.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,12 +1422,13 @@ checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
14221422

14231423
[[package]]
14241424
name = "flate2"
1425-
version = "1.1.5"
1425+
version = "1.1.9"
14261426
source = "registry+https://github.com/rust-lang/crates.io-index"
1427-
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
1427+
checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
14281428
dependencies = [
14291429
"crc32fast",
14301430
"miniz_oxide",
1431+
"zlib-rs",
14311432
]
14321433

14331434
[[package]]
@@ -6973,3 +6974,9 @@ dependencies = [
69736974
"quote",
69746975
"syn 2.0.110",
69756976
]
6977+
6978+
[[package]]
6979+
name = "zlib-rs"
6980+
version = "0.6.3"
6981+
source = "registry+https://github.com/rust-lang/crates.io-index"
6982+
checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513"

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,19 @@ impl<'a> AstValidator<'a> {
173173
{
174174
let mut state = State::new();
175175

176+
let mut needs_comma = !ty_alias.after_where_clause.predicates.is_empty();
176177
if !ty_alias.after_where_clause.has_where_token {
177178
state.space();
178179
state.word_space("where");
180+
} else if !needs_comma {
181+
state.space();
179182
}
180183

181-
let mut first = ty_alias.after_where_clause.predicates.is_empty();
182184
for p in &ty_alias.generics.where_clause.predicates {
183-
if !first {
185+
if needs_comma {
184186
state.word_space(",");
185187
}
186-
first = false;
188+
needs_comma = true;
187189
state.print_where_predicate(p);
188190
}
189191

@@ -1832,7 +1834,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
18321834
Some((right, snippet))
18331835
}
18341836
};
1835-
let left_sp = err.span;
1837+
let left_sp = self
1838+
.sess
1839+
.source_map()
1840+
.span_extend_prev_while(err.span, char::is_whitespace)
1841+
.unwrap_or(err.span);
18361842
self.lint_buffer.dyn_buffer_lint(
18371843
DEPRECATED_WHERE_CLAUSE_LOCATION,
18381844
item.id,
@@ -1846,9 +1852,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
18461852
sugg,
18471853
}
18481854
}
1849-
None => {
1850-
errors::DeprecatedWhereClauseLocationSugg::RemoveWhere { span: left_sp }
1851-
}
1855+
None => errors::DeprecatedWhereClauseLocationSugg::RemoveWhere {
1856+
span: err.span,
1857+
},
18521858
};
18531859
errors::DeprecatedWhereClauseLocation { suggestion }.into_diag(dcx, level)
18541860
},

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
2+
use rustc_errors::msg;
23
use rustc_feature::template;
34
use rustc_hir::Target;
45
use rustc_hir::attrs::{
56
AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow,
67
};
78
use rustc_hir::lints::AttributeLintKind;
9+
use rustc_session::parse::feature_err;
810
use rustc_span::{Span, Symbol, edition, sym};
911
use thin_vec::ThinVec;
1012

@@ -481,15 +483,19 @@ impl DocParser {
481483
}
482484
macro_rules! no_args_and_crate_level {
483485
($ident: ident) => {{
486+
no_args_and_crate_level!($ident, |span| {});
487+
}};
488+
($ident: ident, |$span:ident| $extra_validation:block) => {{
484489
if let Err(span) = args.no_args() {
485490
expected_no_args(cx, span);
486491
return;
487492
}
488-
let span = path.span();
489-
if !check_attr_crate_level(cx, span) {
493+
let $span = path.span();
494+
if !check_attr_crate_level(cx, $span) {
490495
return;
491496
}
492-
self.attribute.$ident = Some(span);
497+
$extra_validation
498+
self.attribute.$ident = Some($span);
493499
}};
494500
}
495501
macro_rules! string_arg_and_crate_level {
@@ -553,7 +559,17 @@ impl DocParser {
553559
),
554560
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
555561
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
556-
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo),
562+
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
563+
if !cx.features().rustdoc_internals() {
564+
feature_err(
565+
cx.sess(),
566+
sym::rustdoc_internals,
567+
span,
568+
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
569+
)
570+
.emit();
571+
}
572+
}),
557573
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
558574
Some(sym::test) => {
559575
let Some(list) = args.list() else {

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 87 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -594,29 +594,108 @@ pub(crate) struct AttributeParseError<'a> {
594594
pub(crate) suggestions: Vec<String>,
595595
}
596596

597+
impl<'a> AttributeParseError<'a> {
598+
fn render_expected_specific_argument<G>(
599+
&self,
600+
diag: &mut Diag<'_, G>,
601+
possibilities: &[Symbol],
602+
strings: bool,
603+
) where
604+
G: EmissionGuarantee,
605+
{
606+
let quote = if strings { '"' } else { '`' };
607+
match possibilities {
608+
&[] => {}
609+
&[x] => {
610+
diag.span_label(
611+
self.span,
612+
format!("the only valid argument here is {quote}{x}{quote}"),
613+
);
614+
}
615+
[first, second] => {
616+
diag.span_label(
617+
self.span,
618+
format!("valid arguments are {quote}{first}{quote} or {quote}{second}{quote}"),
619+
);
620+
}
621+
[first @ .., second_to_last, last] => {
622+
let mut res = String::new();
623+
for i in first {
624+
res.push_str(&format!("{quote}{i}{quote}, "));
625+
}
626+
res.push_str(&format!("{quote}{second_to_last}{quote} or {quote}{last}{quote}"));
627+
628+
diag.span_label(self.span, format!("valid arguments are {res}"));
629+
}
630+
}
631+
}
632+
633+
fn render_expected_specific_argument_list<G>(
634+
&self,
635+
diag: &mut Diag<'_, G>,
636+
possibilities: &[Symbol],
637+
strings: bool,
638+
) where
639+
G: EmissionGuarantee,
640+
{
641+
let description = self.description();
642+
643+
let quote = if strings { '"' } else { '`' };
644+
match possibilities {
645+
&[] => {}
646+
&[x] => {
647+
diag.span_label(
648+
self.span,
649+
format!(
650+
"this {description} is only valid with {quote}{x}{quote} as an argument"
651+
),
652+
);
653+
}
654+
[first, second] => {
655+
diag.span_label(self.span, format!("this {description} is only valid with either {quote}{first}{quote} or {quote}{second}{quote} as an argument"));
656+
}
657+
[first @ .., second_to_last, last] => {
658+
let mut res = String::new();
659+
for i in first {
660+
res.push_str(&format!("{quote}{i}{quote}, "));
661+
}
662+
res.push_str(&format!("{quote}{second_to_last}{quote} or {quote}{last}{quote}"));
663+
664+
diag.span_label(self.span, format!("this {description} is only valid with one of the following arguments: {res}"));
665+
}
666+
}
667+
}
668+
669+
fn description(&self) -> &'static str {
670+
match self.description {
671+
ParsedDescription::Attribute => "attribute",
672+
ParsedDescription::Macro => "macro",
673+
}
674+
}
675+
}
676+
597677
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
598678
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
599679
let name = self.path.to_string();
600680

601-
let description = match self.description {
602-
ParsedDescription::Attribute => "attribute",
603-
ParsedDescription::Macro => "macro",
604-
};
681+
let description = self.description();
605682

606683
let mut diag = Diag::new(dcx, level, format!("malformed `{name}` {description} input"));
607684
diag.span(self.attr_span);
608685
diag.code(E0539);
609-
match self.reason {
686+
match &self.reason {
610687
AttributeParseErrorReason::ExpectedStringLiteral { byte_string } => {
611688
if let Some(start_point_span) = byte_string {
612689
diag.span_suggestion(
613-
start_point_span,
690+
*start_point_span,
614691
"consider removing the prefix",
615692
"",
616693
Applicability::MaybeIncorrect,
617694
);
618695
diag.note("expected a normal string literal, not a byte string literal");
619696

697+
// Avoid emitting an "attribute must be of the form" suggestion, as the
698+
// attribute is likely to be well-formed already.
620699
return diag;
621700
} else {
622701
diag.span_label(self.span, "expected a string literal here");
@@ -693,62 +772,14 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
693772
strings,
694773
list: false,
695774
} => {
696-
let quote = if strings { '"' } else { '`' };
697-
match possibilities {
698-
&[] => {}
699-
&[x] => {
700-
diag.span_label(
701-
self.span,
702-
format!("the only valid argument here is {quote}{x}{quote}"),
703-
);
704-
}
705-
[first, second] => {
706-
diag.span_label(self.span, format!("valid arguments are {quote}{first}{quote} or {quote}{second}{quote}"));
707-
}
708-
[first @ .., second_to_last, last] => {
709-
let mut res = String::new();
710-
for i in first {
711-
res.push_str(&format!("{quote}{i}{quote}, "));
712-
}
713-
res.push_str(&format!(
714-
"{quote}{second_to_last}{quote} or {quote}{last}{quote}"
715-
));
716-
717-
diag.span_label(self.span, format!("valid arguments are {res}"));
718-
}
719-
}
775+
self.render_expected_specific_argument(&mut diag, *possibilities, *strings);
720776
}
721777
AttributeParseErrorReason::ExpectedSpecificArgument {
722778
possibilities,
723779
strings,
724780
list: true,
725781
} => {
726-
let quote = if strings { '"' } else { '`' };
727-
match possibilities {
728-
&[] => {}
729-
&[x] => {
730-
diag.span_label(
731-
self.span,
732-
format!(
733-
"this {description} is only valid with {quote}{x}{quote} as an argument"
734-
),
735-
);
736-
}
737-
[first, second] => {
738-
diag.span_label(self.span, format!("this {description} is only valid with either {quote}{first}{quote} or {quote}{second}{quote} as an argument"));
739-
}
740-
[first @ .., second_to_last, last] => {
741-
let mut res = String::new();
742-
for i in first {
743-
res.push_str(&format!("{quote}{i}{quote}, "));
744-
}
745-
res.push_str(&format!(
746-
"{quote}{second_to_last}{quote} or {quote}{last}{quote}"
747-
));
748-
749-
diag.span_label(self.span, format!("this {description} is only valid with one of the following arguments: {res}"));
750-
}
751-
}
782+
self.render_expected_specific_argument_list(&mut diag, *possibilities, *strings);
752783
}
753784
AttributeParseErrorReason::ExpectedIdentifier => {
754785
diag.span_label(self.span, "expected a valid identifier here");

compiler/rustc_data_structures/src/sync/parallel.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ fn par_slice<I: DynSend>(
145145

146146
const MAX_GROUP_COUNT: usize = 128;
147147
let group_size = items.len().div_ceil(MAX_GROUP_COUNT);
148-
let groups = items.chunks_mut(group_size);
148+
let mut groups = items.chunks_mut(group_size);
149+
150+
let Some(first_group) = groups.next() else { return };
149151

150152
// Reverse the order of the later functions since Rayon executes them in reverse
151153
// order when using a single thread. This ensures the execution order matches
@@ -159,6 +161,11 @@ fn par_slice<I: DynSend>(
159161
}
160162
});
161163
}
164+
165+
// Run the first function without spawning to avoid overwhelming stealing.
166+
for i in first_group.iter_mut() {
167+
guard.run(|| for_each(i));
168+
}
162169
});
163170
}
164171

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,16 +751,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
751751
adjustment::Adjust::Borrow(ref autoref) => {
752752
self.walk_autoref(expr, &place_with_id, autoref);
753753
}
754-
755-
adjustment::Adjust::ReborrowPin(mutbl) => {
756-
// Reborrowing a Pin is like a combinations of a deref and a borrow, so we do
757-
// both.
758-
let bk = match mutbl {
759-
ty::Mutability::Not => ty::BorrowKind::Immutable,
760-
ty::Mutability::Mut => ty::BorrowKind::Mutable,
761-
};
762-
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
763-
}
764754
}
765755
place_with_id = self.cat_expr_adjusted(expr, place_with_id, adjustment)?;
766756
}
@@ -1292,8 +1282,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12921282

12931283
adjustment::Adjust::NeverToAny
12941284
| adjustment::Adjust::Pointer(_)
1295-
| adjustment::Adjust::Borrow(_)
1296-
| adjustment::Adjust::ReborrowPin(..) => {
1285+
| adjustment::Adjust::Borrow(_) => {
12971286
// Result is an rvalue.
12981287
Ok(self.cat_rvalue(expr.hir_id, target))
12991288
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
337337
Adjust::Pointer(_pointer_coercion) => {
338338
// FIXME(const_trait_impl): We should probably enforce these.
339339
}
340-
Adjust::ReborrowPin(_mutability) => {
341-
// FIXME(const_trait_impl): We could enforce these; they correspond to
342-
// `&mut T: DerefMut` tho, so it's kinda moot.
343-
}
344340
Adjust::Borrow(_) => {
345341
// No effects to enforce here.
346342
}

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use rustc_lint::builtin::{
1818
};
1919
use rustc_middle::traits::ObligationCauseCode;
2020
use rustc_middle::ty::adjustment::{
21-
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
21+
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
22+
PointerCoercion,
2223
};
2324
use rustc_middle::ty::{
2425
self, AssocContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt,
@@ -243,12 +244,16 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
243244
ty::Ref(_, ty, _) => *ty,
244245
_ => bug!("Expected a reference type for argument to Pin"),
245246
};
247+
adjustments.push(Adjustment {
248+
kind: Adjust::Deref(DerefAdjustKind::Pin),
249+
target: inner_ty,
250+
});
246251
Ty::new_pinned_ref(self.tcx, region, inner_ty, mutbl)
247252
}
248253
_ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"),
249254
};
250-
251-
adjustments.push(Adjustment { kind: Adjust::ReborrowPin(mutbl), target });
255+
adjustments
256+
.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Pin(mutbl)), target });
252257
}
253258
None => {}
254259
}

0 commit comments

Comments
 (0)