Skip to content

Commit 9693b17

Browse files
committed
Auto merge of #110252 - matthiaskrgr:rollup-ovaixra, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #109810 (Replace rustdoc-ui/{c,z}-help tests with a stable run-make test ) - #110035 (fix: ensure bad `#[test]` invocs retain correct AST) - #110089 (sync::mpsc: synchronize receiver disconnect with initialization) - #110103 (Report overflows gracefully with new solver) - #110122 (Fix x check --stage 1 when download-ci-llvm=false) - #110133 (Do not use ImplDerivedObligationCause for inherent impl method error reporting) - #110135 (Revert "Don't recover lifetimes/labels containing emojis as character literals") - #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

+40-22
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

+43-33
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

compiler/rustc_errors/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,6 @@ pub enum StashKey {
475475
/// When an invalid lifetime e.g. `'2` should be reinterpreted
476476
/// as a char literal in the parser
477477
LifetimeIsChar,
478-
/// When an invalid lifetime e.g. `'🐱` contains emoji.
479-
LifetimeContainsEmoji,
480478
/// Maybe there was a typo where a comma was forgotten before
481479
/// FRU syntax
482480
MaybeFruTypo,

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578578

579579
#[instrument(skip(self), level = "debug")]
580580
pub(in super::super) fn report_ambiguity_errors(&self) {
581-
let mut errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors();
581+
let mut errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
582582

583583
if !errors.is_empty() {
584584
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7878
// Finally, for ambiguity-related errors, we actually want to look
7979
// for a parameter that is the source of the inference type left
8080
// over in this predicate.
81-
if let traits::FulfillmentErrorCode::CodeAmbiguity = error.code {
81+
if let traits::FulfillmentErrorCode::CodeAmbiguity { .. } = error.code {
8282
fallback_param_to_point_at = None;
8383
self_param_to_point_at = None;
8484
param_to_point_at =

compiler/rustc_hir_typeck/src/method/probe.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -1531,23 +1531,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15311531

15321532
// Convert the bounds into obligations.
15331533
let impl_obligations = traits::predicates_for_generics(
1534-
|_idx, span| {
1535-
let misc = traits::ObligationCause::misc(span, self.body_id);
1536-
let parent_trait_pred = ty::Binder::dummy(ty::TraitPredicate {
1537-
trait_ref: ty::TraitRef::from_method(self.tcx, impl_def_id, substs),
1538-
constness: ty::BoundConstness::NotConst,
1539-
polarity: ty::ImplPolarity::Positive,
1540-
});
1541-
misc.derived_cause(parent_trait_pred, |derived| {
1542-
traits::ImplDerivedObligation(Box::new(
1543-
traits::ImplDerivedObligationCause {
1544-
derived,
1545-
impl_or_alias_def_id: impl_def_id,
1546-
impl_def_predicate_index: None,
1547-
span,
1548-
},
1549-
))
1550-
})
1534+
|idx, span| {
1535+
let code = if span.is_dummy() {
1536+
traits::ExprItemObligation(impl_def_id, self.scope_expr_id, idx)
1537+
} else {
1538+
traits::ExprBindingObligation(
1539+
impl_def_id,
1540+
span,
1541+
self.scope_expr_id,
1542+
idx,
1543+
)
1544+
};
1545+
ObligationCause::new(self.span, self.body_id, code)
15511546
},
15521547
self.param_env,
15531548
impl_bounds,

compiler/rustc_hir_typeck/src/method/suggest.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -661,19 +661,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
661661
// Find all the requirements that come from a local `impl` block.
662662
let mut skip_list: FxHashSet<_> = Default::default();
663663
let mut spanned_predicates = FxHashMap::default();
664-
for (p, parent_p, impl_def_id, cause) in unsatisfied_predicates
665-
.iter()
666-
.filter_map(|(p, parent, c)| c.as_ref().map(|c| (p, parent, c)))
667-
.filter_map(|(p, parent, c)| match c.code() {
668-
ObligationCauseCode::ImplDerivedObligation(data)
669-
if matches!(p.kind().skip_binder(), ty::PredicateKind::Clause(_)) =>
670-
{
671-
Some((p, parent, data.impl_or_alias_def_id, data))
664+
for (p, parent_p, cause) in unsatisfied_predicates {
665+
// Extract the predicate span and parent def id of the cause,
666+
// if we have one.
667+
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
668+
Some(ObligationCauseCode::ImplDerivedObligation(data)) => {
669+
(data.impl_or_alias_def_id, data.span)
672670
}
673-
_ => None,
674-
})
675-
{
676-
match self.tcx.hir().get_if_local(impl_def_id) {
671+
Some(
672+
ObligationCauseCode::ExprBindingObligation(def_id, span, _, _)
673+
| ObligationCauseCode::BindingObligation(def_id, span),
674+
) => (*def_id, *span),
675+
_ => continue,
676+
};
677+
678+
// Don't point out the span of `WellFormed` predicates.
679+
if !matches!(p.kind().skip_binder(), ty::PredicateKind::Clause(_)) {
680+
continue;
681+
};
682+
683+
match self.tcx.hir().get_if_local(item_def_id) {
677684
// Unmet obligation comes from a `derive` macro, point at it once to
678685
// avoid multiple span labels pointing at the same place.
679686
Some(Node::Item(hir::Item {
@@ -718,7 +725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
718725
}
719726
});
720727
for param in generics.params {
721-
if param.span == cause.span && sized_pred {
728+
if param.span == cause_span && sized_pred {
722729
let (sp, sugg) = match param.colon_span {
723730
Some(sp) => (sp.shrink_to_hi(), " ?Sized +"),
724731
None => (param.span.shrink_to_hi(), ": ?Sized"),
@@ -741,9 +748,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
741748
(FxHashSet::default(), FxHashSet::default(), Vec::new())
742749
});
743750
entry.2.push(p);
744-
if cause.span != *item_span {
745-
entry.0.insert(cause.span);
746-
entry.1.insert((cause.span, "unsatisfied trait bound introduced here"));
751+
if cause_span != *item_span {
752+
entry.0.insert(cause_span);
753+
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
747754
} else {
748755
if let Some(trait_ref) = of_trait {
749756
entry.0.insert(trait_ref.path.span);
@@ -775,9 +782,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775782
let entry = entry.or_insert_with(|| {
776783
(FxHashSet::default(), FxHashSet::default(), Vec::new())
777784
});
778-
entry.0.insert(cause.span);
785+
entry.0.insert(cause_span);
779786
entry.1.insert((ident.span, ""));
780-
entry.1.insert((cause.span, "unsatisfied trait bound introduced here"));
787+
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
781788
entry.2.push(p);
782789
}
783790
Some(node) => unreachable!("encountered `{node:?}`"),

compiler/rustc_infer/src/traits/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
3838

3939
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
4040

41-
fn collect_remaining_errors(&mut self) -> Vec<FulfillmentError<'tcx>>;
41+
fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
4242

4343
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
4444

@@ -78,6 +78,6 @@ impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
7878
return errors;
7979
}
8080

81-
self.collect_remaining_errors()
81+
self.collect_remaining_errors(infcx)
8282
}
8383
}

compiler/rustc_infer/src/traits/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ pub enum FulfillmentErrorCode<'tcx> {
128128
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
129129
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
130130
CodeConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
131-
CodeAmbiguity,
131+
CodeAmbiguity {
132+
/// Overflow reported from the new solver `-Ztrait-solver=next`, which will
133+
/// be reported as an regular error as opposed to a fatal error.
134+
overflow: bool,
135+
},
132136
}
133137

134138
impl<'tcx, O> Obligation<'tcx, O> {

compiler/rustc_infer/src/traits/structural_impls.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
4646
super::CodeConstEquateError(ref a, ref b) => {
4747
write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
4848
}
49-
super::CodeAmbiguity => write!(f, "Ambiguity"),
49+
super::CodeAmbiguity { overflow: false } => write!(f, "Ambiguity"),
50+
super::CodeAmbiguity { overflow: true } => write!(f, "Overflow"),
5051
super::CodeCycle(ref cycle) => write!(f, "Cycle({:?})", cycle),
5152
}
5253
}

0 commit comments

Comments
 (0)