Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace some trivial struct_span_err!s in typeck.
  • Loading branch information
jumbatm committed Sep 1, 2020
commit 57edf88b400ff6c6ae1de255fbd7e3448aca4fb2
1 change: 1 addition & 0 deletions compiler/rustc_typeck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ doctest = false
[dependencies]
rustc_arena = { path = "../rustc_arena" }
tracing = "0.1"
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::astconv::{
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
};
use crate::errors::AssocTypeBindingNotAllowed;
use rustc_ast::ast::ParamKindOrd;
use rustc_errors::{pluralize, struct_span_err, DiagnosticId, ErrorReported};
use rustc_hir as hir;
Expand Down Expand Up @@ -544,13 +545,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

/// Emits an error regarding forbidden type binding associations
pub fn prohibit_assoc_ty_binding(tcx: TyCtxt<'_>, span: Span) {
let mut err = struct_span_err!(
tcx.sess,
span,
E0229,
"associated type bindings are not allowed here"
);
err.span_label(span, "associated type not allowed here").emit();
tcx.sess.emit_err(AssocTypeBindingNotAllowed { span });
}

/// Prohibits explicit lifetime arguments if late-bound lifetime parameters
Expand Down
57 changes: 14 additions & 43 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ mod generics;

use crate::bounds::Bounds;
use crate::collect::PlaceholderHirTyCollector;
use crate::errors::{
AmbiguousLifetimeBound, MultipleRelaxedDefaultBounds, TraitObjectDeclaredWithNoTraits,
TypeofReservedKeywordUsed, ValueOfAssociatedStructAlreadySpecified,
};
use crate::middle::resolve_lifetime as rl;
use crate::require_c_abi_if_c_variadic;
use rustc_ast::util::lev_distance::find_best_match_for_name;
Expand Down Expand Up @@ -684,14 +688,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if unbound.is_none() {
unbound = Some(&ptr.trait_ref);
} else {
struct_span_err!(
tcx.sess,
span,
E0203,
"type parameter has more than one relaxed default \
bound, only one is supported"
)
.emit();
tcx.sess.emit_err(MultipleRelaxedDefaultBounds { span });
}
}
}
Expand Down Expand Up @@ -927,18 +924,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
dup_bindings
.entry(assoc_ty.def_id)
.and_modify(|prev_span| {
struct_span_err!(
self.tcx().sess,
binding.span,
E0719,
"the value of the associated type `{}` (from trait `{}`) \
is already specified",
binding.item_name,
tcx.def_path_str(assoc_ty.container.id())
)
.span_label(binding.span, "re-bound here")
.span_label(*prev_span, format!("`{}` bound here first", binding.item_name))
.emit();
self.tcx().sess.emit_err(ValueOfAssociatedStructAlreadySpecified {
span: binding.span,
prev_span: *prev_span,
item_name: binding.item_name,
def_path: tcx.def_path_str(assoc_ty.container.id()),
});
})
.or_insert(binding.span);
}
Expand Down Expand Up @@ -1051,13 +1042,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}

if regular_traits.is_empty() && auto_traits.is_empty() {
struct_span_err!(
tcx.sess,
span,
E0224,
"at least one trait is required for an object type"
)
.emit();
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span });
return tcx.ty_error();
}

Expand Down Expand Up @@ -2059,15 +2044,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.normalize_ty(ast_ty.span, array_ty)
}
hir::TyKind::Typeof(ref _e) => {
struct_span_err!(
tcx.sess,
ast_ty.span,
E0516,
"`typeof` is a reserved keyword but unimplemented"
)
.span_label(ast_ty.span, "reserved keyword")
.emit();

tcx.sess.emit_err(TypeofReservedKeywordUsed { span: ast_ty.span });
tcx.ty_error()
}
hir::TyKind::Infer => {
Expand Down Expand Up @@ -2283,13 +2260,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// error.
let r = derived_region_bounds[0];
if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
struct_span_err!(
tcx.sess,
span,
E0227,
"ambiguous lifetime bound, explicit lifetime bound required"
)
.emit();
tcx.sess.emit_err(AmbiguousLifetimeBound { span });
}
Some(r)
}
Expand Down
27 changes: 11 additions & 16 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorReported};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
Expand Down Expand Up @@ -366,24 +367,18 @@ fn check_region_bounds_on_impl_item<'tcx>(
let item_kind = assoc_item_kind_str(impl_m);
let def_span = tcx.sess.source_map().guess_head_span(span);
let span = tcx.hir().get_generics(impl_m.def_id).map(|g| g.span).unwrap_or(def_span);
let mut err = struct_span_err!(
tcx.sess,
let generics_span = if let Some(sp) = tcx.hir().span_if_local(trait_m.def_id) {
let def_sp = tcx.sess.source_map().guess_head_span(sp);
Some(tcx.hir().get_generics(trait_m.def_id).map(|g| g.span).unwrap_or(def_sp))
} else {
None
};
tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
span,
E0195,
"lifetime parameters or bounds on {} `{}` do not match the trait declaration",
item_kind,
impl_m.ident,
);
err.span_label(span, &format!("lifetimes do not match {} in trait", item_kind));
if let Some(sp) = tcx.hir().span_if_local(trait_m.def_id) {
let def_sp = tcx.sess.source_map().guess_head_span(sp);
let sp = tcx.hir().get_generics(trait_m.def_id).map(|g| g.span).unwrap_or(def_sp);
err.span_label(
sp,
&format!("lifetimes in impl do not match this {} in trait", item_kind),
);
}
err.emit();
ident: impl_m.ident,
generics_span,
});
return Err(ErrorReported);
}

Expand Down
69 changes: 20 additions & 49 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ use crate::check::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExp
use crate::check::FnCtxt;
use crate::check::Needs;
use crate::check::TupleArgumentsFlag::DontTupleArguments;
use crate::errors::{
FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct,
YieldExprOutsideOfGenerator,
};
use crate::type_error_struct;

use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive};
use rustc_ast as ast;
use rustc_ast::util::lev_distance::find_best_match_for_name;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -439,14 +444,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
});
if !is_named {
struct_span_err!(
self.tcx.sess,
oprnd.span,
E0745,
"cannot take address of a temporary"
)
.span_label(oprnd.span, "temporary value")
.emit();
self.tcx.sess.emit_err(AddressOfTemporaryTaken { span: oprnd.span })
}
}

Expand Down Expand Up @@ -665,13 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
if self.ret_coercion.is_none() {
struct_span_err!(
self.tcx.sess,
expr.span,
E0572,
"return statement outside of function body",
)
.emit();
self.tcx.sess.emit_err(ReturnStmtOutsideOfFnBody { span: expr.span });
} else if let Some(ref e) = expr_opt {
if self.ret_coercion_span.borrow().is_none() {
*self.ret_coercion_span.borrow_mut() = Some(e.span);
Expand Down Expand Up @@ -740,6 +732,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_span: &Span,
) {
if !lhs.is_syntactic_place_expr() {
// FIXME: Make this use SessionDiagnostic once error codes can be dynamically set.
let mut err = self.tcx.sess.struct_span_err_with_code(
*expr_span,
"invalid left-hand side of assignment",
Expand Down Expand Up @@ -1120,14 +1113,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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() {
struct_span_err!(
self.tcx.sess,
expr.span,
E0639,
"cannot create non-exhaustive {} using struct expression",
adt.variant_descr()
)
.emit();
self.tcx
.sess
.emit_err(StructExprNonExhaustive { span: expr.span, what: adt.variant_descr() });
}

let error_happened = self.check_expr_struct_fields(
Expand Down Expand Up @@ -1165,13 +1153,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.insert(expr.hir_id, fru_field_types);
}
_ => {
struct_span_err!(
self.tcx.sess,
base_expr.span,
E0436,
"functional record update syntax requires a struct"
)
.emit();
self.tcx
.sess
.emit_err(FunctionalRecordUpdateOnNonStruct { span: base_expr.span });
}
}
}
Expand Down Expand Up @@ -1234,18 +1218,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
error_happened = true;
if let Some(prev_span) = seen_fields.get(&ident) {
let mut err = struct_span_err!(
self.tcx.sess,
field.ident.span,
E0062,
"field `{}` specified more than once",
ident
);

err.span_label(field.ident.span, "used more than once");
err.span_label(*prev_span, format!("first use of `{}`", ident));

err.emit();
tcx.sess.emit_err(FieldMultiplySpecifiedInInitializer {
span: field.ident.span,
prev_span: *prev_span,
ident,
});
} else {
self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name, span);
}
Expand Down Expand Up @@ -1876,13 +1853,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.mk_unit()
}
_ => {
struct_span_err!(
self.tcx.sess,
expr.span,
E0627,
"yield expression outside of generator literal"
)
.emit();
self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span });
self.tcx.mk_unit()
}
}
Expand Down
47 changes: 11 additions & 36 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Type-checking for the rust-intrinsic and platform-intrinsic
//! intrinsics that the compiler exposes.

use crate::errors::{
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
WrongNumberOfTypeArgumentsToInstrinsic,
};
use crate::require_same_types;

use rustc_errors::struct_span_err;
Expand Down Expand Up @@ -41,17 +45,11 @@ fn equate_intrinsic_type<'tcx>(
_ => bug!(),
};

struct_span_err!(
tcx.sess,
tcx.sess.emit_err(WrongNumberOfTypeArgumentsToInstrinsic {
span,
E0094,
"intrinsic has wrong number of type \
parameters: found {}, expected {}",
i_n_tps,
n_tps
)
.span_label(span, format!("expected {} type parameter", n_tps))
.emit();
found: i_n_tps,
expected: n_tps,
});
return;
}

Expand Down Expand Up @@ -146,15 +144,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
| "umin" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], param(0)),
"fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk_unit()),
op => {
struct_span_err!(
tcx.sess,
it.span,
E0092,
"unrecognized atomic operation function: `{}`",
op
)
.span_label(it.span, "unrecognized atomic operation")
.emit();
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op });
return;
}
};
Expand Down Expand Up @@ -380,15 +370,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),

other => {
struct_span_err!(
tcx.sess,
it.span,
E0093,
"unrecognized intrinsic function: `{}`",
other,
)
.span_label(it.span, "unrecognized intrinsic")
.emit();
tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
return;
}
};
Expand Down Expand Up @@ -468,14 +450,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
(2, params, param(1))
}
Err(_) => {
struct_span_err!(
tcx.sess,
it.span,
E0439,
"invalid `simd_shuffle`, needs length: `{}`",
name
)
.emit();
tcx.sess.emit_err(SimdShuffleMissingLength { span: it.span, name });
return;
}
}
Expand Down
Loading