Skip to content

Commit f198510

Browse files
committed
Auto merge of rust-lang#93921 - matthiaskrgr:rollup-wn3jlxj, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#90955 (Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`) - rust-lang#91607 (Make `span_extend_to_prev_str()` more robust) - rust-lang#92895 (Remove some unused functionality) - rust-lang#93635 (Add missing platform-specific information on current_dir and set_current_dir) - rust-lang#93660 (rustdoc-json: Add some tests for typealias item) - rust-lang#93782 (Split `pauth` target feature) - rust-lang#93868 (Fix incorrect register conflict detection in asm!) - rust-lang#93888 (Implement `AsFd` for `&T` and `&mut T`.) - rust-lang#93909 (Fix typo: explicitely -> explicitly) - rust-lang#93910 (fix mention of moved function in `rustc_hir` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e789f3a + de0feb3 commit f198510

File tree

41 files changed

+487
-99
lines changed

Some content is hidden

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

41 files changed

+487
-99
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
373373
err.emit();
374374
}
375375
Entry::Vacant(v) => {
376-
v.insert(idx);
376+
if r == reg {
377+
v.insert(idx);
378+
}
377379
}
378380
}
379381
};

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub fn inject(
1111
mut krate: ast::Crate,
1212
resolver: &mut dyn ResolverExpand,
1313
sess: &Session,
14-
alt_std_name: Option<Symbol>,
1514
) -> ast::Crate {
1615
let edition = sess.parse_sess.edition;
1716

@@ -53,7 +52,7 @@ pub fn inject(
5352
span,
5453
ident,
5554
vec![cx.attribute(cx.meta_word(span, sym::macro_use))],
56-
ast::ItemKind::ExternCrate(alt_std_name),
55+
ast::ItemKind::ExternCrate(None),
5756
),
5857
);
5958
}

compiler/rustc_codegen_llvm/src/attributes.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,33 @@ pub fn from_fn_attrs<'ll, 'tcx>(
322322
// The target doesn't care; the subtarget reads our attribute.
323323
apply_tune_cpu_attr(cx, llfn);
324324

325-
let mut function_features = codegen_fn_attrs
326-
.target_features
325+
let function_features =
326+
codegen_fn_attrs.target_features.iter().map(|f| f.as_str()).collect::<Vec<&str>>();
327+
328+
if let Some(f) = llvm_util::check_tied_features(
329+
cx.tcx.sess,
330+
&function_features.iter().map(|f| (*f, true)).collect(),
331+
) {
332+
let span = cx
333+
.tcx
334+
.get_attrs(instance.def_id())
335+
.iter()
336+
.find(|a| a.has_name(rustc_span::sym::target_feature))
337+
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
338+
let msg = format!(
339+
"the target features {} must all be either enabled or disabled together",
340+
f.join(", ")
341+
);
342+
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
343+
err.help("add the missing features in a `target_feature` attribute");
344+
err.emit();
345+
return;
346+
}
347+
348+
let mut function_features = function_features
327349
.iter()
328-
.flat_map(|f| {
329-
let feature = f.as_str();
330-
llvm_util::to_llvm_feature(cx.tcx.sess, feature)
350+
.flat_map(|feat| {
351+
llvm_util::to_llvm_feature(cx.tcx.sess, feat)
331352
.into_iter()
332353
.map(|f| format!("+{}", f))
333354
.collect::<Vec<String>>()

compiler/rustc_codegen_llvm/src/llvm_util.rs

+41-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::back::write::create_informational_target_machine;
22
use crate::{llvm, llvm_util};
33
use libc::c_int;
44
use libloading::Library;
5-
use rustc_codegen_ssa::target_features::supported_target_features;
6-
use rustc_data_structures::fx::FxHashSet;
5+
use rustc_codegen_ssa::target_features::{supported_target_features, tied_target_features};
6+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_fs_util::path_to_c_string;
88
use rustc_middle::bug;
99
use rustc_session::config::PrintRequest;
@@ -191,10 +191,30 @@ pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> Vec<&'a str> {
191191
("aarch64", "frintts") => vec!["fptoint"],
192192
("aarch64", "fcma") => vec!["complxnum"],
193193
("aarch64", "pmuv3") => vec!["perfmon"],
194+
("aarch64", "paca") => vec!["pauth"],
195+
("aarch64", "pacg") => vec!["pauth"],
194196
(_, s) => vec![s],
195197
}
196198
}
197199

200+
// Given a map from target_features to whether they are enabled or disabled,
201+
// ensure only valid combinations are allowed.
202+
pub fn check_tied_features(
203+
sess: &Session,
204+
features: &FxHashMap<&str, bool>,
205+
) -> Option<&'static [&'static str]> {
206+
for tied in tied_target_features(sess) {
207+
// Tied features must be set to the same value, or not set at all
208+
let mut tied_iter = tied.iter();
209+
let enabled = features.get(tied_iter.next().unwrap());
210+
211+
if tied_iter.any(|f| enabled != features.get(f)) {
212+
return Some(tied);
213+
}
214+
}
215+
None
216+
}
217+
198218
pub fn target_features(sess: &Session) -> Vec<Symbol> {
199219
let target_machine = create_informational_target_machine(sess);
200220
supported_target_features(sess)
@@ -395,15 +415,19 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
395415
Some(_) | None => {}
396416
};
397417

418+
fn strip(s: &str) -> &str {
419+
s.strip_prefix(&['+', '-']).unwrap_or(s)
420+
}
421+
398422
let filter = |s: &str| {
399423
if s.is_empty() {
400424
return vec![];
401425
}
402-
let feature = if s.starts_with('+') || s.starts_with('-') {
403-
&s[1..]
404-
} else {
426+
let feature = strip(s);
427+
if feature == s {
405428
return vec![s.to_string()];
406-
};
429+
}
430+
407431
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
408432
// are not passed down to LLVM.
409433
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
@@ -420,8 +444,17 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
420444
features.extend(sess.target.features.split(',').flat_map(&filter));
421445

422446
// -Ctarget-features
423-
features.extend(sess.opts.cg.target_feature.split(',').flat_map(&filter));
424-
447+
let feats: Vec<&str> = sess.opts.cg.target_feature.split(',').collect();
448+
// LLVM enables based on the last occurence of a feature
449+
if let Some(f) =
450+
check_tied_features(sess, &feats.iter().map(|f| (strip(f), !f.starts_with("-"))).collect())
451+
{
452+
sess.err(&format!(
453+
"Target features {} must all be enabled or disabled together",
454+
f.join(", ")
455+
));
456+
}
457+
features.extend(feats.iter().flat_map(|&f| filter(f)));
425458
features
426459
}
427460

compiler/rustc_codegen_ssa/src/target_features.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
7474
("ssbs", Some(sym::aarch64_target_feature)),
7575
// FEAT_SB
7676
("sb", Some(sym::aarch64_target_feature)),
77-
// FEAT_PAUTH
78-
("pauth", Some(sym::aarch64_target_feature)),
77+
// FEAT_PAUTH (address authentication)
78+
("paca", Some(sym::aarch64_target_feature)),
79+
// FEAT_PAUTH (generic authentication)
80+
("pacg", Some(sym::aarch64_target_feature)),
7981
// FEAT_DPB
8082
("dpb", Some(sym::aarch64_target_feature)),
8183
// FEAT_DPB2
@@ -137,6 +139,8 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
137139
("v8.7a", Some(sym::aarch64_target_feature)),
138140
];
139141

142+
const AARCH64_TIED_FEATURES: &[&[&str]] = &[&["paca", "pacg"]];
143+
140144
const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
141145
("adx", Some(sym::adx_target_feature)),
142146
("aes", None),
@@ -256,6 +260,13 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
256260
}
257261
}
258262

263+
pub fn tied_target_features(sess: &Session) -> &'static [&'static [&'static str]] {
264+
match &*sess.target.arch {
265+
"aarch64" => AARCH64_TIED_FEATURES,
266+
_ => &[],
267+
}
268+
}
269+
259270
pub(crate) fn provide(providers: &mut Providers) {
260271
providers.supported_target_features = |tcx, cnum| {
261272
assert_eq!(cnum, LOCAL_CRATE);

compiler/rustc_hir/src/itemlikevisit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{ForeignItem, ImplItem, Item, TraitItem};
88
///
99
/// 1. **Shallow visit**: Get a simple callback for every item (or item-like thing) in the HIR.
1010
/// - Example: find all items with a `#[foo]` attribute on them.
11-
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir().krate().visit_all_item_likes()`.
11+
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir().visit_all_item_likes()`.
1212
/// - Pro: Efficient; just walks the lists of item-like things, not the nodes themselves.
1313
/// - Con: Don't get information about nesting
1414
/// - Con: Don't have methods for specific bits of HIR, like "on
@@ -19,9 +19,9 @@ use super::{ForeignItem, ImplItem, Item, TraitItem};
1919
/// - Example: Examine each expression to look for its type and do some check or other.
2020
/// - How: Implement `intravisit::Visitor` and override the `nested_visit_map()` method
2121
/// to return `NestedVisitorMap::OnlyBodies` and use
22-
/// `tcx.hir().krate().visit_all_item_likes(&mut visitor.as_deep_visitor())`. Within
23-
/// your `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget
24-
/// to invoke `intravisit::walk_expr()` to keep walking the subparts).
22+
/// `tcx.hir().visit_all_item_likes(&mut visitor.as_deep_visitor())`. Within your
23+
/// `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
24+
/// `intravisit::walk_expr()` to keep walking the subparts).
2525
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
2626
/// - Pro: Integrates well into dependency tracking.
2727
/// - Con: Don't get information about nesting between items

compiler/rustc_interface/src/passes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ pub fn configure_and_expand(
286286
rustc_builtin_macros::register_builtin_macros(resolver);
287287

288288
krate = sess.time("crate_injection", || {
289-
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));
290-
rustc_builtin_macros::standard_library_imports::inject(krate, resolver, sess, alt_std_name)
289+
rustc_builtin_macros::standard_library_imports::inject(krate, resolver, sess)
291290
});
292291

293292
util::check_attr_crate_type(sess, &krate.attrs, &mut resolver.lint_buffer());

compiler/rustc_interface/src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn get_stack_size() -> Option<usize> {
118118
/// Like a `thread::Builder::spawn` followed by a `join()`, but avoids the need
119119
/// for `'static` bounds.
120120
#[cfg(not(parallel_compiler))]
121-
pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
121+
fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
122122
// SAFETY: join() is called immediately, so any closure captures are still
123123
// alive.
124124
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
@@ -379,7 +379,7 @@ fn sysroot_candidates() -> Vec<PathBuf> {
379379
}
380380
}
381381

382-
pub fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> MakeBackendFn {
382+
fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> MakeBackendFn {
383383
// For now we only allow this function to be called once as it'll dlopen a
384384
// few things, which seems to work best if we only do that once. In
385385
// general this assertion never trips due to the once guard in `get_codegen_backend`,

compiler/rustc_resolve/src/diagnostics.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -453,28 +453,28 @@ impl<'a> Resolver<'a> {
453453
// edit:
454454
// only do this if the const and usage of the non-constant value are on the same line
455455
// the further the two are apart, the higher the chance of the suggestion being wrong
456-
// also make sure that the pos for the suggestion is not 0 (ICE #90878)
457456

458-
let sp =
459-
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
460-
461-
let pos_for_suggestion = sp.lo().0.saturating_sub(current.len() as u32);
457+
let sp = self
458+
.session
459+
.source_map()
460+
.span_extend_to_prev_str(ident.span, current, true, false);
462461

463-
if sp.lo().0 == 0
464-
|| pos_for_suggestion == 0
465-
|| self.session.source_map().is_multiline(sp)
466-
{
467-
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
468-
} else {
469-
let sp = sp.with_lo(BytePos(pos_for_suggestion));
470-
err.span_suggestion(
471-
sp,
472-
&format!("consider using `{}` instead of `{}`", sugg, current),
473-
format!("{} {}", sugg, ident),
474-
Applicability::MaybeIncorrect,
475-
);
476-
err.span_label(span, "non-constant value");
462+
match sp {
463+
Some(sp) if !self.session.source_map().is_multiline(sp) => {
464+
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
465+
err.span_suggestion(
466+
sp,
467+
&format!("consider using `{}` instead of `{}`", sugg, current),
468+
format!("{} {}", sugg, ident),
469+
Applicability::MaybeIncorrect,
470+
);
471+
err.span_label(span, "non-constant value");
472+
}
473+
_ => {
474+
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
475+
}
477476
}
477+
478478
err
479479
}
480480
ResolutionError::BindingShadowsSomethingUnacceptable {

compiler/rustc_session/src/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ impl Default for Options {
770770
externs: Externs(BTreeMap::new()),
771771
extern_dep_specs: ExternDepSpecs(BTreeMap::new()),
772772
crate_name: None,
773-
alt_std_name: None,
774773
libs: Vec::new(),
775774
unstable_features: UnstableFeatures::Disallow,
776775
debug_assertions: true,
@@ -2382,7 +2381,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
23822381
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
23832382
extern_dep_specs,
23842383
crate_name,
2385-
alt_std_name: None,
23862384
libs,
23872385
debug_assertions,
23882386
actually_rustdoc: false,

compiler/rustc_session/src/options.rs

-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ top_level_options!(
184184
externs: Externs [UNTRACKED],
185185
extern_dep_specs: ExternDepSpecs [UNTRACKED],
186186
crate_name: Option<String> [TRACKED],
187-
/// An optional name to use as the crate for std during std injection,
188-
/// written `extern crate name as std`. Defaults to `std`. Used by
189-
/// out-of-tree drivers.
190-
alt_std_name: Option<String> [TRACKED],
191187
/// Indicates how the compiler should treat unstable features.
192188
unstable_features: UnstableFeatures [TRACKED],
193189

compiler/rustc_span/src/source_map.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -629,26 +629,41 @@ impl SourceMap {
629629
}
630630

631631
/// Extends the given `Span` to just after the previous occurrence of `pat` when surrounded by
632-
/// whitespace. Returns the same span if no character could be found or if an error occurred
633-
/// while retrieving the code snippet.
634-
pub fn span_extend_to_prev_str(&self, sp: Span, pat: &str, accept_newlines: bool) -> Span {
632+
/// whitespace. Returns None if the pattern could not be found or if an error occurred while
633+
/// retrieving the code snippet.
634+
pub fn span_extend_to_prev_str(
635+
&self,
636+
sp: Span,
637+
pat: &str,
638+
accept_newlines: bool,
639+
include_whitespace: bool,
640+
) -> Option<Span> {
635641
// assure that the pattern is delimited, to avoid the following
636642
// fn my_fn()
637643
// ^^^^ returned span without the check
638644
// ---------- correct span
645+
let prev_source = self.span_to_prev_source(sp).ok()?;
639646
for ws in &[" ", "\t", "\n"] {
640647
let pat = pat.to_owned() + ws;
641-
if let Ok(prev_source) = self.span_to_prev_source(sp) {
642-
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
643-
if prev_source.is_empty() && sp.lo().0 != 0 {
644-
return sp.with_lo(BytePos(sp.lo().0 - 1));
645-
} else if accept_newlines || !prev_source.contains('\n') {
646-
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
648+
if let Some(pat_pos) = prev_source.rfind(&pat) {
649+
let just_after_pat_pos = pat_pos + pat.len() - 1;
650+
let just_after_pat_plus_ws = if include_whitespace {
651+
just_after_pat_pos
652+
+ prev_source[just_after_pat_pos..]
653+
.find(|c: char| !c.is_whitespace())
654+
.unwrap_or(0)
655+
} else {
656+
just_after_pat_pos
657+
};
658+
let len = prev_source.len() - just_after_pat_plus_ws;
659+
let prev_source = &prev_source[just_after_pat_plus_ws..];
660+
if accept_newlines || !prev_source.trim_start().contains('\n') {
661+
return Some(sp.with_lo(BytePos(sp.lo().0 - len as u32)));
647662
}
648663
}
649664
}
650665

651-
sp
666+
None
652667
}
653668

654669
/// Returns the source snippet as `String` after the given `Span`.
@@ -927,7 +942,7 @@ impl SourceMap {
927942
}
928943

929944
pub fn generate_fn_name_span(&self, span: Span) -> Option<Span> {
930-
let prev_span = self.span_extend_to_prev_str(span, "fn", true);
945+
let prev_span = self.span_extend_to_prev_str(span, "fn", true, true).unwrap_or(span);
931946
if let Ok(snippet) = self.span_to_snippet(prev_span) {
932947
debug!(
933948
"generate_fn_name_span: span={:?}, prev_span={:?}, snippet={:?}",
@@ -968,8 +983,7 @@ impl SourceMap {
968983
pub fn generate_local_type_param_snippet(&self, span: Span) -> Option<(Span, String)> {
969984
// Try to extend the span to the previous "fn" keyword to retrieve the function
970985
// signature.
971-
let sugg_span = self.span_extend_to_prev_str(span, "fn", false);
972-
if sugg_span != span {
986+
if let Some(sugg_span) = self.span_extend_to_prev_str(span, "fn", false, true) {
973987
if let Ok(snippet) = self.span_to_snippet(sugg_span) {
974988
// Consume the function name.
975989
let mut offset = snippet

0 commit comments

Comments
 (0)