Skip to content

Commit 4a91ff6

Browse files
committed
Auto merge of rust-lang#132661 - matthiaskrgr:rollup-npytbl6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#132259 (rustc_codegen_llvm: Add a new 'pc' option to branch-protection) - rust-lang#132409 (CI: switch 7 linux jobs to free runners) - rust-lang#132498 (Suggest fixing typos and let bindings at the same time) - rust-lang#132524 (chore(style): sync submodule exclusion list between tidy and rustfmt) - rust-lang#132567 (Properly suggest `E::assoc` when we encounter `E::Variant::assoc`) - rust-lang#132571 (add const_eval_select macro to reduce redundancy) - rust-lang#132637 (Do not filter empty lint passes & re-do CTFE pass) - rust-lang#132642 (Add documentation on `ast::Attribute`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc5cf99 + 4346249 commit 4a91ff6

Some content is hidden

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

45 files changed

+761
-528
lines changed

.github/workflows/ci.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ jobs:
110110
# less disk space.
111111
- name: free up disk space
112112
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
113-
if: contains(matrix.os, 'ubuntu')
114-
with:
115-
# Removing packages with APT saves ~5 GiB, but takes several
116-
# minutes (and potentially removes important packages).
117-
large-packages: false
113+
if: matrix.free_disk
118114

119115
# Rust Log Analyzer can't currently detect the PR number of a GitHub
120116
# Actions build on its own, so a hint in the log message is needed to

compiler/rustc_ast/src/attr/mod.rs

+46
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,35 @@ impl Attribute {
136136
}
137137
}
138138

139+
/// Returns a list of meta items if the attribute is delimited with parenthesis:
140+
///
141+
/// ```text
142+
/// #[attr(a, b = "c")] // Returns `Some()`.
143+
/// #[attr = ""] // Returns `None`.
144+
/// #[attr] // Returns `None`.
145+
/// ```
139146
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
140147
match &self.kind {
141148
AttrKind::Normal(normal) => normal.item.meta_item_list(),
142149
AttrKind::DocComment(..) => None,
143150
}
144151
}
145152

153+
/// Returns the string value in:
154+
///
155+
/// ```text
156+
/// #[attribute = "value"]
157+
/// ^^^^^^^
158+
/// ```
159+
///
160+
/// It returns `None` in any other cases, including doc comments if they
161+
/// are not under the form `#[doc = "..."]`.
162+
///
163+
/// It also returns `None` for:
164+
///
165+
/// ```text
166+
/// #[attr("value")]
167+
/// ```
146168
pub fn value_str(&self) -> Option<Symbol> {
147169
match &self.kind {
148170
AttrKind::Normal(normal) => normal.item.value_str(),
@@ -232,6 +254,18 @@ impl AttrItem {
232254
}
233255
}
234256

257+
/// Returns the string value in:
258+
///
259+
/// ```text
260+
/// #[attribute = "value"]
261+
/// ^^^^^^^
262+
/// ```
263+
///
264+
/// It returns `None` in any other cases like:
265+
///
266+
/// ```text
267+
/// #[attr("value")]
268+
/// ```
235269
fn value_str(&self) -> Option<Symbol> {
236270
match &self.args {
237271
AttrArgs::Eq(_, args) => args.value_str(),
@@ -315,6 +349,18 @@ impl MetaItem {
315349
Some(self.name_value_literal()?.span)
316350
}
317351

352+
/// Returns the string value in:
353+
///
354+
/// ```text
355+
/// #[attribute = "value"]
356+
/// ^^^^^^^
357+
/// ```
358+
///
359+
/// It returns `None` in any other cases like:
360+
///
361+
/// ```text
362+
/// #[attr("value")]
363+
/// ```
318364
pub fn value_str(&self) -> Option<Symbol> {
319365
match &self.kind {
320366
MetaItemKind::NameValue(v) => v.kind.str(),

compiler/rustc_codegen_llvm/src/attributes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
419419
if bti {
420420
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
421421
}
422-
if let Some(PacRet { leaf, key }) = pac_ret {
422+
if let Some(PacRet { leaf, pc, key }) = pac_ret {
423+
if pc {
424+
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-protection-pauth-lr"));
425+
}
423426
to_add.push(llvm::CreateAttrStringValue(
424427
cx.llcx,
425428
"sign-return-address",

compiler/rustc_codegen_llvm/src/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ pub(crate) unsafe fn create_module<'ll>(
308308
"sign-return-address",
309309
pac_ret.is_some().into(),
310310
);
311-
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
311+
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, pc: false, key: PAuthKey::A });
312+
llvm::add_module_flag_u32(
313+
llmod,
314+
llvm::ModuleFlagMergeBehavior::Min,
315+
"branch-protection-pauth-lr",
316+
pac_opts.pc.into(),
317+
);
312318
llvm::add_module_flag_u32(
313319
llmod,
314320
llvm::ModuleFlagMergeBehavior::Min,

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ fn test_unstable_options_tracking_hash() {
764764
branch_protection,
765765
Some(BranchProtection {
766766
bti: true,
767-
pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
767+
pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B })
768768
})
769769
);
770770
tracked!(codegen_backend, Some("abc".to_string()));

compiler/rustc_lint/src/late.rs

+3
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
422422
.into_iter()
423423
.filter(|pass| {
424424
let lints = (**pass).get_lints();
425+
// Lintless passes are always in
426+
lints.is_empty() ||
427+
// If the pass doesn't have a single needed lint, omit it
425428
!lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
426429
})
427430
.collect();

compiler/rustc_resolve/src/late/diagnostics.rs

+42-13
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
459459
return (err, Vec::new());
460460
}
461461

462-
let (found, mut candidates) = self.try_lookup_name_relaxed(
462+
let (found, suggested_candidates, mut candidates) = self.try_lookup_name_relaxed(
463463
&mut err,
464464
source,
465465
path,
@@ -478,7 +478,15 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
478478
}
479479

480480
let mut fallback = self.suggest_trait_and_bounds(&mut err, source, res, span, &base_error);
481-
fallback |= self.suggest_typo(&mut err, source, path, following_seg, span, &base_error);
481+
fallback |= self.suggest_typo(
482+
&mut err,
483+
source,
484+
path,
485+
following_seg,
486+
span,
487+
&base_error,
488+
suggested_candidates,
489+
);
482490

483491
if fallback {
484492
// Fallback label.
@@ -589,7 +597,16 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
589597
span: Span,
590598
res: Option<Res>,
591599
base_error: &BaseError,
592-
) -> (bool, Vec<ImportSuggestion>) {
600+
) -> (bool, FxHashSet<String>, Vec<ImportSuggestion>) {
601+
let span = match following_seg {
602+
Some(_) if path[0].ident.span.eq_ctxt(path[path.len() - 1].ident.span) => {
603+
// The path `span` that comes in includes any following segments, which we don't
604+
// want to replace in the suggestions.
605+
path[0].ident.span.to(path[path.len() - 1].ident.span)
606+
}
607+
_ => span,
608+
};
609+
let mut suggested_candidates = FxHashSet::default();
593610
// Try to lookup name in more relaxed fashion for better error reporting.
594611
let ident = path.last().unwrap().ident;
595612
let is_expected = &|res| source.is_expected(res);
@@ -646,6 +663,11 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
646663
};
647664
let msg = format!("{preamble}try using the variant's enum");
648665

666+
suggested_candidates.extend(
667+
enum_candidates
668+
.iter()
669+
.map(|(_variant_path, enum_ty_path)| enum_ty_path.clone()),
670+
);
649671
err.span_suggestions(
650672
span,
651673
msg,
@@ -658,7 +680,8 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
658680
// Try finding a suitable replacement.
659681
let typo_sugg = self
660682
.lookup_typo_candidate(path, following_seg, source.namespace(), is_expected)
661-
.to_opt_suggestion();
683+
.to_opt_suggestion()
684+
.filter(|sugg| !suggested_candidates.contains(sugg.candidate.as_str()));
662685
if let [segment] = path
663686
&& !matches!(source, PathSource::Delegation)
664687
&& self.self_type_is_available()
@@ -719,7 +742,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
719742
}
720743
}
721744
self.r.add_typo_suggestion(err, typo_sugg, ident_span);
722-
return (true, candidates);
745+
return (true, suggested_candidates, candidates);
723746
}
724747

725748
// If the first argument in call is `self` suggest calling a method.
@@ -737,7 +760,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
737760
format!("self.{path_str}({args_snippet})"),
738761
Applicability::MachineApplicable,
739762
);
740-
return (true, candidates);
763+
return (true, suggested_candidates, candidates);
741764
}
742765
}
743766

@@ -754,7 +777,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
754777
) {
755778
// We do this to avoid losing a secondary span when we override the main error span.
756779
self.r.add_typo_suggestion(err, typo_sugg, ident_span);
757-
return (true, candidates);
780+
return (true, suggested_candidates, candidates);
758781
}
759782
}
760783

@@ -772,7 +795,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
772795
ident.span,
773796
format!("the binding `{path_str}` is available in a different scope in the same function"),
774797
);
775-
return (true, candidates);
798+
return (true, suggested_candidates, candidates);
776799
}
777800
}
778801
}
@@ -781,7 +804,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
781804
candidates = self.smart_resolve_partial_mod_path_errors(path, following_seg);
782805
}
783806

784-
(false, candidates)
807+
(false, suggested_candidates, candidates)
785808
}
786809

787810
fn suggest_trait_and_bounds(
@@ -869,13 +892,16 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
869892
following_seg: Option<&Segment>,
870893
span: Span,
871894
base_error: &BaseError,
895+
suggested_candidates: FxHashSet<String>,
872896
) -> bool {
873897
let is_expected = &|res| source.is_expected(res);
874898
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
875899
let typo_sugg =
876900
self.lookup_typo_candidate(path, following_seg, source.namespace(), is_expected);
877901
let mut fallback = false;
878-
let typo_sugg = typo_sugg.to_opt_suggestion();
902+
let typo_sugg = typo_sugg
903+
.to_opt_suggestion()
904+
.filter(|sugg| !suggested_candidates.contains(sugg.candidate.as_str()));
879905
if !self.r.add_typo_suggestion(err, typo_sugg, ident_span) {
880906
fallback = true;
881907
match self.diag_metadata.current_let_binding {
@@ -894,10 +920,13 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
894920

895921
// If the trait has a single item (which wasn't matched by the algorithm), suggest it
896922
let suggestion = self.get_single_associated_item(path, &source, is_expected);
897-
if !self.r.add_typo_suggestion(err, suggestion, ident_span) {
898-
fallback = !self.let_binding_suggestion(err, ident_span);
899-
}
923+
self.r.add_typo_suggestion(err, suggestion, ident_span);
900924
}
925+
926+
if self.let_binding_suggestion(err, ident_span) {
927+
fallback = false;
928+
}
929+
901930
fallback
902931
}
903932

compiler/rustc_session/src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,7 @@ pub enum PAuthKey {
13201320
#[derive(Clone, Copy, Hash, Debug, PartialEq)]
13211321
pub struct PacRet {
13221322
pub leaf: bool,
1323+
pub pc: bool,
13231324
pub key: PAuthKey,
13241325
}
13251326

compiler/rustc_session/src/options.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ mod desc {
442442
pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
443443
pub(crate) const parse_stack_protector: &str =
444444
"one of (`none` (default), `basic`, `strong`, or `all`)";
445-
pub(crate) const parse_branch_protection: &str =
446-
"a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
445+
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf`";
447446
pub(crate) const parse_proc_macro_execution_strategy: &str =
448447
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
449448
pub(crate) const parse_remap_path_scope: &str =
@@ -1401,7 +1400,7 @@ pub mod parse {
14011400
match opt {
14021401
"bti" => slot.bti = true,
14031402
"pac-ret" if slot.pac_ret.is_none() => {
1404-
slot.pac_ret = Some(PacRet { leaf: false, key: PAuthKey::A })
1403+
slot.pac_ret = Some(PacRet { leaf: false, pc: false, key: PAuthKey::A })
14051404
}
14061405
"leaf" => match slot.pac_ret.as_mut() {
14071406
Some(pac) => pac.leaf = true,
@@ -1411,6 +1410,10 @@ pub mod parse {
14111410
Some(pac) => pac.key = PAuthKey::B,
14121411
_ => return false,
14131412
},
1413+
"pc" => match slot.pac_ret.as_mut() {
1414+
Some(pac) => pac.pc = true,
1415+
_ => return false,
1416+
},
14141417
_ => return false,
14151418
};
14161419
}

library/core/src/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! impl char {}
22
33
use super::*;
4-
use crate::macros::const_panic;
4+
use crate::panic::const_panic;
55
use crate::slice;
66
use crate::str::from_utf8_unchecked_mut;
77
use crate::unicode::printable::is_printable;

0 commit comments

Comments
 (0)