Skip to content

Commit c8334ce

Browse files
Move autoderef to rustc_hir_analysis
1 parent ef4046e commit c8334ce

File tree

16 files changed

+70
-46
lines changed

16 files changed

+70
-46
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ hir_analysis_self_in_impl_self =
120120
121121
hir_analysis_linkage_type =
122122
invalid type for variable with `#[linkage]` attribute
123+
124+
hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
125+
.label = deref recursion limit reached
126+
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entri
22
33
trait_selection_unable_to_construct_constant_value = unable to construct a constant value for the unevaluated constant {$unevaluated}
44
5-
trait_selection_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
6-
.label = deref recursion limit reached
7-
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
8-
95
trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`
106
.label = empty on-clause here
117

compiler/rustc_trait_selection/src/autoderef.rs renamed to compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
178178
self.state.obligations
179179
}
180180

181+
pub fn current_obligations(&self) -> Vec<traits::PredicateObligation<'tcx>> {
182+
self.state.obligations.clone()
183+
}
184+
181185
pub fn steps(&self) -> &[(Ty<'tcx>, AutoderefKind)] {
182186
&self.state.steps
183187
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use crate::autoderef::Autoderef;
12
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
3+
24
use hir::def::DefKind;
35
use rustc_ast as ast;
46
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
@@ -22,7 +24,6 @@ use rustc_session::parse::feature_err;
2224
use rustc_span::symbol::{sym, Ident, Symbol};
2325
use rustc_span::{Span, DUMMY_SP};
2426
use rustc_target::spec::abi::Abi;
25-
use rustc_trait_selection::autoderef::Autoderef;
2627
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
2728
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
2829
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,15 @@ pub(crate) struct LinkageType {
300300
#[primary_span]
301301
pub span: Span,
302302
}
303+
304+
#[derive(Diagnostic)]
305+
#[help]
306+
#[diag(hir_analysis_auto_deref_reached_recursion_limit, code = "E0055")]
307+
pub struct AutoDerefReachedRecursionLimit<'a> {
308+
#[primary_span]
309+
#[label]
310+
pub span: Span,
311+
pub ty: Ty<'a>,
312+
pub suggested_limit: rustc_session::Limit,
313+
pub crate_name: Symbol,
314+
}

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern crate rustc_middle;
8484
pub mod check;
8585

8686
pub mod astconv;
87+
pub mod autoderef;
8788
mod bounds;
8889
mod check_unused;
8990
mod coherence;

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
use super::method::MethodCallee;
33
use super::{FnCtxt, PlaceOp};
44

5+
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
56
use rustc_infer::infer::InferOk;
67
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
78
use rustc_middle::ty::{self, Ty};
89
use rustc_span::Span;
9-
use rustc_trait_selection::autoderef::{Autoderef, AutoderefKind};
1010

1111
use std::iter;
1212

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed,
88
use rustc_hir as hir;
99
use rustc_hir::def::{self, CtorKind, Namespace, Res};
1010
use rustc_hir::def_id::DefId;
11+
use rustc_hir_analysis::autoderef::Autoderef;
1112
use rustc_infer::{
1213
infer,
1314
traits::{self, Obligation},
@@ -25,7 +26,6 @@ use rustc_span::def_id::LocalDefId;
2526
use rustc_span::symbol::{sym, Ident};
2627
use rustc_span::Span;
2728
use rustc_target::spec::abi;
28-
use rustc_trait_selection::autoderef::Autoderef;
2929
use rustc_trait_selection::infer::InferCtxtExt as _;
3030
use rustc_trait_selection::traits::error_reporting::DefIdOrName;
3131
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::subst::GenericArgKind;
2020
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitable};
2121
use rustc_session::Session;
2222
use rustc_span::symbol::Ident;
23-
use rustc_span::{self, Span};
23+
use rustc_span::{self, Span, DUMMY_SP};
2424
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
2525

2626
use std::cell::{Cell, RefCell};
@@ -175,6 +175,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
175175
fn_sig
176176
})
177177
}),
178+
autoderef_steps: Box::new(|ty| {
179+
let mut autoderef = self.autoderef(DUMMY_SP, ty).silence_errors();
180+
let mut steps = vec![];
181+
while let Some((ty, _)) = autoderef.next() {
182+
steps.push((ty, autoderef.current_obligations()));
183+
}
184+
steps
185+
}),
178186
}
179187
}
180188

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::Applicability;
1010
use rustc_hir as hir;
1111
use rustc_hir::def::DefKind;
12+
use rustc_hir_analysis::autoderef::{self, Autoderef};
1213
use rustc_infer::infer::canonical::OriginalQueryValues;
1314
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
1415
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -29,7 +30,6 @@ use rustc_span::lev_distance::{
2930
};
3031
use rustc_span::symbol::sym;
3132
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
32-
use rustc_trait_selection::autoderef::{self, Autoderef};
3333
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3434
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3535
use rustc_trait_selection::traits::query::method_autoderef::{

0 commit comments

Comments
 (0)