]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/astconv.rs
Rollup merge of #68005 - GuillaumeGomez:explanation-e0184, r=Dylan-DPC
[rust.git] / src / librustc_typeck / astconv.rs
index 8934fd4df742a7853d2f1acfd33a5cc706d84e3d..0233b68a7ce21c30cac8aa7eb3ea01178806cf25 100644 (file)
@@ -3,40 +3,41 @@
 //! instance of `AstConv`.
 
 use crate::collect::PlaceholderHirTyCollector;
-use crate::hir::def::{CtorOf, DefKind, Res};
-use crate::hir::def_id::DefId;
-use crate::hir::intravisit::Visitor;
-use crate::hir::print;
-use crate::hir::{self, ExprKind, GenericArg, GenericArgs};
 use crate::lint;
 use crate::middle::lang_items::SizedTraitLangItem;
 use crate::middle::resolve_lifetime as rl;
 use crate::namespace::Namespace;
 use crate::require_c_abi_if_c_variadic;
 use crate::util::common::ErrorReported;
-use crate::util::nodemap::FxHashMap;
-use errors::{Applicability, DiagnosticId};
+use errors::{struct_span_err, Applicability, DiagnosticId};
 use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
 use rustc::traits;
+use rustc::traits::astconv_object_safety_violations;
+use rustc::traits::error_reporting::report_object_safety_error;
+use rustc::traits::wf::object_region_bounds;
 use rustc::ty::subst::{self, InternalSubsts, Subst, SubstsRef};
-use rustc::ty::wf::object_region_bounds;
 use rustc::ty::{self, Const, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable};
 use rustc::ty::{GenericParamDef, GenericParamDefKind};
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_hir as hir;
+use rustc_hir::def::{CtorOf, DefKind, Res};
+use rustc_hir::def_id::DefId;
+use rustc_hir::intravisit::Visitor;
+use rustc_hir::print;
+use rustc_hir::{ExprKind, GenericArg, GenericArgs};
+use rustc_span::symbol::sym;
 use rustc_span::{MultiSpan, Span, DUMMY_SP};
 use rustc_target::spec::abi;
 use smallvec::SmallVec;
 use syntax::ast;
 use syntax::errors::pluralize;
 use syntax::feature_gate::feature_err;
-use syntax::symbol::sym;
 use syntax::util::lev_distance::find_best_match_for_name;
 
 use std::collections::BTreeSet;
 use std::iter;
 use std::slice;
 
-use rustc_data_structures::fx::FxHashSet;
-
 use rustc_error_codes::*;
 
 #[derive(Debug)]
@@ -1118,13 +1119,14 @@ pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound<'_>], span: Span) -> bo
                 if unbound.is_none() {
                     unbound = Some(&ptr.trait_ref);
                 } else {
-                    span_err!(
+                    struct_span_err!(
                         tcx.sess,
                         span,
                         E0203,
                         "type parameter has more than one relaxed default \
                         bound, only one is supported"
-                    );
+                    )
+                    .emit();
                 }
             }
         }
@@ -1444,7 +1446,13 @@ fn conv_object_ty_poly_trait_ref(
         }
 
         if regular_traits.is_empty() && auto_traits.is_empty() {
-            span_err!(tcx.sess, span, E0224, "at least one trait is required for an object type");
+            struct_span_err!(
+                tcx.sess,
+                span,
+                E0224,
+                "at least one trait is required for an object type"
+            )
+            .emit();
             return tcx.types.err;
         }
 
@@ -1453,9 +1461,10 @@ fn conv_object_ty_poly_trait_ref(
         // to avoid ICEs.
         for item in &regular_traits {
             let object_safety_violations =
-                tcx.astconv_object_safety_violations(item.trait_ref().def_id());
+                astconv_object_safety_violations(tcx, item.trait_ref().def_id());
             if !object_safety_violations.is_empty() {
-                tcx.report_object_safety_error(
+                report_object_safety_error(
+                    tcx,
                     span,
                     item.trait_ref().def_id(),
                     object_safety_violations,
@@ -1599,13 +1608,14 @@ fn conv_object_ty_poly_trait_ref(
                     self.ast_region_to_region(lifetime, None)
                 } else {
                     self.re_infer(None, span).unwrap_or_else(|| {
-                        span_err!(
+                        struct_span_err!(
                             tcx.sess,
                             span,
                             E0228,
                             "the lifetime bound for this object type cannot be deduced \
                              from context; please supply an explicit bound"
-                        );
+                        )
+                        .emit();
                         tcx.lifetimes.re_static
                     })
                 }
@@ -2556,12 +2566,12 @@ pub fn res_to_ty(
                 assert_eq!(opt_self_ty, None);
                 self.prohibit_generics(path.segments);
                 match prim_ty {
-                    hir::Bool => tcx.types.bool,
-                    hir::Char => tcx.types.char,
-                    hir::Int(it) => tcx.mk_mach_int(it),
-                    hir::Uint(uit) => tcx.mk_mach_uint(uit),
-                    hir::Float(ft) => tcx.mk_mach_float(ft),
-                    hir::Str => tcx.mk_str(),
+                    hir::PrimTy::Bool => tcx.types.bool,
+                    hir::PrimTy::Char => tcx.types.char,
+                    hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
+                    hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
+                    hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
+                    hir::PrimTy::Str => tcx.mk_str(),
                 }
             }
             Res::Err => {
@@ -2775,11 +2785,11 @@ pub fn ty_of_fn(
         }
         let input_tys = decl.inputs.iter().map(|a| self.ty_of_arg(a, None));
         let output_ty = match decl.output {
-            hir::Return(ref output) => {
+            hir::FunctionRetTy::Return(ref output) => {
                 visitor.visit_ty(output);
                 self.ast_ty_to_ty(output)
             }
-            hir::DefaultReturn(..) => tcx.mk_unit(),
+            hir::FunctionRetTy::DefaultReturn(..) => tcx.mk_unit(),
         };
 
         debug!("ty_of_fn: output_ty={:?}", output_ty);
@@ -2878,12 +2888,13 @@ fn compute_object_lifetime_bound(
         // error.
         let r = derived_region_bounds[0];
         if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
-            span_err!(
+            struct_span_err!(
                 tcx.sess,
                 span,
                 E0227,
                 "ambiguous lifetime bound, explicit lifetime bound required"
-            );
+            )
+            .emit();
         }
         return Some(r);
     }