Skip to content

Commit 69b12ff

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 9aa3f05 + 749b487 commit 69b12ff

File tree

28 files changed

+446
-179
lines changed

28 files changed

+446
-179
lines changed

compiler/rustc_builtin_macros/src/test_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn inject(krate: &mut ast::Crate, sess: &Session, resolver: &mut dyn Resolve
5353
// even in non-test builds
5454
let test_runner = get_test_runner(span_diagnostic, &krate);
5555

56-
if sess.opts.test {
56+
if sess.is_test_crate() {
5757
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
5858
(PanicStrategy::Abort, true) => PanicStrategy::Abort,
5959
(PanicStrategy::Abort, false) => {

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ fn add_native_libs_from_crate(
23012301
|| (whole_archive == None
23022302
&& bundle
23032303
&& cnum == LOCAL_CRATE
2304-
&& sess.opts.test);
2304+
&& sess.is_test_crate());
23052305

23062306
if bundle && cnum != LOCAL_CRATE {
23072307
if let Some(filename) = lib.filename {

compiler/rustc_hir_analysis/messages.ftl

+36
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,39 @@ hir_analysis_return_type_notation_equality_bound =
189189
190190
hir_analysis_return_type_notation_missing_method =
191191
cannot find associated function `{$assoc_name}` in trait `{$trait_name}`
192+
193+
hir_analysis_placeholder_not_allowed_item_signatures = the placeholder `_` is not allowed within types on item signatures for {$kind}
194+
.label = not allowed in type signatures
195+
196+
hir_analysis_associated_type_trait_uninferred_generic_params = cannot use the associated type of a trait with uninferred generic parameters
197+
.suggestion = use a fully qualified path with inferred lifetimes
198+
199+
hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion = use a fully qualified path with explicit lifetimes
200+
201+
hir_analysis_enum_discriminant_overflowed = enum discriminant overflowed
202+
.label = overflowed on value after {$discr}
203+
.note = explicitly set `{$item_name} = {$wrapped_discr}` if that is desired outcome
204+
205+
hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation
206+
.help = add `#![feature(unboxed_closures)]` to the crate attributes to use it
207+
208+
hir_analysis_must_implement_one_of_attribute = the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
209+
210+
hir_analysis_must_be_name_of_associated_function = must be a name of an associated function
211+
212+
hir_analysis_function_not_have_default_implementation = function doesn't have a default implementation
213+
.note = required by this annotation
214+
215+
hir_analysis_must_implement_not_function = not a function
216+
217+
hir_analysis_must_implement_not_function_span_note = required by this annotation
218+
219+
hir_analysis_must_implement_not_function_note = all `#[rustc_must_implement_one_of]` arguments must be associated function names
220+
221+
hir_analysis_function_not_found_in_trait = function not found in this trait
222+
223+
hir_analysis_functions_names_duplicated = functions names are duplicated
224+
.note = all `#[rustc_must_implement_one_of]` arguments must be unique
225+
226+
hir_analysis_simd_ffi_highly_experimental = use of SIMD type{$snip} in FFI is highly experimental and may result in invalid code
227+
.help = add `#![feature(simd_ffi)]` to the crate attributes to enable

compiler/rustc_hir_analysis/src/collect.rs

+55-110
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::errors;
2020
use hir::def::DefKind;
2121
use rustc_data_structures::captures::Captures;
2222
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
23-
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
23+
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
2424
use rustc_hir as hir;
2525
use rustc_hir::def_id::{DefId, LocalDefId};
2626
use rustc_hir::intravisit::{self, Visitor};
@@ -333,17 +333,7 @@ fn bad_placeholder<'tcx>(
333333
let kind = if kind.ends_with('s') { format!("{}es", kind) } else { format!("{}s", kind) };
334334

335335
spans.sort();
336-
let mut err = struct_span_err!(
337-
tcx.sess,
338-
spans.clone(),
339-
E0121,
340-
"the placeholder `_` is not allowed within types on item signatures for {}",
341-
kind
342-
);
343-
for span in spans {
344-
err.span_label(span, "not allowed in type signatures");
345-
}
346-
err
336+
tcx.sess.create_err(errors::PlaceholderNotAllowedItemSignatures { spans, kind })
347337
}
348338

349339
impl<'tcx> ItemCtxt<'tcx> {
@@ -419,13 +409,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
419409
self.tcx().mk_projection(item_def_id, item_substs)
420410
} else {
421411
// There are no late-bound regions; we can just ignore the binder.
422-
let mut err = struct_span_err!(
423-
self.tcx().sess,
424-
span,
425-
E0212,
426-
"cannot use the associated type of a trait \
427-
with uninferred generic parameters"
428-
);
412+
let (mut mpart_sugg, mut inferred_sugg) = (None, None);
413+
let mut bound = String::new();
429414

430415
match self.node() {
431416
hir::Node::Field(_) | hir::Node::Ctor(_) | hir::Node::Variant(_) => {
@@ -444,31 +429,25 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
444429
(bound.span.shrink_to_lo(), format!("{}, ", lt_name))
445430
}
446431
};
447-
let suggestions = vec![
448-
(lt_sp, sugg),
449-
(
450-
span.with_hi(item_segment.ident.span.lo()),
451-
format!(
452-
"{}::",
453-
// Replace the existing lifetimes with a new named lifetime.
454-
self.tcx.replace_late_bound_regions_uncached(
455-
poly_trait_ref,
456-
|_| {
457-
self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
458-
def_id: item_def_id,
459-
index: 0,
460-
name: Symbol::intern(&lt_name),
461-
})
462-
}
463-
),
432+
mpart_sugg = Some(errors::AssociatedTypeTraitUninferredGenericParamsMultipartSuggestion {
433+
fspan: lt_sp,
434+
first: sugg,
435+
sspan: span.with_hi(item_segment.ident.span.lo()),
436+
second: format!(
437+
"{}::",
438+
// Replace the existing lifetimes with a new named lifetime.
439+
self.tcx.replace_late_bound_regions_uncached(
440+
poly_trait_ref,
441+
|_| {
442+
self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
443+
def_id: item_def_id,
444+
index: 0,
445+
name: Symbol::intern(&lt_name),
446+
})
447+
}
464448
),
465449
),
466-
];
467-
err.multipart_suggestion(
468-
"use a fully qualified path with explicit lifetimes",
469-
suggestions,
470-
Applicability::MaybeIncorrect,
471-
);
450+
});
472451
}
473452
_ => {}
474453
}
@@ -482,20 +461,23 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
482461
| hir::Node::ForeignItem(_)
483462
| hir::Node::TraitItem(_)
484463
| hir::Node::ImplItem(_) => {
485-
err.span_suggestion_verbose(
486-
span.with_hi(item_segment.ident.span.lo()),
487-
"use a fully qualified path with inferred lifetimes",
488-
format!(
489-
"{}::",
490-
// Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
491-
self.tcx.anonymize_bound_vars(poly_trait_ref).skip_binder(),
492-
),
493-
Applicability::MaybeIncorrect,
464+
inferred_sugg = Some(span.with_hi(item_segment.ident.span.lo()));
465+
bound = format!(
466+
"{}::",
467+
// Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
468+
self.tcx.anonymize_bound_vars(poly_trait_ref).skip_binder(),
494469
);
495470
}
496471
_ => {}
497472
}
498-
self.tcx().ty_error(err.emit())
473+
self.tcx().ty_error(self.tcx().sess.emit_err(
474+
errors::AssociatedTypeTraitUninferredGenericParams {
475+
span,
476+
inferred_sugg,
477+
bound,
478+
mpart_sugg,
479+
},
480+
))
499481
}
500482
}
501483

@@ -763,14 +745,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
763745
Some(discr)
764746
} else {
765747
let span = tcx.def_span(variant.def_id);
766-
struct_span_err!(tcx.sess, span, E0370, "enum discriminant overflowed")
767-
.span_label(span, format!("overflowed on value after {}", prev_discr.unwrap()))
768-
.note(&format!(
769-
"explicitly set `{} = {}` if that is desired outcome",
770-
tcx.item_name(variant.def_id),
771-
wrapped_discr
772-
))
773-
.emit();
748+
tcx.sess.emit_err(errors::EnumDiscriminantOverflowed {
749+
span,
750+
discr: prev_discr.unwrap().to_string(),
751+
item_name: tcx.item_name(variant.def_id),
752+
wrapped_discr: wrapped_discr.to_string(),
753+
});
774754
None
775755
}
776756
.unwrap_or(wrapped_discr),
@@ -915,14 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
915895

916896
let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar);
917897
if paren_sugar && !tcx.features().unboxed_closures {
918-
tcx.sess
919-
.struct_span_err(
920-
item.span,
921-
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
922-
which traits can use parenthetical notation",
923-
)
924-
.help("add `#![feature(unboxed_closures)]` to the crate attributes to use it")
925-
.emit();
898+
tcx.sess.emit_err(errors::ParenSugarAttribute { span: item.span });
926899
}
927900

928901
let is_marker = tcx.has_attr(def_id, sym::marker);
@@ -942,13 +915,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
942915
// and that they are all identifiers
943916
.and_then(|attr| match attr.meta_item_list() {
944917
Some(items) if items.len() < 2 => {
945-
tcx.sess
946-
.struct_span_err(
947-
attr.span,
948-
"the `#[rustc_must_implement_one_of]` attribute must be \
949-
used with at least 2 args",
950-
)
951-
.emit();
918+
tcx.sess.emit_err(errors::MustImplementOneOfAttribute { span: attr.span });
952919

953920
None
954921
}
@@ -957,9 +924,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
957924
.map(|item| item.ident().ok_or(item.span()))
958925
.collect::<Result<Box<[_]>, _>>()
959926
.map_err(|span| {
960-
tcx.sess
961-
.struct_span_err(span, "must be a name of an associated function")
962-
.emit();
927+
tcx.sess.emit_err(errors::MustBeNameOfAssociatedFunction { span });
963928
})
964929
.ok()
965930
.zip(Some(attr.span)),
@@ -975,33 +940,25 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
975940
match item {
976941
Some(item) if matches!(item.kind, hir::AssocItemKind::Fn { .. }) => {
977942
if !tcx.impl_defaultness(item.id.owner_id).has_value() {
978-
tcx.sess
979-
.struct_span_err(
980-
item.span,
981-
"function doesn't have a default implementation",
982-
)
983-
.span_note(attr_span, "required by this annotation")
984-
.emit();
943+
tcx.sess.emit_err(errors::FunctionNotHaveDefaultImplementation {
944+
span: item.span,
945+
note_span: attr_span,
946+
});
985947

986948
return Some(());
987949
}
988950

989951
return None;
990952
}
991953
Some(item) => {
992-
tcx.sess
993-
.struct_span_err(item.span, "not a function")
994-
.span_note(attr_span, "required by this annotation")
995-
.note(
996-
"all `#[rustc_must_implement_one_of]` arguments must be associated \
997-
function names",
998-
)
999-
.emit();
954+
tcx.sess.emit_err(errors::MustImplementNotFunction {
955+
span: item.span,
956+
span_note: errors::MustImplementNotFunctionSpanNote { span: attr_span },
957+
note: errors::MustImplementNotFunctionNote {},
958+
});
1000959
}
1001960
None => {
1002-
tcx.sess
1003-
.struct_span_err(ident.span, "function not found in this trait")
1004-
.emit();
961+
tcx.sess.emit_err(errors::FunctionNotFoundInTrait { span: ident.span });
1005962
}
1006963
}
1007964

@@ -1018,9 +975,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
1018975
for ident in &*list {
1019976
if let Some(dup) = set.insert(ident.name, ident.span) {
1020977
tcx.sess
1021-
.struct_span_err(vec![dup, ident.span], "functions names are duplicated")
1022-
.note("all `#[rustc_must_implement_one_of]` arguments must be unique")
1023-
.emit();
978+
.emit_err(errors::FunctionNamesDuplicated { spans: vec![dup, ident.span] });
1024979

1025980
no_dups = false;
1026981
}
@@ -1485,17 +1440,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
14851440
.source_map()
14861441
.span_to_snippet(ast_ty.span)
14871442
.map_or_else(|_| String::new(), |s| format!(" `{}`", s));
1488-
tcx.sess
1489-
.struct_span_err(
1490-
ast_ty.span,
1491-
&format!(
1492-
"use of SIMD type{} in FFI is highly experimental and \
1493-
may result in invalid code",
1494-
snip
1495-
),
1496-
)
1497-
.help("add `#![feature(simd_ffi)]` to the crate attributes to enable")
1498-
.emit();
1443+
tcx.sess.emit_err(errors::SIMDFFIHighlyExperimental { span: ast_ty.span, snip });
14991444
}
15001445
};
15011446
for (input, ty) in iter::zip(decl.inputs, fty.inputs().skip_binder()) {

0 commit comments

Comments
 (0)