Skip to content

Commit 1bc3683

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

32 files changed

+395
-111
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
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

-1
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

-35
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

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

-4
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

+20-4
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

+1
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

+14
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

+13-1
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

+11
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()

compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ pub struct Resolver<'a> {
881881
/// Used for hints during error reporting.
882882
field_names: FxHashMap<DefId, Vec<Spanned<Symbol>>>,
883883

884+
/// Span of the privacy modifier in fields of an item `DefId` accessible with dot syntax.
885+
/// Used for hints during error reporting.
886+
field_visibility_spans: FxHashMap<DefId, Vec<Span>>,
887+
884888
/// All imports known to succeed or fail.
885889
determined_imports: Vec<&'a Import<'a>>,
886890

@@ -1268,6 +1272,7 @@ impl<'a> Resolver<'a> {
12681272

12691273
has_self: FxHashSet::default(),
12701274
field_names: FxHashMap::default(),
1275+
field_visibility_spans: FxHashMap::default(),
12711276

12721277
determined_imports: Vec::new(),
12731278
indeterminate_imports: Vec::new(),

compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
5555

5656
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
5757
self.infcx.probe(|_| {
58-
if a.is_ty_infer() || b.is_ty_infer() {
58+
if a.is_ty_var() || b.is_ty_var() {
5959
Ok(a)
6060
} else {
6161
self.infcx.super_combine_tys(self, a, b).or_else(|e| {
@@ -71,10 +71,13 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
7171
a: ty::Const<'tcx>,
7272
b: ty::Const<'tcx>,
7373
) -> RelateResult<'tcx, ty::Const<'tcx>> {
74-
if a == b {
75-
return Ok(a);
76-
}
77-
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
74+
self.infcx.probe(|_| {
75+
if a.is_ct_infer() || b.is_ct_infer() {
76+
Ok(a)
77+
} else {
78+
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
79+
}
80+
})
7881
}
7982

8083
fn binders<T: Relate<'tcx>>(

src/librustdoc/clean/types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,23 @@ impl Item {
676676
}
677677
let header = match *self.kind {
678678
ItemKind::ForeignFunctionItem(_) => {
679-
let abi = tcx.fn_sig(self.item_id.as_def_id().unwrap()).abi();
679+
let def_id = self.item_id.as_def_id().unwrap();
680+
let abi = tcx.fn_sig(def_id).abi();
680681
hir::FnHeader {
681682
unsafety: if abi == Abi::RustIntrinsic {
682683
intrinsic_operation_unsafety(tcx, self.item_id.as_def_id().unwrap())
683684
} else {
684685
hir::Unsafety::Unsafe
685686
},
686687
abi,
687-
constness: hir::Constness::NotConst,
688+
constness: if abi == Abi::RustIntrinsic
689+
&& tcx.is_const_fn(def_id)
690+
&& is_unstable_const_fn(tcx, def_id).is_none()
691+
{
692+
hir::Constness::Const
693+
} else {
694+
hir::Constness::NotConst
695+
},
688696
asyncness: hir::IsAsync::NotAsync,
689697
}
690698
}

src/tools/tidy/src/error_codes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ const IGNORE_DOCTEST_CHECK: &[&str] =
3131
&["E0208", "E0464", "E0570", "E0601", "E0602", "E0640", "E0717"];
3232

3333
// Error codes that don't yet have a UI test. This list will eventually be removed.
34-
const IGNORE_UI_TEST_CHECK: &[&str] = &[
35-
"E0461", "E0465", "E0476", "E0490", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729",
36-
"E0789",
37-
];
34+
const IGNORE_UI_TEST_CHECK: &[&str] =
35+
&["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729", "E0789"];
3836

3937
macro_rules! verbose_print {
4038
($verbose:expr, $($fmt:tt)*) => {

tests/rustdoc/const-intrinsic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(intrinsics)]
2+
#![feature(staged_api)]
3+
4+
#![crate_name = "foo"]
5+
#![stable(since="1.0.0", feature="rust1")]
6+
7+
extern "rust-intrinsic" {
8+
// @has 'foo/fn.transmute.html'
9+
// @has - '//pre[@class="rust fn"]' 'pub const unsafe extern "rust-intrinsic" fn transmute<T, U>(_: T) -> U'
10+
#[stable(since="1.0.0", feature="rust1")]
11+
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
12+
pub fn transmute<T, U>(_: T) -> U;
13+
14+
// @has 'foo/fn.unreachable.html'
15+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
16+
#[stable(since="1.0.0", feature="rust1")]
17+
pub fn unreachable() -> !;
18+
}
19+
20+
extern "C" {
21+
// @has 'foo/fn.needs_drop.html'
22+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "C" fn needs_drop() -> !'
23+
#[stable(since="1.0.0", feature="rust1")]
24+
pub fn needs_drop() -> !;
25+
}

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ struct SubdiagnosticEagerLint {
723723
#[diag(compiletest_example)]
724724
struct SubdiagnosticEagerCorrect {
725725
#[subdiagnostic(eager)]
726-
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
727726
note: Note,
728727
}
729728

@@ -744,7 +743,6 @@ pub(crate) struct SubdiagnosticWithSuggestion {
744743
#[diag(compiletest_example)]
745744
struct SubdiagnosticEagerSuggestion {
746745
#[subdiagnostic(eager)]
747-
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
748746
sub: SubdiagnosticWithSuggestion,
749747
}
750748

0 commit comments

Comments
 (0)