Skip to content

Commit a76ec18

Browse files
committed
Auto merge of #116804 - matthiaskrgr:rollup-m2qm8ul, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #114157 (Enable triagebot no-merges check) - #116257 (Suggest trait bounds for used associated type on type param) - #116430 (vendoring in tarball sources) - #116709 (Update minifier version to 0.2.3) - #116786 (Update my mailmap entry) - #116790 (opt-dist: disable unused features for tabled crate) - #116802 (Remove `DefiningAnchor::Bubble` from opaque wf check) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4af886f + b0572f1 commit a76ec18

26 files changed

+209
-120
lines changed

.mailmap

+3-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ Lindsey Kuper <[email protected]> <[email protected]>
346346
347347
Liu Dingming <[email protected]>
348348
Loo Maclin <[email protected]>
349-
Loïc BRANSTETT <[email protected]>
349+
350+
351+
350352
351353
352354
Lukas Lueg <[email protected]>

Cargo.lock

+2-40
Original file line numberDiff line numberDiff line change
@@ -2418,9 +2418,9 @@ dependencies = [
24182418

24192419
[[package]]
24202420
name = "minifier"
2421-
version = "0.2.2"
2421+
version = "0.2.3"
24222422
source = "registry+https://github.com/rust-lang/crates.io-index"
2423-
checksum = "8eb022374af2f446981254e6bf9efb6e2c9e1a53176d395fca02792fd4435729"
2423+
checksum = "5394aa376422b4b2b6c02fd9cfcb657e4ec544ae98e43d7d5d785fd0d042fd6d"
24242424

24252425
[[package]]
24262426
name = "minimal-lexical"
@@ -2970,30 +2970,6 @@ dependencies = [
29702970
"pad",
29712971
]
29722972

2973-
[[package]]
2974-
name = "proc-macro-error"
2975-
version = "1.0.4"
2976-
source = "registry+https://github.com/rust-lang/crates.io-index"
2977-
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
2978-
dependencies = [
2979-
"proc-macro-error-attr",
2980-
"proc-macro2",
2981-
"quote",
2982-
"syn 1.0.109",
2983-
"version_check",
2984-
]
2985-
2986-
[[package]]
2987-
name = "proc-macro-error-attr"
2988-
version = "1.0.4"
2989-
source = "registry+https://github.com/rust-lang/crates.io-index"
2990-
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
2991-
dependencies = [
2992-
"proc-macro2",
2993-
"quote",
2994-
"version_check",
2995-
]
2996-
29972973
[[package]]
29982974
name = "proc-macro-hack"
29992975
version = "0.5.20+deprecated"
@@ -5252,23 +5228,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
52525228
checksum = "4d38d39c754ae037a9bc3ca1580a985db7371cd14f1229172d1db9093feb6739"
52535229
dependencies = [
52545230
"papergrid",
5255-
"tabled_derive",
52565231
"unicode-width",
52575232
]
52585233

5259-
[[package]]
5260-
name = "tabled_derive"
5261-
version = "0.6.0"
5262-
source = "registry+https://github.com/rust-lang/crates.io-index"
5263-
checksum = "99f688a08b54f4f02f0a3c382aefdb7884d3d69609f785bd253dc033243e3fe4"
5264-
dependencies = [
5265-
"heck",
5266-
"proc-macro-error",
5267-
"proc-macro2",
5268-
"quote",
5269-
"syn 1.0.109",
5270-
]
5271-
52725234
[[package]]
52735235
name = "tar"
52745236
version = "0.4.38"

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
22
use rustc_errors::ErrorGuaranteed;
3+
use rustc_hir::def::DefKind;
34
use rustc_hir::def_id::LocalDefId;
45
use rustc_hir::OpaqueTyOrigin;
56
use rustc_infer::infer::InferCtxt;
@@ -308,20 +309,19 @@ fn check_opaque_type_well_formed<'tcx>(
308309
return Ok(definition_ty);
309310
};
310311
let param_env = tcx.param_env(def_id);
311-
// HACK This bubble is required for this tests to pass:
312-
// nested-return-type2-tait2.rs
313-
// nested-return-type2-tait3.rs
312+
313+
let mut parent_def_id = def_id;
314+
while tcx.def_kind(parent_def_id) == DefKind::OpaqueTy {
315+
parent_def_id = tcx.local_parent(parent_def_id);
316+
}
317+
314318
// FIXME(-Ztrait-solver=next): We probably should use `DefiningAnchor::Error`
315319
// and prepopulate this `InferCtxt` with known opaque values, rather than
316320
// using the `Bind` anchor here. For now it's fine.
317321
let infcx = tcx
318322
.infer_ctxt()
319323
.with_next_trait_solver(next_trait_solver)
320-
.with_opaque_type_inference(if next_trait_solver {
321-
DefiningAnchor::Bind(def_id)
322-
} else {
323-
DefiningAnchor::Bubble
324-
})
324+
.with_opaque_type_inference(DefiningAnchor::Bind(parent_def_id))
325325
.build();
326326
let ocx = ObligationCtxt::new(&infcx);
327327
let identity_args = GenericArgs::identity_for_item(tcx, def_id);

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
284284
self.one_bound_for_assoc_type(
285285
|| traits::supertraits(tcx, trait_ref),
286286
trait_ref.skip_binder().print_only_trait_name(),
287+
None,
287288
binding.item_name,
288289
path_span,
289290
match binding.kind {

compiler/rustc_hir_analysis/src/astconv/errors.rs

+53-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use crate::errors::{
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
88
use rustc_hir as hir;
9-
use rustc_hir::def_id::DefId;
9+
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_infer::traits::FulfillmentError;
11-
use rustc_middle::ty::TyCtxt;
12-
use rustc_middle::ty::{self, Ty};
11+
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TyCtxt};
1312
use rustc_session::parse::feature_err;
1413
use rustc_span::edit_distance::find_best_match_for_name;
1514
use rustc_span::symbol::{sym, Ident};
@@ -102,6 +101,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
102101
&self,
103102
all_candidates: impl Fn() -> I,
104103
ty_param_name: &str,
104+
ty_param_def_id: Option<LocalDefId>,
105105
assoc_name: Ident,
106106
span: Span,
107107
) -> ErrorGuaranteed
@@ -190,13 +190,61 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
190190
})
191191
.collect::<Vec<_>>()[..]
192192
{
193+
let trait_name = self.tcx().def_path_str(*best_trait);
194+
let an = if suggested_name != assoc_name.name { "a similarly named" } else { "an" };
193195
err.span_label(
194196
assoc_name.span,
195197
format!(
196-
"there is a similarly named associated type `{suggested_name}` in the trait `{}`",
197-
self.tcx().def_path_str(*best_trait)
198+
"there is {an} associated type `{suggested_name}` in the \
199+
trait `{trait_name}`",
198200
),
199201
);
202+
let hir = self.tcx().hir();
203+
if let Some(def_id) = ty_param_def_id
204+
&& let parent = hir.get_parent_item(hir.local_def_id_to_hir_id(def_id))
205+
&& let Some(generics) = hir.get_generics(parent.def_id)
206+
{
207+
if generics.bounds_for_param(def_id)
208+
.flat_map(|pred| pred.bounds.iter())
209+
.any(|b| match b {
210+
hir::GenericBound::Trait(t, ..) => {
211+
t.trait_ref.trait_def_id().as_ref() == Some(best_trait)
212+
}
213+
_ => false,
214+
})
215+
{
216+
// The type param already has a bound for `trait_name`, we just need to
217+
// change the associated type.
218+
err.span_suggestion_verbose(
219+
assoc_name.span,
220+
format!(
221+
"change the associated type name to use `{suggested_name}` from \
222+
`{trait_name}`",
223+
),
224+
suggested_name.to_string(),
225+
Applicability::MaybeIncorrect,
226+
);
227+
} else if suggest_constraining_type_param(
228+
self.tcx(),
229+
generics,
230+
&mut err,
231+
&ty_param_name,
232+
&trait_name,
233+
None,
234+
None,
235+
)
236+
&& suggested_name != assoc_name.name
237+
{
238+
// We suggested constraining a type parameter, but the associated type on it
239+
// was also not an exact match, so we also suggest changing it.
240+
err.span_suggestion_verbose(
241+
assoc_name.span,
242+
"and also change the associated type name",
243+
suggested_name.to_string(),
244+
Applicability::MaybeIncorrect,
245+
);
246+
}
247+
}
200248
return err.emit();
201249
}
202250
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10621062
)
10631063
},
10641064
param_name,
1065+
Some(ty_param_def_id),
10651066
assoc_name,
10661067
span,
10671068
None,
@@ -1075,6 +1076,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10751076
&self,
10761077
all_candidates: impl Fn() -> I,
10771078
ty_param_name: impl Display,
1079+
ty_param_def_id: Option<LocalDefId>,
10781080
assoc_name: Ident,
10791081
span: Span,
10801082
is_equality: Option<ty::Term<'tcx>>,
@@ -1096,6 +1098,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10961098
let reported = self.complain_about_assoc_type_not_found(
10971099
all_candidates,
10981100
&ty_param_name.to_string(),
1101+
ty_param_def_id,
10991102
assoc_name,
11001103
span,
11011104
);
@@ -1143,39 +1146,34 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11431146
err.span_label(
11441147
bound_span,
11451148
format!(
1146-
"ambiguous `{}` from `{}`",
1147-
assoc_name,
1149+
"ambiguous `{assoc_name}` from `{}`",
11481150
bound.print_only_trait_path(),
11491151
),
11501152
);
11511153
if let Some(constraint) = &is_equality {
11521154
where_bounds.push(format!(
1153-
" T: {trait}::{assoc} = {constraint}",
1155+
" T: {trait}::{assoc_name} = {constraint}",
11541156
trait=bound.print_only_trait_path(),
1155-
assoc=assoc_name,
1156-
constraint=constraint,
11571157
));
11581158
} else {
11591159
err.span_suggestion_verbose(
11601160
span.with_hi(assoc_name.span.lo()),
11611161
"use fully qualified syntax to disambiguate",
1162-
format!("<{} as {}>::", ty_param_name, bound.print_only_trait_path()),
1162+
format!("<{ty_param_name} as {}>::", bound.print_only_trait_path()),
11631163
Applicability::MaybeIncorrect,
11641164
);
11651165
}
11661166
} else {
11671167
err.note(format!(
1168-
"associated type `{}` could derive from `{}`",
1169-
ty_param_name,
1168+
"associated type `{ty_param_name}` could derive from `{}`",
11701169
bound.print_only_trait_path(),
11711170
));
11721171
}
11731172
}
11741173
if !where_bounds.is_empty() {
11751174
err.help(format!(
11761175
"consider introducing a new type parameter `T` and adding `where` constraints:\
1177-
\n where\n T: {},\n{}",
1178-
ty_param_name,
1176+
\n where\n T: {ty_param_name},\n{}",
11791177
where_bounds.join(",\n"),
11801178
));
11811179
}
@@ -1397,6 +1395,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13971395
)
13981396
},
13991397
kw::SelfUpper,
1398+
None,
14001399
assoc_ident,
14011400
span,
14021401
None,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: ty::Predicate<'_>) -
364364
/// Type parameter needs more bounds. The trivial case is `T` `where T: Bound`, but
365365
/// it can also be an `impl Trait` param that needs to be decomposed to a type
366366
/// param for cleaner code.
367-
fn suggest_restriction<'tcx>(
367+
pub fn suggest_restriction<'tcx>(
368368
tcx: TyCtxt<'tcx>,
369369
item_id: LocalDefId,
370370
hir_generics: &hir::Generics<'tcx>,

src/bootstrap/builder/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
2222
..Config::parse(&["check".to_owned()])
2323
});
2424
submodule_build.update_submodule(Path::new("src/doc/book"));
25-
submodule_build.update_submodule(Path::new("src/tools/rust-analyzer"));
2625
config.submodules = Some(false);
2726

2827
config.ninja_in_file = false;

src/bootstrap/dist.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,15 @@ impl Step for PlainSourceTarball {
10021002
channel::write_commit_info_file(&plain_dst_src, info);
10031003
}
10041004

1005-
// If we're building from git sources, we need to vendor a complete distribution.
1006-
if builder.rust_info().is_managed_git_subrepository() {
1007-
// Ensure we have the submodules checked out.
1008-
builder.update_submodule(Path::new("src/tools/cargo"));
1009-
builder.update_submodule(Path::new("src/tools/rust-analyzer"));
1005+
// If we're building from git or tarball sources, we need to vendor
1006+
// a complete distribution.
1007+
if builder.rust_info().is_managed_git_subrepository()
1008+
|| builder.rust_info().is_from_tarball()
1009+
{
1010+
if builder.rust_info().is_managed_git_subrepository() {
1011+
// Ensure we have the submodules checked out.
1012+
builder.update_submodule(Path::new("src/tools/cargo"));
1013+
}
10101014

10111015
// Vendor all Cargo dependencies
10121016
let mut cmd = Command::new(&builder.initial_cargo);

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ path = "lib.rs"
1010
arrayvec = { version = "0.7", default-features = false }
1111
askama = { version = "0.12", default-features = false, features = ["config"] }
1212
itertools = "0.10.1"
13-
minifier = "0.2.2"
13+
minifier = "0.2.3"
1414
once_cell = "1.10.0"
1515
regex = "1"
1616
rustdoc-json-types = { path = "../rustdoc-json-types" }

src/tools/opt-dist/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ glob = "0.3"
2323
tempfile = "3.5"
2424
derive_builder = "0.12"
2525
clap = { version = "4", features = ["derive"] }
26-
tabled = "0.13"
26+
tabled = { version = "0.13", default-features = false, features = ["std"] }

tests/rustdoc-ui/issues/issue-96287.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ error[E0220]: associated type `Assoc` not found for `V`
22
--> $DIR/issue-96287.rs:7:33
33
|
44
LL | pub type Foo<V> = impl Trait<V::Assoc>;
5-
| ^^^^^ there is a similarly named associated type `Assoc` in the trait `TraitWithAssoc`
5+
| ^^^^^ there is an associated type `Assoc` in the trait `TraitWithAssoc`
6+
|
7+
help: consider restricting type parameter `V`
8+
|
9+
LL | pub type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>;
10+
| ++++++++++++++++
611

712
error: aborting due to previous error
813

tests/ui/impl-trait/async_scope_creep.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(type_alias_impl_trait)]
22
// edition:2021
3-
//[rpit] check-pass
3+
// check-pass
44
// revisions: tait rpit
55

66
struct Pending {}
@@ -23,7 +23,7 @@ impl Pending {
2323

2424
#[cfg(tait)]
2525
fn read_fut(&mut self) -> OpeningReadFuture<'_> {
26-
self.read() //[tait]~ ERROR: cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>`
26+
self.read()
2727
}
2828

2929
#[cfg(rpit)]

tests/ui/impl-trait/async_scope_creep.tait.stderr

-9
This file was deleted.

tests/ui/impl-trait/nested-return-type2-tait2.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// check-pass
2+
13
#![feature(type_alias_impl_trait)]
24

35
trait Duh {}
@@ -17,6 +19,7 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
1719

1820
type Sendable = impl Send;
1921
type Traitable = impl Trait<Assoc = Sendable>;
22+
//~^ WARN opaque type `Traitable` does not satisfy its associated type bounds
2023

2124
// The `impl Send` here is then later compared against the inference var
2225
// created, causing the inference var to be set to `impl Send` instead of
@@ -25,7 +28,6 @@ type Traitable = impl Trait<Assoc = Sendable>;
2528
// type does not implement `Duh`, even if its hidden type does. So we error out.
2629
fn foo() -> Traitable {
2730
|| 42
28-
//~^ ERROR `Sendable: Duh` is not satisfied
2931
}
3032

3133
fn main() {

0 commit comments

Comments
 (0)