use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::print::PrintCx;
-use crate::ty::subst::{Subst, Substs};
+use crate::ty::subst::{Subst, SubstsRef};
use crate::middle::cstore::{ExternCrate, ExternCrateSource};
use syntax::ast;
use syntax::symbol::{keywords, Symbol};
pub fn item_path_str_with_substs_and_ns(
self,
def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> String {
debug!("item_path_str: def_id={:?}, substs={:?}, ns={:?}", def_id, substs, ns);
pub fn default_print_item_path(
&mut self,
def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> P::Path {
debug!("default_print_item_path: def_id={:?}, substs={:?}, ns={:?}", def_id, substs, ns);
fn default_print_impl_path(
&mut self,
impl_def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> P::Path {
debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
fn print_item_path(
self: &mut PrintCx<'_, '_, 'tcx, Self>,
def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> Self::Path {
self.default_print_item_path(def_id, substs, ns)
fn print_impl_path(
self: &mut PrintCx<'_, '_, 'tcx, Self>,
impl_def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> Self::Path {
self.default_print_impl_path(impl_def_id, substs, ns)
fn print_item_path(
self: &mut PrintCx<'_, '_, 'tcx, Self>,
def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> Self::Path {
self.try_print_visible_item_path(def_id, ns)
fn print_impl_path(
self: &mut PrintCx<'_, '_, 'tcx, Self>,
impl_def_id: DefId,
- substs: Option<&Substs<'tcx>>,
+ substs: Option<SubstsRef<'tcx>>,
ns: Namespace,
) -> Self::Path {
// Always use types for non-local impls, where types are always
use rustc_data_structures::bit_set::GrowableBitSet;
use rustc_data_structures::sync::{MTRef, MTLock, ParallelIterator, par_iter};
+use std::iter;
+
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum MonoItemCollectionMode {
Eager,
// We include the const length in the type length, as it's better
// to be overly conservative.
if type_length + const_length > type_length_limit {
- // The instance name is already known to be too long for rustc. Use
- // `{:.64}` to avoid blasting the user's terminal with thousands of
- // lines of type-name.
- let instance_name = instance.to_string();
- let msg = format!("reached the type-length limit while instantiating `{:.64}...`",
- instance_name);
- let mut diag = if let Some(hir_id) = tcx.hir().as_local_hir_id(instance.def_id()) {
- tcx.sess.struct_span_fatal(tcx.hir().span_by_hir_id(hir_id), &msg)
- } else {
- tcx.sess.struct_fatal(&msg)
+ // The instance name is already known to be too long for rustc.
+ // Show only the first and last 32 characters to avoid blasting
+ // the user's terminal with thousands of lines of type-name.
+ let shrink = |s: String, before: usize, after: usize| {
+ // An iterator of all byte positions including the end of the string.
+ let positions = || s.char_indices().map(|(i, _)| i).chain(iter::once(s.len()));
+
+ let shrunk = format!(
+ "{before}...{after}",
+ before = &s[..positions().nth(before).unwrap_or(s.len())],
+ after = &s[positions().rev().nth(after).unwrap_or(0)..],
+ );
+
+ // Only use the shrunk version if it's really shorter.
+ // This also avoids the case where before and after slices overlap.
+ if shrunk.len() < s.len() {
+ shrunk
+ } else {
+ s
+ }
};
-
+ let msg = format!("reached the type-length limit while instantiating `{}`",
+ shrink(instance.to_string(), 32, 32));
+ let mut diag = tcx.sess.struct_span_fatal(tcx.def_span(instance.def_id()), &msg);
diag.note(&format!(
"consider adding a `#![type_length_limit=\"{}\"]` attribute to your crate",
- type_length_limit * 2));
+ type_length));
diag.emit();
tcx.sess.abort_if_errors();
}
LL | | }
| |_____^
|
- = note: consider adding a `#![type_length_limit="40000000"]` attribute to your crate
+ = note: consider adding a `#![type_length_limit="26214380"]` attribute to your crate
error: aborting due to previous error
-error: reached the type-length limit while instantiating `<(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(), &()), &(&(), &())), &...`
+error: reached the type-length limit while instantiating `<(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(...))))))))))))))) as Foo>::recurse`
--> $DIR/issue-37311.rs:13:5
|
LL | / fn recurse(&self) {
LL | | }
| |_____^
|
- = note: consider adding a `#![type_length_limit="2097152"]` attribute to your crate
+ = note: consider adding a `#![type_length_limit="2097149"]` attribute to your crate
error: aborting due to previous error
+// ignore-musl
+// ignore-x86
// error-pattern: reached the type-length limit while instantiating
// Test that the type length limit can be changed.
-error: reached the type-length limit while instantiating `std::mem::drop::<std::option::Option<((((((G, G, G), (G, G, G), ...`
+error: reached the type-length limit while instantiating `std::mem::drop::<std::option::Op... G), (G, G, G), (G, G, G))))))>>`
+ --> $SRC_DIR/libcore/mem.rs:LL:COL
|
- = note: consider adding a `#![type_length_limit="512"]` attribute to your crate
+LL | pub fn drop<T>(_x: T) { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: consider adding a `#![type_length_limit="1094"]` attribute to your crate
error: aborting due to previous error