Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9693b17

Browse files
committedApr 12, 2023
Auto merge of rust-lang#110252 - matthiaskrgr:rollup-ovaixra, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#109810 (Replace rustdoc-ui/{c,z}-help tests with a stable run-make test ) - rust-lang#110035 (fix: ensure bad `#[test]` invocs retain correct AST) - rust-lang#110089 (sync::mpsc: synchronize receiver disconnect with initialization) - rust-lang#110103 (Report overflows gracefully with new solver) - rust-lang#110122 (Fix x check --stage 1 when download-ci-llvm=false) - rust-lang#110133 (Do not use ImplDerivedObligationCause for inherent impl method error reporting) - rust-lang#110135 (Revert "Don't recover lifetimes/labels containing emojis as character literals") - rust-lang#110235 (Fix `--extend-css` option) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4087dea + b01f0d3 commit 9693b17

Some content is hidden

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

55 files changed

+502
-700
lines changed
 

‎compiler/rustc_builtin_macros/src/test.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,22 @@ pub fn expand_test_or_bench(
118118
}
119119
}
120120
other => {
121-
cx.struct_span_err(
122-
other.span(),
123-
"`#[test]` attribute is only allowed on non associated functions",
124-
)
125-
.emit();
121+
not_testable_error(cx, attr_sp, None);
126122
return vec![other];
127123
}
128124
};
129125

130-
// Note: non-associated fn items are already handled by `expand_test_or_bench`
131126
let ast::ItemKind::Fn(fn_) = &item.kind else {
132-
let diag = &cx.sess.parse_sess.span_diagnostic;
133-
let msg = "the `#[test]` attribute may only be used on a non-associated function";
134-
let mut err = match item.kind {
135-
// These were a warning before #92959 and need to continue being that to avoid breaking
136-
// stable user code (#94508).
137-
ast::ItemKind::MacCall(_) => diag.struct_span_warn(attr_sp, msg),
138-
// `.forget_guarantee()` needed to get these two arms to match types. Because of how
139-
// locally close the `.emit()` call is I'm comfortable with it, but if it can be
140-
// reworked in the future to not need it, it'd be nice.
141-
_ => diag.struct_span_err(attr_sp, msg).forget_guarantee(),
127+
not_testable_error(cx, attr_sp, Some(&item));
128+
return if is_stmt {
129+
vec![Annotatable::Stmt(P(ast::Stmt {
130+
id: ast::DUMMY_NODE_ID,
131+
span: item.span,
132+
kind: ast::StmtKind::Item(item),
133+
}))]
134+
} else {
135+
vec![Annotatable::Item(item)]
142136
};
143-
err.span_label(attr_sp, "the `#[test]` macro causes a function to be run on a test and has no effect on non-functions")
144-
.span_label(item.span, format!("expected a non-associated function, found {} {}", item.kind.article(), item.kind.descr()))
145-
.span_suggestion(attr_sp, "replace with conditional compilation to make the item only exist when tests are being run", "#[cfg(test)]", Applicability::MaybeIncorrect)
146-
.emit();
147-
148-
return vec![Annotatable::Item(item)];
149137
};
150138

151139
// has_*_signature will report any errors in the type so compilation
@@ -398,6 +386,36 @@ pub fn expand_test_or_bench(
398386
}
399387
}
400388

389+
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
390+
let diag = &cx.sess.parse_sess.span_diagnostic;
391+
let msg = "the `#[test]` attribute may only be used on a non-associated function";
392+
let mut err = match item.map(|i| &i.kind) {
393+
// These were a warning before #92959 and need to continue being that to avoid breaking
394+
// stable user code (#94508).
395+
Some(ast::ItemKind::MacCall(_)) => diag.struct_span_warn(attr_sp, msg),
396+
// `.forget_guarantee()` needed to get these two arms to match types. Because of how
397+
// locally close the `.emit()` call is I'm comfortable with it, but if it can be
398+
// reworked in the future to not need it, it'd be nice.
399+
_ => diag.struct_span_err(attr_sp, msg).forget_guarantee(),
400+
};
401+
if let Some(item) = item {
402+
err.span_label(
403+
item.span,
404+
format!(
405+
"expected a non-associated function, found {} {}",
406+
item.kind.article(),
407+
item.kind.descr()
408+
),
409+
);
410+
}
411+
err.span_label(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
412+
.span_suggestion(attr_sp,
413+
"replace with conditional compilation to make the item only exist when tests are being run",
414+
"#[cfg(test)]",
415+
Applicability::MaybeIncorrect)
416+
.emit();
417+
}
418+
401419
fn get_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> (Symbol, usize, usize, usize, usize) {
402420
let span = item.ident.span;
403421
let (source_file, lo_line, lo_col, hi_line, hi_col) =

‎compiler/rustc_driver_impl/src/lib.rs

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_metadata::locator;
3737
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
3838
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
3939
use rustc_session::cstore::MetadataLoader;
40-
use rustc_session::getopts;
40+
use rustc_session::getopts::{self, Matches};
4141
use rustc_session::lint::{Lint, LintId};
4242
use rustc_session::{config, Session};
4343
use rustc_session::{early_error, early_error_no_abort, early_warn};
@@ -956,6 +956,46 @@ Available lint options:
956956
}
957957
}
958958

959+
/// Show help for flag categories shared between rustdoc and rustc.
960+
///
961+
/// Returns whether a help option was printed.
962+
pub fn describe_flag_categories(matches: &Matches) -> bool {
963+
// Handle the special case of -Wall.
964+
let wall = matches.opt_strs("W");
965+
if wall.iter().any(|x| *x == "all") {
966+
print_wall_help();
967+
rustc_errors::FatalError.raise();
968+
}
969+
970+
// Don't handle -W help here, because we might first load plugins.
971+
let debug_flags = matches.opt_strs("Z");
972+
if debug_flags.iter().any(|x| *x == "help") {
973+
describe_debug_flags();
974+
return true;
975+
}
976+
977+
let cg_flags = matches.opt_strs("C");
978+
if cg_flags.iter().any(|x| *x == "help") {
979+
describe_codegen_flags();
980+
return true;
981+
}
982+
983+
if cg_flags.iter().any(|x| *x == "no-stack-check") {
984+
early_warn(
985+
ErrorOutputType::default(),
986+
"the --no-stack-check flag is deprecated and does nothing",
987+
);
988+
}
989+
990+
if cg_flags.iter().any(|x| *x == "passes=list") {
991+
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
992+
get_codegen_backend(&None, backend_name).print_passes();
993+
return true;
994+
}
995+
996+
false
997+
}
998+
959999
fn describe_debug_flags() {
9601000
println!("\nAvailable options:\n");
9611001
print_flag_list("-Z", config::Z_OPTIONS);
@@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
9661006
print_flag_list("-C", config::CG_OPTIONS);
9671007
}
9681008

969-
pub fn print_flag_list<T>(
1009+
fn print_flag_list<T>(
9701010
cmdline_opt: &str,
9711011
flag_list: &[(&'static str, T, &'static str, &'static str)],
9721012
) {
@@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10591099
return None;
10601100
}
10611101

1062-
// Handle the special case of -Wall.
1063-
let wall = matches.opt_strs("W");
1064-
if wall.iter().any(|x| *x == "all") {
1065-
print_wall_help();
1066-
rustc_errors::FatalError.raise();
1067-
}
1068-
1069-
// Don't handle -W help here, because we might first load plugins.
1070-
let debug_flags = matches.opt_strs("Z");
1071-
if debug_flags.iter().any(|x| *x == "help") {
1072-
describe_debug_flags();
1073-
return None;
1074-
}
1075-
1076-
let cg_flags = matches.opt_strs("C");
1077-
1078-
if cg_flags.iter().any(|x| *x == "help") {
1079-
describe_codegen_flags();
1080-
return None;
1081-
}
1082-
1083-
if cg_flags.iter().any(|x| *x == "no-stack-check") {
1084-
early_warn(
1085-
ErrorOutputType::default(),
1086-
"the --no-stack-check flag is deprecated and does nothing",
1087-
);
1088-
}
1089-
1090-
if cg_flags.iter().any(|x| *x == "passes=list") {
1091-
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1092-
get_codegen_backend(&None, backend_name).print_passes();
1102+
if describe_flag_categories(&matches) {
10931103
return None;
10941104
}
10951105

0 commit comments

Comments
 (0)
Please sign in to comment.