Skip to content

Commit 1bc3683

Browse files
committed
Auto merge of #106773 - Nilstrieb:rollup-sq73pyg, r=Nilstrieb
Rollup of 6 pull requests Successful merges: - #105806 (Support eager subdiagnostics again) - #106322 (Handle inference variables in `CollectAllMismatches` correctly) - #106579 (Suggest making private tuple struct field public) - #106714 (remove unreachable error code `E0490`) - #106751 (Fix rendering 'const' in header for intrinsics) - #106761 (Add `WaffleLapkin` to compiler reviewers) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 222d1ff + 89f9569 commit 1bc3683

File tree

32 files changed

+395
-111
lines changed

32 files changed

+395
-111
lines changed

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ E0791: include_str!("./error_codes/E0791.md"),
618618
// E0487, // unsafe use of destructor: destructor might be called while...
619619
// E0488, // lifetime of variable does not enclose its declaration
620620
// E0489, // type/lifetime parameter not in scope here
621-
E0490, // a value of type `..` is borrowed for too long
621+
// E0490, // removed: unreachable
622622
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
623623
// E0526, // shuffle indices are not constant
624624
// E0540, // multiple rustc_deprecated attributes

compiler/rustc_error_messages/locales/en-US/infer.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ infer_subtype_2 = ...so that {$requirement ->
101101
infer_reborrow = ...so that reference does not outlive borrowed content
102102
infer_reborrow_upvar = ...so that closure can access `{$name}`
103103
infer_relate_object_bound = ...so that it can be closed over into an object
104-
infer_data_borrowed = ...so that the type `{$name}` is not borrowed for too long
105104
infer_reference_outlives_referent = ...so that the reference type `{$name}` does not outlive the data it points at
106105
infer_relate_param_bound = ...so that the type `{$name}` will meet its required lifetime bounds{$continues ->
107106
[true] ...

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2929
RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound }
3030
.add_to_diagnostic(err);
3131
}
32-
infer::DataBorrowed(ty, span) => {
33-
RegionOriginNote::WithName {
34-
span,
35-
msg: fluent::infer_data_borrowed,
36-
name: &self.ty_to_string(ty),
37-
continues: false,
38-
}
39-
.add_to_diagnostic(err);
40-
}
4132
infer::ReferenceOutlivesReferent(ty, span) => {
4233
RegionOriginNote::WithName {
4334
span,
@@ -227,32 +218,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
227218
);
228219
err
229220
}
230-
infer::DataBorrowed(ty, span) => {
231-
let mut err = struct_span_err!(
232-
self.tcx.sess,
233-
span,
234-
E0490,
235-
"a value of type `{}` is borrowed for too long",
236-
self.ty_to_string(ty)
237-
);
238-
note_and_explain_region(
239-
self.tcx,
240-
&mut err,
241-
"the type is valid for ",
242-
sub,
243-
"",
244-
None,
245-
);
246-
note_and_explain_region(
247-
self.tcx,
248-
&mut err,
249-
"but the borrow lasts for ",
250-
sup,
251-
"",
252-
None,
253-
);
254-
err
255-
}
256221
infer::ReferenceOutlivesReferent(ty, span) => {
257222
let mut err = struct_span_err!(
258223
self.tcx.sess,

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -702,26 +702,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
702702
// Obtain the spans for all the places that can
703703
// influence the constraints on this value for
704704
// richer diagnostics in `static_impl_trait`.
705-
let influences: Vec<Span> = self
706-
.data
707-
.constraints
708-
.iter()
709-
.filter_map(|(constraint, origin)| match (constraint, origin) {
710-
(
711-
Constraint::VarSubVar(_, sup),
712-
SubregionOrigin::DataBorrowed(_, sp),
713-
) if sup == &node_vid => Some(*sp),
714-
_ => None,
715-
})
716-
.collect();
717-
718-
self.collect_error_for_expanding_node(
719-
graph,
720-
&mut dup_vec,
721-
node_vid,
722-
errors,
723-
influences,
724-
);
705+
706+
self.collect_error_for_expanding_node(graph, &mut dup_vec, node_vid, errors);
725707
}
726708
}
727709
}
@@ -775,7 +757,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
775757
dup_vec: &mut IndexVec<RegionVid, Option<RegionVid>>,
776758
node_idx: RegionVid,
777759
errors: &mut Vec<RegionResolutionError<'tcx>>,
778-
influences: Vec<Span>,
779760
) {
780761
// Errors in expanding nodes result from a lower-bound that is
781762
// not contained by an upper-bound.
@@ -830,7 +811,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
830811
lower_bound.region,
831812
upper_bound.origin.clone(),
832813
upper_bound.region,
833-
influences,
814+
vec![],
834815
));
835816
return;
836817
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ pub enum SubregionOrigin<'tcx> {
410410
/// Creating a pointer `b` to contents of another reference
411411
Reborrow(Span),
412412

413-
/// Data with type `Ty<'tcx>` was borrowed
414-
DataBorrowed(Ty<'tcx>, Span),
415-
416413
/// (&'a &'b T) where a >= b
417414
ReferenceOutlivesReferent(Ty<'tcx>, Span),
418415

@@ -1978,7 +1975,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
19781975
RelateParamBound(a, ..) => a,
19791976
RelateRegionParamBound(a) => a,
19801977
Reborrow(a) => a,
1981-
DataBorrowed(_, a) => a,
19821978
ReferenceOutlivesReferent(_, a) => a,
19831979
CompareImplItemObligation { span, .. } => span,
19841980
AscribeUserTypeProvePredicate(span) => span,

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,26 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
382382
return Ok(quote! { #diag.subdiagnostic(#binding); });
383383
}
384384
}
385-
(Meta::List(_), "subdiagnostic") => {
386-
throw_invalid_attr!(attr, &meta, |diag| {
387-
diag.help("`subdiagnostic` does not support nested attributes")
388-
})
385+
(Meta::List(MetaList { ref nested, .. }), "subdiagnostic") => {
386+
if nested.len() == 1
387+
&& let Some(NestedMeta::Meta(Meta::Path(path))) = nested.first()
388+
&& path.is_ident("eager") {
389+
let handler = match &self.parent.kind {
390+
DiagnosticDeriveKind::Diagnostic { handler } => handler,
391+
DiagnosticDeriveKind::LintDiagnostic => {
392+
throw_invalid_attr!(attr, &meta, |diag| {
393+
diag.help("eager subdiagnostics are not supported on lints")
394+
})
395+
}
396+
};
397+
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
398+
} else {
399+
throw_invalid_attr!(attr, &meta, |diag| {
400+
diag.help(
401+
"`eager` is the only supported nested attribute for `subdiagnostic`",
402+
)
403+
})
404+
}
389405
}
390406
_ => (),
391407
}

compiler/rustc_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(allow_internal_unstable)]
22
#![feature(if_let_guard)]
3+
#![feature(let_chains)]
34
#![feature(never_type)]
45
#![feature(proc_macro_diagnostic)]
56
#![feature(proc_macro_span)]

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
334334
self.r.field_names.insert(def_id, field_names);
335335
}
336336

337+
fn insert_field_visibilities_local(&mut self, def_id: DefId, vdata: &ast::VariantData) {
338+
let field_vis = vdata
339+
.fields()
340+
.iter()
341+
.map(|field| field.vis.span.until(field.ident.map_or(field.ty.span, |i| i.span)))
342+
.collect();
343+
self.r.field_visibility_spans.insert(def_id, field_vis);
344+
}
345+
337346
fn insert_field_names_extern(&mut self, def_id: DefId) {
338347
let field_names =
339348
self.r.cstore().struct_field_names_untracked(def_id, self.r.session).collect();
@@ -737,6 +746,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
737746

738747
// Record field names for error reporting.
739748
self.insert_field_names_local(def_id, vdata);
749+
self.insert_field_visibilities_local(def_id, vdata);
740750

741751
// If this is a tuple or unit struct, define a name
742752
// in the value namespace as well.
@@ -770,6 +780,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
770780
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id.to_def_id());
771781
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, sp, expansion));
772782
self.r.visibilities.insert(ctor_def_id, ctor_vis);
783+
// We need the field visibility spans also for the constructor for E0603.
784+
self.insert_field_visibilities_local(ctor_def_id.to_def_id(), vdata);
773785

774786
self.r
775787
.struct_constructors
@@ -783,6 +795,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
783795

784796
// Record field names for error reporting.
785797
self.insert_field_names_local(def_id, vdata);
798+
self.insert_field_visibilities_local(def_id, vdata);
786799
}
787800

788801
ItemKind::Trait(..) => {
@@ -1510,6 +1523,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
15101523

15111524
// Record field names for error reporting.
15121525
self.insert_field_names_local(def_id.to_def_id(), &variant.data);
1526+
self.insert_field_visibilities_local(def_id.to_def_id(), &variant.data);
15131527

15141528
visit::walk_variant(self, variant);
15151529
}

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use rustc_ast::{self as ast, Crate, ItemKind, ModKind, NodeId, Path, CRATE_NODE_
66
use rustc_ast_pretty::pprust;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_errors::struct_span_err;
9-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
9+
use rustc_errors::{
10+
pluralize, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
11+
};
1012
use rustc_feature::BUILTIN_ATTRIBUTES;
1113
use rustc_hir::def::Namespace::{self, *};
1214
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
@@ -1604,6 +1606,16 @@ impl<'a> Resolver<'a> {
16041606
err.span_label(ident.span, &format!("private {}", descr));
16051607
if let Some(span) = ctor_fields_span {
16061608
err.span_label(span, "a constructor is private if any of the fields is private");
1609+
if let Res::Def(_, d) = res && let Some(fields) = self.field_visibility_spans.get(&d) {
1610+
err.multipart_suggestion_verbose(
1611+
&format!(
1612+
"consider making the field{} publicly accessible",
1613+
pluralize!(fields.len())
1614+
),
1615+
fields.iter().map(|span| (*span, "pub ".to_string())).collect(),
1616+
Applicability::MaybeIncorrect,
1617+
);
1618+
}
16071619
}
16081620

16091621
// Print the whole import chain to make it easier to see what happens.

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,17 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
14511451
.collect();
14521452

14531453
if non_visible_spans.len() > 0 {
1454+
if let Some(fields) = self.r.field_visibility_spans.get(&def_id) {
1455+
err.multipart_suggestion_verbose(
1456+
&format!(
1457+
"consider making the field{} publicly accessible",
1458+
pluralize!(fields.len())
1459+
),
1460+
fields.iter().map(|span| (*span, "pub ".to_string())).collect(),
1461+
Applicability::MaybeIncorrect,
1462+
);
1463+
}
1464+
14541465
let mut m: MultiSpan = non_visible_spans.clone().into();
14551466
non_visible_spans
14561467
.into_iter()

0 commit comments

Comments
 (0)