Skip to content

Commit 8778809

Browse files
committed
Auto merge of rust-lang#101577 - Dylan-DPC:rollup-l9xw7i7, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes) - rust-lang#101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2) - rust-lang#101424 (Adjust and slightly generalize operator error suggestion) - rust-lang#101496 (Allow lower_lifetime_binder receive a closure) - rust-lang#101501 (Allow lint passes to be bound by `TyCtxt`) - rust-lang#101515 (Recover from typo where == is used in place of =) - rust-lang#101545 (Remove unnecessary `PartialOrd` and `Ord`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 24d6992 + 720a82d commit 8778809

Some content is hidden

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

59 files changed

+1038
-662
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -849,21 +849,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
849849
(body_id, generator_option)
850850
});
851851

852-
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
853-
// Lower outside new scope to preserve `is_in_loop_condition`.
854-
let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
855-
856-
let c = self.arena.alloc(hir::Closure {
857-
binder: binder_clause,
858-
capture_clause,
859-
bound_generic_params,
860-
fn_decl,
861-
body: body_id,
862-
fn_decl_span: self.lower_span(fn_decl_span),
863-
movability: generator_option,
864-
});
852+
self.lower_lifetime_binder(closure_id, generic_params, |lctx, bound_generic_params| {
853+
// Lower outside new scope to preserve `is_in_loop_condition`.
854+
let fn_decl = lctx.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
855+
856+
let c = lctx.arena.alloc(hir::Closure {
857+
binder: binder_clause,
858+
capture_clause,
859+
bound_generic_params,
860+
fn_decl,
861+
body: body_id,
862+
fn_decl_span: lctx.lower_span(fn_decl_span),
863+
movability: generator_option,
864+
});
865865

866-
hir::ExprKind::Closure(c)
866+
hir::ExprKind::Closure(c)
867+
})
867868
}
868869

869870
fn generator_movability_for_fn(
@@ -950,23 +951,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
950951
body_id
951952
});
952953

953-
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
954-
955-
// We need to lower the declaration outside the new scope, because we
956-
// have to conserve the state of being inside a loop condition for the
957-
// closure argument types.
958-
let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
959-
960-
let c = self.arena.alloc(hir::Closure {
961-
binder: binder_clause,
962-
capture_clause,
963-
bound_generic_params,
964-
fn_decl,
965-
body,
966-
fn_decl_span: self.lower_span(fn_decl_span),
967-
movability: None,
968-
});
969-
hir::ExprKind::Closure(c)
954+
self.lower_lifetime_binder(closure_id, generic_params, |lctx, bound_generic_params| {
955+
// We need to lower the declaration outside the new scope, because we
956+
// have to conserve the state of being inside a loop condition for the
957+
// closure argument types.
958+
let fn_decl = lctx.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
959+
960+
let c = lctx.arena.alloc(hir::Closure {
961+
binder: binder_clause,
962+
capture_clause,
963+
bound_generic_params,
964+
fn_decl,
965+
body,
966+
fn_decl_span: lctx.lower_span(fn_decl_span),
967+
movability: None,
968+
});
969+
hir::ExprKind::Closure(c)
970+
})
970971
}
971972

972973
/// Destructure the LHS of complex assignments.

compiler/rustc_ast_lowering/src/lib.rs

+33-20
Original file line numberDiff line numberDiff line change
@@ -810,23 +810,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
810810
/// name resolver owing to lifetime elision; this also populates the resolver's node-id->def-id
811811
/// map, so that later calls to `opt_node_id_to_def_id` that refer to these extra lifetime
812812
/// parameters will be successful.
813-
#[instrument(level = "debug", skip(self))]
813+
#[instrument(level = "debug", skip(self, in_binder))]
814814
#[inline]
815-
fn lower_lifetime_binder(
815+
fn lower_lifetime_binder<R>(
816816
&mut self,
817817
binder: NodeId,
818818
generic_params: &[GenericParam],
819-
) -> &'hir [hir::GenericParam<'hir>] {
820-
let mut generic_params: Vec<_> = self.lower_generic_params_mut(generic_params).collect();
819+
in_binder: impl FnOnce(&mut Self, &'hir [hir::GenericParam<'hir>]) -> R,
820+
) -> R {
821821
let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder);
822822
debug!(?extra_lifetimes);
823-
generic_params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
824-
self.lifetime_res_to_generic_param(ident, node_id, res)
825-
}));
823+
let extra_lifetimes: Vec<_> = extra_lifetimes
824+
.into_iter()
825+
.filter_map(|(ident, node_id, res)| {
826+
self.lifetime_res_to_generic_param(ident, node_id, res)
827+
})
828+
.collect();
829+
830+
let generic_params: Vec<_> = self
831+
.lower_generic_params_mut(generic_params)
832+
.chain(extra_lifetimes.into_iter())
833+
.collect();
826834
let generic_params = self.arena.alloc_from_iter(generic_params);
827835
debug!(?generic_params);
828836

829-
generic_params
837+
in_binder(self, generic_params)
830838
}
831839

832840
fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
@@ -1236,14 +1244,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12361244
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
12371245
}
12381246
TyKind::BareFn(ref f) => {
1239-
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1240-
hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy {
1241-
generic_params,
1242-
unsafety: self.lower_unsafety(f.unsafety),
1243-
abi: self.lower_extern(f.ext),
1244-
decl: self.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None),
1245-
param_names: self.lower_fn_params_to_names(&f.decl),
1246-
}))
1247+
self.lower_lifetime_binder(t.id, &f.generic_params, |lctx, generic_params| {
1248+
hir::TyKind::BareFn(lctx.arena.alloc(hir::BareFnTy {
1249+
generic_params,
1250+
unsafety: lctx.lower_unsafety(f.unsafety),
1251+
abi: lctx.lower_extern(f.ext),
1252+
decl: lctx.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None),
1253+
param_names: lctx.lower_fn_params_to_names(&f.decl),
1254+
}))
1255+
})
12471256
}
12481257
TyKind::Never => hir::TyKind::Never,
12491258
TyKind::Tup(ref tys) => hir::TyKind::Tup(
@@ -2143,10 +2152,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21432152
p: &PolyTraitRef,
21442153
itctx: &mut ImplTraitContext,
21452154
) -> hir::PolyTraitRef<'hir> {
2146-
let bound_generic_params =
2147-
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
2148-
let trait_ref = self.lower_trait_ref(&p.trait_ref, itctx);
2149-
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
2155+
self.lower_lifetime_binder(
2156+
p.trait_ref.ref_id,
2157+
&p.bound_generic_params,
2158+
|lctx, bound_generic_params| {
2159+
let trait_ref = lctx.lower_trait_ref(&p.trait_ref, itctx);
2160+
hir::PolyTraitRef { bound_generic_params, trait_ref, span: lctx.lower_span(p.span) }
2161+
},
2162+
)
21502163
}
21512164

21522165
fn lower_mt(&mut self, mt: &MutTy, itctx: &mut ImplTraitContext) -> hir::MutTy<'hir> {

compiler/rustc_borrowck/src/region_infer/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ pub struct RegionInferenceContext<'tcx> {
135135
/// adds a new lower bound to the SCC it is analyzing: so you wind up
136136
/// with `'R: 'O` where `'R` is the pick-region and `'O` is the
137137
/// minimal viable option.
138-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
139138
pub(crate) struct AppliedMemberConstraint {
140139
/// The SCC that was affected. (The "member region".)
141140
///

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

+3
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ parser_left_arrow_operator = unexpected token: `<-`
153153
154154
parser_remove_let = expected pattern, found `let`
155155
.suggestion = remove the unnecessary `let` keyword
156+
157+
parser_use_eq_instead = unexpected `==`
158+
.suggestion = try using `=` instead

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

+42
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,45 @@ session_feature_diagnostic_for_issue =
1414
1515
session_feature_diagnostic_help =
1616
add `#![feature({$feature})]` to the crate attributes to enable
17+
18+
session_not_circumvent_feature = `-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature gates, except when testing error paths in the CTFE engine
19+
20+
session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist.
21+
22+
session_linker_plugin_lto_windows_not_supported = linker plugin based LTO is not supported together with `-C prefer-dynamic` when targeting Windows-like targets
23+
24+
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist.
25+
26+
session_target_requires_unwind_tables = target requires unwind tables, they cannot be disabled with `-C force-unwind-tables=no`
27+
28+
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
29+
30+
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target
31+
32+
session_cannot_mix_and_match_sanitizers = `-Zsanitizer={$first}` is incompatible with `-Zsanitizer={$second}`
33+
34+
session_cannot_enable_crt_static_linux = sanitizer is incompatible with statically linked libc, disable it using `-C target-feature=-crt-static`
35+
36+
session_sanitizer_cfi_enabled = `-Zsanitizer=cfi` requires `-Clto`
37+
38+
session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination` requires `-Clto`
39+
40+
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
41+
42+
session_target_invalid_address_space = invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
43+
44+
session_target_invalid_bits = invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
45+
46+
session_target_missing_alignment = missing alignment for `{$cause}` in "data-layout"
47+
48+
session_target_invalid_alignment = invalid alignment for `{$cause}` in "data-layout": {$err}
49+
50+
session_target_inconsistent_architecture = inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
51+
52+
session_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
53+
54+
session_target_invalid_bits_size = {$err}
55+
56+
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
57+
58+
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform

compiler/rustc_errors/src/diagnostic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_span::edition::LATEST_STABLE_EDITION;
1111
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1212
use rustc_span::{edition::Edition, Span, DUMMY_SP};
13-
use rustc_target::spec::PanicStrategy;
13+
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
1414
use std::borrow::Cow;
1515
use std::fmt;
1616
use std::hash::{Hash, Hasher};
17+
use std::num::ParseIntError;
1718
use std::path::{Path, PathBuf};
1819

1920
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
@@ -91,6 +92,10 @@ into_diagnostic_arg_using_display!(
9192
Edition,
9293
Ident,
9394
MacroRulesNormalizedIdent,
95+
ParseIntError,
96+
StackProtector,
97+
&TargetTriple,
98+
SplitDebuginfo
9499
);
95100

96101
impl IntoDiagnosticArg for bool {

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ struct HandlerInner {
456456
}
457457

458458
/// A key denoting where from a diagnostic was stashed.
459-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
459+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
460460
pub enum StashKey {
461461
ItemNoType,
462462
UnderscoreForArrayLengths,

compiler/rustc_hir/src/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl PartialRes {
457457

458458
/// Different kinds of symbols can coexist even if they share the same textual name.
459459
/// Therefore, they each have a separate universe (known as a "namespace").
460-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
460+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
461461
pub enum Namespace {
462462
/// The type namespace includes `struct`s, `enum`s, `union`s, `trait`s, and `mod`s
463463
/// (and, by extension, crates).

compiler/rustc_lexer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub enum TokenKind {
141141
Unknown,
142142
}
143143

144-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
144+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
145145
pub enum DocStyle {
146146
Outer,
147147
Inner,

compiler/rustc_lint/src/context.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ use std::cell::Cell;
5050
use std::iter;
5151
use std::slice;
5252

53+
type EarlyLintPassFactory = dyn Fn() -> EarlyLintPassObject + sync::Send + sync::Sync;
54+
type LateLintPassFactory =
55+
dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::Send + sync::Sync;
56+
5357
/// Information about the registered lints.
5458
///
5559
/// This is basically the subset of `Context` that we can
@@ -64,11 +68,11 @@ pub struct LintStore {
6468
/// interior mutability, we don't enforce this (and lints should, in theory,
6569
/// be compatible with being constructed more than once, though not
6670
/// necessarily in a sane manner. This is safe though.)
67-
pub pre_expansion_passes: Vec<Box<dyn Fn() -> EarlyLintPassObject + sync::Send + sync::Sync>>,
68-
pub early_passes: Vec<Box<dyn Fn() -> EarlyLintPassObject + sync::Send + sync::Sync>>,
69-
pub late_passes: Vec<Box<dyn Fn() -> LateLintPassObject + sync::Send + sync::Sync>>,
71+
pub pre_expansion_passes: Vec<Box<EarlyLintPassFactory>>,
72+
pub early_passes: Vec<Box<EarlyLintPassFactory>>,
73+
pub late_passes: Vec<Box<LateLintPassFactory>>,
7074
/// This is unique in that we construct them per-module, so not once.
71-
pub late_module_passes: Vec<Box<dyn Fn() -> LateLintPassObject + sync::Send + sync::Sync>>,
75+
pub late_module_passes: Vec<Box<LateLintPassFactory>>,
7276

7377
/// Lints indexed by name.
7478
by_name: FxHashMap<String, TargetLint>,
@@ -186,14 +190,20 @@ impl LintStore {
186190

187191
pub fn register_late_pass(
188192
&mut self,
189-
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync,
193+
pass: impl for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx>
194+
+ 'static
195+
+ sync::Send
196+
+ sync::Sync,
190197
) {
191198
self.late_passes.push(Box::new(pass));
192199
}
193200

194201
pub fn register_late_mod_pass(
195202
&mut self,
196-
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync,
203+
pass: impl for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx>
204+
+ 'static
205+
+ sync::Send
206+
+ sync::Sync,
197207
) {
198208
self.late_module_passes.push(Box::new(pass));
199209
}
@@ -558,7 +568,7 @@ pub trait LintPassObject: Sized {}
558568

559569
impl LintPassObject for EarlyLintPassObject {}
560570

561-
impl LintPassObject for LateLintPassObject {}
571+
impl LintPassObject for LateLintPassObject<'_> {}
562572

563573
pub trait LintContext: Sized {
564574
type PassObject: LintPassObject;
@@ -949,8 +959,8 @@ impl<'a> EarlyContext<'a> {
949959
}
950960
}
951961

952-
impl LintContext for LateContext<'_> {
953-
type PassObject = LateLintPassObject;
962+
impl<'tcx> LintContext for LateContext<'tcx> {
963+
type PassObject = LateLintPassObject<'tcx>;
954964

955965
/// Gets the overall compiler `Session` object.
956966
fn sess(&self) -> &Session {

compiler/rustc_lint/src/late.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
306306
}
307307
}
308308

309-
struct LateLintPassObjects<'a> {
310-
lints: &'a mut [LateLintPassObject],
309+
struct LateLintPassObjects<'a, 'tcx> {
310+
lints: &'a mut [LateLintPassObject<'tcx>],
311311
}
312312

313313
#[allow(rustc::lint_pass_impl_without_macro)]
314-
impl LintPass for LateLintPassObjects<'_> {
314+
impl LintPass for LateLintPassObjects<'_, '_> {
315315
fn name(&self) -> &'static str {
316316
panic!()
317317
}
@@ -329,7 +329,7 @@ macro_rules! expand_late_lint_pass_impl_methods {
329329

330330
macro_rules! late_lint_pass_impl {
331331
([], [$hir:tt], $methods:tt) => {
332-
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_> {
332+
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_, $hir> {
333333
expand_late_lint_pass_impl_methods!([$hir], $methods);
334334
}
335335
};
@@ -382,7 +382,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
382382
late_lint_mod_pass(tcx, module_def_id, builtin_lints);
383383

384384
let mut passes: Vec<_> =
385-
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();
385+
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)(tcx)).collect();
386386

387387
if !passes.is_empty() {
388388
late_lint_mod_pass(tcx, module_def_id, LateLintPassObjects { lints: &mut passes[..] });
@@ -418,7 +418,8 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
418418
}
419419

420420
fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
421-
let mut passes = unerased_lint_store(tcx).late_passes.iter().map(|p| (p)()).collect::<Vec<_>>();
421+
let mut passes =
422+
unerased_lint_store(tcx).late_passes.iter().map(|p| (p)(tcx)).collect::<Vec<_>>();
422423

423424
if !tcx.sess.opts.unstable_opts.no_interleave_lints {
424425
if !passes.is_empty() {
@@ -434,7 +435,7 @@ fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints
434435
}
435436

436437
let mut passes: Vec<_> =
437-
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();
438+
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)(tcx)).collect();
438439

439440
for pass in &mut passes {
440441
tcx.sess.prof.extra_verbose_generic_activity("run_late_module_lint", pass.name()).run(

0 commit comments

Comments
 (0)