Skip to content

Commit 886b2c3

Browse files
committed
Auto merge of rust-lang#107650 - compiler-errors:rollup-4pntchf, r=compiler-errors
Rollup of 8 pull requests Successful merges: - rust-lang#106887 (Make const/fn return params more suggestable) - rust-lang#107519 (Add type alias for raw OS errors) - rust-lang#107551 ( Replace `ConstFnMutClosure` with const closures ) - rust-lang#107595 (Retry opening proc-macro DLLs a few times on Windows.) - rust-lang#107615 (Replace nbsp in all rustdoc code blocks) - rust-lang#107621 (Intern external constraints in new solver) - rust-lang#107631 (loudly tell people when they change `Cargo.lock`) - rust-lang#107632 (Clarifying that .map() returns None if None.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 658fad6 + 13bd75f commit 886b2c3

Some content is hidden

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

44 files changed

+391
-249
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2945,12 +2945,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29452945
if r.is_erased() { tcx.lifetimes.re_static } else { r }
29462946
});
29472947
let span = ast_ty.span;
2948-
tcx.sess.emit_err(TypeofReservedKeywordUsed {
2949-
span,
2950-
ty,
2951-
opt_sugg: Some((span, Applicability::MachineApplicable))
2952-
.filter(|_| ty.is_suggestable(tcx, false)),
2953-
});
2948+
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
2949+
(ty, Some((span, Applicability::MachineApplicable)))
2950+
} else {
2951+
(ty, None)
2952+
};
2953+
tcx.sess.emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg });
29542954

29552955
ty
29562956
}

compiler/rustc_hir_analysis/src/collect.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -1199,28 +1199,22 @@ fn infer_return_ty_for_fn_sig<'tcx>(
11991199
visitor.visit_ty(ty);
12001200
let mut diag = bad_placeholder(tcx, visitor.0, "return type");
12011201
let ret_ty = fn_sig.output();
1202-
if ret_ty.is_suggestable(tcx, false) {
1202+
if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false) {
12031203
diag.span_suggestion(
12041204
ty.span,
12051205
"replace with the correct return type",
12061206
ret_ty,
12071207
Applicability::MachineApplicable,
12081208
);
1209-
} else if matches!(ret_ty.kind(), ty::FnDef(..)) {
1210-
let fn_sig = ret_ty.fn_sig(tcx);
1211-
if fn_sig
1212-
.skip_binder()
1213-
.inputs_and_output
1214-
.iter()
1215-
.all(|t| t.is_suggestable(tcx, false))
1216-
{
1217-
diag.span_suggestion(
1218-
ty.span,
1219-
"replace with the correct return type",
1220-
fn_sig,
1221-
Applicability::MachineApplicable,
1222-
);
1223-
}
1209+
} else if matches!(ret_ty.kind(), ty::FnDef(..))
1210+
&& let Some(fn_sig) = ret_ty.fn_sig(tcx).make_suggestable(tcx, false)
1211+
{
1212+
diag.span_suggestion(
1213+
ty.span,
1214+
"replace with the correct return type",
1215+
fn_sig,
1216+
Applicability::MachineApplicable,
1217+
);
12241218
} else if let Some(sugg) = suggest_impl_trait(tcx, ret_ty, ty.span, hir_id, def_id) {
12251219
diag.span_suggestion(
12261220
ty.span,
@@ -1280,9 +1274,7 @@ fn suggest_impl_trait<'tcx>(
12801274
let trait_name = tcx.item_name(trait_def_id);
12811275
let args_tuple = substs.type_at(1);
12821276
let ty::Tuple(types) = *args_tuple.kind() else { return None; };
1283-
if !types.is_suggestable(tcx, false) {
1284-
return None;
1285-
}
1277+
let types = types.make_suggestable(tcx, false)?;
12861278
let maybe_ret =
12871279
if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") };
12881280
Some(format!(
@@ -1337,7 +1329,7 @@ fn suggest_impl_trait<'tcx>(
13371329
// FIXME(compiler-errors): We may benefit from resolving regions here.
13381330
if ocx.select_where_possible().is_empty()
13391331
&& let item_ty = infcx.resolve_vars_if_possible(item_ty)
1340-
&& item_ty.is_suggestable(tcx, false)
1332+
&& let Some(item_ty) = item_ty.make_suggestable(tcx, false)
13411333
&& let Some(sugg) = formatter(tcx, infcx.resolve_vars_if_possible(substs), trait_def_id, assoc_item_def_id, item_ty)
13421334
{
13431335
return Some(sugg);

compiler/rustc_hir_analysis/src/collect/type_of.rs

+14-33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_middle::hir::nested_filter;
88
use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::subst::InternalSubsts;
1010
use rustc_middle::ty::util::IntTypeExt;
11-
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
11+
use rustc_middle::ty::{
12+
self, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable,
13+
};
1214
use rustc_span::symbol::Ident;
1315
use rustc_span::{Span, DUMMY_SP};
1416

@@ -845,37 +847,23 @@ fn infer_placeholder_type<'a>(
845847
) -> Ty<'a> {
846848
// Attempts to make the type nameable by turning FnDefs into FnPtrs.
847849
struct MakeNameable<'tcx> {
848-
success: bool,
849850
tcx: TyCtxt<'tcx>,
850851
}
851852

852-
impl<'tcx> MakeNameable<'tcx> {
853-
fn new(tcx: TyCtxt<'tcx>) -> Self {
854-
MakeNameable { success: true, tcx }
855-
}
856-
}
857-
858853
impl<'tcx> TypeFolder<'tcx> for MakeNameable<'tcx> {
859854
fn tcx(&self) -> TyCtxt<'tcx> {
860855
self.tcx
861856
}
862857

863858
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
864-
if !self.success {
865-
return ty;
866-
}
867-
868-
match ty.kind() {
859+
let ty = match *ty.kind() {
869860
ty::FnDef(def_id, substs) => {
870-
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst(self.tcx, substs))
861+
self.tcx.mk_fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs))
871862
}
872-
// FIXME: non-capturing closures should also suggest a function pointer
873-
ty::Closure(..) | ty::Generator(..) => {
874-
self.success = false;
875-
ty
876-
}
877-
_ => ty.super_fold_with(self),
878-
}
863+
_ => ty,
864+
};
865+
866+
ty.super_fold_with(self)
879867
}
880868
}
881869

@@ -898,15 +886,11 @@ fn infer_placeholder_type<'a>(
898886
suggestions.clear();
899887
}
900888

901-
// Suggesting unnameable types won't help.
902-
let mut mk_nameable = MakeNameable::new(tcx);
903-
let ty = mk_nameable.fold_ty(ty);
904-
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
905-
if let Some(sugg_ty) = sugg_ty {
889+
if let Some(ty) = ty.make_suggestable(tcx, false) {
906890
err.span_suggestion(
907891
span,
908892
&format!("provide a type for the {item}", item = kind),
909-
format!("{colon} {sugg_ty}"),
893+
format!("{colon} {ty}"),
910894
Applicability::MachineApplicable,
911895
);
912896
} else {
@@ -923,15 +907,12 @@ fn infer_placeholder_type<'a>(
923907
let mut diag = bad_placeholder(tcx, vec![span], kind);
924908

925909
if !ty.references_error() {
926-
let mut mk_nameable = MakeNameable::new(tcx);
927-
let ty = mk_nameable.fold_ty(ty);
928-
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
929-
if let Some(sugg_ty) = sugg_ty {
910+
if let Some(ty) = ty.make_suggestable(tcx, false) {
930911
diag.span_suggestion(
931912
span,
932913
"replace with the correct type",
933-
sugg_ty,
934-
Applicability::MaybeIncorrect,
914+
ty,
915+
Applicability::MachineApplicable,
935916
);
936917
} else {
937918
with_forced_trimmed_paths!(diag.span_note(

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
687687
return true;
688688
}
689689
&hir::FnRetTy::DefaultReturn(span) if expected.is_unit() => {
690-
if found.is_suggestable(self.tcx, false) {
690+
if let Some(found) = found.make_suggestable(self.tcx, false) {
691691
err.subdiagnostic(AddReturnTypeSuggestion::Add { span, found: found.to_string() });
692692
return true;
693693
} else if let ty::Closure(_, substs) = found.kind()

compiler/rustc_hir_typeck/src/op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
490490
if let Some(output_def_id) = output_def_id
491491
&& let Some(trait_def_id) = trait_def_id
492492
&& self.tcx.parent(output_def_id) == trait_def_id
493-
&& output_ty.is_suggestable(self.tcx, false)
493+
&& let Some(output_ty) = output_ty.make_suggestable(self.tcx, false)
494494
{
495-
Some(("Output", *output_ty))
495+
Some(("Output", output_ty))
496496
} else {
497497
None
498498
}

compiler/rustc_metadata/src/creader.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple};
3333
use proc_macro::bridge::client::ProcMacro;
3434
use std::ops::Fn;
3535
use std::path::Path;
36+
use std::time::Duration;
3637
use std::{cmp, env};
3738

3839
#[derive(Clone)]
@@ -689,8 +690,7 @@ impl<'a> CrateLoader<'a> {
689690
) -> Result<&'static [ProcMacro], CrateError> {
690691
// Make sure the path contains a / or the linker will search for it.
691692
let path = env::current_dir().unwrap().join(path);
692-
let lib = unsafe { libloading::Library::new(path) }
693-
.map_err(|err| CrateError::DlOpen(err.to_string()))?;
693+
let lib = load_dylib(&path, 5).map_err(|err| CrateError::DlOpen(err))?;
694694

695695
let sym_name = self.sess.generate_proc_macro_decls_symbol(stable_crate_id);
696696
let sym = unsafe { lib.get::<*const &[ProcMacro]>(sym_name.as_bytes()) }
@@ -1093,3 +1093,41 @@ fn alloc_error_handler_spans(sess: &Session, krate: &ast::Crate) -> Vec<Span> {
10931093
visit::walk_crate(&mut f, krate);
10941094
f.spans
10951095
}
1096+
1097+
// On Windows the compiler would sometimes intermittently fail to open the
1098+
// proc-macro DLL with `Error::LoadLibraryExW`. It is suspected that something in the
1099+
// system still holds a lock on the file, so we retry a few times before calling it
1100+
// an error.
1101+
fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, String> {
1102+
assert!(max_attempts > 0);
1103+
1104+
let mut last_error = None;
1105+
1106+
for attempt in 0..max_attempts {
1107+
match unsafe { libloading::Library::new(&path) } {
1108+
Ok(lib) => {
1109+
if attempt > 0 {
1110+
debug!(
1111+
"Loaded proc-macro `{}` after {} attempts.",
1112+
path.display(),
1113+
attempt + 1
1114+
);
1115+
}
1116+
return Ok(lib);
1117+
}
1118+
Err(err) => {
1119+
// Only try to recover from this specific error.
1120+
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
1121+
return Err(err.to_string());
1122+
}
1123+
1124+
last_error = Some(err);
1125+
std::thread::sleep(Duration::from_millis(100));
1126+
debug!("Failed to load proc-macro `{}`. Retrying.", path.display());
1127+
}
1128+
}
1129+
}
1130+
1131+
debug!("Failed to load proc-macro `{}` even after {} attempts.", path.display(), max_attempts);
1132+
Err(format!("{} (retried {} times)", last_error.unwrap(), max_attempts))
1133+
}

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ macro_rules! arena_types {
112112

113113
[decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
114114
[] bit_set_u32: rustc_index::bit_set::BitSet<u32>,
115+
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>,
115116
]);
116117
)
117118
}

compiler/rustc_middle/src/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
mod chalk;
66
pub mod query;
77
pub mod select;
8+
pub mod solve;
89
pub mod specialization_graph;
910
mod structural_impls;
1011
pub mod util;
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::ops::ControlFlow;
2+
3+
use rustc_data_structures::intern::Interned;
4+
5+
use crate::ty::{FallibleTypeFolder, Ty, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor};
6+
7+
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
8+
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
9+
10+
impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
11+
type Target = ExternalConstraintsData<'tcx>;
12+
13+
fn deref(&self) -> &Self::Target {
14+
&*self.0
15+
}
16+
}
17+
18+
/// Additional constraints returned on success.
19+
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
20+
pub struct ExternalConstraintsData<'tcx> {
21+
// FIXME: implement this.
22+
pub regions: (),
23+
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
24+
}
25+
26+
impl<'tcx> TypeFoldable<'tcx> for ExternalConstraints<'tcx> {
27+
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
28+
Ok(FallibleTypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
29+
regions: (),
30+
opaque_types: self
31+
.opaque_types
32+
.iter()
33+
.map(|opaque| opaque.try_fold_with(folder))
34+
.collect::<Result<_, F::Error>>()?,
35+
}))
36+
}
37+
38+
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
39+
TypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
40+
regions: (),
41+
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
42+
})
43+
}
44+
}
45+
46+
impl<'tcx> TypeVisitable<'tcx> for ExternalConstraints<'tcx> {
47+
fn visit_with<V: TypeVisitor<'tcx>>(
48+
&self,
49+
visitor: &mut V,
50+
) -> std::ops::ControlFlow<V::BreakTy> {
51+
self.regions.visit_with(visitor)?;
52+
self.opaque_types.visit_with(visitor)?;
53+
ControlFlow::Continue(())
54+
}
55+
}

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::mir::{
1717
};
1818
use crate::thir::Thir;
1919
use crate::traits;
20+
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData};
2021
use crate::ty::query::{self, TyCtxtAt};
2122
use crate::ty::{
2223
self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, DefIdTree, FloatTy, FloatVar,
@@ -148,6 +149,7 @@ pub struct CtxtInterners<'tcx> {
148149
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
149150
layout: InternedSet<'tcx, LayoutS<VariantIdx>>,
150151
adt_def: InternedSet<'tcx, AdtDefData>,
152+
external_constraints: InternedSet<'tcx, ExternalConstraintsData<'tcx>>,
151153
}
152154

153155
impl<'tcx> CtxtInterners<'tcx> {
@@ -169,6 +171,7 @@ impl<'tcx> CtxtInterners<'tcx> {
169171
bound_variable_kinds: Default::default(),
170172
layout: Default::default(),
171173
adt_def: Default::default(),
174+
external_constraints: Default::default(),
172175
}
173176
}
174177

@@ -1449,6 +1452,7 @@ direct_interners! {
14491452
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
14501453
layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>,
14511454
adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>,
1455+
external_constraints: intern_external_constraints(ExternalConstraintsData<'tcx>): ExternalConstraints -> ExternalConstraints<'tcx>,
14521456
}
14531457

14541458
macro_rules! slice_interners {

0 commit comments

Comments
 (0)