Skip to content

Commit 139fb22

Browse files
committed
Auto merge of rust-lang#119549 - fmease:rollup-jxvbfes, r=fmease
Rollup of 21 pull requests Successful merges: - rust-lang#119086 (Query panic!() to useful diagnostic) - rust-lang#119239 (Remove unnecessary arm in `check_expr_yield`) - rust-lang#119298 (suppress change-tracker warnings in CI containers) - rust-lang#119319 (Document that File does not buffer reads/writes) - rust-lang#119434 (rc: Take *const T in is_dangling) - rust-lang#119444 (Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`) - rust-lang#119474 (Update tracking issue of naked_functions) - rust-lang#119476 (Pretty-print always-const trait predicates correctly) - rust-lang#119477 (rustdoc ui: adjust tooltip z-index to be above sidebar) - rust-lang#119479 (Remove two unused feature gates from rustc_query_impl) - rust-lang#119487 (Minor improvements in comment on `freshen.rs`) - rust-lang#119492 (Update books) - rust-lang#119494 (Deny defaults for higher-ranked generic parameters) - rust-lang#119498 (Update deadlinks of `strict_provenance` lints) - rust-lang#119505 (Don't synthesize host effect params for trait associated functions marked const) - rust-lang#119510 (Report I/O errors from rmeta encoding with emit_fatal) - rust-lang#119512 (Mark myself as back from leave) - rust-lang#119514 (coverage: Avoid a query stability hazard in `function_coverage_map`) - rust-lang#119523 (llvm: Allow `noundef` in codegen tests) - rust-lang#119534 (Update `thread_local` examples to use `local_key_cell_methods`) - rust-lang#119544 (Fix: Properly set vendor in i686-win7-windows-msvc target) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1a47f5b + 9b2a44a commit 139fb22

File tree

77 files changed

+676
-285
lines changed

Some content is hidden

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

77 files changed

+676
-285
lines changed

compiler/rustc_ast_lowering/messages.ftl

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ ast_lowering_closure_cannot_be_static = closures cannot be static
4545
ast_lowering_coroutine_too_many_parameters =
4646
too many parameters for a coroutine (expected 0 or 1 parameters)
4747
48-
ast_lowering_default_parameter_in_binder = default parameter is not allowed in this binder
49-
5048
ast_lowering_does_not_support_modifiers =
5149
the `{$class_name}` register class does not support template modifiers
5250
@@ -58,6 +56,9 @@ ast_lowering_functional_record_update_destructuring_assignment =
5856
functional record updates are not allowed in destructuring assignments
5957
.suggestion = consider removing the trailing pattern
6058
59+
ast_lowering_generic_param_default_in_binder =
60+
defaults for generic parameters are not allowed in `for<...>` binders
61+
6162
ast_lowering_generic_type_with_parentheses =
6263
parenthesized type parameters may only be used with a `Fn` trait
6364
.label = only `Fn` traits may use parentheses

compiler/rustc_ast_lowering/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ pub enum BadReturnTypeNotation {
397397
}
398398

399399
#[derive(Diagnostic)]
400-
#[diag(ast_lowering_default_parameter_in_binder)]
401-
pub(crate) struct UnexpectedDefaultParameterInBinder {
400+
#[diag(ast_lowering_generic_param_default_in_binder)]
401+
pub(crate) struct GenericParamDefaultInBinder {
402402
#[primary_span]
403403
pub span: Span,
404404
}

compiler/rustc_ast_lowering/src/item.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
12411241
coroutine_kind: Option<CoroutineKind>,
12421242
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
12431243
let header = self.lower_fn_header(sig.header);
1244+
// Don't pass along the user-provided constness of trait associated functions; we don't want to
1245+
// synthesize a host effect param for them. We reject `const` on them during AST validation.
1246+
let constness = if kind == FnDeclKind::Inherent { sig.header.constness } else { Const::No };
12441247
let itctx = ImplTraitContext::Universal;
1245-
let (generics, decl) =
1246-
self.lower_generics(generics, sig.header.constness, id, &itctx, |this| {
1247-
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
1248-
});
1248+
let (generics, decl) = self.lower_generics(generics, constness, id, &itctx, |this| {
1249+
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
1250+
});
12491251
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
12501252
}
12511253

compiler/rustc_ast_lowering/src/lib.rs

+40-30
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use rustc_session::parse::{add_feature_diagnostics, feature_err};
6666
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6767
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
6868
use smallvec::SmallVec;
69-
use std::borrow::Cow;
7069
use std::collections::hash_map::Entry;
7170
use thin_vec::ThinVec;
7271

@@ -884,27 +883,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
884883
binder: NodeId,
885884
generic_params: &[GenericParam],
886885
) -> &'hir [hir::GenericParam<'hir>] {
887-
let mut generic_params: Vec<_> = generic_params
888-
.iter()
889-
.map(|param| {
890-
let param = match param.kind {
891-
GenericParamKind::Type { ref default } if let Some(ty) = default => {
892-
// Default type is not permitted in non-lifetime binders.
893-
// So we emit an error and default to `None` to prevent
894-
// potential ice.
895-
self.dcx().emit_err(errors::UnexpectedDefaultParameterInBinder {
896-
span: ty.span(),
897-
});
898-
let param = GenericParam {
899-
kind: GenericParamKind::Type { default: None },
900-
..param.clone()
901-
};
902-
Cow::Owned(param)
903-
}
904-
_ => Cow::Borrowed(param),
905-
};
906-
self.lower_generic_param(param.as_ref(), hir::GenericParamSource::Binder)
907-
})
886+
let mut generic_params: Vec<_> = self
887+
.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder)
908888
.collect();
909889
let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder);
910890
debug!(?extra_lifetimes);
@@ -2136,7 +2116,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21362116
param: &GenericParam,
21372117
source: hir::GenericParamSource,
21382118
) -> hir::GenericParam<'hir> {
2139-
let (name, kind) = self.lower_generic_param_kind(param);
2119+
let (name, kind) = self.lower_generic_param_kind(param, source);
21402120

21412121
let hir_id = self.lower_node_id(param.id);
21422122
self.lower_attrs(hir_id, &param.attrs);
@@ -2155,6 +2135,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21552135
fn lower_generic_param_kind(
21562136
&mut self,
21572137
param: &GenericParam,
2138+
source: hir::GenericParamSource,
21582139
) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
21592140
match &param.kind {
21602141
GenericParamKind::Lifetime => {
@@ -2173,22 +2154,51 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21732154
(param_name, kind)
21742155
}
21752156
GenericParamKind::Type { default, .. } => {
2176-
let kind = hir::GenericParamKind::Type {
2177-
default: default.as_ref().map(|x| {
2157+
// Not only do we deny type param defaults in binders but we also map them to `None`
2158+
// since later compiler stages cannot handle them (and shouldn't need to be able to).
2159+
let default = default
2160+
.as_ref()
2161+
.filter(|_| match source {
2162+
hir::GenericParamSource::Generics => true,
2163+
hir::GenericParamSource::Binder => {
2164+
self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2165+
span: param.span(),
2166+
});
2167+
2168+
false
2169+
}
2170+
})
2171+
.map(|def| {
21782172
self.lower_ty(
2179-
x,
2173+
def,
21802174
&ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
21812175
)
2182-
}),
2183-
synthetic: false,
2184-
};
2176+
});
2177+
2178+
let kind = hir::GenericParamKind::Type { default, synthetic: false };
21852179

21862180
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
21872181
}
21882182
GenericParamKind::Const { ty, kw_span: _, default } => {
21892183
let ty = self
21902184
.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
2191-
let default = default.as_ref().map(|def| self.lower_anon_const(def));
2185+
2186+
// Not only do we deny const param defaults in binders but we also map them to `None`
2187+
// since later compiler stages cannot handle them (and shouldn't need to be able to).
2188+
let default = default
2189+
.as_ref()
2190+
.filter(|_| match source {
2191+
hir::GenericParamSource::Generics => true,
2192+
hir::GenericParamSource::Binder => {
2193+
self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2194+
span: param.span(),
2195+
});
2196+
2197+
false
2198+
}
2199+
})
2200+
.map(|def| self.lower_anon_const(def));
2201+
21922202
(
21932203
hir::ParamName::Plain(self.lower_ident(param.ident)),
21942204
hir::GenericParamKind::Const { ty, default, is_host_effect: false },

compiler/rustc_ast_passes/messages.ftl

+15-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,21 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
233233
.item = this item cannot have `~const` trait bounds
234234
235235
ast_passes_trait_fn_const =
236-
functions in traits cannot be declared const
237-
.label = functions in traits cannot be const
236+
functions in {$in_impl ->
237+
[true] trait impls
238+
*[false] traits
239+
} cannot be declared const
240+
.label = functions in {$in_impl ->
241+
[true] trait impls
242+
*[false] traits
243+
} cannot be const
244+
.const_context_label = this declares all associated functions implicitly const
245+
.remove_const_sugg = remove the `const`{$requires_multiple_changes ->
246+
[true] {" ..."}
247+
*[false] {""}
248+
}
249+
.make_impl_const_sugg = ... and declare the impl to be const instead
250+
.make_trait_const_sugg = ... and declare the trait to be a `#[const_trait]` instead
238251
239252
ast_passes_trait_object_single_bound = only a single explicit lifetime bound is permitted
240253

0 commit comments

Comments
 (0)