Skip to content

Commit 36ba2c7

Browse files
committed
Auto merge of #155687 - GuillaumeGomez:rollup-aZ7YrAD, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #155469 (Account for titlecase in casing lints) - #155644 (delegation: support self ty propagation for functions in free to trait reuse) - #154957 (Fix ICE when const closure appears inside a non-const trait method) - #155442 (Change keyword order for `impl` restrictions) - #155561 (Use singular wording for single _ placeholders in type suggestions) - #155637 (Fix E0191 suggestion for empty dyn trait args) - #155661 (Remove `AttributeLintKind` variants - part 6)
2 parents 2eaa5de + 0a4e73e commit 36ba2c7

234 files changed

Lines changed: 1685 additions & 1352 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,10 +3786,10 @@ pub struct TraitAlias {
37863786

37873787
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
37883788
pub struct Trait {
3789+
pub impl_restriction: ImplRestriction,
37893790
pub constness: Const,
37903791
pub safety: Safety,
37913792
pub is_auto: IsAuto,
3792-
pub impl_restriction: ImplRestriction,
37933793
pub ident: Ident,
37943794
pub generics: Generics,
37953795
#[visitable(extra = BoundKind::SuperTraits)]

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
143143

144144
let (param_count, c_variadic) = self.param_count(sig_id);
145145

146-
let mut generics = self.uplift_delegation_generics(delegation, sig_id, item_id);
146+
let mut generics =
147+
self.uplift_delegation_generics(delegation, sig_id, item_id, is_method);
147148

148149
let body_id = self.lower_delegation_body(
149150
delegation,
@@ -301,6 +302,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
301302
hir::InferDelegationSig::Output(self.arena.alloc(hir::DelegationGenerics {
302303
child_args_segment_id: generics.child.args_segment_id,
303304
parent_args_segment_id: generics.parent.args_segment_id,
305+
self_ty_id: generics.self_ty_id,
306+
propagate_self_ty: generics.propagate_self_ty,
304307
})),
305308
)),
306309
span,
@@ -554,6 +557,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
554557
}
555558
};
556559

560+
generics.self_ty_id = match new_path {
561+
hir::QPath::Resolved(ty, _) => ty,
562+
hir::QPath::TypeRelative(ty, _) => Some(ty),
563+
}
564+
.map(|ty| ty.hir_id);
565+
557566
let callee_path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(new_path), span));
558567
self.arena.alloc(self.mk_expr(hir::ExprKind::Call(callee_path, args), span))
559568
};

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ pub(super) struct GenericsGenerationResult<'hir> {
6767
pub(super) struct GenericsGenerationResults<'hir> {
6868
pub(super) parent: GenericsGenerationResult<'hir>,
6969
pub(super) child: GenericsGenerationResult<'hir>,
70+
pub(super) self_ty_id: Option<HirId>,
71+
pub(super) propagate_self_ty: bool,
7072
}
7173

7274
pub(super) struct GenericArgsPropagationDetails {
@@ -209,6 +211,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
209211
delegation: &Delegation,
210212
sig_id: DefId,
211213
item_id: NodeId,
214+
is_method: bool,
212215
) -> GenericsGenerationResults<'hir> {
213216
let delegation_parent_kind =
214217
self.tcx.def_kind(self.tcx.local_parent(self.local_def_id(item_id)));
@@ -230,21 +233,27 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
230233
let child = DelegationGenerics::trait_impl(sig_params, child_user_specified);
231234
let child = GenericsGenerationResult::new(child);
232235

233-
return GenericsGenerationResults { parent, child };
236+
return GenericsGenerationResults {
237+
parent,
238+
child,
239+
self_ty_id: None,
240+
propagate_self_ty: false,
241+
};
234242
}
235243

236244
let delegation_in_free_ctx =
237245
!matches!(delegation_parent_kind, DefKind::Trait | DefKind::Impl { .. });
238246

239247
let sig_parent = self.tcx.parent(sig_id);
240248
let sig_in_trait = matches!(self.tcx.def_kind(sig_parent), DefKind::Trait);
249+
let free_to_trait_delegation = delegation_in_free_ctx && sig_in_trait;
250+
let generate_self = free_to_trait_delegation && is_method && delegation.qself.is_none();
241251

242252
let can_add_generics_to_parent = len >= 2
243253
&& self.get_resolution_id(segments[len - 2].id).is_some_and(|def_id| {
244254
matches!(self.tcx.def_kind(def_id), DefKind::Trait | DefKind::TraitAlias)
245255
});
246256

247-
let generate_self = delegation_in_free_ctx && sig_in_trait;
248257
let parent_generics = if can_add_generics_to_parent {
249258
let sig_parent_params = &self.tcx.generics_of(sig_parent).own_params[..];
250259

@@ -278,6 +287,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
278287
GenericsGenerationResults {
279288
parent: GenericsGenerationResult::new(parent_generics),
280289
child: GenericsGenerationResult::new(child_generics),
290+
self_ty_id: None,
291+
propagate_self_ty: free_to_trait_delegation && !generate_self,
281292
}
282293
}
283294

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
556556
})
557557
}
558558
ItemKind::Trait(box Trait {
559+
impl_restriction,
559560
constness,
560561
is_auto,
561562
safety,
562-
impl_restriction,
563563
ident,
564564
generics,
565565
bounds,
@@ -586,10 +586,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
586586
},
587587
);
588588
hir::ItemKind::Trait(
589+
impl_restriction,
589590
constness,
590591
*is_auto,
591592
safety,
592-
impl_restriction,
593593
ident,
594594
generics,
595595
bounds,

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,21 @@ impl<'a> State<'a> {
371371
self.bclose(item.span, empty, cb);
372372
}
373373
ast::ItemKind::Trait(box ast::Trait {
374+
impl_restriction,
374375
constness,
375376
safety,
376377
is_auto,
377-
impl_restriction,
378378
ident,
379379
generics,
380380
bounds,
381381
items,
382382
}) => {
383383
let (cb, ib) = self.head("");
384384
self.print_visibility(&item.vis);
385+
self.print_impl_restriction(impl_restriction);
385386
self.print_constness(*constness);
386387
self.print_safety(*safety);
387388
self.print_is_auto(*is_auto);
388-
self.print_impl_restriction(impl_restriction);
389389
self.word_nbsp("trait");
390390
self.print_ident(*ident);
391391
self.print_generic_params(&generics.params);

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::Range;
22

3-
use rustc_errors::E0232;
3+
use rustc_errors::{Diagnostic, E0232};
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
66
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
@@ -18,6 +18,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym};
1818
use thin_vec::{ThinVec, thin_vec};
1919

2020
use crate::context::{AcceptContext, Stage};
21+
use crate::errors::{
22+
DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption,
23+
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError,
24+
};
2125
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
2226

2327
pub(crate) mod do_not_recommend;
@@ -112,12 +116,12 @@ fn merge<T, S: Stage>(
112116
match (first, later) {
113117
(Some(_) | None, None) => {}
114118
(Some((first_span, _)), Some((later_span, _))) => {
115-
cx.emit_lint(
119+
let first_span = *first_span;
120+
cx.emit_dyn_lint(
116121
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
117-
AttributeLintKind::IgnoredDiagnosticOption {
118-
first_span: *first_span,
119-
later_span,
120-
option_name,
122+
move |dcx, level| {
123+
IgnoredDiagnosticOption { first_span, later_span, option_name }
124+
.into_diag(dcx, level)
121125
},
122126
later_span,
123127
);
@@ -157,12 +161,15 @@ fn parse_list<'p, S: Stage>(
157161
);
158162
}
159163
ArgParser::NameValue(_) => {
160-
cx.emit_lint(
164+
cx.emit_dyn_lint(
161165
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
162-
AttributeLintKind::MalFormedDiagnosticAttribute {
163-
attribute: mode.as_str(),
164-
options: mode.allowed_options(),
165-
span,
166+
move |dcx, level| {
167+
MalFormedDiagnosticAttributeLint {
168+
attribute: mode.as_str(),
169+
options: mode.allowed_options(),
170+
span,
171+
}
172+
.into_diag(dcx, level)
166173
},
167174
span,
168175
);
@@ -188,12 +195,15 @@ fn parse_directive_items<'p, S: Stage>(
188195
let span = item.span();
189196

190197
macro malformed() {{
191-
cx.emit_lint(
198+
cx.emit_dyn_lint(
192199
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
193-
AttributeLintKind::MalFormedDiagnosticAttribute {
194-
attribute: mode.as_str(),
195-
options: mode.allowed_options(),
196-
span,
200+
move |dcx, level| {
201+
MalFormedDiagnosticAttributeLint {
202+
attribute: mode.as_str(),
203+
options: mode.allowed_options(),
204+
span,
205+
}
206+
.into_diag(dcx, level)
197207
},
198208
span,
199209
);
@@ -210,13 +220,14 @@ fn parse_directive_items<'p, S: Stage>(
210220
}}
211221

212222
macro duplicate($name: ident, $($first_span:tt)*) {{
213-
cx.emit_lint(
223+
let first_span = $($first_span)*;
224+
cx.emit_dyn_lint(
214225
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
215-
AttributeLintKind::IgnoredDiagnosticOption {
216-
first_span: $($first_span)*,
226+
move |dcx, level| IgnoredDiagnosticOption {
227+
first_span,
217228
later_span: span,
218229
option_name: $name,
219-
},
230+
}.into_diag(dcx, level),
220231
span,
221232
);
222233
}}
@@ -245,22 +256,35 @@ fn parse_directive_items<'p, S: Stage>(
245256
let (FormatWarning::InvalidSpecifier { span, .. }
246257
| FormatWarning::PositionalArgument { span, .. }
247258
| FormatWarning::DisallowedPlaceholder { span }) = warning;
248-
cx.emit_lint(
259+
cx.emit_dyn_lint(
249260
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
250-
AttributeLintKind::MalformedDiagnosticFormat { warning },
261+
move |dcx, level| match warning {
262+
FormatWarning::PositionalArgument { .. } => {
263+
DisallowedPositionalArgument.into_diag(dcx, level)
264+
}
265+
FormatWarning::InvalidSpecifier { .. } => {
266+
InvalidFormatSpecifier.into_diag(dcx, level)
267+
}
268+
FormatWarning::DisallowedPlaceholder { .. } => {
269+
DisallowedPlaceholder.into_diag(dcx, level)
270+
}
271+
},
251272
span,
252273
);
253274
}
254275

255276
f
256277
}
257278
Err(e) => {
258-
cx.emit_lint(
279+
cx.emit_dyn_lint(
259280
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
260-
AttributeLintKind::DiagnosticWrappedParserError {
261-
description: e.description,
262-
label: e.label,
263-
span: slice_span(input.span, e.span, is_snippet),
281+
move |dcx, level| {
282+
WrappedParserError {
283+
description: &e.description,
284+
label: &e.label,
285+
span: slice_span(input.span, e.span.clone(), is_snippet),
286+
}
287+
.into_diag(dcx, level)
264288
},
265289
input.span,
266290
);

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_hir::Target;
55
use rustc_hir::attrs::{
66
AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow,
77
};
8-
use rustc_hir::lints::AttributeLintKind;
98
use rustc_session::parse::feature_err;
109
use rustc_span::{Span, Symbol, edition, sym};
1110
use thin_vec::ThinVec;
@@ -17,7 +16,8 @@ use crate::errors::{
1716
AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow,
1817
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral,
1918
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
20-
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
19+
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
20+
IllFormedAttributeInput, MalformedDoc,
2121
};
2222
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
2323
use crate::session_diagnostics::{
@@ -84,18 +84,18 @@ fn expected_name_value<S: Stage>(
8484
span: Span,
8585
_name: Option<Symbol>,
8686
) {
87-
cx.emit_lint(
87+
cx.emit_dyn_lint(
8888
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
89-
AttributeLintKind::ExpectedNameValue,
89+
|dcx, level| ExpectedNameValue.into_diag(dcx, level),
9090
span,
9191
);
9292
}
9393

9494
// FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead.
9595
fn expected_no_args<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, span: Span) {
96-
cx.emit_lint(
96+
cx.emit_dyn_lint(
9797
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
98-
AttributeLintKind::ExpectedNoArgs,
98+
|dcx, level| ExpectedNoArgs.into_diag(dcx, level),
9999
span,
100100
);
101101
}
@@ -107,9 +107,9 @@ fn expected_string_literal<S: Stage>(
107107
span: Span,
108108
_actual_literal: Option<&MetaItemLit>,
109109
) {
110-
cx.emit_lint(
110+
cx.emit_dyn_lint(
111111
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
112-
AttributeLintKind::MalformedDoc,
112+
|dcx, level| MalformedDoc.into_diag(dcx, level),
113113
span,
114114
);
115115
}
@@ -203,9 +203,9 @@ impl DocParser {
203203
// FIXME: remove this method once merged and uncomment the line below instead.
204204
// cx.expected_list(cx.attr_span, args);
205205
let span = cx.attr_span;
206-
cx.emit_lint(
206+
cx.emit_dyn_lint(
207207
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
208-
AttributeLintKind::MalformedDoc,
208+
|dcx, level| MalformedDoc.into_diag(dcx, level),
209209
span,
210210
);
211211
return;
@@ -399,9 +399,9 @@ impl DocParser {
399399
// FIXME: remove this method once merged and uncomment the line
400400
// below instead.
401401
// cx.expected_identifier(sub_item.path().span());
402-
cx.emit_lint(
402+
cx.emit_dyn_lint(
403403
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
404-
AttributeLintKind::MalformedDoc,
404+
|dcx, level| MalformedDoc.into_diag(dcx, level),
405405
sub_item.path().span(),
406406
);
407407
continue;
@@ -605,9 +605,9 @@ impl DocParser {
605605
// FIXME: remove this method once merged and uncomment the line
606606
// below instead.
607607
// cx.unexpected_literal(lit.span);
608-
cx.emit_lint(
608+
cx.emit_dyn_lint(
609609
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
610-
AttributeLintKind::MalformedDoc,
610+
|dcx, level| MalformedDoc.into_diag(dcx, level),
611611
lit.span,
612612
);
613613
}

0 commit comments

Comments
 (0)