Skip to content

Commit b685242

Browse files
committed
Auto merge of rust-lang#105365 - matthiaskrgr:rollup-g0mrrt7, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#104439 (Add prototype to generate `COPYRIGHT` from REUSE metadata) - rust-lang#105005 (On E0195 point at where clause lifetime bounds) - rust-lang#105098 (propagate the error from parsing enum variant to the parser and emit out) - rust-lang#105243 (remove no-op 'let _ = ') - rust-lang#105254 (Recurse into nested impl-trait when computing variance.) - rust-lang#105287 (Synthesize substitutions for bad auto traits in dyn types) - rust-lang#105310 (Be more careful about unresolved exprs in suggestion) - rust-lang#105318 (Make `get_impl_future_output_ty` work with AFIT) - rust-lang#105339 (support `ConstKind::Expr` in `is_const_evaluatable` and `WfPredicates::compute`) - rust-lang#105340 (Avoid ICE by accounting for missing type) - rust-lang#105342 (Make `note_obligation_cause_code` take a `impl ToPredicate` for predicate) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9db224f + a9ffe7c commit b685242

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

+1404
-122
lines changed

Cargo.lock

+77
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ dependencies = [
581581
"libc",
582582
"num-integer",
583583
"num-traits",
584+
"serde",
584585
"time",
585586
"winapi",
586587
]
@@ -730,6 +731,16 @@ dependencies = [
730731
"rustc-semver",
731732
]
732733

734+
[[package]]
735+
name = "collect-license-metadata"
736+
version = "0.1.0"
737+
dependencies = [
738+
"anyhow",
739+
"serde",
740+
"serde_json",
741+
"spdx-rs",
742+
]
743+
733744
[[package]]
734745
name = "color-eyre"
735746
version = "0.6.2"
@@ -1552,6 +1563,15 @@ dependencies = [
15521563
"termcolor",
15531564
]
15541565

1566+
[[package]]
1567+
name = "generate-copyright"
1568+
version = "0.1.0"
1569+
dependencies = [
1570+
"anyhow",
1571+
"serde",
1572+
"serde_json",
1573+
]
1574+
15551575
[[package]]
15561576
name = "generic-array"
15571577
version = "0.14.4"
@@ -4864,6 +4884,35 @@ dependencies = [
48644884
"winapi",
48654885
]
48664886

4887+
[[package]]
4888+
name = "spdx-expression"
4889+
version = "0.5.2"
4890+
source = "registry+https://github.com/rust-lang/crates.io-index"
4891+
checksum = "53d7ac03c67c572d85049d6db815e20a4a19b41b3d5cca732ac582342021ad77"
4892+
dependencies = [
4893+
"nom",
4894+
"serde",
4895+
"thiserror",
4896+
"tracing",
4897+
]
4898+
4899+
[[package]]
4900+
name = "spdx-rs"
4901+
version = "0.5.1"
4902+
source = "registry+https://github.com/rust-lang/crates.io-index"
4903+
checksum = "b3c02f6eb7e7b4100c272f685a9ccaccaab302324e8c7ec3e2ee72340fb29ff3"
4904+
dependencies = [
4905+
"chrono",
4906+
"log",
4907+
"nom",
4908+
"serde",
4909+
"spdx-expression",
4910+
"strum",
4911+
"strum_macros",
4912+
"thiserror",
4913+
"uuid",
4914+
]
4915+
48674916
[[package]]
48684917
name = "stable_deref_trait"
48694918
version = "1.2.0"
@@ -4967,6 +5016,25 @@ version = "0.10.0"
49675016
source = "registry+https://github.com/rust-lang/crates.io-index"
49685017
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
49695018

5019+
[[package]]
5020+
name = "strum"
5021+
version = "0.24.1"
5022+
source = "registry+https://github.com/rust-lang/crates.io-index"
5023+
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
5024+
5025+
[[package]]
5026+
name = "strum_macros"
5027+
version = "0.24.3"
5028+
source = "registry+https://github.com/rust-lang/crates.io-index"
5029+
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
5030+
dependencies = [
5031+
"heck",
5032+
"proc-macro2",
5033+
"quote",
5034+
"rustversion",
5035+
"syn",
5036+
]
5037+
49705038
[[package]]
49715039
name = "syn"
49725040
version = "1.0.102"
@@ -5596,6 +5664,15 @@ version = "0.1.1"
55965664
source = "registry+https://github.com/rust-lang/crates.io-index"
55975665
checksum = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d"
55985666

5667+
[[package]]
5668+
name = "uuid"
5669+
version = "0.8.2"
5670+
source = "registry+https://github.com/rust-lang/crates.io-index"
5671+
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
5672+
dependencies = [
5673+
"getrandom 0.2.0",
5674+
]
5675+
55995676
[[package]]
56005677
name = "valuable"
56015678
version = "0.1.0"

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ members = [
3939
"src/tools/bump-stage0",
4040
"src/tools/replace-version-placeholder",
4141
"src/tools/lld-wrapper",
42+
"src/tools/collect-license-metadata",
43+
"src/tools/generate-copyright",
4244
]
4345

4446
exclude = [

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
121121

122122
pub(super) fn prove_predicates(
123123
&mut self,
124-
predicates: impl IntoIterator<
125-
Item = impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
126-
>,
124+
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx> + std::fmt::Debug>,
127125
locations: Locations,
128126
category: ConstraintCategory<'tcx>,
129127
) {
@@ -135,7 +133,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
135133
#[instrument(skip(self), level = "debug")]
136134
pub(super) fn prove_predicate(
137135
&mut self,
138-
predicate: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
136+
predicate: impl ToPredicate<'tcx> + std::fmt::Debug,
139137
locations: Locations,
140138
category: ConstraintCategory<'tcx>,
141139
) {

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

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ hir_analysis_lifetimes_or_bounds_mismatch_on_trait =
1717
lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration
1818
.label = lifetimes do not match {$item_kind} in trait
1919
.generics_label = lifetimes in impl do not match this {$item_kind} in trait
20+
.where_label = this `where` clause might not match the one in the trait
21+
.bounds_label = this bound might be missing in the impl
2022
2123
hir_analysis_drop_impl_on_wrong_item =
2224
the `Drop` trait may only be implemented for local structs, enums, and unions

compiler/rustc_hir_analysis/src/check/compare_method.rs

+40-11
Original file line numberDiff line numberDiff line change
@@ -751,27 +751,56 @@ fn check_region_bounds_on_impl_item<'tcx>(
751751
.get_generics(impl_m.def_id.expect_local())
752752
.expect("expected impl item to have generics or else we can't compare them")
753753
.span;
754-
let generics_span = if let Some(local_def_id) = trait_m.def_id.as_local() {
755-
Some(
756-
tcx.hir()
757-
.get_generics(local_def_id)
758-
.expect("expected trait item to have generics or else we can't compare them")
759-
.span,
760-
)
761-
} else {
762-
None
763-
};
764754

755+
let mut generics_span = None;
756+
let mut bounds_span = vec![];
757+
let mut where_span = None;
758+
if let Some(trait_node) = tcx.hir().get_if_local(trait_m.def_id)
759+
&& let Some(trait_generics) = trait_node.generics()
760+
{
761+
generics_span = Some(trait_generics.span);
762+
// FIXME: we could potentially look at the impl's bounds to not point at bounds that
763+
// *are* present in the impl.
764+
for p in trait_generics.predicates {
765+
if let hir::WherePredicate::BoundPredicate(pred) = p {
766+
for b in pred.bounds {
767+
if let hir::GenericBound::Outlives(lt) = b {
768+
bounds_span.push(lt.ident.span);
769+
}
770+
}
771+
}
772+
}
773+
if let Some(impl_node) = tcx.hir().get_if_local(impl_m.def_id)
774+
&& let Some(impl_generics) = impl_node.generics()
775+
{
776+
let mut impl_bounds = 0;
777+
for p in impl_generics.predicates {
778+
if let hir::WherePredicate::BoundPredicate(pred) = p {
779+
for b in pred.bounds {
780+
if let hir::GenericBound::Outlives(_) = b {
781+
impl_bounds += 1;
782+
}
783+
}
784+
}
785+
}
786+
if impl_bounds == bounds_span.len() {
787+
bounds_span = vec![];
788+
} else if impl_generics.has_where_clause_predicates {
789+
where_span = Some(impl_generics.where_clause_span);
790+
}
791+
}
792+
}
765793
let reported = tcx
766794
.sess
767795
.create_err(LifetimesOrBoundsMismatchOnTrait {
768796
span,
769797
item_kind: assoc_item_kind_str(impl_m),
770798
ident: impl_m.ident(tcx),
771799
generics_span,
800+
bounds_span,
801+
where_span,
772802
})
773803
.emit_unless(delay);
774-
775804
return Err(reported);
776805
}
777806

compiler/rustc_hir_analysis/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub struct LifetimesOrBoundsMismatchOnTrait {
4343
pub span: Span,
4444
#[label(generics_label)]
4545
pub generics_span: Option<Span>,
46+
#[label(where_label)]
47+
pub where_span: Option<Span>,
48+
#[label(bounds_label)]
49+
pub bounds_span: Vec<Span>,
4650
pub item_kind: &'static str,
4751
pub ident: Ident,
4852
}

compiler/rustc_hir_analysis/src/variance/mod.rs

+38-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use rustc_arena::DroplessArena;
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_middle::ty::query::Providers;
10-
use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt, TypeSuperVisitable, TypeVisitable};
10+
use rustc_middle::ty::{self, CrateVariancesMap, SubstsRef, Ty, TyCtxt};
11+
use rustc_middle::ty::{DefIdTree, TypeSuperVisitable, TypeVisitable};
1112
use std::ops::ControlFlow;
1213

1314
/// Defines the `TermsContext` basically houses an arena where we can
@@ -75,18 +76,50 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
7576
// type Foo<'a, 'b, 'c> = impl Trait<'a> + 'b;
7677
// ```
7778
// we may not use `'c` in the hidden type.
78-
struct OpaqueTypeLifetimeCollector {
79+
struct OpaqueTypeLifetimeCollector<'tcx> {
80+
tcx: TyCtxt<'tcx>,
81+
root_def_id: DefId,
7982
variances: Vec<ty::Variance>,
8083
}
8184

82-
impl<'tcx> ty::TypeVisitor<'tcx> for OpaqueTypeLifetimeCollector {
85+
impl<'tcx> OpaqueTypeLifetimeCollector<'tcx> {
86+
#[instrument(level = "trace", skip(self), ret)]
87+
fn visit_opaque(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> ControlFlow<!> {
88+
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
89+
let child_variances = self.tcx.variances_of(def_id);
90+
for (a, v) in substs.iter().zip(child_variances) {
91+
if *v != ty::Bivariant {
92+
a.visit_with(self)?;
93+
}
94+
}
95+
ControlFlow::CONTINUE
96+
} else {
97+
substs.visit_with(self)
98+
}
99+
}
100+
}
101+
102+
impl<'tcx> ty::TypeVisitor<'tcx> for OpaqueTypeLifetimeCollector<'tcx> {
83103
#[instrument(level = "trace", skip(self), ret)]
84104
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
85105
if let ty::RegionKind::ReEarlyBound(ebr) = r.kind() {
86106
self.variances[ebr.index as usize] = ty::Invariant;
87107
}
88108
r.super_visit_with(self)
89109
}
110+
111+
#[instrument(level = "trace", skip(self), ret)]
112+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
113+
match t.kind() {
114+
ty::Opaque(def_id, substs) => self.visit_opaque(*def_id, substs),
115+
ty::Projection(proj)
116+
if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder =>
117+
{
118+
self.visit_opaque(proj.item_def_id, proj.substs)
119+
}
120+
_ => t.super_visit_with(self),
121+
}
122+
}
90123
}
91124

92125
// By default, RPIT are invariant wrt type and const generics, but they are bivariant wrt
@@ -111,7 +144,8 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
111144
}
112145
}
113146

114-
let mut collector = OpaqueTypeLifetimeCollector { variances };
147+
let mut collector =
148+
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
115149
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id.to_def_id());
116150
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
117151
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);

compiler/rustc_hir_typeck/src/method/suggest.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1482,25 +1482,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14821482
ident_name: Symbol,
14831483
}
14841484

1485+
// FIXME: This really should be taking scoping, etc into account.
14851486
impl<'v> Visitor<'v> for LetVisitor<'v> {
14861487
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
1487-
if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind {
1488-
if let Binding(_, _, ident, ..) = pat.kind &&
1489-
ident.name == self.ident_name {
1490-
self.result = *init;
1491-
}
1488+
if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind
1489+
&& let Binding(_, _, ident, ..) = pat.kind
1490+
&& ident.name == self.ident_name
1491+
{
1492+
self.result = *init;
1493+
} else {
1494+
hir::intravisit::walk_stmt(self, ex);
14921495
}
1493-
hir::intravisit::walk_stmt(self, ex);
14941496
}
14951497
}
14961498

14971499
let mut visitor = LetVisitor { result: None, ident_name: seg1.ident.name };
14981500
visitor.visit_body(&body);
14991501

15001502
let parent = self.tcx.hir().get_parent_node(seg1.hir_id);
1501-
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
1502-
let Some(expr) = visitor.result {
1503-
let self_ty = self.node_ty(expr.hir_id);
1503+
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent)
1504+
&& let Some(expr) = visitor.result
1505+
&& let Some(self_ty) = self.node_ty_opt(expr.hir_id)
1506+
{
15041507
let probe = self.lookup_probe(
15051508
seg2.ident,
15061509
self_ty,
@@ -1513,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15131516
sm.span_extend_while(seg1.ident.span.shrink_to_hi(), |c| c == ':').unwrap(),
15141517
"you may have meant to call an instance method",
15151518
".".to_string(),
1516-
Applicability::MaybeIncorrect
1519+
Applicability::MaybeIncorrect,
15171520
);
15181521
}
15191522
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,15 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
341341

342342
impl<'tcx> InferCtxt<'tcx> {
343343
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
344-
let ty::Opaque(def_id, substs) = *ty.kind() else { return None; };
344+
let (def_id, substs) = match *ty.kind() {
345+
ty::Opaque(def_id, substs) => (def_id, substs),
346+
ty::Projection(data)
347+
if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder =>
348+
{
349+
(data.item_def_id, data.substs)
350+
}
351+
_ => return None,
352+
};
345353

346354
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
347355
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];

compiler/rustc_middle/src/ty/generics.rs

+14
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ impl GenericParamDef {
101101
_ => None,
102102
}
103103
}
104+
105+
pub fn to_error<'tcx>(
106+
&self,
107+
tcx: TyCtxt<'tcx>,
108+
preceding_substs: &[ty::GenericArg<'tcx>],
109+
) -> ty::GenericArg<'tcx> {
110+
match &self.kind {
111+
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
112+
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
113+
ty::GenericParamDefKind::Const { .. } => {
114+
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
115+
}
116+
}
117+
}
104118
}
105119

106120
#[derive(Default)]

0 commit comments

Comments
 (0)