diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 97eda369ff4c3..095b0e5f484e7 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -915,10 +915,14 @@ impl<'tcx> TyCtxt<'tcx> { pub fn is_implicit_trait(self, def_id: DefId, including_sized: bool) -> bool { self.is_default_trait(def_id) - || matches!(self.as_lang_item(def_id), Some(LangItem::Move)) + || self.is_move_trait(def_id) || (including_sized && self.is_sizedness_trait(def_id)) } + pub fn is_move_trait(self, def_id: DefId) -> bool { + matches!(self.as_lang_item(def_id), Some(LangItem::Move)) + } + pub fn is_sizedness_trait(self, def_id: DefId) -> bool { matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::MetaSized)) } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 3c7e3b63ee9b5..849df87836668 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1467,10 +1467,25 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { first = false; } + // Keep track if we need to add `!Move` at the end + // FIXME(zannabianca1997) I guess there will be a + // list of bounds like this in the future... + let mut ty_is_move = false; + // Builtin bounds. // FIXME(eddyb) avoid printing twice (needed to ensure // that the auto traits are sorted *and* printed via p). - let mut auto_traits: Vec<_> = predicates.auto_traits().collect(); + let mut auto_traits: Vec<_> = predicates + .auto_traits() + .filter(|t| { + if self.tcx().is_move_trait(*t) { + ty_is_move = true; + false + } else { + true + } + }) + .collect(); // The auto traits come ordered by `DefPathHash`. While // `DefPathHash` is *stable* in the sense that it depends on @@ -1490,6 +1505,21 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { self.print_def_path(def_id, &[])?; } + if !ty_is_move && let Some(move_trait) = self.tcx().lang_items().move_trait() { + if !first { + write!(self, " + ")?; + } + // FIXME(zannabianca1997) put this back when more is + // added after, commented out to avoid warning + // first = false; + + // maybe we should refer someway to the actual ast? + // we did not with the `+` so assuming no + write!(self, "!")?; + + self.print_def_path(move_trait, &[])?; + } + Ok(()) }