Skip to content

Commit a6796c1

Browse files
committed
Auto merge of #3768 - rust-lang:rustup-2024-07-27, r=RalfJung
Automatic Rustup
2 parents adbb89e + 822286f commit a6796c1

File tree

439 files changed

+6833
-6170
lines changed

Some content is hidden

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

439 files changed

+6833
-6170
lines changed

Cargo.lock

+20-11
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
573573

574574
[[package]]
575575
name = "clippy"
576-
version = "0.1.81"
576+
version = "0.1.82"
577577
dependencies = [
578578
"anstream",
579579
"clippy_config",
@@ -594,13 +594,13 @@ dependencies = [
594594
"termize",
595595
"tokio",
596596
"toml 0.7.8",
597-
"ui_test 0.23.0",
597+
"ui_test 0.24.0",
598598
"walkdir",
599599
]
600600

601601
[[package]]
602602
name = "clippy_config"
603-
version = "0.1.81"
603+
version = "0.1.82"
604604
dependencies = [
605605
"rustc-semver",
606606
"serde",
@@ -623,7 +623,7 @@ dependencies = [
623623

624624
[[package]]
625625
name = "clippy_lints"
626-
version = "0.1.81"
626+
version = "0.1.82"
627627
dependencies = [
628628
"arrayvec",
629629
"cargo_metadata 0.18.1",
@@ -648,7 +648,7 @@ dependencies = [
648648

649649
[[package]]
650650
name = "clippy_utils"
651-
version = "0.1.81"
651+
version = "0.1.82"
652652
dependencies = [
653653
"arrayvec",
654654
"clippy_config",
@@ -969,7 +969,7 @@ dependencies = [
969969

970970
[[package]]
971971
name = "declare_clippy_lint"
972-
version = "0.1.81"
972+
version = "0.1.82"
973973
dependencies = [
974974
"itertools",
975975
"quote",
@@ -2977,6 +2977,16 @@ dependencies = [
29772977
"pad",
29782978
]
29792979

2980+
[[package]]
2981+
name = "prettydiff"
2982+
version = "0.7.0"
2983+
source = "registry+https://github.com/rust-lang/crates.io-index"
2984+
checksum = "abec3fb083c10660b3854367697da94c674e9e82aa7511014dc958beeb7215e9"
2985+
dependencies = [
2986+
"owo-colors",
2987+
"pad",
2988+
]
2989+
29802990
[[package]]
29812991
name = "proc-macro-hack"
29822992
version = "0.5.20+deprecated"
@@ -5825,7 +5835,7 @@ dependencies = [
58255835
"indicatif",
58265836
"lazy_static",
58275837
"levenshtein",
5828-
"prettydiff",
5838+
"prettydiff 0.6.4",
58295839
"regex",
58305840
"rustc_version",
58315841
"rustfix 0.6.1",
@@ -5836,9 +5846,9 @@ dependencies = [
58365846

58375847
[[package]]
58385848
name = "ui_test"
5839-
version = "0.23.0"
5849+
version = "0.24.0"
58405850
source = "registry+https://github.com/rust-lang/crates.io-index"
5841-
checksum = "29e5f4ffcbab82453958fbf59990e981b8e8a177dcd60c2bd8f9b52c3036a6e1"
5851+
checksum = "bc1c6c78d55482388711c8d417b8e547263046a607512278fed274c54633bbe4"
58425852
dependencies = [
58435853
"annotate-snippets 0.11.4",
58445854
"anyhow",
@@ -5852,14 +5862,13 @@ dependencies = [
58525862
"indicatif",
58535863
"lazy_static",
58545864
"levenshtein",
5855-
"prettydiff",
5865+
"prettydiff 0.7.0",
58565866
"regex",
58575867
"rustc_version",
58585868
"rustfix 0.8.1",
58595869
"serde",
58605870
"serde_json",
58615871
"spanned",
5862-
"tempfile",
58635872
]
58645873

58655874
[[package]]

compiler/rustc_ast_lowering/src/item.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
172172
id: NodeId,
173173
hir_id: hir::HirId,
174174
ident: &mut Ident,
175-
attrs: Option<&'hir [Attribute]>,
175+
attrs: &'hir [Attribute],
176176
vis_span: Span,
177177
i: &ItemKind,
178178
) -> hir::ItemKind<'hir> {
@@ -488,7 +488,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
488488
id: NodeId,
489489
vis_span: Span,
490490
ident: &mut Ident,
491-
attrs: Option<&'hir [Attribute]>,
491+
attrs: &'hir [Attribute],
492492
) -> hir::ItemKind<'hir> {
493493
let path = &tree.prefix;
494494
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
@@ -566,7 +566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
566566
// `ItemLocalId` and the new owner. (See `lower_node_id`)
567567
let kind =
568568
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
569-
if let Some(attrs) = attrs {
569+
if !attrs.is_empty() {
570570
this.attrs.insert(hir::ItemLocalId::ZERO, attrs);
571571
}
572572

@@ -1525,8 +1525,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
15251525
continue;
15261526
}
15271527
let is_param = *is_param.get_or_insert_with(compute_is_param);
1528-
if !is_param {
1529-
self.dcx().emit_err(MisplacedRelaxTraitBound { span: bound.span() });
1528+
if !is_param && !self.tcx.features().more_maybe_bounds {
1529+
self.tcx
1530+
.sess
1531+
.create_feature_err(
1532+
MisplacedRelaxTraitBound { span: bound.span() },
1533+
sym::more_maybe_bounds,
1534+
)
1535+
.emit();
15301536
}
15311537
}
15321538
}

compiler/rustc_ast_lowering/src/lib.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -913,15 +913,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
913913
ret
914914
}
915915

916-
fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
916+
fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> &'hir [Attribute] {
917917
if attrs.is_empty() {
918-
None
918+
&[]
919919
} else {
920920
debug_assert_eq!(id.owner, self.current_hir_id_owner);
921921
let ret = self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a)));
922922
debug_assert!(!ret.is_empty());
923923
self.attrs.insert(id.local_id, ret);
924-
Some(ret)
924+
ret
925925
}
926926
}
927927

@@ -1216,6 +1216,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12161216
itctx,
12171217
TraitBoundModifiers::NONE,
12181218
);
1219+
let bound = (bound, hir::TraitBoundModifier::None);
12191220
let bounds = this.arena.alloc_from_iter([bound]);
12201221
let lifetime_bound = this.elided_dyn_bound(t.span);
12211222
(bounds, lifetime_bound)
@@ -1348,21 +1349,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13481349
// We can safely ignore constness here since AST validation
13491350
// takes care of rejecting invalid modifier combinations and
13501351
// const trait bounds in trait object types.
1351-
GenericBound::Trait(ty, modifiers) => match modifiers.polarity {
1352-
BoundPolarity::Positive | BoundPolarity::Negative(_) => {
1353-
Some(this.lower_poly_trait_ref(
1354-
ty,
1355-
itctx,
1356-
// Still, don't pass along the constness here; we don't want to
1357-
// synthesize any host effect args, it'd only cause problems.
1358-
TraitBoundModifiers {
1359-
constness: BoundConstness::Never,
1360-
..*modifiers
1361-
},
1362-
))
1363-
}
1364-
BoundPolarity::Maybe(_) => None,
1365-
},
1352+
GenericBound::Trait(ty, modifiers) => {
1353+
// Still, don't pass along the constness here; we don't want to
1354+
// synthesize any host effect args, it'd only cause problems.
1355+
let modifiers = TraitBoundModifiers {
1356+
constness: BoundConstness::Never,
1357+
..*modifiers
1358+
};
1359+
let trait_ref = this.lower_poly_trait_ref(ty, itctx, modifiers);
1360+
let polarity = this.lower_trait_bound_modifiers(modifiers);
1361+
Some((trait_ref, polarity))
1362+
}
13661363
GenericBound::Outlives(lifetime) => {
13671364
if lifetime_bound.is_none() {
13681365
lifetime_bound = Some(this.lower_lifetime(lifetime));
@@ -2688,6 +2685,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26882685
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
26892686
span: self.lower_span(span),
26902687
};
2688+
let principal = (principal, hir::TraitBoundModifier::None);
26912689

26922690
// The original ID is taken by the `PolyTraitRef`,
26932691
// so the `Ty` itself needs a different one.

compiler/rustc_ast_passes/src/ast_validation.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -1345,14 +1345,28 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13451345
match bound {
13461346
GenericBound::Trait(trait_ref, modifiers) => {
13471347
match (ctxt, modifiers.constness, modifiers.polarity) {
1348-
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_)) => {
1349-
self.dcx().emit_err(errors::OptionalTraitSupertrait {
1350-
span: trait_ref.span,
1351-
path_str: pprust::path_to_string(&trait_ref.trait_ref.path),
1352-
});
1348+
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_))
1349+
if !self.features.more_maybe_bounds =>
1350+
{
1351+
self.session
1352+
.create_feature_err(
1353+
errors::OptionalTraitSupertrait {
1354+
span: trait_ref.span,
1355+
path_str: pprust::path_to_string(&trait_ref.trait_ref.path),
1356+
},
1357+
sym::more_maybe_bounds,
1358+
)
1359+
.emit();
13531360
}
1354-
(BoundKind::TraitObject, BoundConstness::Never, BoundPolarity::Maybe(_)) => {
1355-
self.dcx().emit_err(errors::OptionalTraitObject { span: trait_ref.span });
1361+
(BoundKind::TraitObject, BoundConstness::Never, BoundPolarity::Maybe(_))
1362+
if !self.features.more_maybe_bounds =>
1363+
{
1364+
self.session
1365+
.create_feature_err(
1366+
errors::OptionalTraitObject { span: trait_ref.span },
1367+
sym::more_maybe_bounds,
1368+
)
1369+
.emit();
13561370
}
13571371
(
13581372
BoundKind::TraitObject,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1442,9 +1442,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
14421442
// See `tests/ui/moves/needs-clone-through-deref.rs`
14431443
return false;
14441444
}
1445+
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
14451446
if self.in_move_closure(expr) {
14461447
return false;
14471448
}
1449+
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
1450+
if let hir::ExprKind::Closure(_) = expr.kind {
1451+
return false;
1452+
}
14481453
// Try to find predicates on *generic params* that would allow copying `ty`
14491454
let mut suggestion =
14501455
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ declare_features! (
205205
(unstable, lifetime_capture_rules_2024, "1.76.0", None),
206206
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
207207
(unstable, link_cfg, "1.14.0", None),
208+
/// Allows using `?Trait` trait bounds in more contexts.
209+
(internal, more_maybe_bounds, "CURRENT_RUSTC_VERSION", None),
208210
/// Allows the `multiple_supertrait_upcastable` lint.
209211
(unstable, multiple_supertrait_upcastable, "1.69.0", None),
210212
/// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!

compiler/rustc_hir/src/hir.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,11 @@ pub enum TyKind<'hir> {
28322832
OpaqueDef(ItemId, &'hir [GenericArg<'hir>], bool),
28332833
/// A trait object type `Bound1 + Bound2 + Bound3`
28342834
/// where `Bound` is a trait or a lifetime.
2835-
TraitObject(&'hir [PolyTraitRef<'hir>], &'hir Lifetime, TraitObjectSyntax),
2835+
TraitObject(
2836+
&'hir [(PolyTraitRef<'hir>, TraitBoundModifier)],
2837+
&'hir Lifetime,
2838+
TraitObjectSyntax,
2839+
),
28362840
/// Unused for now.
28372841
Typeof(&'hir AnonConst),
28382842
/// `TyKind::Infer` means the type should be inferred instead of it having been

compiler/rustc_hir/src/intravisit.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,9 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
902902
try_visit!(visitor.visit_array_length(length));
903903
}
904904
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
905-
walk_list!(visitor, visit_poly_trait_ref, bounds);
905+
for (bound, _modifier) in bounds {
906+
try_visit!(visitor.visit_poly_trait_ref(bound));
907+
}
906908
try_visit!(visitor.visit_lifetime(lifetime));
907909
}
908910
TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)),

compiler/rustc_hir/src/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ language_item_table! {
162162
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;
163163
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);
164164
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
165+
CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
165166
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
166167
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
167168
/// The associated item of the `DiscriminantKind` trait.

compiler/rustc_hir_analysis/messages.ftl

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
hir_analysis_ambiguous_assoc_item = ambiguous associated {$assoc_kind} `{$assoc_name}` in bounds of `{$ty_param_name}`
1+
hir_analysis_ambiguous_assoc_item = ambiguous associated {$assoc_kind} `{$assoc_name}` in bounds of `{$qself}`
22
.label = ambiguous associated {$assoc_kind} `{$assoc_name}`
33
44
hir_analysis_ambiguous_lifetime_bound =
@@ -12,16 +12,21 @@ hir_analysis_assoc_item_is_private = {$kind} `{$name}` is private
1212
.label = private {$kind}
1313
.defined_here_label = the {$kind} is defined here
1414
15-
hir_analysis_assoc_item_not_found = associated {$assoc_kind} `{$assoc_name}` not found for `{$ty_param_name}`
15+
hir_analysis_assoc_item_not_found = associated {$assoc_kind} `{$assoc_name}` not found for `{$qself}`
1616
1717
hir_analysis_assoc_item_not_found_found_in_other_trait_label = there is {$identically_named ->
1818
[true] an
1919
*[false] a similarly named
2020
} associated {$assoc_kind} `{$suggested_name}` in the trait `{$trait_name}`
2121
hir_analysis_assoc_item_not_found_label = associated {$assoc_kind} `{$assoc_name}` not found
22-
hir_analysis_assoc_item_not_found_other_sugg = `{$ty_param_name}` has the following associated {$assoc_kind}
22+
hir_analysis_assoc_item_not_found_other_sugg = `{$qself}` has the following associated {$assoc_kind}
23+
hir_analysis_assoc_item_not_found_similar_in_other_trait_qpath_sugg =
24+
consider fully qualifying{$identically_named ->
25+
[true] {""}
26+
*[false] {" "}and renaming
27+
} the associated {$assoc_kind}
2328
hir_analysis_assoc_item_not_found_similar_in_other_trait_sugg = change the associated {$assoc_kind} name to use `{$suggested_name}` from `{$trait_name}`
24-
hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg = and also change the associated {$assoc_kind} name
29+
hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg = ...and changing the associated {$assoc_kind} name
2530
hir_analysis_assoc_item_not_found_similar_sugg = there is an associated {$assoc_kind} with a similar name
2631
2732
hir_analysis_assoc_kind_mismatch = expected {$expected}, found {$got}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> {
831831

832832
fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
833833
match ty.kind {
834-
hir::TyKind::TraitObject([trait_ref], ..) => match trait_ref.trait_ref.path.segments {
834+
hir::TyKind::TraitObject([(trait_ref, _)], ..) => match trait_ref.trait_ref.path.segments {
835835
[s] => s.res.opt_def_id() == Some(trait_def_id.to_def_id()),
836836
_ => false,
837837
},

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
652652
debug!(?bounds, ?lifetime, "TraitObject");
653653
let scope = Scope::TraitRefBoundary { s: self.scope };
654654
self.with(scope, |this| {
655-
for bound in bounds {
655+
for (bound, _) in bounds {
656656
this.visit_poly_trait_ref_inner(
657657
bound,
658658
NonLifetimeBinderAllowed::Deny("trait object types"),

0 commit comments

Comments
 (0)