Auto merge of #149058 - LorrensP-2158466:amb-trait-lint, r= · rust-lang/rust@47eaa3b (original) (raw)
`@@ -106,7 +106,7 @@ pub(crate) struct Candidate<'tcx> {
`
106
106
`pub(crate) enum CandidateKind<'tcx> {
`
107
107
`InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
`
108
108
`ObjectCandidate(ty::PolyTraitRef<'tcx>),
`
109
``
`-
TraitCandidate(ty::PolyTraitRef<'tcx>),
`
``
109
`+
TraitCandidate(ty::PolyTraitRef<'tcx>, bool /* lint_ambiguous */),
`
110
110
`WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
`
111
111
`}
`
112
112
``
`@@ -235,7 +235,10 @@ pub(crate) struct Pick<'tcx> {
`
235
235
`pub(crate) enum PickKind<'tcx> {
`
236
236
`InherentImplPick,
`
237
237
`ObjectPick,
`
238
``
`-
TraitPick,
`
``
238
`+
TraitPick(
`
``
239
`+
// Is Ambiguously Imported
`
``
240
`+
bool,
`
``
241
`+
),
`
239
242
`WhereClausePick(
`
240
243
`// Trait
`
241
244
` ty::PolyTraitRef<'tcx>,
`
`@@ -560,7 +563,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
`
560
563
` probe_cx.push_candidate(
`
561
564
`Candidate {
`
562
565
` item,
`
563
``
`-
kind: CandidateKind::TraitCandidate(ty::Binder::dummy(trait_ref)),
`
``
566
`+
kind: CandidateKind::TraitCandidate(
`
``
567
`+
ty::Binder::dummy(trait_ref),
`
``
568
`+
false,
`
``
569
`+
),
`
564
570
`import_ids: smallvec![],
`
565
571
`},
`
566
572
`false,
`
`@@ -1018,6 +1024,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1018
1024
`self.assemble_extension_candidates_for_trait(
`
1019
1025
`&trait_candidate.import_ids,
`
1020
1026
` trait_did,
`
``
1027
`+
trait_candidate.lint_ambiguous,
`
1021
1028
`);
`
1022
1029
`}
`
1023
1030
`}
`
`@@ -1029,7 +1036,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1029
1036
`let mut duplicates = FxHashSet::default();
`
1030
1037
`for trait_info in suggest::all_traits(self.tcx) {
`
1031
1038
`if duplicates.insert(trait_info.def_id) {
`
1032
``
`-
self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id);
`
``
1039
`+
self.assemble_extension_candidates_for_trait(
`
``
1040
`+
&smallvec![],
`
``
1041
`+
trait_info.def_id,
`
``
1042
`+
false,
`
``
1043
`+
);
`
1033
1044
`}
`
1034
1045
`}
`
1035
1046
`}
`
`@@ -1055,6 +1066,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1055
1066
`&mut self,
`
1056
1067
`import_ids: &SmallVec<[LocalDefId; 1]>,
`
1057
1068
`trait_def_id: DefId,
`
``
1069
`+
lint_ambiguous: bool,
`
1058
1070
`) {
`
1059
1071
`let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
`
1060
1072
`let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
`
`@@ -1076,7 +1088,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1076
1088
`Candidate {
`
1077
1089
` item,
`
1078
1090
`import_ids: import_ids.clone(),
`
1079
``
`-
kind: TraitCandidate(bound_trait_ref),
`
``
1091
`+
kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
`
1080
1092
`},
`
1081
1093
`false,
`
1082
1094
`);
`
`@@ -1099,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1099
1111
`Candidate {
`
1100
1112
` item,
`
1101
1113
`import_ids: import_ids.clone(),
`
1102
``
`-
kind: TraitCandidate(ty::Binder::dummy(trait_ref)),
`
``
1114
`+
kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
`
1103
1115
`},
`
1104
1116
`false,
`
1105
1117
`);
`
`@@ -1842,7 +1854,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1842
1854
`ObjectCandidate() | WhereClauseCandidate() => {
`
1843
1855
`CandidateSource::Trait(candidate.item.container_id(self.tcx))
`
1844
1856
`}
`
1845
``
`-
TraitCandidate(trait_ref) => self.probe(|_| {
`
``
1857
`+
TraitCandidate(trait_ref, ) => self.probe(|| {
`
1846
1858
`let trait_ref = self.instantiate_binder_with_fresh_vars(
`
1847
1859
`self.span,
`
1848
1860
`BoundRegionConversionTime::FnCall,
`
`@@ -1872,7 +1884,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1872
1884
`fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
`
1873
1885
`match pick.kind {
`
1874
1886
`InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
`
1875
``
`-
ObjectPick | WhereClausePick(_) | TraitPick => {
`
``
1887
`+
ObjectPick | WhereClausePick() | TraitPick() => {
`
1876
1888
`CandidateSource::Trait(pick.item.container_id(self.tcx))
`
1877
1889
`}
`
1878
1890
`}
`
`@@ -1948,7 +1960,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
1948
1960
` impl_bounds,
`
1949
1961
`));
`
1950
1962
`}
`
1951
``
`-
TraitCandidate(poly_trait_ref) => {
`
``
1963
`+
TraitCandidate(poly_trait_ref, _) => {
`
1952
1964
`// Some trait methods are excluded for arrays before 2021.
`
1953
1965
`` // (array.into_iter() wants a slice iterator for compatibility.)
``
1954
1966
`if let Some(method_name) = self.method_name {
`
`@@ -2274,11 +2286,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
2274
2286
`}
`
2275
2287
`}
`
2276
2288
``
``
2289
`+
let lint_ambiguous = match probes[0].0.kind {
`
``
2290
`+
TraitCandidate(_, lint) => lint,
`
``
2291
`+
_ => false,
`
``
2292
`+
};
`
``
2293
+
2277
2294
`// FIXME: check the return type here somehow.
`
2278
2295
`// If so, just use this trait and call it a day.
`
2279
2296
`Some(Pick {
`
2280
2297
`item: probes[0].0.item,
`
2281
``
`-
kind: TraitPick,
`
``
2298
`+
kind: TraitPick(lint_ambiguous),
`
2282
2299
`import_ids: probes[0].0.import_ids.clone(),
`
2283
2300
`autoderefs: 0,
`
2284
2301
`autoref_or_ptr_adjustment: None,
`
`@@ -2348,9 +2365,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
`
2348
2365
`}
`
2349
2366
`}
`
2350
2367
``
``
2368
`+
let lint_ambiguous = match probes[0].0.kind {
`
``
2369
`+
TraitCandidate(_, lint) => lint,
`
``
2370
`+
_ => false,
`
``
2371
`+
};
`
``
2372
+
2351
2373
`Some(Pick {
`
2352
2374
`item: child_candidate.item,
`
2353
``
`-
kind: TraitPick,
`
``
2375
`+
kind: TraitPick(lint_ambiguous),
`
2354
2376
`import_ids: child_candidate.import_ids.clone(),
`
2355
2377
`autoderefs: 0,
`
2356
2378
`autoref_or_ptr_adjustment: None,
`
`@@ -2611,7 +2633,7 @@ impl<'tcx> Candidate<'tcx> {
`
2611
2633
`kind: match self.kind {
`
2612
2634
`InherentImplCandidate { .. } => InherentImplPick,
`
2613
2635
`ObjectCandidate(_) => ObjectPick,
`
2614
``
`-
TraitCandidate(_) => TraitPick,
`
``
2636
`+
TraitCandidate(_, lint_ambiguous) => TraitPick(lint_ambiguous),
`
2615
2637
`WhereClauseCandidate(trait_ref) => {
`
2616
2638
`// Only trait derived from where-clauses should
`
2617
2639
`// appear here, so they should not contain any
`