// option. This file may not be copied, modified, or distributed
// except according to those terms.
-/*
+/*!
# check.rs
Within the check phase of type check, we check each item one at a time
(bodies of function expressions are checked as part of the containing
-function). Inference is used to supply types wherever they are
-unknown.
+function). Inference is used to supply types wherever they are unknown.
By far the most complex case is checking the body of a function. This
can be broken down into several distinct phases:
The types of top-level items, which never contain unbound type
variables, are stored directly into the `tcx` tables.
-N.B.: A type variable is not the same thing as a type parameter. A
+N.B., a type variable is not the same thing as a type parameter. A
type variable is rather an "instance" of a type parameter: that is,
given a generic function `fn foo<T>(t: T)`: while checking the
function `foo`, the type `ty_param(0)` refers to the type `T`, which
*/
-pub use self::Expectation::*;
-use self::autoderef::Autoderef;
-use self::callee::DeferredCallResolution;
-use self::coercion::{CoerceMany, DynamicCoerceMany};
-pub use self::compare_method::{compare_impl_method, compare_const_impl};
-use self::method::MethodCallee;
-use self::TupleArgumentsFlag::*;
+mod autoderef;
+pub mod dropck;
+pub mod _match;
+pub mod writeback;
+mod regionck;
+pub mod coercion;
+pub mod demand;
+pub mod method;
+mod upvar;
+mod wfcheck;
+mod cast;
+mod closure;
+mod callee;
+mod compare_method;
+mod generator_interior;
+mod intrinsic;
+mod op;
use astconv::AstConv;
-use hir::GenericArg;
-use hir::def::Def;
-use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
-use std::slice;
+use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
+use rustc::hir::{self, GenericArg, Node, ItemKind, PatKind};
+use rustc::hir::def::Def;
+use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
+use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use rustc::hir::itemlikevisit::ItemLikeVisitor;
+use middle::lang_items;
use namespace::Namespace;
+use rustc_data_structures::indexed_vec::Idx;
+use rustc_data_structures::sync::Lrc;
+use rustc_target::spec::abi::Abi;
use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
use rustc::infer::opaque_types::OpaqueTypeDecl;
use rustc::infer::type_variable::{TypeVariableOrigin};
use rustc::ty::query::Providers;
use rustc::ty::util::{Representability, IntTypeExt, Discr};
use rustc::ty::layout::VariantIdx;
-use rustc_data_structures::indexed_vec::Idx;
-use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
-
-use require_c_abi_if_variadic;
-use session::{CompileIncomplete, config, Session};
-use TypeAndSubsts;
-use lint;
-use util::common::{ErrorReported, indenter};
-use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap};
+use syntax_pos::{self, BytePos, Span, MultiSpan};
+use syntax::ast;
+use syntax::attr;
+use syntax::feature_gate::{GateIssue, emit_feature_err};
+use syntax::ptr::P;
+use syntax::source_map::{DUMMY_SP, original_sp};
+use syntax::symbol::{Symbol, LocalInternedString, keywords};
+use syntax::util::lev_distance::find_best_match_for_name;
use std::cell::{Cell, RefCell, Ref, RefMut};
-use rustc_data_structures::sync::Lrc;
use std::collections::hash_map::Entry;
use std::cmp;
use std::fmt::Display;
use std::iter;
use std::mem::replace;
use std::ops::{self, Deref};
-use rustc_target::spec::abi::Abi;
-use syntax::ast;
-use syntax::attr;
-use syntax::source_map::DUMMY_SP;
-use syntax::source_map::original_sp;
-use syntax::feature_gate::{GateIssue, emit_feature_err};
-use syntax::ptr::P;
-use syntax::symbol::{Symbol, LocalInternedString, keywords};
-use syntax::util::lev_distance::find_best_match_for_name;
-use syntax_pos::{self, BytePos, Span, MultiSpan};
+use std::slice;
-use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
-use rustc::hir::itemlikevisit::ItemLikeVisitor;
-use rustc::hir::Node;
-use rustc::hir::{self, PatKind, ItemKind};
-use rustc::middle::lang_items;
+use require_c_abi_if_variadic;
+use session::{CompileIncomplete, config, Session};
+use TypeAndSubsts;
+use lint;
+use util::common::{ErrorReported, indenter};
+use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap};
-mod autoderef;
-pub mod dropck;
-pub mod _match;
-pub mod writeback;
-mod regionck;
-pub mod coercion;
-pub mod demand;
-pub mod method;
-mod upvar;
-mod wfcheck;
-mod cast;
-mod closure;
-mod callee;
-mod compare_method;
-mod generator_interior;
-mod intrinsic;
-mod op;
+pub use self::Expectation::*;
+use self::autoderef::Autoderef;
+use self::callee::DeferredCallResolution;
+use self::coercion::{CoerceMany, DynamicCoerceMany};
+pub use self::compare_method::{compare_impl_method, compare_const_impl};
+use self::method::MethodCallee;
+use self::TupleArgumentsFlag::*;
/// The type of a local binding, including the revealed type for anon types.
#[derive(Copy, Clone)]
pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, def_id: DefId)
-> InheritedBuilder<'a, 'gcx, 'tcx> {
let hir_id_root = if def_id.is_local() {
- let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
- let hir_id = tcx.hir.definitions().node_to_hir_id(node_id);
+ let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
+ let hir_id = tcx.hir().definitions().node_to_hir_id(node_id);
DefId::local(hir_id.owner)
} else {
def_id
impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self {
let tcx = infcx.tcx;
- let item_id = tcx.hir.as_local_node_id(def_id);
- let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id));
+ let item_id = tcx.hir().as_local_node_id(def_id);
+ let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(id));
let implicit_region_bound = body_id.map(|body_id| {
- let body = tcx.hir.body(body_id);
+ let body = tcx.hir().body(body_id);
tcx.mk_region(ty::ReScope(region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::CallSite
pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
tcx.sess.track_errors(|| {
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
- tcx.hir.krate().visit_all_item_likes(&mut visit.as_deep_visitor());
+ tcx.hir().krate().visit_all_item_likes(&mut visit.as_deep_visitor());
})
}
pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
tcx.sess.track_errors(|| {
- tcx.hir.krate().visit_all_item_likes(&mut CheckItemTypesVisitor { tcx });
+ tcx.hir().krate().visit_all_item_likes(&mut CheckItemTypesVisitor { tcx });
})
}
id: ast::NodeId)
-> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)>
{
- match tcx.hir.get(id) {
+ match tcx.hir().get(id) {
Node::Item(item) => {
match item.node {
hir::ItemKind::Const(_, body) |
return tcx.has_typeck_tables(outer_def_id);
}
- let id = tcx.hir.as_local_node_id(def_id).unwrap();
+ let id = tcx.hir().as_local_node_id(def_id).unwrap();
primary_body_of(tcx, id).is_some()
}
return tcx.typeck_tables_of(outer_def_id);
}
- let id = tcx.hir.as_local_node_id(def_id).unwrap();
- let span = tcx.hir.span(id);
+ let id = tcx.hir().as_local_node_id(def_id).unwrap();
+ let span = tcx.hir().span(id);
// Figure out what primary body this item has.
let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id);
});
- let body = tcx.hir.body(body_id);
+ let body = tcx.hir().body(body_id);
let tables = Inherited::build(tcx, def_id).enter(|inh| {
let param_env = tcx.param_env(def_id);
// Consistency check our TypeckTables instance can hold all ItemLocalIds
// it will need to hold.
assert_eq!(tables.local_id_root,
- Some(DefId::local(tcx.hir.definitions().node_to_hir_id(id).owner)));
+ Some(DefId::local(tcx.hir().definitions().node_to_hir_id(id).owner)));
tables
}
fcx.yield_ty = Some(yield_ty);
}
- let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir.local_def_id(fn_id));
- let outer_node_id = fcx.tcx.hir.as_local_node_id(outer_def_id).unwrap();
+ let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id(fn_id));
+ let outer_node_id = fcx.tcx.hir().as_local_node_id(outer_def_id).unwrap();
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_node_id, }.visit_body(body);
// Add formal parameters.
fcx.write_ty(arg.hir_id, arg_ty);
}
- let fn_hir_id = fcx.tcx.hir.node_to_hir_id(fn_id);
+ let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id);
inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig);
fcx.check_return_expr(&body.value);
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() {
- if panic_impl_did == fcx.tcx.hir.local_def_id(fn_id) {
+ if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) {
if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() {
// at this point we don't care if there are duplicate handlers or if the handler has
// the wrong signature as this value we'll be used when writing metadata and that
}
let inputs = fn_sig.inputs();
- let span = fcx.tcx.hir.span(fn_id);
+ let span = fcx.tcx.hir().span(fn_id);
if inputs.len() == 1 {
let arg_is_panic_info = match inputs[0].sty {
ty::Ref(region, ty, mutbl) => match ty.sty {
);
}
- if let Node::Item(item) = fcx.tcx.hir.get(fn_id) {
+ if let Node::Item(item) = fcx.tcx.hir().get(fn_id) {
if let ItemKind::Fn(_, _, ref generics, _) = item.node {
if !generics.params.is_empty() {
fcx.tcx.sess.span_err(
// Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !`
if let Some(alloc_error_handler_did) = fcx.tcx.lang_items().oom() {
- if alloc_error_handler_did == fcx.tcx.hir.local_def_id(fn_id) {
+ if alloc_error_handler_did == fcx.tcx.hir().local_def_id(fn_id) {
if let Some(alloc_layout_did) = fcx.tcx.lang_items().alloc_layout() {
if declared_ret_ty.sty != ty::Never {
fcx.tcx.sess.span_err(
}
let inputs = fn_sig.inputs();
- let span = fcx.tcx.hir.span(fn_id);
+ let span = fcx.tcx.hir().span(fn_id);
if inputs.len() == 1 {
let arg_is_alloc_layout = match inputs[0].sty {
ty::Adt(ref adt, _) => {
);
}
- if let Node::Item(item) = fcx.tcx.hir.get(fn_id) {
+ if let Node::Item(item) = fcx.tcx.hir().get(fn_id) {
if let ItemKind::Fn(_, _, ref generics, _) = item.node {
if !generics.params.is_empty() {
fcx.tcx.sess.span_err(
fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: ast::NodeId,
span: Span) {
- let def_id = tcx.hir.local_def_id(id);
+ let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id);
fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: ast::NodeId,
span: Span) {
- let def_id = tcx.hir.local_def_id(id);
+ let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id);
debug!(
"check_item_type(it.id={}, it.name={})",
it.id,
- tcx.item_path_str(tcx.hir.local_def_id(it.id))
+ tcx.item_path_str(tcx.hir().local_def_id(it.id))
);
let _indenter = indenter();
match it.node {
// Consts can play a role in type-checking, so they are included here.
hir::ItemKind::Static(..) => {
- let def_id = tcx.hir.local_def_id(it.id);
+ let def_id = tcx.hir().local_def_id(it.id);
tcx.typeck_tables_of(def_id);
maybe_check_static_with_link_section(tcx, def_id, it.span);
}
hir::ItemKind::Const(..) => {
- tcx.typeck_tables_of(tcx.hir.local_def_id(it.id));
+ tcx.typeck_tables_of(tcx.hir().local_def_id(it.id));
}
hir::ItemKind::Enum(ref enum_definition, _) => {
check_enum(tcx, it.span, &enum_definition.variants, it.id);
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
hir::ItemKind::Impl(.., ref impl_item_refs) => {
debug!("ItemKind::Impl {} with id {}", it.name, it.id);
- let impl_def_id = tcx.hir.local_def_id(it.id);
+ let impl_def_id = tcx.hir().local_def_id(it.id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
check_impl_items_against_trait(
tcx,
}
}
hir::ItemKind::Trait(..) => {
- let def_id = tcx.hir.local_def_id(it.id);
+ let def_id = tcx.hir().local_def_id(it.id);
check_on_unimplemented(tcx, def_id, it);
}
hir::ItemKind::Struct(..) => {
check_union(tcx, it.id, it.span);
}
hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => {
- let def_id = tcx.hir.local_def_id(it.id);
+ let def_id = tcx.hir().local_def_id(it.id);
let pty_ty = tcx.type_of(def_id);
let generics = tcx.generics_of(def_id);
check_bounds_are_used(tcx, &generics, pty_ty);
}
} else {
for item in &m.items {
- let generics = tcx.generics_of(tcx.hir.local_def_id(item.id));
+ let generics = tcx.generics_of(tcx.hir().local_def_id(item.id));
if generics.params.len() - generics.own_counts().lifetimes != 0 {
let mut err = struct_span_err!(
tcx.sess,
fn check_on_unimplemented<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_def_id: DefId,
item: &hir::Item) {
- let item_def_id = tcx.hir.local_def_id(item.id);
+ let item_def_id = tcx.hir().local_def_id(item.id);
// an error would be reported if this fails.
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id);
}
let trait_def = tcx.trait_def(impl_trait_ref.def_id);
let mut overridden_associated_type = None;
- let impl_items = || impl_item_refs.iter().map(|iiref| tcx.hir.impl_item(iiref.id));
+ let impl_items = || impl_item_refs.iter().map(|iiref| tcx.hir().impl_item(iiref.id));
// Check existing impl methods to see if they are both present in trait
// and compatible with trait signature
for impl_item in impl_items() {
- let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id));
+ let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.id));
let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id)
.find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) &&
tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id))
err.span_label(impl_item.span, "does not match trait");
// We can only get the spans from local trait definition
// Same for E0324 and E0325
- if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir().span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, "item in trait");
}
err.emit()
}
}
hir::ImplItemKind::Method(..) => {
- let trait_span = tcx.hir.span_if_local(ty_trait_item.def_id);
+ let trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
if ty_trait_item.kind == ty::AssociatedKind::Method {
compare_impl_method(tcx,
&ty_impl_item,
ty_impl_item.ident,
impl_trait_ref);
err.span_label(impl_item.span, "does not match trait");
- if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir().span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, "item in trait");
}
err.emit()
ty_impl_item.ident,
impl_trait_ref);
err.span_label(impl_item.span, "does not match trait");
- if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
+ if let Some(trait_span) = tcx.hir().span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, "item in trait");
}
err.emit()
.map(|trait_item| trait_item.ident.to_string())
.collect::<Vec<_>>().join("`, `")));
for trait_item in missing_items {
- if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) {
+ if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
err.span_label(span, format!("`{}` from trait", trait_item.ident));
} else {
err.note_trait_signature(trait_item.ident.to_string(),
let param_env = tcx.param_env(field.did);
let layout = tcx.layout_of(param_env.and(ty));
// We are currently checking the type this field came from, so it must be local
- let span = tcx.hir.span_if_local(field.did).unwrap();
+ let span = tcx.hir().span_if_local(field.did).unwrap();
let zst = layout.map(|layout| layout.is_zst()).unwrap_or(false);
let align1 = layout.map(|layout| layout.align.abi.bytes() == 1).unwrap_or(false);
(span, zst, align1)
sp: Span,
vs: &'tcx [hir::Variant],
id: ast::NodeId) {
- let def_id = tcx.hir.local_def_id(id);
+ let def_id = tcx.hir().local_def_id(id);
let def = tcx.adt_def(def_id);
def.destructor(tcx); // force the destructor to be evaluated
for v in vs {
if let Some(ref e) = v.node.disr_expr {
- tcx.typeck_tables_of(tcx.hir.local_def_id(e.id));
+ tcx.typeck_tables_of(tcx.hir().local_def_id(e.id));
}
}
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
let variant_did = def.variants[VariantIdx::new(i)].did;
- let variant_i_node_id = tcx.hir.as_local_node_id(variant_did).unwrap();
- let variant_i = tcx.hir.expect_variant(variant_i_node_id);
+ let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap();
+ let variant_i = tcx.hir().expect_variant(variant_i_node_id);
let i_span = match variant_i.node.disr_expr {
- Some(ref expr) => tcx.hir.span(expr.id),
- None => tcx.hir.span(variant_i_node_id)
+ Some(ref expr) => tcx.hir().span(expr.id),
+ None => tcx.hir().span(variant_i_node_id)
};
let span = match v.node.disr_expr {
- Some(ref expr) => tcx.hir.span(expr.id),
+ Some(ref expr) => tcx.hir().span(expr.id),
None => v.span
};
struct_span_err!(tcx.sess, span, E0081,
-> Lrc<ty::GenericPredicates<'tcx>>
{
let tcx = self.tcx;
- let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
- let item_id = tcx.hir.ty_param_owner(node_id);
- let item_def_id = tcx.hir.local_def_id(item_id);
+ let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
+ let item_id = tcx.hir().ty_param_owner(node_id);
+ let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
Lrc::new(ty::GenericPredicates {
pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> LocalTy<'tcx> {
self.locals.borrow().get(&nid).cloned().unwrap_or_else(||
span_bug!(span, "no type for local variable {}",
- self.tcx.hir.node_to_string(nid))
+ self.tcx.hir().node_to_string(nid))
)
}
}
pub fn write_field_index(&self, node_id: ast::NodeId, index: usize) {
- let hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ let hir_id = self.tcx.hir().node_to_hir_id(node_id);
self.tables.borrow_mut().field_indices_mut().insert(hir_id, index);
}
parent_id: ast::NodeId,
value: &T,
) -> T {
- let parent_def_id = self.tcx.hir.local_def_id(parent_id);
+ let parent_def_id = self.tcx.hir().local_def_id(parent_id);
debug!("instantiate_opaque_types_from_value(parent_def_id={:?}, value={:?})",
parent_def_id,
value);
Some(&t) => t,
None if self.is_tainted_by_errors() => self.tcx.types.err,
None => {
- let node_id = self.tcx.hir.hir_to_node_id(id);
+ let node_id = self.tcx.hir().hir_to_node_id(id);
bug!("no type for node {}: {} in fcx {}",
- node_id, self.tcx.hir.node_to_string(node_id),
+ node_id, self.tcx.hir().node_to_string(node_id),
self.tag());
}
}
);
self.check_argument_types(sp, expr_sp, &method.sig.inputs()[1..], &expected_arg_tys[..],
args_no_rcvr, method.sig.variadic, tuple_arguments,
- self.tcx.hir.span_if_local(method.def_id));
+ self.tcx.hir().span_if_local(method.def_id));
method.sig.output()
}
formal_tys.iter().map(|t| self.ty_to_string(*t)).collect::<Vec<String>>());
// Check the arguments.
- // We do this in a pretty awful way: first we typecheck any arguments
- // that are not closures, then we typecheck the closures. This is so
+ // We do this in a pretty awful way: first we type-check any arguments
+ // that are not closures, then we type-check the closures. This is so
// that we have more information about the types of arguments when we
- // typecheck the functions. This isn't really the right way to do this.
+ // type-check the functions. This isn't really the right way to do this.
for &check_closures in &[false, true] {
debug!("check_closures={}", check_closures);
for (i, arg) in args.iter().take(t).enumerate() {
// Warn only for the first loop (the "no closures" one).
// Closure arguments themselves can't be diverging, but
- // a previous argument can, e.g. `foo(panic!(), || {})`.
+ // a previous argument can, e.g., `foo(panic!(), || {})`.
if !check_closures {
self.warn_if_unreachable(arg.id, arg.span, "expression");
}
self.check_expr_with_expectation_and_needs(expr, NoExpectation, needs)
}
- // determine the `self` type, using fresh variables for all variables
+ // Determine the `Self` type, using fresh variables for all variables
// declared on the impl declaration e.g., `impl<A,B> for Vec<(A,B)>`
- // would return ($0, $1) where $0 and $1 are freshly instantiated type
+ // would return `($0, $1)` where `$0` and `$1` are freshly instantiated type
// variables.
pub fn impl_self_ty(&self,
span: Span, // (potential) receiver for this impl
len.assert_usize(self.tcx),
field.as_str().parse::<u64>()
) {
- let base = self.tcx.hir.node_to_pretty_string(base.id);
+ let base = self.tcx.hir().node_to_pretty_string(base.id);
let help = "instead of using tuple indexing, use array indexing";
let suggestion = format!("{}[{}]", base, field);
let applicability = if len < user_index {
}
}
ty::RawPtr(..) => {
- let base = self.tcx.hir.node_to_pretty_string(base.id);
+ let base = self.tcx.hir().node_to_pretty_string(base.id);
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
let suggestion = format!("(*{}).{}", base, field);
err.span_suggestion_with_applicability(
let mut error_happened = false;
- // Typecheck each field.
+ // Type-check each field.
for field in ast_fields {
let ident = tcx.adjust_ident(field.ident, variant.did, self.body_id).0;
let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) {
seen_fields.insert(ident, field.span);
self.write_field_index(field.id, i);
- // we don't look at stability attributes on
+ // We don't look at stability attributes on
// struct-like enums (yet...), but it's definitely not
- // a bug to have construct one.
+ // a bug to have constructed one.
if adt_kind != ty::AdtKind::Enum {
tcx.check_stability(v_field.did, Some(expr_id), field.span);
}
};
// Make sure to give a type to the field even if there's
- // an error, so we can continue typechecking
+ // an error, so we can continue type-checking.
self.check_expr_coercable_to_type(&field.expr, field_type);
}
if let Some((variant, did, substs)) = variant {
debug!("check_struct_path: did={:?} substs={:?}", did, substs);
- let hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ let hir_id = self.tcx.hir().node_to_hir_id(node_id);
self.write_user_substs_from_substs(hir_id, substs, None);
// Check bounds on type arguments used in the path.
hir::QPath::TypeRelative(ref qself, _) => qself.span
};
- // Prohibit struct expressions when non exhaustive flag is set.
+ // Prohibit struct expressions when non-exhaustive flag is set.
let adt = adt_ty.ty_adt_def().expect("`check_struct_path` returned non-ADT type");
if !adt.did.is_local() && variant.is_field_list_non_exhaustive() {
span_err!(self.tcx.sess, expr.span, E0639,
expr: &'gcx hir::Expr,
expected: Expectation<'tcx>,
needs: Needs) -> Ty<'tcx> {
- debug!(">> typechecking: expr={:?} expected={:?}",
+ debug!(">> type-checking: expr={:?} expected={:?}",
expr, expected);
// Warn for expressions after diverging siblings.
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);
- debug!("type of {} is...", self.tcx.hir.node_to_string(expr.id));
+ debug!("type of {} is...", self.tcx.hir().node_to_string(expr.id));
debug!("... {:?}, expected is {:?}", ty, expected);
ty
if !tcx.features().unsized_locals {
// We want to remove some Sized bounds from std functions,
// but don't want to expose the removal to stable Rust.
- // i.e. we don't want to allow
+ // i.e., we don't want to allow
//
// ```rust
// drop as fn(str);
}
}
}
- // There was an error, make typecheck fail
+ // There was an error; make type-check fail.
tcx.types.err
}
if destination.target_id.is_ok() {
tcx.types.never
} else {
- // There was an error, make typecheck fail
+ // There was an error; make type-check fail.
tcx.types.err
}
}
tcx.mk_array(element_ty, args.len() as u64)
}
hir::ExprKind::Repeat(ref element, ref count) => {
- let count_def_id = tcx.hir.local_def_id(count.id);
+ let count_def_id = tcx.hir().local_def_id(count.id);
let param_env = ty::ParamEnv::empty();
let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id);
let instance = ty::Instance::resolve(
}
if needs_note {
err.help("to access tuple elements, use tuple indexing \
- syntax (e.g. `tuple.0`)");
+ syntax (e.g., `tuple.0`)");
}
}
err.emit();
ty, def, segment);
// Write back the new resolution.
- let hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ let hir_id = self.tcx.hir().node_to_hir_id(node_id);
self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, def);
(def, ty)
(self.to_ty(qself), segment)
}
};
- let hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ let hir_id = self.tcx.hir().node_to_hir_id(node_id);
if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) {
// Return directly on cache hit. This is useful to avoid doubly reporting
// errors with default match binding modes. See #44614.
pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, bool)> {
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
// `while` before reaching it, as block tail returns are not available in them.
- if let Some(fn_id) = self.tcx.hir.get_return_block(blk_id) {
- let parent = self.tcx.hir.get(fn_id);
+ if let Some(fn_id) = self.tcx.hir().get_return_block(blk_id) {
+ let parent = self.tcx.hir().get(fn_id);
if let Node::Item(&hir::Item {
name, node: hir::ItemKind::Fn(ref decl, ..), ..
Def::Local(nid) | Def::Upvar(nid, ..) => {
let ty = self.local_ty(span, nid).decl_ty;
let ty = self.normalize_associated_types_in(span, &ty);
- self.write_ty(self.tcx.hir.node_to_hir_id(node_id), ty);
+ self.write_ty(self.tcx.hir().node_to_hir_id(node_id), ty);
return (ty, def);
}
_ => {}
assert!(!substs.has_escaping_bound_vars());
assert!(!ty.has_escaping_bound_vars());
- // Write the "user substs" down first thing for later.
- let hir_id = self.tcx.hir.node_to_hir_id(node_id);
+ // First, store the "user substs" for later.
+ let hir_id = self.tcx.hir().node_to_hir_id(node_id);
self.write_user_substs_from_substs(hir_id, substs, user_self_ty);
// Add all the obligations that are required, substituting and
// If our calling expression is indeed the function itself, we're good!
// If not, generate an error that this can only be called directly.
- if let Node::Expr(expr) = self.tcx.hir.get(self.tcx.hir.get_parent_node(node_id)) {
+ if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(node_id)) {
if let hir::ExprKind::Call(ref callee, ..) = expr.node {
if callee.id == node_id {
return
});
for (&used, param) in types_used.iter().zip(types) {
if !used {
- let id = tcx.hir.as_local_node_id(param.def_id).unwrap();
- let span = tcx.hir.span(id);
+ let id = tcx.hir().as_local_node_id(param.def_id).unwrap();
+ let span = tcx.hir().span(id);
struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name)
.span_label(span, "unused type parameter")
.emit();