Skip to content

Commit 0dda415

Browse files
committed
Fix tools
1 parent 042464f commit 0dda415

File tree

7 files changed

+55
-57
lines changed

7 files changed

+55
-57
lines changed

compiler/rustc_error_codes/src/error_codes/E0284.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,29 @@ as the `collect` method for `Iterator`s.
55
For example:
66

77
```compile_fail,E0284
8-
fn foo() -> Result<bool, ()> {
9-
let results = [Ok(true), Ok(false), Err(())].iter().cloned();
10-
let v: Vec<bool> = results.collect()?;
11-
// Do things with v...
12-
Ok(true)
8+
fn main() {
9+
let n: u32 = 1;
10+
let mut d: u64 = 2;
11+
d = d + n.into();
1312
}
1413
```
1514

16-
Here we have an iterator `results` over `Result<bool, ()>`.
17-
Hence, `results.collect()` can return any type implementing
18-
`FromIterator<Result<bool, ()>>`. On the other hand, the
19-
`?` operator can accept any type implementing `Try`.
15+
Here we have an addition of `d` and `n.into()`. Hence, `n.into()` can return
16+
any type `T` where `u64: Add<T>`. On the other hand, the `into` method can
17+
rteurn any type where `u32: Into<T>`.
2018

21-
The author of this code probably wants `collect()` to return a
22-
`Result<Vec<bool>, ()>`, but the compiler can't be sure
23-
that there isn't another type `T` implementing both `Try` and
24-
`FromIterator<Result<bool, ()>>` in scope such that
25-
`T::Ok == Vec<bool>`. Hence, this code is ambiguous and an error
26-
is returned.
19+
The author of this code probably wants `into()` to return a `u64`, but the
20+
compiler can't be sure that there isn't another type `T` where both
21+
`u32: Into<T>` and `u64: Add<T>`.
2722

2823
To resolve this error, use a concrete type for the intermediate expression:
2924

3025
```
31-
fn foo() -> Result<bool, ()> {
32-
let results = [Ok(true), Ok(false), Err(())].iter().cloned();
33-
let v = {
34-
let temp: Result<Vec<bool>, ()> = results.collect();
35-
temp?
36-
};
37-
// Do things with v...
38-
Ok(true)
26+
fn main() {
27+
let n: u32 = 1;
28+
let mut d: u64 = 2;
29+
let m: u64 = n.into();
30+
d = d + m;
3931
}
4032
```
4133

src/librustdoc/clean/mod.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::bug;
2121
use rustc_middle::middle::resolve_lifetime as rl;
2222
use rustc_middle::middle::stability;
2323
use rustc_middle::ty::fold::TypeFolder;
24-
use rustc_middle::ty::subst::InternalSubsts;
24+
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2525
use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt};
2626
use rustc_mir::const_eval::{is_const_fn, is_min_const_fn, is_unstable_const_fn};
2727
use rustc_span::hygiene::MacroKind;
@@ -1268,13 +1268,10 @@ impl Clean<Item> for ty::AssocItem {
12681268
ty::AssocKind::Type => {
12691269
let my_name = self.ident.name.clean(cx);
12701270

1271-
if let ty::TraitContainer(did) = self.container {
1272-
// When loading a cross-crate associated type, the bounds for this type
1273-
// are actually located on the trait/impl itself, so we need to load
1274-
// all of the generics from there and then look for bounds that are
1275-
// applied to this associated type in question.
1276-
let predicates = cx.tcx.explicit_predicates_of(did);
1277-
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
1271+
if let ty::TraitContainer(_) = self.container {
1272+
let bounds = cx.tcx.explicit_item_bounds(self.def_id);
1273+
let predicates = ty::GenericPredicates { parent: None, predicates: bounds };
1274+
let generics = (cx.tcx.generics_of(self.def_id), predicates).clean(cx);
12781275
let mut bounds = generics
12791276
.where_predicates
12801277
.iter()
@@ -1678,19 +1675,22 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
16781675

16791676
ty::Opaque(def_id, substs) => {
16801677
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
1681-
// by looking up the projections associated with the def_id.
1682-
let predicates_of = cx.tcx.explicit_predicates_of(def_id);
1678+
// by looking up the bounds associated with the def_id.
16831679
let substs = cx.tcx.lift(&substs).expect("Opaque lift failed");
1684-
let bounds = predicates_of.instantiate(cx.tcx, substs);
1680+
let bounds = cx
1681+
.tcx
1682+
.explicit_item_bounds(def_id)
1683+
.iter()
1684+
.map(|(bound, _)| bound.subst(cx.tcx, substs))
1685+
.collect::<Vec<_>>();
16851686
let mut regions = vec![];
16861687
let mut has_sized = false;
16871688
let mut bounds = bounds
1688-
.predicates
16891689
.iter()
1690-
.filter_map(|predicate| {
1690+
.filter_map(|bound| {
16911691
// Note: The substs of opaque types can contain unbound variables,
16921692
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
1693-
let trait_ref = match predicate.bound_atom(cx.tcx).skip_binder() {
1693+
let trait_ref = match bound.bound_atom(cx.tcx).skip_binder() {
16941694
ty::PredicateAtom::Trait(tr, _constness) => {
16951695
ty::Binder::bind(tr.trait_ref)
16961696
}
@@ -1711,11 +1711,10 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
17111711
}
17121712

17131713
let bounds: Vec<_> = bounds
1714-
.predicates
17151714
.iter()
1716-
.filter_map(|pred| {
1715+
.filter_map(|bound| {
17171716
if let ty::PredicateAtom::Projection(proj) =
1718-
pred.bound_atom(cx.tcx).skip_binder()
1717+
bound.bound_atom(cx.tcx).skip_binder()
17191718
{
17201719
if proj.projection_ty.trait_ref(cx.tcx)
17211720
== trait_ref.skip_binder()
@@ -2067,13 +2066,10 @@ impl Clean<Item> for doctree::OpaqueTy<'_> {
20672066
visibility: self.vis.clean(cx),
20682067
stability: cx.stability(self.id).clean(cx),
20692068
deprecation: cx.deprecation(self.id).clean(cx),
2070-
inner: OpaqueTyItem(
2071-
OpaqueTy {
2072-
bounds: self.opaque_ty.bounds.clean(cx),
2073-
generics: self.opaque_ty.generics.clean(cx),
2074-
},
2075-
false,
2076-
),
2069+
inner: OpaqueTyItem(OpaqueTy {
2070+
bounds: self.opaque_ty.bounds.clean(cx),
2071+
generics: self.opaque_ty.generics.clean(cx),
2072+
}),
20772073
}
20782074
}
20792075
}

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub enum ItemEnum {
252252
FunctionItem(Function),
253253
ModuleItem(Module),
254254
TypedefItem(Typedef, bool /* is associated type */),
255-
OpaqueTyItem(OpaqueTy, bool /* is associated type */),
255+
OpaqueTyItem(OpaqueTy),
256256
StaticItem(Static),
257257
ConstantItem(Constant),
258258
TraitItem(Trait),

src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache)
17091709
clean::ConstantItem(ref c) => item_constant(buf, cx, item, c),
17101710
clean::ForeignTypeItem => item_foreign_type(buf, cx, item, cache),
17111711
clean::KeywordItem(_) => item_keyword(buf, cx, item),
1712-
clean::OpaqueTyItem(ref e, _) => item_opaque_ty(buf, cx, item, e, cache),
1712+
clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e, cache),
17131713
clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta, cache),
17141714
_ => {
17151715
// We don't generate pages for any other type.

src/tools/clippy/clippy_lints/src/future_not_send.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_hir::intravisit::FnKind;
33
use rustc_hir::{Body, FnDecl, HirId};
44
use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_lint::{LateContext, LateLintPass};
6+
use rustc_middle::ty::subst::Subst;
67
use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
78
use rustc_session::{declare_lint_pass, declare_tool_lint};
89
use rustc_span::{sym, Span};
@@ -62,9 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6263
}
6364
let ret_ty = utils::return_ty(cx, hir_id);
6465
if let Opaque(id, subst) = *ret_ty.kind() {
65-
let preds = cx.tcx.predicates_of(id).instantiate(cx.tcx, subst);
66+
let preds = cx.tcx.explicit_item_bounds(id);
6667
let mut is_future = false;
67-
for p in preds.predicates {
68+
for &(p, _span) in preds {
69+
let p = p.subst(cx.tcx, subst);
6870
if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
6971
if Some(trait_ref.def_id()) == cx.tcx.lang_items().future_trait() {
7072
is_future = true;
@@ -90,8 +92,13 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9092
|db| {
9193
cx.tcx.infer_ctxt().enter(|infcx| {
9294
for FulfillmentError { obligation, .. } in send_errors {
93-
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
95+
infcx.maybe_note_obligation_cause_for_async_await(
96+
db,
97+
&obligation,
98+
);
99+
if let Trait(trait_pred, _) =
100+
obligation.predicate.skip_binders()
101+
{
95102
db.note(&format!(
96103
"`{}` doesn't implement `{}`",
97104
trait_pred.self_ty(),

src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16671667
// if return type is impl trait, check the associated types
16681668
if let ty::Opaque(def_id, _) = *ret_ty.kind() {
16691669
// one of the associated types must be Self
1670-
for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
1671-
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
1670+
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
1671+
if let ty::PredicateAtom::Projection(projection_predicate) =
1672+
predicate.skip_binders()
1673+
{
16721674
// walk the associated type and check for Self
16731675
if contains_ty(projection_predicate.ty, self_ty) {
16741676
return;

src/tools/clippy/clippy_lints/src/utils/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,10 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
12851285
},
12861286
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
12871287
ty::Opaque(ref def_id, _) => {
1288-
for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
1288+
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
12891289
if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() {
1290-
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
1290+
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some()
1291+
{
12911292
return true;
12921293
}
12931294
}

0 commit comments

Comments
 (0)