Skip to content

Commit ee933f6

Browse files
committed
Auto merge of #121627 - GuillaumeGomez:rollup-udp3m0k, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #120656 (Allow tests to specify a `//@ filecheck-flags:` header) - #120840 (Split Diagnostics for Uncommon Codepoints: Add Individual Identifier Types) - #121554 (Don't unnecessarily change `SIGPIPE` disposition in `unix_sigpipe` tests) - #121590 (Correctly handle if rustdoc JS script hash changed) - #121620 (Fix more #121208 fallout (round 3)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dc00e8c + 76f303d commit ee933f6

30 files changed

+399
-198
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13311331
}
13321332
}
13331333

1334-
self.tcx.dcx().span_bug(
1334+
self.tcx.dcx().span_delayed_bug(
13351335
lifetime_ref.ident.span,
13361336
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
13371337
);

compiler/rustc_hir_typeck/src/method/probe.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804804
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
805805
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
806806
if new_trait_ref.has_non_region_bound_vars() {
807-
this.dcx().span_bug(
807+
this.dcx().span_delayed_bug(
808808
this.span,
809809
"tried to select method from HRTB with non-lifetime bound vars",
810810
);
811+
return;
811812
}
812813

813814
let new_trait_ref = this.instantiate_bound_regions_with_erased(new_trait_ref);

compiler/rustc_lint/messages.ftl

+21-2
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,28 @@ lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of
244244
lint_identifier_non_ascii_char = identifier contains non-ASCII characters
245245
246246
lint_identifier_uncommon_codepoints = identifier contains {$codepoints_len ->
247-
[one] an uncommon Unicode codepoint
248-
*[other] uncommon Unicode codepoints
247+
[one] { $identifier_type ->
248+
[Exclusion] a character from an archaic script
249+
[Technical] a character that is for non-linguistic, specialized usage
250+
[Limited_Use] a character from a script in limited use
251+
[Not_NFKC] a non normalized (NFKC) character
252+
*[other] an uncommon character
253+
}
254+
*[other] { $identifier_type ->
255+
[Exclusion] {$codepoints_len} characters from archaic scripts
256+
[Technical] {$codepoints_len} characters that are for non-linguistic, specialized usage
257+
[Limited_Use] {$codepoints_len} characters from scripts in limited use
258+
[Not_NFKC] {$codepoints_len} non normalized (NFKC) characters
259+
*[other] uncommon characters
260+
}
249261
}: {$codepoints}
262+
.note = {$codepoints_len ->
263+
[one] this character is
264+
*[other] these characters are
265+
} included in the{$identifier_type ->
266+
[Restricted] {""}
267+
*[other] {" "}{$identifier_type}
268+
} Unicode general security profile
250269
251270
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level
252271

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(array_windows)]
3232
#![feature(box_patterns)]
3333
#![feature(control_flow_enum)]
34+
#![feature(extract_if)]
3435
#![feature(generic_nonzero)]
3536
#![feature(if_let_guard)]
3637
#![feature(iter_order_by)]

compiler/rustc_lint/src/lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,11 @@ pub struct IdentifierNonAsciiChar;
11291129

11301130
#[derive(LintDiagnostic)]
11311131
#[diag(lint_identifier_uncommon_codepoints)]
1132+
#[note]
11321133
pub struct IdentifierUncommonCodepoints {
11331134
pub codepoints: Vec<char>,
11341135
pub codepoints_len: usize,
1136+
pub identifier_type: &'static str,
11351137
}
11361138

11371139
#[derive(LintDiagnostic)]

compiler/rustc_lint/src/non_ascii_idents.rs

+39-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast as ast;
77
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_data_structures::unord::UnordMap;
99
use rustc_span::symbol::Symbol;
10+
use unicode_security::general_security_profile::IdentifierType;
1011

1112
declare_lint! {
1213
/// The `non_ascii_idents` lint detects non-ASCII identifiers.
@@ -189,17 +190,47 @@ impl EarlyLintPass for NonAsciiIdents {
189190
if check_uncommon_codepoints
190191
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
191192
{
192-
let codepoints: Vec<_> = symbol_str
193+
let mut chars: Vec<_> = symbol_str
193194
.chars()
194-
.filter(|c| !GeneralSecurityProfile::identifier_allowed(*c))
195+
.map(|c| (c, GeneralSecurityProfile::identifier_type(c)))
195196
.collect();
196-
let codepoints_len = codepoints.len();
197197

198-
cx.emit_span_lint(
199-
UNCOMMON_CODEPOINTS,
200-
sp,
201-
IdentifierUncommonCodepoints { codepoints, codepoints_len },
202-
);
198+
for (id_ty, id_ty_descr) in [
199+
(IdentifierType::Exclusion, "Exclusion"),
200+
(IdentifierType::Technical, "Technical"),
201+
(IdentifierType::Limited_Use, "Limited_Use"),
202+
(IdentifierType::Not_NFKC, "Not_NFKC"),
203+
] {
204+
let codepoints: Vec<_> =
205+
chars.extract_if(|(_, ty)| *ty == Some(id_ty)).collect();
206+
if codepoints.is_empty() {
207+
continue;
208+
}
209+
cx.emit_span_lint(
210+
UNCOMMON_CODEPOINTS,
211+
sp,
212+
IdentifierUncommonCodepoints {
213+
codepoints_len: codepoints.len(),
214+
codepoints: codepoints.into_iter().map(|(c, _)| c).collect(),
215+
identifier_type: id_ty_descr,
216+
},
217+
);
218+
}
219+
220+
let remaining = chars
221+
.extract_if(|(c, _)| !GeneralSecurityProfile::identifier_allowed(*c))
222+
.collect::<Vec<_>>();
223+
if !remaining.is_empty() {
224+
cx.emit_span_lint(
225+
UNCOMMON_CODEPOINTS,
226+
sp,
227+
IdentifierUncommonCodepoints {
228+
codepoints_len: remaining.len(),
229+
codepoints: remaining.into_iter().map(|(c, _)| c).collect(),
230+
identifier_type: "Restricted",
231+
},
232+
);
233+
}
203234
}
204235
}
205236

src/librustdoc/html/static/js/main.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ function preLoadCss(cssUrl) {
185185
(function() {
186186
const isHelpPage = window.location.pathname.endsWith("/help.html");
187187

188-
function loadScript(url) {
188+
function loadScript(url, errorCallback) {
189189
const script = document.createElement("script");
190190
script.src = url;
191+
if (errorCallback !== undefined) {
192+
script.onerror = errorCallback;
193+
}
191194
document.head.append(script);
192195
}
193196

@@ -292,11 +295,16 @@ function preLoadCss(cssUrl) {
292295
return;
293296
}
294297
let searchLoaded = false;
298+
// If you're browsing the nightly docs, the page might need to be refreshed for the
299+
// search to work because the hash of the JS scripts might have changed.
300+
function sendSearchForm() {
301+
document.getElementsByClassName("search-form")[0].submit();
302+
}
295303
function loadSearch() {
296304
if (!searchLoaded) {
297305
searchLoaded = true;
298-
loadScript(getVar("static-root-path") + getVar("search-js"));
299-
loadScript(resourcePath("search-index", ".js"));
306+
loadScript(getVar("static-root-path") + getVar("search-js"), sendSearchForm);
307+
loadScript(resourcePath("search-index", ".js"), sendSearchForm);
300308
}
301309
}
302310

src/tools/compiletest/src/header.rs

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ pub struct TestProps {
197197
/// Extra flags to pass to `llvm-cov` when producing coverage reports.
198198
/// Only used by the "coverage-run" test mode.
199199
pub llvm_cov_flags: Vec<String>,
200+
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
201+
pub filecheck_flags: Vec<String>,
200202
}
201203

202204
mod directives {
@@ -236,6 +238,7 @@ mod directives {
236238
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
237239
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
238240
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
241+
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
239242
// This isn't a real directive, just one that is probably mistyped often
240243
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
241244
}
@@ -286,6 +289,7 @@ impl TestProps {
286289
mir_unit_test: None,
287290
remap_src_base: false,
288291
llvm_cov_flags: vec![],
292+
filecheck_flags: vec![],
289293
}
290294
}
291295

@@ -542,6 +546,10 @@ impl TestProps {
542546
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
543547
self.llvm_cov_flags.extend(split_flags(&flags));
544548
}
549+
550+
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
551+
self.filecheck_flags.extend(split_flags(&flags));
552+
}
545553
},
546554
);
547555

src/tools/compiletest/src/runtest.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -2909,25 +2909,32 @@ impl<'test> TestCx<'test> {
29092909
fn verify_with_filecheck(&self, output: &Path) -> ProcRes {
29102910
let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap());
29112911
filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file);
2912-
// It would be more appropriate to make most of the arguments configurable through
2913-
// a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very
2914-
// useful flag.
2915-
//
2916-
// For now, though…
2917-
let prefix_for_target =
2918-
if self.config.target.contains("msvc") { "MSVC" } else { "NONMSVC" };
2919-
let prefixes = if let Some(rev) = self.revision {
2920-
format!("CHECK,{},{}", prefix_for_target, rev)
2921-
} else {
2922-
format!("CHECK,{}", prefix_for_target)
2923-
};
2924-
if self.config.llvm_version.unwrap_or(0) >= 130000 {
2925-
filecheck.args(&["--allow-unused-prefixes", "--check-prefixes", &prefixes]);
2926-
} else {
2927-
filecheck.args(&["--check-prefixes", &prefixes]);
2912+
2913+
// FIXME: Consider making some of these prefix flags opt-in per test,
2914+
// via `filecheck-flags` or by adding new header directives.
2915+
2916+
// Because we use custom prefixes, we also have to register the default prefix.
2917+
filecheck.arg("--check-prefix=CHECK");
2918+
2919+
// Some tests use the current revision name as a check prefix.
2920+
if let Some(rev) = self.revision {
2921+
filecheck.arg("--check-prefix").arg(rev);
29282922
}
2923+
2924+
// Some tests also expect either the MSVC or NONMSVC prefix to be defined.
2925+
let msvc_or_not = if self.config.target.contains("msvc") { "MSVC" } else { "NONMSVC" };
2926+
filecheck.arg("--check-prefix").arg(msvc_or_not);
2927+
2928+
// The filecheck tool normally fails if a prefix is defined but not used.
2929+
// However, we define several prefixes globally for all tests.
2930+
filecheck.arg("--allow-unused-prefixes");
2931+
29292932
// Provide more context on failures.
29302933
filecheck.args(&["--dump-input-context", "100"]);
2934+
2935+
// Add custom flags supplied by the `filecheck-flags:` test header.
2936+
filecheck.args(&self.props.filecheck_flags);
2937+
29312938
self.compose_and_run(filecheck, "", None, None)
29322939
}
29332940

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//@ edition: 2021
2+
//@ needs-profiler-support
3+
//@ compile-flags: -Cinstrument-coverage -Copt-level=0
4+
//@ revisions: LINUX DARWIN WINDOWS
5+
6+
//@ [LINUX] only-linux
7+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_DATA=__llvm_prf_data
8+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_NAME=__llvm_prf_names
9+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_CNTS=__llvm_prf_cnts
10+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_COVMAP=__llvm_covmap
11+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_COVFUN=__llvm_covfun
12+
//@ [LINUX] filecheck-flags: '-DCOMDAT_IF_SUPPORTED=, comdat'
13+
14+
//@ [DARWIN] only-macos
15+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_DATA=__DATA,__llvm_prf_data,regular,live_support
16+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_NAME=__DATA,__llvm_prf_names
17+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_CNTS=__DATA,__llvm_prf_cnts
18+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_COVMAP=__LLVM_COV,__llvm_covmap
19+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_COVFUN=__LLVM_COV,__llvm_covfun
20+
//@ [DARWIN] filecheck-flags: -DCOMDAT_IF_SUPPORTED=
21+
22+
//@ [WINDOWS] only-windows
23+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_DATA=.lprfd$M
24+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_NAME=.lprfn$M
25+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_CNTS=.lprfc$M
26+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_COVMAP=.lcovmap$M
27+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_COVFUN=.lcovfun$M
28+
//@ [WINDOWS] filecheck-flags: '-DCOMDAT_IF_SUPPORTED=, comdat'
29+
30+
// ignore-tidy-linelength
31+
32+
pub fn will_be_called() -> &'static str {
33+
let val = "called";
34+
println!("{}", val);
35+
val
36+
}
37+
38+
pub fn will_not_be_called() -> bool {
39+
println!("should not have been called");
40+
false
41+
}
42+
43+
pub fn print<T>(left: &str, value: T, right: &str)
44+
where
45+
T: std::fmt::Display,
46+
{
47+
println!("{}{}{}", left, value, right);
48+
}
49+
50+
pub fn wrap_with<F, T>(inner: T, should_wrap: bool, wrapper: F)
51+
where
52+
F: FnOnce(&T)
53+
{
54+
if should_wrap {
55+
wrapper(&inner)
56+
}
57+
}
58+
59+
fn main() {
60+
let less = 1;
61+
let more = 100;
62+
63+
if less < more {
64+
wrap_with(will_be_called(), less < more, |inner| print(" ***", inner, "*** "));
65+
wrap_with(will_be_called(), more < less, |inner| print(" ***", inner, "*** "));
66+
} else {
67+
wrap_with(will_not_be_called(), true, |inner| print("wrapped result is: ", inner, ""));
68+
}
69+
}
70+
71+
// Check for metadata, variables, declarations, and function definitions injected
72+
// into LLVM IR when compiling with -Cinstrument-coverage.
73+
74+
// WINDOWS: $__llvm_profile_runtime_user = comdat any
75+
76+
// CHECK: @__llvm_coverage_mapping = private constant
77+
// CHECK-SAME: section "[[INSTR_PROF_COVMAP]]", align 8
78+
79+
// CHECK: @__covrec_{{[A-F0-9]+}}u = linkonce_odr hidden constant
80+
// CHECK-SAME: section "[[INSTR_PROF_COVFUN]]"[[COMDAT_IF_SUPPORTED]], align 8
81+
82+
// WINDOWS: @__llvm_profile_runtime = external{{.*}}global i32
83+
84+
// CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = {{private|internal}} global
85+
// CHECK-SAME: section "[[INSTR_PROF_CNTS]]"{{.*}}, align 8
86+
87+
// CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = {{private|internal}} global
88+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called
89+
// CHECK-SAME: section "[[INSTR_PROF_DATA]]"{{.*}}, align 8
90+
91+
// CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main = {{private|internal}} global
92+
// CHECK-SAME: section "[[INSTR_PROF_CNTS]]"{{.*}}, align 8
93+
94+
// CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog4main = {{private|internal}} global
95+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main
96+
// CHECK-SAME: section "[[INSTR_PROF_DATA]]"{{.*}}, align 8
97+
98+
// CHECK: @__llvm_prf_nm = private constant
99+
// CHECK-SAME: section "[[INSTR_PROF_NAME]]", align 1
100+
101+
// CHECK: @llvm.used = appending global
102+
// CHECK-SAME: @__llvm_coverage_mapping
103+
// CHECK-SAME: @__llvm_prf_nm
104+
// CHECK-SAME: section "llvm.metadata"
105+
106+
// CHECK: define internal { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} {
107+
// CHECK-NEXT: start:
108+
// CHECK-NOT: define internal
109+
// CHECK: atomicrmw add ptr
110+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called,
111+
112+
// CHECK: declare void @llvm.instrprof.increment(ptr, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]]
113+
114+
// WINDOWS: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() #[[LLVM_PROFILE_RUNTIME_USER_ATTR:[0-9]+]] comdat {
115+
// WINDOWS-NEXT: %1 = load i32, ptr @__llvm_profile_runtime
116+
// WINDOWS-NEXT: ret i32 %1
117+
// WINDOWS-NEXT: }
118+
119+
// CHECK: attributes #[[LLVM_INSTRPROF_INCREMENT_ATTR]] = { nounwind }
120+
// WINDOWS: attributes #[[LLVM_PROFILE_RUNTIME_USER_ATTR]] = { noinline }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Simple test that uses the default CHECK prefix and should always succeed.
2+
3+
// CHECK: main
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Arguments provided via `filecheck-flags` should be passed to `filecheck`.
2+
3+
//@ revisions: good bad
4+
//@ [good] filecheck-flags: --check-prefix=CUSTOM
5+
//@ [bad] should-fail
6+
7+
// CUSTOM: main
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This is exactly like `msvc-prefix-good.rs`, except that it should always fail.
2+
3+
//@ should-fail
4+
5+
// MSVC: text that should not match
6+
// NONMSVC: text that should not match
7+
fn main() {}

0 commit comments

Comments
 (0)