Skip to content

Commit f3d71c9

Browse files
committed
Auto merge of #120496 - GuillaumeGomez:rollup-fmu9jre, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - #117906 (Improve display of crate name when hovered) - #118533 (Suppress unhelpful diagnostics for unresolved top level attributes) - #120293 (Deduplicate more sized errors on call exprs) - #120295 (Remove `raw_os_nonzero` feature.) - #120310 (adapt test for v0 symbol mangling) - #120342 (Remove various `has_errors` or `err_count` uses) - #120434 (Revert outdated version of "Add the wasm32-wasi-preview2 target") - #120445 (Fix some `Arc` allocator leaks) - #120475 (Improve error message when `cargo build` is used to build the compiler) - #120476 (Remove some unnecessary check logic for lang items in HIR typeck) - #120485 (add missing potential_query_instability for keys and values in hashmap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5ad7454 + 27bc496 commit f3d71c9

File tree

190 files changed

+885
-1603
lines changed

Some content is hidden

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

190 files changed

+885
-1603
lines changed

compiler/rustc_builtin_macros/src/format.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
139139
_ => {
140140
let expr = p.parse_expr()?;
141141
if !args.named_args().is_empty() {
142-
ecx.dcx().emit_err(errors::PositionalAfterNamed {
142+
return Err(ecx.dcx().create_err(errors::PositionalAfterNamed {
143143
span: expr.span,
144144
args: args
145145
.named_args()
146146
.iter()
147147
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
148148
.map(|(arg, n)| n.span.to(arg.expr.span))
149149
.collect(),
150-
});
150+
}));
151151
}
152152
args.add(FormatArgument { kind: FormatArgumentKind::Normal, expr });
153153
}
@@ -313,6 +313,8 @@ fn make_format_args(
313313
}
314314
use ArgRef::*;
315315

316+
let mut unnamed_arg_after_named_arg = false;
317+
316318
let mut lookup_arg = |arg: ArgRef<'_>,
317319
span: Option<Span>,
318320
used_as: PositionUsedAs,
@@ -352,6 +354,7 @@ fn make_format_args(
352354
// For the moment capturing variables from format strings expanded from macros is
353355
// disabled (see RFC #2795)
354356
ecx.dcx().emit_err(errors::FormatNoArgNamed { span, name });
357+
unnamed_arg_after_named_arg = true;
355358
DummyResult::raw_expr(span, true)
356359
};
357360
Ok(args.add(FormatArgument { kind: FormatArgumentKind::Captured(ident), expr }))
@@ -510,7 +513,8 @@ fn make_format_args(
510513
})
511514
.collect::<Vec<_>>();
512515

513-
if !unused.is_empty() {
516+
let has_unused = !unused.is_empty();
517+
if has_unused {
514518
// If there's a lot of unused arguments,
515519
// let's check if this format arguments looks like another syntax (printf / shell).
516520
let detect_foreign_fmt = unused.len() > args.explicit_args().len() / 2;
@@ -529,7 +533,7 @@ fn make_format_args(
529533

530534
// Only check for unused named argument names if there are no other errors to avoid causing
531535
// too much noise in output errors, such as when a named argument is entirely unused.
532-
if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() {
536+
if invalid_refs.is_empty() && !has_unused && !unnamed_arg_after_named_arg {
533537
for &(index, span, used_as) in &numeric_refences_to_named_arg {
534538
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
535539
Placeholder(pspan) => (span, pspan),

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
403403
let mut result = items.clone();
404404

405405
for cgu in cgus {
406+
#[allow(rustc::potential_query_instability)]
406407
for item in cgu.items().keys() {
407408
if let mir::mono::MonoItem::Fn(ref instance) = item {
408409
let did = instance.def_id();

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl CguReuseTracker {
267267

268268
fn check_expected_reuse(&self, sess: &Session) {
269269
if let Some(ref data) = self.data {
270+
#[allow(rustc::potential_query_instability)]
270271
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
271272
keys.sort_unstable();
272273
for cgu_name in keys {

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ fn link_dwarf_object<'a>(
682682
}
683683

684684
// Input rlibs contain .o/.dwo files from dependencies.
685+
#[allow(rustc::potential_query_instability)]
685686
let input_rlibs = cg_results
686687
.crate_info
687688
.used_crate_source

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub enum StashKey {
514514
MaybeForgetReturn,
515515
/// Query cycle detected, stashing in favor of a better error.
516516
Cycle,
517+
UndeterminedMacroResolution,
517518
}
518519

519520
fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {

compiler/rustc_expand/src/mbe/macro_rules.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ pub fn compile_declarative_macro(
485485
)
486486
.pop()
487487
.unwrap();
488-
valid &= check_lhs_nt_follows(sess, def, &tt);
488+
// We don't handle errors here, the driver will abort
489+
// after parsing/expansion. we can report every error in every macro this way.
490+
valid &= check_lhs_nt_follows(sess, def, &tt).is_ok();
489491
return tt;
490492
}
491493
sess.dcx().span_bug(def.span, "wrong-structured lhs")
@@ -589,18 +591,19 @@ pub fn compile_declarative_macro(
589591
(mk_syn_ext(expander), rule_spans)
590592
}
591593

592-
fn check_lhs_nt_follows(sess: &Session, def: &ast::Item, lhs: &mbe::TokenTree) -> bool {
594+
fn check_lhs_nt_follows(
595+
sess: &Session,
596+
def: &ast::Item,
597+
lhs: &mbe::TokenTree,
598+
) -> Result<(), ErrorGuaranteed> {
593599
// lhs is going to be like TokenTree::Delimited(...), where the
594600
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
595601
if let mbe::TokenTree::Delimited(.., delimited) = lhs {
596602
check_matcher(sess, def, &delimited.tts)
597603
} else {
598604
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
599-
sess.dcx().span_err(lhs.span(), msg);
600-
false
605+
Err(sess.dcx().span_err(lhs.span(), msg))
601606
}
602-
// we don't abort on errors on rejection, the driver will do that for us
603-
// after parsing/expansion. we can report every error in every macro this way.
604607
}
605608

606609
fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
@@ -675,12 +678,15 @@ fn check_rhs(sess: &Session, rhs: &mbe::TokenTree) -> bool {
675678
false
676679
}
677680

678-
fn check_matcher(sess: &Session, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
681+
fn check_matcher(
682+
sess: &Session,
683+
def: &ast::Item,
684+
matcher: &[mbe::TokenTree],
685+
) -> Result<(), ErrorGuaranteed> {
679686
let first_sets = FirstSets::new(matcher);
680687
let empty_suffix = TokenSet::empty();
681-
let err = sess.dcx().err_count();
682-
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
683-
err == sess.dcx().err_count()
688+
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix)?;
689+
Ok(())
684690
}
685691

686692
fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
@@ -1020,11 +1026,13 @@ fn check_matcher_core<'tt>(
10201026
first_sets: &FirstSets<'tt>,
10211027
matcher: &'tt [mbe::TokenTree],
10221028
follow: &TokenSet<'tt>,
1023-
) -> TokenSet<'tt> {
1029+
) -> Result<TokenSet<'tt>, ErrorGuaranteed> {
10241030
use mbe::TokenTree;
10251031

10261032
let mut last = TokenSet::empty();
10271033

1034+
let mut errored = Ok(());
1035+
10281036
// 2. For each token and suffix [T, SUFFIX] in M:
10291037
// ensure that T can be followed by SUFFIX, and if SUFFIX may be empty,
10301038
// then ensure T can also be followed by any element of FOLLOW.
@@ -1068,7 +1076,7 @@ fn check_matcher_core<'tt>(
10681076
token::CloseDelim(d.delim),
10691077
span.close,
10701078
));
1071-
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix);
1079+
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix)?;
10721080
// don't track non NT tokens
10731081
last.replace_with_irrelevant();
10741082

@@ -1100,7 +1108,7 @@ fn check_matcher_core<'tt>(
11001108
// At this point, `suffix_first` is built, and
11011109
// `my_suffix` is some TokenSet that we can use
11021110
// for checking the interior of `seq_rep`.
1103-
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix);
1111+
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix)?;
11041112
if next.maybe_empty {
11051113
last.add_all(&next);
11061114
} else {
@@ -1206,14 +1214,15 @@ fn check_matcher_core<'tt>(
12061214
));
12071215
}
12081216
}
1209-
err.emit();
1217+
errored = Err(err.emit());
12101218
}
12111219
}
12121220
}
12131221
}
12141222
}
12151223
}
1216-
last
1224+
errored?;
1225+
Ok(last)
12171226
}
12181227

12191228
fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {

compiler/rustc_hir_typeck/messages.ftl

-5
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ hir_typeck_lossy_provenance_ptr2int =
9696
hir_typeck_method_call_on_unknown_raw_pointee =
9797
cannot call a method on a raw pointer with an unknown pointee type
9898
99-
hir_typeck_missing_fn_lang_items = failed to find an overloaded call trait for closure call
100-
.help = make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods
101-
10299
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
103100
104101
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
@@ -108,8 +105,6 @@ hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {
108105
109106
hir_typeck_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
110107
111-
hir_typeck_op_trait_generic_params = `{$method_name}` must not have any generic parameters
112-
113108
hir_typeck_option_result_asref = use `{$def_path}::as_ref` to convert `{$expected_ty}` to `{$expr_ty}`
114109
hir_typeck_option_result_cloned = use `{$def_path}::cloned` to clone the value inside the `{$def_path}`
115110
hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value inside the `{$def_path}`

compiler/rustc_hir_typeck/src/callee.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7777
callee_expr,
7878
Expectation::NoExpectation,
7979
arg_exprs,
80+
Some(call_expr),
8081
),
8182
_ => self.check_expr(callee_expr),
8283
};
@@ -253,28 +254,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
253254
adjusted_ty,
254255
opt_input_type.as_ref().map(slice::from_ref),
255256
) {
256-
// Check for `self` receiver on the method, otherwise we can't use this as a `Fn*` trait.
257-
if !self.tcx.associated_item(ok.value.def_id).fn_has_self_parameter {
258-
self.dcx().span_delayed_bug(
259-
call_expr.span,
260-
"input to overloaded call fn is not a self receiver",
261-
);
262-
return None;
263-
}
264-
265257
let method = self.register_infer_ok_obligations(ok);
266258
let mut autoref = None;
267259
if borrow {
268260
// Check for &self vs &mut self in the method signature. Since this is either
269261
// the Fn or FnMut trait, it should be one of those.
270262
let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() else {
271-
// The `fn`/`fn_mut` lang item is ill-formed, which should have
272-
// caused an error elsewhere.
273-
self.dcx().span_delayed_bug(
274-
call_expr.span,
275-
"input to call/call_mut is not a ref",
276-
);
277-
return None;
263+
bug!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut")
278264
};
279265

280266
// For initial two-phase borrow
@@ -948,9 +934,11 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
948934
);
949935
}
950936
None => {
951-
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
952-
// lang items are not defined (issue #86238).
953-
fcx.dcx().emit_err(errors::MissingFnLangItems { span: self.call_expr.span });
937+
span_bug!(
938+
self.call_expr.span,
939+
"Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{}`",
940+
self.adjusted_ty
941+
)
954942
}
955943
}
956944
}

compiler/rustc_hir_typeck/src/check.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,22 @@ pub(super) fn check_fn<'a, 'tcx>(
152152
}
153153

154154
fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>) {
155+
let span = tcx.def_span(fn_id);
156+
155157
let DefKind::Fn = tcx.def_kind(fn_id) else {
156-
let span = tcx.def_span(fn_id);
157158
tcx.dcx().span_err(span, "should be a function");
158159
return;
159160
};
160161

161162
let generic_counts = tcx.generics_of(fn_id).own_counts();
162163
if generic_counts.types != 0 {
163-
let span = tcx.def_span(fn_id);
164164
tcx.dcx().span_err(span, "should have no type parameters");
165165
}
166166
if generic_counts.consts != 0 {
167-
let span = tcx.def_span(fn_id);
168167
tcx.dcx().span_err(span, "should have no const parameters");
169168
}
170169

171-
let Some(panic_info_did) = tcx.lang_items().panic_info() else {
172-
tcx.dcx().err("language item required, but not found: `panic_info`");
173-
return;
174-
};
170+
let panic_info_did = tcx.require_lang_item(hir::LangItem::PanicInfo, Some(span));
175171

176172
// build type `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !`
177173
let panic_info_ty = tcx.type_of(panic_info_did).instantiate(
@@ -203,11 +199,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
203199

204200
let _ = check_function_signature(
205201
tcx,
206-
ObligationCause::new(
207-
tcx.def_span(fn_id),
208-
fn_id,
209-
ObligationCauseCode::LangFunctionType(sym::panic_impl),
210-
),
202+
ObligationCause::new(span, fn_id, ObligationCauseCode::LangFunctionType(sym::panic_impl)),
211203
fn_id.into(),
212204
expected_sig,
213205
);

compiler/rustc_hir_typeck/src/errors.rs

-16
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ pub struct MethodCallOnUnknownRawPointee {
8383
pub span: Span,
8484
}
8585

86-
#[derive(Diagnostic)]
87-
#[diag(hir_typeck_missing_fn_lang_items)]
88-
#[help]
89-
pub struct MissingFnLangItems {
90-
#[primary_span]
91-
pub span: Span,
92-
}
93-
9486
#[derive(Diagnostic)]
9587
#[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)]
9688
pub struct FunctionalRecordUpdateOnNonStruct {
@@ -193,14 +185,6 @@ pub struct AddMissingParenthesesInRange {
193185
pub right: Span,
194186
}
195187

196-
#[derive(Diagnostic)]
197-
#[diag(hir_typeck_op_trait_generic_params)]
198-
pub struct OpMethodGenericParams {
199-
#[primary_span]
200-
pub span: Span,
201-
pub method_name: String,
202-
}
203-
204188
pub struct TypeMismatchFruTypo {
205189
/// Span of the LHS of the range
206190
pub expr_span: Span,

0 commit comments

Comments
 (0)