From 4582c14bd48c74521e549fafc1e4a7d30e2b7b85 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 22 Mar 2020 20:02:29 +0100 Subject: [PATCH 01/12] Implement Hash for Infallible --- src/libcore/convert/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/convert/mod.rs b/src/libcore/convert/mod.rs index 47ab8715cfa..eef9ee7cb00 100644 --- a/src/libcore/convert/mod.rs +++ b/src/libcore/convert/mod.rs @@ -41,6 +41,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::fmt; +use crate::hash::{Hash, Hasher}; mod num; @@ -746,3 +747,10 @@ impl From for Infallible { x } } + +#[stable(feature = "convert_infallible_hash", since = "1.44.0")] +impl Hash for Infallible { + fn hash(&self, _: &mut H) { + match *self {} + } +} From af1146bd23634d34d953255114b1235e131f2c80 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 26 Mar 2020 09:31:29 +0100 Subject: [PATCH 02/12] parse: recover on `const fn()` / `async fn()`. --- src/librustc_parse/parser/item.rs | 4 +- src/librustc_parse/parser/ty.rs | 44 +++-- .../keyword-extern-as-identifier-type.rs | 2 +- .../keyword-extern-as-identifier-type.stderr | 6 +- src/test/ui/parser/issue-63116.stderr | 2 +- .../ui/parser/recover-const-async-fn-ptr.rs | 25 +++ .../parser/recover-const-async-fn-ptr.stderr | 155 ++++++++++++++++++ 7 files changed, 215 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/parser/recover-const-async-fn-ptr.rs create mode 100644 src/test/ui/parser/recover-const-async-fn-ptr.stderr diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 7a4f7680415..a0e82b7ca1e 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1494,7 +1494,7 @@ impl<'a> Parser<'a> { } /// Is the current token the start of an `FnHeader` / not a valid parse? - fn check_fn_front_matter(&mut self) -> bool { + pub(super) fn check_fn_front_matter(&mut self) -> bool { // We use an over-approximation here. // `const const`, `fn const` won't parse, but we're not stepping over other syntax either. const QUALS: [Symbol; 4] = [kw::Const, kw::Async, kw::Unsafe, kw::Extern]; @@ -1521,7 +1521,7 @@ impl<'a> Parser<'a> { /// FnQual = "const"? "async"? "unsafe"? Extern? ; /// FnFrontMatter = FnQual? "fn" ; /// ``` - fn parse_fn_front_matter(&mut self) -> PResult<'a, FnHeader> { + pub(super) fn parse_fn_front_matter(&mut self) -> PResult<'a, FnHeader> { let constness = self.parse_constness(); let asyncness = self.parse_asyncness(); let unsafety = self.parse_unsafety(); diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index c21ac8d04f1..a6015504a32 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -127,16 +127,16 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(kw::Underscore) { // A type to be inferred `_` TyKind::Infer - } else if self.token_is_bare_fn_keyword() { + } else if self.check_fn_front_matter() { // Function pointer type - self.parse_ty_bare_fn(Vec::new())? + self.parse_ty_bare_fn(lo, Vec::new())? } else if self.check_keyword(kw::For) { // Function pointer type or bound list (trait object type) starting with a poly-trait. // `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T` // `for<'lt> Trait1<'lt> + Trait2 + 'a` let lifetime_defs = self.parse_late_bound_lifetime_defs()?; - if self.token_is_bare_fn_keyword() { - self.parse_ty_bare_fn(lifetime_defs)? + if self.check_fn_front_matter() { + self.parse_ty_bare_fn(lo, lifetime_defs)? } else { let path = self.parse_path(PathStyle::Type)?; let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus(); @@ -291,13 +291,6 @@ impl<'a> Parser<'a> { Ok(TyKind::Typeof(expr)) } - /// Is the current token one of the keywords that signals a bare function type? - fn token_is_bare_fn_keyword(&mut self) -> bool { - self.check_keyword(kw::Fn) - || self.check_keyword(kw::Unsafe) - || self.check_keyword(kw::Extern) - } - /// Parses a function pointer type (`TyKind::BareFn`). /// ``` /// [unsafe] [extern "ABI"] fn (S) -> T @@ -306,12 +299,31 @@ impl<'a> Parser<'a> { /// | | | Return type /// Function Style ABI Parameter types /// ``` - fn parse_ty_bare_fn(&mut self, generic_params: Vec) -> PResult<'a, TyKind> { - let unsafety = self.parse_unsafety(); - let ext = self.parse_extern()?; - self.expect_keyword(kw::Fn)?; + /// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers. + fn parse_ty_bare_fn(&mut self, lo: Span, params: Vec) -> PResult<'a, TyKind> { + let ast::FnHeader { ext, unsafety, constness, asyncness } = self.parse_fn_front_matter()?; let decl = self.parse_fn_decl(|_| false, AllowPlus::No)?; - Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params, decl }))) + let whole_span = lo.to(self.prev_token.span); + if let ast::Const::Yes(span) = constness { + self.error_fn_ptr_bad_qualifier(whole_span, span, "const"); + } + if let ast::Async::Yes { span, .. } = asyncness { + self.error_fn_ptr_bad_qualifier(whole_span, span, "async"); + } + Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params: params, decl }))) + } + + /// Emit an error for the given bad function pointer qualifier. + fn error_fn_ptr_bad_qualifier(&self, span: Span, qual_span: Span, qual: &str) { + self.struct_span_err(span, &format!("an `fn` pointer type cannot be `{}`", qual)) + .span_label(qual_span, format!("`{}` because of this", qual)) + .span_suggestion_short( + qual_span, + &format!("remove the `{}` qualifier", qual), + String::new(), + Applicability::MaybeIncorrect, + ) + .emit(); } /// Parses an `impl B0 + ... + Bn` type. diff --git a/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.rs b/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.rs index 3845a9aa017..12aa059766b 100644 --- a/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.rs +++ b/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.rs @@ -1,3 +1,3 @@ -type A = extern::foo::bar; //~ ERROR expected `fn`, found `::` +type A = extern::foo::bar; //~ ERROR expected type, found keyword `extern` fn main() {} diff --git a/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.stderr b/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.stderr index 48c2f556f1d..20ecf6bac76 100644 --- a/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.stderr +++ b/src/test/ui/keyword/extern/keyword-extern-as-identifier-type.stderr @@ -1,8 +1,8 @@ -error: expected `fn`, found `::` - --> $DIR/keyword-extern-as-identifier-type.rs:1:16 +error: expected type, found keyword `extern` + --> $DIR/keyword-extern-as-identifier-type.rs:1:10 | LL | type A = extern::foo::bar; - | ^^ expected `fn` + | ^^^^^^ expected type error: aborting due to previous error diff --git a/src/test/ui/parser/issue-63116.stderr b/src/test/ui/parser/issue-63116.stderr index 15cd3df860b..80a450dbd36 100644 --- a/src/test/ui/parser/issue-63116.stderr +++ b/src/test/ui/parser/issue-63116.stderr @@ -12,7 +12,7 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `;` LL | impl W `, `...`, `::`, `<`, `>`, `?`, `[`, `_`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, lifetime, or path, found `;` +error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `->`, `...`, `::`, `<`, `>`, `?`, `[`, `_`, `async`, `const`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, lifetime, or path, found `;` --> $DIR/issue-63116.rs:3:15 | LL | impl W const fn(); //~ ERROR an `fn` pointer type cannot be `const` +type FT1 = for<'a> const extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const` +type FT2 = for<'a> const unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const` +type FT3 = for<'a> async fn(); //~ ERROR an `fn` pointer type cannot be `async` +type FT4 = for<'a> async extern fn(); //~ ERROR an `fn` pointer type cannot be `async` +type FT5 = for<'a> async unsafe extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `async` +type FT6 = for<'a> const async unsafe extern "C" fn(); +//~^ ERROR an `fn` pointer type cannot be `const` +//~| ERROR an `fn` pointer type cannot be `async` + +fn main() { + let _recovery_witness: () = 0; //~ ERROR mismatched types +} diff --git a/src/test/ui/parser/recover-const-async-fn-ptr.stderr b/src/test/ui/parser/recover-const-async-fn-ptr.stderr new file mode 100644 index 00000000000..7012096b644 --- /dev/null +++ b/src/test/ui/parser/recover-const-async-fn-ptr.stderr @@ -0,0 +1,155 @@ +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:3:11 + | +LL | type T0 = const fn(); + | -----^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:4:11 + | +LL | type T1 = const extern "C" fn(); + | -----^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:5:11 + | +LL | type T2 = const unsafe extern fn(); + | -----^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:6:11 + | +LL | type T3 = async fn(); + | -----^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:7:11 + | +LL | type T4 = async extern fn(); + | -----^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:8:11 + | +LL | type T5 = async unsafe extern "C" fn(); + | -----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:9:11 + | +LL | type T6 = const async unsafe extern "C" fn(); + | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:9:11 + | +LL | type T6 = const async unsafe extern "C" fn(); + | ^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:13:12 + | +LL | type FT0 = for<'a> const fn(); + | ^^^^^^^^-----^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:14:12 + | +LL | type FT1 = for<'a> const extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:15:12 + | +LL | type FT2 = for<'a> const unsafe extern fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:16:12 + | +LL | type FT3 = for<'a> async fn(); + | ^^^^^^^^-----^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:17:12 + | +LL | type FT4 = for<'a> async extern fn(); + | ^^^^^^^^-----^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:18:12 + | +LL | type FT5 = for<'a> async unsafe extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error: an `fn` pointer type cannot be `const` + --> $DIR/recover-const-async-fn-ptr.rs:19:12 + | +LL | type FT6 = for<'a> const async unsafe extern "C" fn(); + | ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `const` because of this + | help: remove the `const` qualifier + +error: an `fn` pointer type cannot be `async` + --> $DIR/recover-const-async-fn-ptr.rs:19:12 + | +LL | type FT6 = for<'a> const async unsafe extern "C" fn(); + | ^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `async` because of this + | help: remove the `async` qualifier + +error[E0308]: mismatched types + --> $DIR/recover-const-async-fn-ptr.rs:24:33 + | +LL | let _recovery_witness: () = 0; + | -- ^ expected `()`, found integer + | | + | expected due to this + +error: aborting due to 17 previous errors + +For more information about this error, try `rustc --explain E0308`. From 388f61b7f7e82ec6e296861fd4ad86adc64dee08 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Mar 2020 12:15:13 -0700 Subject: [PATCH 03/12] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 8a0d4d9c9ab..6e07d2dfb7f 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 8a0d4d9c9abc74fd670353094387d62028b40ae9 +Subproject commit 6e07d2dfb7fc87b1c9489de41da4dafa239daf03 From dca3782c18067001bee992523016d55e08b07057 Mon Sep 17 00:00:00 2001 From: Valentin Lazureanu Date: Mon, 30 Mar 2020 17:06:00 +0000 Subject: [PATCH 04/12] Renamed `PerDefTables` to `Tables` --- src/librustc_metadata/rmeta/decoder.rs | 52 ++++---- src/librustc_metadata/rmeta/encoder.rs | 164 ++++++++++++------------- src/librustc_metadata/rmeta/mod.rs | 18 +-- 3 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 004c5f2ebb7..04aa8187e1f 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -633,7 +633,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn maybe_kind(&self, item_id: DefIndex) -> Option { - self.root.per_def.kind.get(self, item_id).map(|k| k.decode(self)) + self.root.tables.kind.get(self, item_id).map(|k| k.decode(self)) } fn kind(&self, item_id: DefIndex) -> EntryKind { @@ -665,7 +665,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { .expect("no name in item_ident"); let span = self .root - .per_def + .tables .ident_span .get(self, item_index) .map(|data| data.decode((self, sess))) @@ -688,7 +688,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn get_span(&self, index: DefIndex, sess: &Session) -> Span { - self.root.per_def.span.get(self, index).unwrap().decode((self, sess)) + self.root.tables.span.get(self, index).unwrap().decode((self, sess)) } fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension { @@ -781,7 +781,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { ctor_did, data.discr, self.root - .per_def + .tables .children .get(self, index) .unwrap_or(Lazy::empty()) @@ -812,7 +812,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { let variants = if let ty::AdtKind::Enum = adt_kind { self.root - .per_def + .tables .children .get(self, item_id) .unwrap_or(Lazy::empty()) @@ -831,7 +831,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { item_id: DefIndex, tcx: TyCtxt<'tcx>, ) -> ty::GenericPredicates<'tcx> { - self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx)) + self.root.tables.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx)) } fn get_inferred_outlives( @@ -840,7 +840,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { tcx: TyCtxt<'tcx>, ) -> &'tcx [(ty::Predicate<'tcx>, Span)] { self.root - .per_def + .tables .inferred_outlives .get(self, item_id) .map(|predicates| predicates.decode((self, tcx))) @@ -852,31 +852,31 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { item_id: DefIndex, tcx: TyCtxt<'tcx>, ) -> ty::GenericPredicates<'tcx> { - self.root.per_def.super_predicates.get(self, item_id).unwrap().decode((self, tcx)) + self.root.tables.super_predicates.get(self, item_id).unwrap().decode((self, tcx)) } fn get_generics(&self, item_id: DefIndex, sess: &Session) -> ty::Generics { - self.root.per_def.generics.get(self, item_id).unwrap().decode((self, sess)) + self.root.tables.generics.get(self, item_id).unwrap().decode((self, sess)) } fn get_type(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - self.root.per_def.ty.get(self, id).unwrap().decode((self, tcx)) + self.root.tables.ty.get(self, id).unwrap().decode((self, tcx)) } fn get_stability(&self, id: DefIndex) -> Option { match self.is_proc_macro(id) { true => self.root.proc_macro_stability, - false => self.root.per_def.stability.get(self, id).map(|stab| stab.decode(self)), + false => self.root.tables.stability.get(self, id).map(|stab| stab.decode(self)), } } fn get_const_stability(&self, id: DefIndex) -> Option { - self.root.per_def.const_stability.get(self, id).map(|stab| stab.decode(self)) + self.root.tables.const_stability.get(self, id).map(|stab| stab.decode(self)) } fn get_deprecation(&self, id: DefIndex) -> Option { self.root - .per_def + .tables .deprecation .get(self, id) .filter(|_| !self.is_proc_macro(id)) @@ -886,7 +886,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_visibility(&self, id: DefIndex) -> ty::Visibility { match self.is_proc_macro(id) { true => ty::Visibility::Public, - false => self.root.per_def.visibility.get(self, id).unwrap().decode(self), + false => self.root.tables.visibility.get(self, id).unwrap().decode(self), } } @@ -914,7 +914,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option> { - self.root.per_def.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx))) + self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx))) } /// Iterates over all the stability attributes in the given crate. @@ -984,7 +984,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { // Iterate over all children. let macros_only = self.dep_kind.lock().macros_only(); - let children = self.root.per_def.children.get(self, id).unwrap_or(Lazy::empty()); + let children = self.root.tables.children.get(self, id).unwrap_or(Lazy::empty()); for child_index in children.decode((self, sess)) { if macros_only { continue; @@ -1004,7 +1004,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { EntryKind::ForeignMod => { let child_children = self .root - .per_def + .tables .children .get(self, child_index) .unwrap_or(Lazy::empty()); @@ -1016,7 +1016,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { vis: self.get_visibility(child_index), span: self .root - .per_def + .tables .span .get(self, child_index) .unwrap() @@ -1096,13 +1096,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn is_item_mir_available(&self, id: DefIndex) -> bool { - !self.is_proc_macro(id) && self.root.per_def.mir.get(self, id).is_some() + !self.is_proc_macro(id) && self.root.tables.mir.get(self, id).is_some() } fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> { let mut cache = self .root - .per_def + .tables .mir .get(self, id) .filter(|_| !self.is_proc_macro(id)) @@ -1121,7 +1121,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { ) -> IndexVec> { let mut cache = self .root - .per_def + .tables .promoted_mir .get(self, id) .filter(|_| !self.is_proc_macro(id)) @@ -1172,7 +1172,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn get_item_variances(&self, id: DefIndex) -> Vec { - self.root.per_def.variances.get(self, id).unwrap_or(Lazy::empty()).decode(self).collect() + self.root.tables.variances.get(self, id).unwrap_or(Lazy::empty()).decode(self).collect() } fn get_ctor_kind(&self, node_id: DefIndex) -> CtorKind { @@ -1209,7 +1209,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { Lrc::from( self.root - .per_def + .tables .attributes .get(self, item_id) .unwrap_or(Lazy::empty()) @@ -1220,7 +1220,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_struct_field_names(&self, id: DefIndex, sess: &Session) -> Vec> { self.root - .per_def + .tables .children .get(self, id) .unwrap_or(Lazy::empty()) @@ -1236,7 +1236,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { ) -> &'tcx [DefId] { tcx.arena.alloc_from_iter( self.root - .per_def + .tables .inherent_impls .get(self, id) .unwrap_or(Lazy::empty()) @@ -1416,7 +1416,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { - self.root.per_def.fn_sig.get(self, id).unwrap().decode((self, tcx)) + self.root.tables.fn_sig.get(self, id).unwrap().decode((self, tcx)) } #[inline] diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index f6e2730cb57..3cc5fb1a991 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -45,7 +45,7 @@ struct EncodeContext<'tcx> { opaque: opaque::Encoder, tcx: TyCtxt<'tcx>, - per_def: PerDefTableBuilders<'tcx>, + tables: TableBuilders<'tcx>, lazy_state: LazyState, type_shorthands: FxHashMap, usize>, @@ -497,8 +497,8 @@ impl<'tcx> EncodeContext<'tcx> { }; i = self.position(); - let per_def = self.per_def.encode(&mut self.opaque); - let per_def_bytes = self.position() - i; + let tables = self.tables.encode(&mut self.opaque); + let tables_bytes = self.position() - i; // Encode the proc macro data i = self.position(); @@ -560,7 +560,7 @@ impl<'tcx> EncodeContext<'tcx> { impls, exported_symbols, interpret_alloc_index, - per_def, + tables, }); let total_bytes = self.position(); @@ -585,7 +585,7 @@ impl<'tcx> EncodeContext<'tcx> { println!(" def-path table bytes: {}", def_path_table_bytes); println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes); println!(" item bytes: {}", item_bytes); - println!(" per-def table bytes: {}", per_def_bytes); + println!(" table bytes: {}", tables_bytes); println!(" zero bytes: {}", zero_bytes); println!(" total bytes: {}", total_bytes); } @@ -597,12 +597,12 @@ impl<'tcx> EncodeContext<'tcx> { impl EncodeContext<'tcx> { fn encode_variances_of(&mut self, def_id: DefId) { debug!("EncodeContext::encode_variances_of({:?})", def_id); - record!(self.per_def.variances[def_id] <- &self.tcx.variances_of(def_id)[..]); + record!(self.tables.variances[def_id] <- &self.tcx.variances_of(def_id)[..]); } fn encode_item_type(&mut self, def_id: DefId) { debug!("EncodeContext::encode_item_type({:?})", def_id); - record!(self.per_def.ty[def_id] <- self.tcx.type_of(def_id)); + record!(self.tables.ty[def_id] <- self.tcx.type_of(def_id)); } fn encode_enum_variant_info(&mut self, enum_did: DefId, index: VariantIdx) { @@ -621,12 +621,12 @@ impl EncodeContext<'tcx> { let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); let enum_vis = &tcx.hir().expect_item(enum_id).vis; - record!(self.per_def.kind[def_id] <- EntryKind::Variant(self.lazy(data))); - record!(self.per_def.visibility[def_id] <- + record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); + record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(enum_vis, enum_id, self.tcx)); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); - record!(self.per_def.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]); - record!(self.per_def.children[def_id] <- variant.fields.iter().map(|f| { + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]); + record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| { assert!(f.did.is_local()); f.did.index })); @@ -637,7 +637,7 @@ impl EncodeContext<'tcx> { if variant.ctor_kind == CtorKind::Fn { // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`. if let Some(ctor_def_id) = variant.ctor_def_id { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); } // FIXME(eddyb) is this ever used? self.encode_variances_of(def_id); @@ -672,14 +672,14 @@ impl EncodeContext<'tcx> { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); } - record!(self.per_def.kind[def_id] <- EntryKind::Variant(self.lazy(data))); - record!(self.per_def.visibility[def_id] <- ctor_vis); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); + record!(self.tables.visibility[def_id] <- ctor_vis); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); self.encode_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.encode_variances_of(def_id); } self.encode_generics(def_id); @@ -707,11 +707,11 @@ impl EncodeContext<'tcx> { }, }; - record!(self.per_def.kind[def_id] <- EntryKind::Mod(self.lazy(data))); - record!(self.per_def.visibility[def_id] <- ty::Visibility::from_hir(vis, id, self.tcx)); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); - record!(self.per_def.attributes[def_id] <- attrs); - record!(self.per_def.children[def_id] <- md.item_ids.iter().map(|item_id| { + record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data))); + record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(vis, id, self.tcx)); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.attributes[def_id] <- attrs); + record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| { tcx.hir().local_def_id(item_id.id).index })); self.encode_stability(def_id); @@ -729,10 +729,10 @@ impl EncodeContext<'tcx> { let variant_id = tcx.hir().as_local_hir_id(variant.def_id).unwrap(); let variant_data = tcx.hir().expect_variant_data(variant_id); - record!(self.per_def.kind[def_id] <- EntryKind::Field); - record!(self.per_def.visibility[def_id] <- field.vis); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); - record!(self.per_def.attributes[def_id] <- variant_data.fields()[field_index].attrs); + record!(self.tables.kind[def_id] <- EntryKind::Field); + record!(self.tables.visibility[def_id] <- field.vis); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs); self.encode_ident_span(def_id, field.ident); self.encode_stability(def_id); self.encode_deprecation(def_id); @@ -771,14 +771,14 @@ impl EncodeContext<'tcx> { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); } - record!(self.per_def.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr)); - record!(self.per_def.visibility[def_id] <- ctor_vis); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr)); + record!(self.tables.visibility[def_id] <- ctor_vis); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); self.encode_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.encode_variances_of(def_id); } self.encode_generics(def_id); @@ -790,12 +790,12 @@ impl EncodeContext<'tcx> { fn encode_generics(&mut self, def_id: DefId) { debug!("EncodeContext::encode_generics({:?})", def_id); - record!(self.per_def.generics[def_id] <- self.tcx.generics_of(def_id)); + record!(self.tables.generics[def_id] <- self.tcx.generics_of(def_id)); } fn encode_explicit_predicates(&mut self, def_id: DefId) { debug!("EncodeContext::encode_explicit_predicates({:?})", def_id); - record!(self.per_def.explicit_predicates[def_id] <- + record!(self.tables.explicit_predicates[def_id] <- self.tcx.explicit_predicates_of(def_id)); } @@ -803,13 +803,13 @@ impl EncodeContext<'tcx> { debug!("EncodeContext::encode_inferred_outlives({:?})", def_id); let inferred_outlives = self.tcx.inferred_outlives_of(def_id); if !inferred_outlives.is_empty() { - record!(self.per_def.inferred_outlives[def_id] <- inferred_outlives); + record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); } } fn encode_super_predicates(&mut self, def_id: DefId) { debug!("EncodeContext::encode_super_predicates({:?})", def_id); - record!(self.per_def.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); + record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); } fn encode_info_for_trait_item(&mut self, def_id: DefId) { @@ -826,7 +826,7 @@ impl EncodeContext<'tcx> { hir::Defaultness::Final => span_bug!(ast_item.span, "traits cannot have final items"), }; - record!(self.per_def.kind[def_id] <- match trait_item.kind { + record!(self.tables.kind[def_id] <- match trait_item.kind { ty::AssocKind::Const => { let rendered = rustc_hir_pretty::to_string( &(&self.tcx.hir() as &dyn intravisit::Map<'_>), @@ -867,9 +867,9 @@ impl EncodeContext<'tcx> { ty::AssocKind::Type => EntryKind::AssocType(container), ty::AssocKind::OpaqueTy => span_bug!(ast_item.span, "opaque type in trait"), }); - record!(self.per_def.visibility[def_id] <- trait_item.vis); - record!(self.per_def.span[def_id] <- ast_item.span); - record!(self.per_def.attributes[def_id] <- ast_item.attrs); + record!(self.tables.visibility[def_id] <- trait_item.vis); + record!(self.tables.span[def_id] <- ast_item.span); + record!(self.tables.attributes[def_id] <- ast_item.attrs); self.encode_ident_span(def_id, ast_item.ident); self.encode_stability(def_id); self.encode_const_stability(def_id); @@ -886,7 +886,7 @@ impl EncodeContext<'tcx> { ty::AssocKind::OpaqueTy => unreachable!(), } if trait_item.kind == ty::AssocKind::Method { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.encode_variances_of(def_id); } self.encode_generics(def_id); @@ -919,7 +919,7 @@ impl EncodeContext<'tcx> { } }; - record!(self.per_def.kind[def_id] <- match impl_item.kind { + record!(self.tables.kind[def_id] <- match impl_item.kind { ty::AssocKind::Const => { if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind { let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id); @@ -951,16 +951,16 @@ impl EncodeContext<'tcx> { ty::AssocKind::OpaqueTy => EntryKind::AssocOpaqueTy(container), ty::AssocKind::Type => EntryKind::AssocType(container) }); - record!(self.per_def.visibility[def_id] <- impl_item.vis); - record!(self.per_def.span[def_id] <- ast_item.span); - record!(self.per_def.attributes[def_id] <- ast_item.attrs); + record!(self.tables.visibility[def_id] <- impl_item.vis); + record!(self.tables.span[def_id] <- ast_item.span); + record!(self.tables.attributes[def_id] <- ast_item.attrs); self.encode_ident_span(def_id, impl_item.ident); self.encode_stability(def_id); self.encode_const_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if impl_item.kind == ty::AssocKind::Method { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.encode_variances_of(def_id); } self.encode_generics(def_id); @@ -1005,14 +1005,14 @@ impl EncodeContext<'tcx> { fn encode_optimized_mir(&mut self, def_id: DefId) { debug!("EntryBuilder::encode_mir({:?})", def_id); if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) { - record!(self.per_def.mir[def_id] <- self.tcx.optimized_mir(def_id)); + record!(self.tables.mir[def_id] <- self.tcx.optimized_mir(def_id)); } } fn encode_promoted_mir(&mut self, def_id: DefId) { debug!("EncodeContext::encode_promoted_mir({:?})", def_id); if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) { - record!(self.per_def.promoted_mir[def_id] <- self.tcx.promoted_mir(def_id)); + record!(self.tables.promoted_mir[def_id] <- self.tcx.promoted_mir(def_id)); } } @@ -1021,7 +1021,7 @@ impl EncodeContext<'tcx> { debug!("EncodeContext::encode_inherent_implementations({:?})", def_id); let implementations = self.tcx.inherent_impls(def_id); if !implementations.is_empty() { - record!(self.per_def.inherent_impls[def_id] <- implementations.iter().map(|&def_id| { + record!(self.tables.inherent_impls[def_id] <- implementations.iter().map(|&def_id| { assert!(def_id.is_local()); def_id.index })); @@ -1031,21 +1031,21 @@ impl EncodeContext<'tcx> { fn encode_stability(&mut self, def_id: DefId) { debug!("EncodeContext::encode_stability({:?})", def_id); if let Some(stab) = self.tcx.lookup_stability(def_id) { - record!(self.per_def.stability[def_id] <- stab) + record!(self.tables.stability[def_id] <- stab) } } fn encode_const_stability(&mut self, def_id: DefId) { debug!("EncodeContext::encode_const_stability({:?})", def_id); if let Some(stab) = self.tcx.lookup_const_stability(def_id) { - record!(self.per_def.const_stability[def_id] <- stab) + record!(self.tables.const_stability[def_id] <- stab) } } fn encode_deprecation(&mut self, def_id: DefId) { debug!("EncodeContext::encode_deprecation({:?})", def_id); if let Some(depr) = self.tcx.lookup_deprecation(def_id) { - record!(self.per_def.deprecation[def_id] <- depr); + record!(self.tables.deprecation[def_id] <- depr); } } @@ -1066,7 +1066,7 @@ impl EncodeContext<'tcx> { self.encode_ident_span(def_id, item.ident); - record!(self.per_def.kind[def_id] <- match item.kind { + record!(self.tables.kind[def_id] <- match item.kind { hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic, hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic, hir::ItemKind::Const(_, body_id) => { @@ -1172,26 +1172,26 @@ impl EncodeContext<'tcx> { hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => bug!("cannot encode info for item {:?}", item), }); - record!(self.per_def.visibility[def_id] <- + record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(&item.vis, item.hir_id, tcx)); - record!(self.per_def.span[def_id] <- item.span); - record!(self.per_def.attributes[def_id] <- item.attrs); + record!(self.tables.span[def_id] <- item.span); + record!(self.tables.attributes[def_id] <- item.attrs); // FIXME(eddyb) there should be a nicer way to do this. match item.kind { - hir::ItemKind::ForeignMod(ref fm) => record!(self.per_def.children[def_id] <- + hir::ItemKind::ForeignMod(ref fm) => record!(self.tables.children[def_id] <- fm.items .iter() .map(|foreign_item| tcx.hir().local_def_id( foreign_item.hir_id).index) ), - hir::ItemKind::Enum(..) => record!(self.per_def.children[def_id] <- + hir::ItemKind::Enum(..) => record!(self.tables.children[def_id] <- self.tcx.adt_def(def_id).variants.iter().map(|v| { assert!(v.def_id.is_local()); v.def_id.index }) ), hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => { - record!(self.per_def.children[def_id] <- + record!(self.tables.children[def_id] <- self.tcx.adt_def(def_id).non_enum_variant().fields.iter().map(|f| { assert!(f.did.is_local()); f.did.index @@ -1200,7 +1200,7 @@ impl EncodeContext<'tcx> { } hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => { let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id); - record!(self.per_def.children[def_id] <- + record!(self.tables.children[def_id] <- associated_item_def_ids.iter().map(|&def_id| { assert!(def_id.is_local()); def_id.index @@ -1225,11 +1225,11 @@ impl EncodeContext<'tcx> { _ => {} } if let hir::ItemKind::Fn(..) = item.kind { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } if let hir::ItemKind::Impl { .. } = item.kind { if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) { - record!(self.per_def.impl_trait_ref[def_id] <- trait_ref); + record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } self.encode_inherent_implementations(def_id); @@ -1288,19 +1288,19 @@ impl EncodeContext<'tcx> { /// Serialize the text of exported macros fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) { let def_id = self.tcx.hir().local_def_id(macro_def.hir_id); - record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone()))); - record!(self.per_def.visibility[def_id] <- ty::Visibility::Public); - record!(self.per_def.span[def_id] <- macro_def.span); - record!(self.per_def.attributes[def_id] <- macro_def.attrs); + record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone()))); + record!(self.tables.visibility[def_id] <- ty::Visibility::Public); + record!(self.tables.span[def_id] <- macro_def.span); + record!(self.tables.attributes[def_id] <- macro_def.attrs); self.encode_ident_span(def_id, macro_def.ident); self.encode_stability(def_id); self.encode_deprecation(def_id); } fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) { - record!(self.per_def.kind[def_id] <- kind); - record!(self.per_def.visibility[def_id] <- ty::Visibility::Public); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.kind[def_id] <- kind); + record!(self.tables.visibility[def_id] <- ty::Visibility::Public); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); if encode_type { self.encode_item_type(def_id); } @@ -1314,7 +1314,7 @@ impl EncodeContext<'tcx> { let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id); - record!(self.per_def.kind[def_id] <- match ty.kind { + record!(self.tables.kind[def_id] <- match ty.kind { ty::Generator(..) => { let data = self.tcx.generator_kind(def_id).unwrap(); EntryKind::Generator(data) @@ -1324,12 +1324,12 @@ impl EncodeContext<'tcx> { _ => bug!("closure that is neither generator nor closure"), }); - record!(self.per_def.visibility[def_id] <- ty::Visibility::Public); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); - record!(self.per_def.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]); + record!(self.tables.visibility[def_id] <- ty::Visibility::Public); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]); self.encode_item_type(def_id); if let ty::Closure(def_id, substs) = ty.kind { - record!(self.per_def.fn_sig[def_id] <- substs.as_closure().sig()); + record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig()); } self.encode_generics(def_id); self.encode_optimized_mir(def_id); @@ -1343,9 +1343,9 @@ impl EncodeContext<'tcx> { let const_data = self.encode_rendered_const_for_body(body_id); let qualifs = self.tcx.mir_const_qualif(def_id); - record!(self.per_def.kind[def_id] <- EntryKind::Const(qualifs, const_data)); - record!(self.per_def.visibility[def_id] <- ty::Visibility::Public); - record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); + record!(self.tables.kind[def_id] <- EntryKind::Const(qualifs, const_data)); + record!(self.tables.visibility[def_id] <- ty::Visibility::Public); + record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); self.encode_item_type(def_id); self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -1516,7 +1516,7 @@ impl EncodeContext<'tcx> { debug!("EncodeContext::encode_info_for_foreign_item({:?})", def_id); - record!(self.per_def.kind[def_id] <- match nitem.kind { + record!(self.tables.kind[def_id] <- match nitem.kind { hir::ForeignItemKind::Fn(_, ref names, _) => { let data = FnData { asyncness: hir::IsAsync::NotAsync, @@ -1533,17 +1533,17 @@ impl EncodeContext<'tcx> { hir::ForeignItemKind::Static(_, hir::Mutability::Not) => EntryKind::ForeignImmStatic, hir::ForeignItemKind::Type => EntryKind::ForeignType, }); - record!(self.per_def.visibility[def_id] <- + record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(&nitem.vis, nitem.hir_id, self.tcx)); - record!(self.per_def.span[def_id] <- nitem.span); - record!(self.per_def.attributes[def_id] <- nitem.attrs); + record!(self.tables.span[def_id] <- nitem.span); + record!(self.tables.attributes[def_id] <- nitem.attrs); self.encode_ident_span(def_id, nitem.ident); self.encode_stability(def_id); self.encode_const_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if let hir::ForeignItemKind::Fn(..) = nitem.kind { - record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id)); + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.encode_variances_of(def_id); } self.encode_generics(def_id); @@ -1630,7 +1630,7 @@ impl EncodeContext<'tcx> { } fn encode_ident_span(&mut self, def_id: DefId, ident: Ident) { - record!(self.per_def.ident_span[def_id] <- ident.span); + record!(self.tables.ident_span[def_id] <- ident.span); } /// In some cases, along with the item itself, we also @@ -1846,7 +1846,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata { let mut ecx = EncodeContext { opaque: encoder, tcx, - per_def: Default::default(), + tables: Default::default(), lazy_state: LazyState::NoNode, type_shorthands: Default::default(), predicate_shorthands: Default::default(), diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index d0ad76b0fc7..8aa70293aab 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -197,7 +197,7 @@ crate struct CrateRoot<'tcx> { impls: Lazy<[TraitImpls]>, interpret_alloc_index: Lazy<[u32]>, - per_def: LazyPerDefTables<'tcx>, + tables: LazyTables<'tcx>, /// The DefIndex's of any proc macros declared by this crate. proc_macro_data: Option>, @@ -228,22 +228,22 @@ crate struct TraitImpls { impls: Lazy<[DefIndex]>, } -/// Define `LazyPerDefTables` and `PerDefTableBuilders` at the same time. -macro_rules! define_per_def_tables { +/// Define `LazyTables` and `TableBuilders` at the same time. +macro_rules! define_tables { ($($name:ident: Table),+ $(,)?) => { #[derive(RustcEncodable, RustcDecodable)] - crate struct LazyPerDefTables<'tcx> { + crate struct LazyTables<'tcx> { $($name: Lazy!(Table)),+ } #[derive(Default)] - struct PerDefTableBuilders<'tcx> { + struct TableBuilders<'tcx> { $($name: TableBuilder),+ } - impl PerDefTableBuilders<'tcx> { - fn encode(&self, buf: &mut Encoder) -> LazyPerDefTables<'tcx> { - LazyPerDefTables { + impl TableBuilders<'tcx> { + fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> { + LazyTables { $($name: self.$name.encode(buf)),+ } } @@ -251,7 +251,7 @@ macro_rules! define_per_def_tables { } } -define_per_def_tables! { +define_tables! { kind: Table>, visibility: Table>, span: Table>, From 4b66a28bb6d92e21f440fe8dfe8c9b73dfb0deec Mon Sep 17 00:00:00 2001 From: lzutao Date: Thu, 2 Apr 2020 08:34:57 +0700 Subject: [PATCH 05/12] Add missing markdown rust annotation --- src/doc/unstable-book/src/language-features/generators.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/generators.md b/src/doc/unstable-book/src/language-features/generators.md index 8bc62418b39..7b865c9c679 100644 --- a/src/doc/unstable-book/src/language-features/generators.md +++ b/src/doc/unstable-book/src/language-features/generators.md @@ -87,7 +87,7 @@ Feedback on the design and usage is always appreciated! The `Generator` trait in `std::ops` currently looks like: -``` +```rust # #![feature(arbitrary_self_types, generator_trait)] # use std::ops::GeneratorState; # use std::pin::Pin; @@ -107,7 +107,7 @@ point for executing the `Generator` itself. The return value of `resume`, `GeneratorState`, looks like: -``` +```rust pub enum GeneratorState { Yielded(Y), Complete(R), From f543689eb65aeacb6ec85c07f0c82800174d21c1 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 2 Apr 2020 00:08:58 -0400 Subject: [PATCH 06/12] Handle unterminated raw strings with no #s properly The modified code to handle parsing raw strings didn't properly account for the case where there was no "#" on either end and erroneously reported this strings as complete. This lead to a panic trying to read off the end of the file. --- src/librustc_lexer/src/lib.rs | 9 ++++++- src/librustc_lexer/src/tests.rs | 27 +++++++++++++++++++ ...77-panic-on-unterminated-raw-str-at-eof.rs | 5 ++++ ...anic-on-unterminated-raw-str-at-eof.stderr | 9 +++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs create mode 100644 src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index fcb7475cc2e..5ccfc1b276b 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -148,6 +148,10 @@ pub enum LiteralKind { pub struct UnvalidatedRawStr { /// The prefix (`r###"`) is valid valid_start: bool, + + /// The postfix (`"###`) is valid + valid_end: bool, + /// The number of leading `#` n_start_hashes: usize, /// The number of trailing `#`. `n_end_hashes` <= `n_start_hashes` @@ -197,7 +201,7 @@ impl UnvalidatedRawStr { let n_start_safe: u16 = self.n_start_hashes.try_into().map_err(|_| LexRawStrError::TooManyDelimiters)?; - if self.n_start_hashes > self.n_end_hashes { + if self.n_start_hashes > self.n_end_hashes || !self.valid_end { Err(LexRawStrError::NoTerminator { expected: self.n_start_hashes, found: self.n_end_hashes, @@ -687,6 +691,7 @@ impl Cursor<'_> { _ => { return UnvalidatedRawStr { valid_start, + valid_end: false, n_start_hashes, n_end_hashes: 0, possible_terminator_offset, @@ -702,6 +707,7 @@ impl Cursor<'_> { if self.is_eof() { return UnvalidatedRawStr { valid_start, + valid_end: false, n_start_hashes, n_end_hashes: max_hashes, possible_terminator_offset, @@ -727,6 +733,7 @@ impl Cursor<'_> { if n_end_hashes == n_start_hashes { return UnvalidatedRawStr { valid_start, + valid_end: true, n_start_hashes, n_end_hashes, possible_terminator_offset: None, diff --git a/src/librustc_lexer/src/tests.rs b/src/librustc_lexer/src/tests.rs index 4af435536f0..06fc159fe25 100644 --- a/src/librustc_lexer/src/tests.rs +++ b/src/librustc_lexer/src/tests.rs @@ -23,6 +23,7 @@ mod tests { n_start_hashes: 0, n_end_hashes: 0, valid_start: true, + valid_end: true, possible_terminator_offset: None, }, Ok(ValidatedRawStr { n_hashes: 0 }), @@ -37,6 +38,7 @@ mod tests { n_start_hashes: 0, n_end_hashes: 0, valid_start: true, + valid_end: true, possible_terminator_offset: None, }, Ok(ValidatedRawStr { n_hashes: 0 }), @@ -51,6 +53,7 @@ mod tests { UnvalidatedRawStr { n_start_hashes: 1, n_end_hashes: 1, + valid_end: true, valid_start: true, possible_terminator_offset: None, }, @@ -65,6 +68,7 @@ mod tests { UnvalidatedRawStr { n_start_hashes: 1, n_end_hashes: 0, + valid_end: false, valid_start: true, possible_terminator_offset: None, }, @@ -80,6 +84,7 @@ mod tests { n_start_hashes: 2, n_end_hashes: 1, valid_start: true, + valid_end: false, possible_terminator_offset: Some(7), }, Err(LexRawStrError::NoTerminator { @@ -95,6 +100,7 @@ mod tests { n_start_hashes: 2, n_end_hashes: 0, valid_start: true, + valid_end: false, possible_terminator_offset: None, }, Err(LexRawStrError::NoTerminator { @@ -113,9 +119,30 @@ mod tests { n_start_hashes: 1, n_end_hashes: 0, valid_start: false, + valid_end: false, possible_terminator_offset: None, }, Err(LexRawStrError::InvalidStarter), ); } + + #[test] + fn test_unterminated_no_pound() { + // https://github.com/rust-lang/rust/issues/70677 + check_raw_str( + r#"""#, + UnvalidatedRawStr { + n_start_hashes: 0, + n_end_hashes: 0, + valid_start: true, + valid_end: false, + possible_terminator_offset: None, + }, + Err(LexRawStrError::NoTerminator { + expected: 0, + found: 0, + possible_terminator_offset: None, + }), + ); + } } diff --git a/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs new file mode 100644 index 00000000000..bdfc29a3d57 --- /dev/null +++ b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs @@ -0,0 +1,5 @@ +// This won't actually panic because of the error comment -- the `"` needs to be +// the last byte in the file (including not having a trailing newline) +// Prior to the fix you get the error: 'expected item, found `r" ...`' +// because the string being unterminated wasn't properly detected. +r" //~ unterminated raw string diff --git a/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr new file mode 100644 index 00000000000..3a7e2a4b14a --- /dev/null +++ b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr @@ -0,0 +1,9 @@ +error[E0748]: unterminated raw string + --> $DIR/issue-70677-panic-on-unterminated-raw-str-at-eof.rs:5:1 + | +LL | r" + | ^ unterminated raw string + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0748`. From c665eaeeb05d2149cd3ecfd8af62b6af7858a6a2 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 1 Apr 2020 16:20:27 +0100 Subject: [PATCH 07/12] add `STILL_FURTHER_SPECIALIZABLE` flag This commit adds a STILL_FURTHER_SPECIALIZABLE flag to `TypeFlags` which replaces `needs_infer` and `needs_subst` in `Instance::resolve` and `assemble_candidates_from_impls.` Signed-off-by: David Wood --- src/librustc_middle/ty/flags.rs | 16 ++- src/librustc_middle/ty/fold.rs | 7 ++ src/librustc_middle/ty/mod.rs | 109 +++++++++--------- src/librustc_middle/ty/sty.rs | 3 + .../traits/project.rs | 2 +- src/librustc_ty/instance.rs | 6 +- 6 files changed, 86 insertions(+), 57 deletions(-) diff --git a/src/librustc_middle/ty/flags.rs b/src/librustc_middle/ty/flags.rs index 5243e1fbf57..99a6511b297 100644 --- a/src/librustc_middle/ty/flags.rs +++ b/src/librustc_middle/ty/flags.rs @@ -1,4 +1,4 @@ -use crate::ty::subst::{GenericArgKind, SubstsRef}; +use crate::ty::subst::{GenericArg, GenericArgKind}; use crate::ty::{self, InferConst, Ty, TypeFlags}; #[derive(Debug)] @@ -81,6 +81,7 @@ impl FlagComputation { &ty::Param(_) => { self.add_flags(TypeFlags::HAS_TY_PARAM); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } &ty::Generator(_, ref substs, _) => { @@ -99,14 +100,17 @@ impl FlagComputation { &ty::Bound(debruijn, _) => { self.add_binder(debruijn); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } &ty::Placeholder(..) => { self.add_flags(TypeFlags::HAS_TY_PLACEHOLDER); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } &ty::Infer(infer) => { self.add_flags(TypeFlags::HAS_TY_INFER); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); match infer { ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {} @@ -218,17 +222,23 @@ impl FlagComputation { } ty::ConstKind::Infer(infer) => { self.add_flags(TypeFlags::HAS_CT_INFER); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); match infer { InferConst::Fresh(_) => {} InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX), } } - ty::ConstKind::Bound(debruijn, _) => self.add_binder(debruijn), + ty::ConstKind::Bound(debruijn, _) => { + self.add_binder(debruijn); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); + } ty::ConstKind::Param(_) => { self.add_flags(TypeFlags::HAS_CT_PARAM); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } ty::ConstKind::Placeholder(_) => { self.add_flags(TypeFlags::HAS_CT_PLACEHOLDER); + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } ty::ConstKind::Value(_) => {} } @@ -243,7 +253,7 @@ impl FlagComputation { self.add_substs(projection_ty.substs); } - fn add_substs(&mut self, substs: SubstsRef<'_>) { + fn add_substs(&mut self, substs: &[GenericArg<'_>]) { for kind in substs { match kind.unpack() { GenericArgKind::Type(ty) => self.add_ty(ty), diff --git a/src/librustc_middle/ty/fold.rs b/src/librustc_middle/ty/fold.rs index 3f4f2407f1e..a3d611a1325 100644 --- a/src/librustc_middle/ty/fold.rs +++ b/src/librustc_middle/ty/fold.rs @@ -142,6 +142,13 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { self.has_type_flags(TypeFlags::HAS_RE_LATE_BOUND) } + /// Indicates whether this value still has parameters/placeholders/inference variables + /// which could be replaced later, in a way that would change the results of `impl` + /// specialization. + fn still_further_specializable(&self) -> bool { + self.has_type_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE) + } + /// A visitor that does not recurse into types, works like `fn walk_shallow` in `Ty`. fn visit_tys_shallow(&self, visit: impl FnMut(Ty<'tcx>) -> bool) -> bool { pub struct Visitor(F); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 43982439d47..2585de07a5b 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -524,101 +524,106 @@ bitflags! { // Does this have parameters? Used to determine whether substitution is // required. /// Does this have [Param]? - const HAS_TY_PARAM = 1 << 0; + const HAS_TY_PARAM = 1 << 0; /// Does this have [ReEarlyBound]? - const HAS_RE_PARAM = 1 << 1; + const HAS_RE_PARAM = 1 << 1; /// Does this have [ConstKind::Param]? - const HAS_CT_PARAM = 1 << 2; + const HAS_CT_PARAM = 1 << 2; - const NEEDS_SUBST = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_RE_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits; + const NEEDS_SUBST = TypeFlags::HAS_TY_PARAM.bits + | TypeFlags::HAS_RE_PARAM.bits + | TypeFlags::HAS_CT_PARAM.bits; /// Does this have [Infer]? - const HAS_TY_INFER = 1 << 3; + const HAS_TY_INFER = 1 << 3; /// Does this have [ReVar]? - const HAS_RE_INFER = 1 << 4; + const HAS_RE_INFER = 1 << 4; /// Does this have [ConstKind::Infer]? - const HAS_CT_INFER = 1 << 5; + const HAS_CT_INFER = 1 << 5; /// Does this have inference variables? Used to determine whether /// inference is required. - const NEEDS_INFER = TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_RE_INFER.bits - | TypeFlags::HAS_CT_INFER.bits; + const NEEDS_INFER = TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_RE_INFER.bits + | TypeFlags::HAS_CT_INFER.bits; /// Does this have [Placeholder]? - const HAS_TY_PLACEHOLDER = 1 << 6; + const HAS_TY_PLACEHOLDER = 1 << 6; /// Does this have [RePlaceholder]? - const HAS_RE_PLACEHOLDER = 1 << 7; + const HAS_RE_PLACEHOLDER = 1 << 7; /// Does this have [ConstKind::Placeholder]? - const HAS_CT_PLACEHOLDER = 1 << 8; + const HAS_CT_PLACEHOLDER = 1 << 8; /// `true` if there are "names" of regions and so forth /// that are local to a particular fn/inferctxt - const HAS_FREE_LOCAL_REGIONS = 1 << 9; + const HAS_FREE_LOCAL_REGIONS = 1 << 9; /// `true` if there are "names" of types and regions and so forth /// that are local to a particular fn - const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits - | TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_CT_INFER.bits - | TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits - | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits; + const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits + | TypeFlags::HAS_CT_PARAM.bits + | TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_CT_INFER.bits + | TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits + | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits; /// Does this have [Projection] or [UnnormalizedProjection]? - const HAS_TY_PROJECTION = 1 << 10; + const HAS_TY_PROJECTION = 1 << 10; /// Does this have [Opaque]? - const HAS_TY_OPAQUE = 1 << 11; + const HAS_TY_OPAQUE = 1 << 11; /// Does this have [ConstKind::Unevaluated]? - const HAS_CT_PROJECTION = 1 << 12; + const HAS_CT_PROJECTION = 1 << 12; /// Could this type be normalized further? - const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits - | TypeFlags::HAS_TY_OPAQUE.bits - | TypeFlags::HAS_CT_PROJECTION.bits; + const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits + | TypeFlags::HAS_TY_OPAQUE.bits + | TypeFlags::HAS_CT_PROJECTION.bits; /// Present if the type belongs in a local type context. /// Set for placeholders and inference variables that are not "Fresh". - const KEEP_IN_LOCAL_TCX = 1 << 13; + const KEEP_IN_LOCAL_TCX = 1 << 13; /// Is an error type reachable? - const HAS_TY_ERR = 1 << 14; + const HAS_TY_ERR = 1 << 14; /// Does this have any region that "appears free" in the type? /// Basically anything but [ReLateBound] and [ReErased]. - const HAS_FREE_REGIONS = 1 << 15; + const HAS_FREE_REGIONS = 1 << 15; /// Does this have any [ReLateBound] regions? Used to check /// if a global bound is safe to evaluate. - const HAS_RE_LATE_BOUND = 1 << 16; + const HAS_RE_LATE_BOUND = 1 << 16; /// Does this have any [ReErased] regions? - const HAS_RE_ERASED = 1 << 17; + const HAS_RE_ERASED = 1 << 17; + + /// Does this value have parameters/placeholders/inference variables which could be + /// replaced later, in a way that would change the results of `impl` specialization? + const STILL_FURTHER_SPECIALIZABLE = 1 << 18; /// Flags representing the nominal content of a type, /// computed by FlagsComputation. If you add a new nominal /// flag, it should be added here too. - const NOMINAL_FLAGS = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_RE_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits - | TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_RE_INFER.bits - | TypeFlags::HAS_CT_INFER.bits - | TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_RE_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits - | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits - | TypeFlags::HAS_TY_PROJECTION.bits - | TypeFlags::HAS_TY_OPAQUE.bits - | TypeFlags::HAS_CT_PROJECTION.bits - | TypeFlags::KEEP_IN_LOCAL_TCX.bits - | TypeFlags::HAS_TY_ERR.bits - | TypeFlags::HAS_FREE_REGIONS.bits - | TypeFlags::HAS_RE_LATE_BOUND.bits - | TypeFlags::HAS_RE_ERASED.bits; + const NOMINAL_FLAGS = TypeFlags::HAS_TY_PARAM.bits + | TypeFlags::HAS_RE_PARAM.bits + | TypeFlags::HAS_CT_PARAM.bits + | TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_RE_INFER.bits + | TypeFlags::HAS_CT_INFER.bits + | TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_RE_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits + | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits + | TypeFlags::HAS_TY_PROJECTION.bits + | TypeFlags::HAS_TY_OPAQUE.bits + | TypeFlags::HAS_CT_PROJECTION.bits + | TypeFlags::KEEP_IN_LOCAL_TCX.bits + | TypeFlags::HAS_TY_ERR.bits + | TypeFlags::HAS_FREE_REGIONS.bits + | TypeFlags::HAS_RE_LATE_BOUND.bits + | TypeFlags::HAS_RE_ERASED.bits + | TypeFlags::STILL_FURTHER_SPECIALIZABLE.bits; } } diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 57df50dc1a0..e98ea097c90 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -1623,16 +1623,19 @@ impl RegionKind { flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_RE_INFER; flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX; + flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE; } ty::RePlaceholder(..) => { flags = flags | TypeFlags::HAS_FREE_REGIONS; flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_RE_PLACEHOLDER; + flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE; } ty::ReEarlyBound(..) => { flags = flags | TypeFlags::HAS_FREE_REGIONS; flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_RE_PARAM; + flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE; } ty::ReFree { .. } | ty::ReScope { .. } => { flags = flags | TypeFlags::HAS_FREE_REGIONS; diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index aae0d467563..3057b79547d 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -1028,7 +1028,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // assume `poly_trait_ref` isn't monomorphic, if it contains any. let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(&poly_trait_ref); - !poly_trait_ref.needs_infer() && !poly_trait_ref.needs_subst() + !poly_trait_ref.still_further_specializable() } else { debug!( "assemble_candidates_from_impls: not eligible due to default: \ diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 47c4b1c41cd..e845cc9a158 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -127,7 +127,11 @@ fn resolve_associated_item<'tcx>( // and the obligation is monomorphic, otherwise passes such as // transmute checking and polymorphic MIR optimizations could // get a result which isn't correct for all monomorphizations. - if param_env.reveal == Reveal::All { !trait_ref.needs_subst() } else { false } + if param_env.reveal == Reveal::All { + !trait_ref.still_further_specializable() + } else { + false + } }; if !eligible { From 124144704fa5d3f08563430d5c24abb23da24423 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Mar 2020 18:16:47 +0200 Subject: [PATCH 08/12] nix rustc_target::abi::* reexport in ty::layout --- src/librustc_codegen_llvm/abi.rs | 14 ++-- src/librustc_codegen_llvm/builder.rs | 21 +++--- src/librustc_codegen_llvm/common.rs | 33 ++++----- src/librustc_codegen_llvm/consts.rs | 5 +- src/librustc_codegen_llvm/context.rs | 9 ++- .../debuginfo/metadata.rs | 68 ++++++++---------- src/librustc_codegen_llvm/debuginfo/mod.rs | 28 ++++---- src/librustc_codegen_llvm/intrinsic.rs | 13 ++-- src/librustc_codegen_llvm/mono_item.rs | 8 +-- src/librustc_codegen_llvm/type_.rs | 7 +- src/librustc_codegen_llvm/type_of.rs | 69 +++++++++---------- src/librustc_codegen_llvm/va_arg.rs | 3 +- src/librustc_codegen_ssa/base.rs | 7 +- src/librustc_codegen_ssa/mir/analyze.rs | 3 +- src/librustc_codegen_ssa/mir/block.rs | 7 +- src/librustc_codegen_ssa/mir/constant.rs | 5 +- src/librustc_codegen_ssa/mir/debuginfo.rs | 3 +- src/librustc_codegen_ssa/mir/operand.rs | 15 ++-- src/librustc_codegen_ssa/mir/place.rs | 34 ++++----- src/librustc_codegen_ssa/mir/rvalue.rs | 11 +-- src/librustc_codegen_ssa/traits/backend.rs | 3 +- src/librustc_codegen_ssa/traits/builder.rs | 3 +- src/librustc_codegen_ssa/traits/consts.rs | 17 ++--- src/librustc_codegen_ssa/traits/debuginfo.rs | 2 +- src/librustc_codegen_ssa/traits/statics.rs | 2 +- src/librustc_codegen_ssa/traits/type_.rs | 7 +- src/librustc_lint/builtin.rs | 3 +- src/librustc_lint/context.rs | 3 +- src/librustc_lint/types.rs | 9 +-- src/librustc_metadata/rmeta/encoder.rs | 2 +- src/librustc_middle/arena.rs | 2 +- .../mir/interpret/allocation.rs | 4 +- src/librustc_middle/mir/interpret/error.rs | 3 +- src/librustc_middle/mir/interpret/mod.rs | 14 ++-- src/librustc_middle/mir/interpret/pointer.rs | 7 +- src/librustc_middle/mir/interpret/value.rs | 7 +- src/librustc_middle/mir/mod.rs | 2 +- src/librustc_middle/mir/tcx.rs | 2 +- src/librustc_middle/query/mod.rs | 2 +- src/librustc_middle/ty/context.rs | 2 +- src/librustc_middle/ty/layout.rs | 2 +- src/librustc_middle/ty/mod.rs | 5 +- src/librustc_middle/ty/print/pretty.rs | 3 +- src/librustc_middle/ty/structural_impls.rs | 2 +- src/librustc_middle/ty/sty.rs | 4 +- src/librustc_middle/ty/util.rs | 4 +- .../borrow_check/diagnostics/mod.rs | 2 +- .../borrow_check/type_check/mod.rs | 2 +- src/librustc_mir/const_eval/eval_queries.rs | 7 +- src/librustc_mir/const_eval/mod.rs | 2 +- src/librustc_mir/dataflow/framework/mod.rs | 2 +- src/librustc_mir/dataflow/impls/mod.rs | 2 +- src/librustc_mir/interpret/cast.rs | 8 +-- src/librustc_mir/interpret/eval_context.rs | 5 +- src/librustc_mir/interpret/intrinsics.rs | 4 +- src/librustc_mir/interpret/memory.rs | 7 +- src/librustc_mir/interpret/operand.rs | 31 ++++----- src/librustc_mir/interpret/operator.rs | 7 +- src/librustc_mir/interpret/place.rs | 28 ++++---- src/librustc_mir/interpret/step.rs | 2 +- src/librustc_mir/interpret/terminator.rs | 9 +-- src/librustc_mir/interpret/traits.rs | 2 +- src/librustc_mir/interpret/validity.rs | 21 +++--- src/librustc_mir/interpret/visitor.rs | 13 ++-- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 5 +- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/transform/generator.rs | 2 +- .../transform/uninhabited_enum_branching.rs | 3 +- src/librustc_mir/util/aggregate.rs | 2 +- src/librustc_mir/util/elaborate_drops.rs | 2 +- src/librustc_mir/util/pretty.rs | 3 +- src/librustc_mir_build/build/matches/mod.rs | 2 +- .../build/matches/simplify.rs | 7 +- src/librustc_mir_build/build/matches/test.rs | 8 +-- src/librustc_mir_build/hair/constant.rs | 3 +- src/librustc_mir_build/hair/cx/mod.rs | 2 +- src/librustc_mir_build/hair/mod.rs | 2 +- src/librustc_mir_build/hair/pattern/_match.rs | 3 +- src/librustc_mir_build/hair/pattern/mod.rs | 6 +- src/librustc_passes/intrinsicck.rs | 3 +- src/librustc_passes/layout_test.rs | 12 +--- .../traits/object_safety.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- 85 files changed, 336 insertions(+), 372 deletions(-) diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index 064ca53bd1b..8e9c5f25ccb 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -10,17 +10,15 @@ use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::MemFlags; use rustc_middle::bug; -use rustc_middle::ty::layout::{self}; +pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; use rustc_middle::ty::Ty; use rustc_target::abi::call::ArgAbi; -use rustc_target::abi::{HasDataLayout, LayoutOf}; +pub use rustc_target::abi::call::*; +use rustc_target::abi::{self, HasDataLayout, Int, LayoutOf}; +pub use rustc_target::spec::abi::Abi; use libc::c_uint; -pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; -pub use rustc_target::abi::call::*; -pub use rustc_target::spec::abi::Abi; - macro_rules! for_each_kind { ($flags: ident, $f: ident, $($kind: ident),+) => ({ $(if $flags.contains(ArgAttribute::$kind) { $f(llvm::Attribute::$kind) })+ @@ -450,11 +448,11 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { PassMode::Indirect(ref attrs, _) => apply(attrs, Some(self.ret.layout.llvm_type(bx))), _ => {} } - if let layout::Abi::Scalar(ref scalar) = self.ret.layout.abi { + if let abi::Abi::Scalar(ref scalar) = self.ret.layout.abi { // If the value is a boolean, the range is 0..2 and that ultimately // become 0..0 when the type becomes i1, which would be rejected // by the LLVM verifier. - if let layout::Int(..) = scalar.value { + if let Int(..) = scalar.value { if !scalar.is_bool() { let range = scalar.valid_range_exclusive(bx); if range.start != range.end { diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index 35946fb71c3..da9060f043f 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -16,9 +16,10 @@ use rustc_codegen_ssa::MemFlags; use rustc_data_structures::const_cstr; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; -use rustc_middle::ty::layout::{self, Align, Size, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::config::{self, Sanitizer}; +use rustc_target::abi::{self, Align, Size}; use rustc_target::spec::{HasTargetSpec, Target}; use std::borrow::Cow; use std::ffi::CStr; @@ -60,8 +61,8 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> { type DIVariable = as BackendTypes>::DIVariable; } -impl ty::layout::HasDataLayout for Builder<'_, '_, '_> { - fn data_layout(&self) -> &ty::layout::TargetDataLayout { +impl abi::HasDataLayout for Builder<'_, '_, '_> { + fn data_layout(&self) -> &abi::TargetDataLayout { self.cx.data_layout() } } @@ -84,7 +85,7 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> { } } -impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> { +impl abi::LayoutOf for Builder<'_, '_, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; @@ -435,17 +436,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn scalar_load_metadata<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, load: &'ll Value, - scalar: &layout::Scalar, + scalar: &abi::Scalar, ) { let vr = scalar.valid_range.clone(); match scalar.value { - layout::Int(..) => { + abi::Int(..) => { let range = scalar.valid_range_exclusive(bx); if range.start != range.end { bx.range_metadata(load, range); } } - layout::Pointer if vr.start() < vr.end() && !vr.contains(&0) => { + abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => { bx.nonnull_metadata(load); } _ => {} @@ -465,16 +466,16 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } let llval = const_llval.unwrap_or_else(|| { let load = self.load(place.llval, place.align); - if let layout::Abi::Scalar(ref scalar) = place.layout.abi { + if let abi::Abi::Scalar(ref scalar) = place.layout.abi { scalar_load_metadata(self, load, scalar); } load }); OperandValue::Immediate(to_immediate(self, llval, place.layout)) - } else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi { + } else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi { let b_offset = a.value.size(self).align_to(b.value.align(self).abi); - let mut load = |i, scalar: &layout::Scalar, align| { + let mut load = |i, scalar: &abi::Scalar, align| { let llptr = self.struct_gep(place.llval, i as u64); let load = self.load(llptr, align); scalar_load_metadata(self, load, scalar); diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 01c8e02fdc2..1415fedf11a 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -2,26 +2,24 @@ //! Code that is useful in various codegen modules. -use crate::consts; +use crate::consts::{self, const_alloc_to_llvm}; +pub use crate::context::CodegenCx; use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; -use log::debug; -use rustc_codegen_ssa::traits::*; -use rustc_middle::bug; - -use crate::consts::const_alloc_to_llvm; -use rustc_codegen_ssa::mir::place::PlaceRef; -use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar}; -use rustc_middle::ty::layout::{self, HasDataLayout, LayoutOf, Size, TyAndLayout}; - -use libc::{c_char, c_uint}; use rustc_ast::ast::Mutability; +use rustc_codegen_ssa::mir::place::PlaceRef; +use rustc_codegen_ssa::traits::*; +use rustc_middle::bug; +use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_span::symbol::Symbol; +use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size}; -pub use crate::context::CodegenCx; +use libc::{c_char, c_uint}; +use log::debug; /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". @@ -229,12 +227,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { }) } - fn scalar_to_backend( - &self, - cv: Scalar, - layout: &layout::Scalar, - llty: &'ll Type, - ) -> &'ll Value { + fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value { let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() }; match cv { Scalar::Raw { size: 0, .. } => { @@ -244,7 +237,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { Scalar::Raw { data, size } => { assert_eq!(size as u64, layout.value.size(self).bytes()); let llval = self.const_uint_big(self.type_ix(bitsize), data); - if layout.value == layout::Pointer { + if layout.value == Pointer { unsafe { llvm::LLVMConstIntToPtr(llval, llty) } } else { self.const_bitcast(llval, llty) @@ -278,7 +271,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { 1, ) }; - if layout.value != layout::Pointer { + if layout.value != Pointer { unsafe { llvm::LLVMConstPtrToInt(llval, llty) } } else { self.const_bitcast(llval, llty) diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index db92f3d382f..2d5564abfb2 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -16,12 +16,11 @@ use rustc_middle::mir::interpret::{ read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer, }; use rustc_middle::mir::mono::MonoItem; -use rustc_middle::ty::layout::{self, Align, LayoutOf, Size}; use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; -use rustc_target::abi::HasDataLayout; +use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size}; use std::ffi::CStr; @@ -56,7 +55,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll as u64; llvals.push(cx.scalar_to_backend( Pointer::new(alloc_id, Size::from_bytes(ptr_offset)).into(), - &layout::Scalar { value: layout::Primitive::Pointer, valid_range: 0..=!0 }, + &Scalar { value: Primitive::Pointer, valid_range: 0..=!0 }, cx.type_i8p(), )); next_offset = offset + pointer_size; diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index add1f46a56d..99a825823c3 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -14,14 +14,13 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::bug; use rustc_middle::mir::mono::CodegenUnit; -use rustc_middle::ty::layout::{ - HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyAndLayout, VariantIdx, -}; +use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_session::config::{self, CFGuard, DebugInfo}; use rustc_session::Session; use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::Symbol; +use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, Target}; use std::cell::{Cell, RefCell}; @@ -817,8 +816,8 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> { } } -impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> { - fn data_layout(&self) -> &ty::layout::TargetDataLayout { +impl HasDataLayout for CodegenCx<'ll, 'tcx> { + fn data_layout(&self) -> &TargetDataLayout { &self.tcx.data_layout } } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index b90c7e51ccd..a9e21c056a3 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -34,9 +34,7 @@ use rustc_middle::ich::NodeIdHashingMode; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::truncate; use rustc_middle::mir::{self, Field, GeneratorLayout}; -use rustc_middle::ty::layout::{ - self, Align, Integer, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, -}; +use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout}; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::Instance; use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; @@ -44,7 +42,9 @@ use rustc_middle::{bug, span_bug}; use rustc_session::config::{self, DebugInfo}; use rustc_span::symbol::{Interner, Symbol}; use rustc_span::{self, FileName, Span}; -use rustc_target::abi::HasDataLayout; +use rustc_target::abi::{Abi, Align, DiscriminantKind, HasDataLayout, Integer, LayoutOf}; +use rustc_target::abi::{Int, Pointer, F32, F64}; +use rustc_target::abi::{Primitive, Size, VariantIdx, Variants}; use libc::{c_longlong, c_uint}; use std::collections::hash_map::Entry; @@ -1364,7 +1364,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { }; match self.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { if let ty::Adt(adt, _) = &self.enum_type.kind { if adt.variants.is_empty() { return vec![]; @@ -1399,8 +1399,8 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { discriminant: None, }] } - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, + Variants::Multiple { + discr_kind: DiscriminantKind::Tag, discr_index, ref variants, .. @@ -1457,9 +1457,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { }) .collect() } - layout::Variants::Multiple { + Variants::Multiple { discr_kind: - layout::DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant }, + DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant }, ref discr, ref variants, discr_index, @@ -1592,7 +1592,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { // Creates `MemberDescription`s for the fields of a single enum variant. struct VariantMemberDescriptionFactory<'ll, 'tcx> { /// Cloned from the `layout::Struct` describing the variant. - offsets: Vec, + offsets: Vec, args: Vec<(String, Ty<'tcx>)>, discriminant_type_metadata: Option<&'ll DIType>, span: Span, @@ -1777,7 +1777,7 @@ fn prepare_enum_metadata( // let file_metadata = unknown_file_metadata(cx); - let discriminant_type_metadata = |discr: layout::Primitive| { + let discriminant_type_metadata = |discr: Primitive| { let enumerators_metadata: Vec<_> = match enum_type.kind { ty::Adt(def, _) => def .discriminants(cx.tcx) @@ -1870,10 +1870,8 @@ fn prepare_enum_metadata( let layout = cx.layout_of(enum_type); if let ( - &layout::Abi::Scalar(_), - &layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, ref discr, .. - }, + &Abi::Scalar(_), + &Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. }, ) = (&layout.abi, &layout.variants) { return FinalMetadata(discriminant_type_metadata(discr.value)); @@ -1881,16 +1879,11 @@ fn prepare_enum_metadata( if use_enum_fallback(cx) { let discriminant_type_metadata = match layout.variants { - layout::Variants::Single { .. } - | layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Niche { .. }, - .. - } => None, - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, - ref discr, - .. - } => Some(discriminant_type_metadata(discr.value)), + Variants::Single { .. } + | Variants::Multiple { discr_kind: DiscriminantKind::Niche { .. }, .. } => None, + Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. } => { + Some(discriminant_type_metadata(discr.value)) + } }; let enum_metadata = { @@ -1938,10 +1931,10 @@ fn prepare_enum_metadata( }; let discriminator_metadata = match layout.variants { // A single-variant enum has no discriminant. - layout::Variants::Single { .. } => None, + Variants::Single { .. } => None, - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Niche { .. }, + Variants::Multiple { + discr_kind: DiscriminantKind::Niche { .. }, ref discr, discr_index, .. @@ -1951,10 +1944,10 @@ fn prepare_enum_metadata( let align = discr.value.align(cx); let discr_type = match discr.value { - layout::Int(t, _) => t, - layout::F32 => Integer::I32, - layout::F64 => Integer::I64, - layout::Pointer => cx.data_layout().ptr_sized_integer(), + Int(t, _) => t, + F32 => Integer::I32, + F64 => Integer::I64, + Pointer => cx.data_layout().ptr_sized_integer(), } .to_ty(cx.tcx, false); @@ -1976,11 +1969,8 @@ fn prepare_enum_metadata( } } - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, - ref discr, - discr_index, - .. + Variants::Multiple { + discr_kind: DiscriminantKind::Tag, ref discr, discr_index, .. } => { let discr_type = discr.value.to_ty(cx.tcx); let (size, align) = cx.size_and_align_of(discr_type); @@ -2005,8 +1995,8 @@ fn prepare_enum_metadata( }; let mut outer_fields = match layout.variants { - layout::Variants::Single { .. } => vec![], - layout::Variants::Multiple { .. } => { + Variants::Single { .. } => vec![], + Variants::Multiple { .. } => { let tuple_mdf = TupleMemberDescriptionFactory { ty: enum_type, component_types: outer_field_tys, diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 848c973c15b..f04ac586504 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -8,35 +8,35 @@ use self::namespace::mangled_name_of_instance; use self::type_names::compute_debuginfo_type_name; use self::utils::{create_DIArray, is_node_local_to_unit, DIB}; +use crate::abi::FnAbi; +use crate::builder::Builder; +use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::{ DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable, }; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; -use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; - -use crate::abi::FnAbi; -use crate::builder::Builder; -use crate::common::CodegenCx; use crate::value::Value; + +use rustc_ast::ast; use rustc_codegen_ssa::debuginfo::type_names; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; +use rustc_codegen_ssa::traits::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc_index::vec::IndexVec; use rustc_middle::mir; +use rustc_middle::ty::layout::HasTyCtxt; +use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::{self, Instance, ParamEnv, Ty}; use rustc_session::config::{self, DebugInfo}; +use rustc_span::symbol::Symbol; +use rustc_span::{self, BytePos, Span}; +use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; use log::debug; -use std::cell::RefCell; - -use rustc_ast::ast; -use rustc_codegen_ssa::traits::*; -use rustc_middle::ty::layout::{self, HasTyCtxt, LayoutOf, Size}; -use rustc_span::symbol::Symbol; -use rustc_span::{self, BytePos, Span}; use smallvec::SmallVec; +use std::cell::RefCell; mod create_scope_map; pub mod gdb; @@ -60,7 +60,7 @@ pub struct CrateDebugContext<'a, 'tcx> { llmod: &'a llvm::Module, builder: &'a mut DIBuilder<'a>, created_files: RefCell, Option), &'a DIFile>>, - created_enum_disr_types: RefCell>, + created_enum_disr_types: RefCell>, type_map: RefCell>, namespace_map: RefCell>, diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 23f6c0a9420..bc7a9c566b4 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -7,23 +7,22 @@ use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::va_arg::emit_va_arg; use crate::value::Value; + use rustc_ast::ast; use rustc_codegen_ssa::base::{compare_simd_types, to_immediate, wants_msvc_seh}; +use rustc_codegen_ssa::common::span_invalid_monomorphization_error; use rustc_codegen_ssa::common::{IntPredicate, TypeKind}; use rustc_codegen_ssa::glue; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; +use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::MemFlags; use rustc_hir as hir; -use rustc_middle::ty::layout::{self, FnAbiExt, HasTyCtxt, LayoutOf, Primitive}; +use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt}; use rustc_middle::ty::{self, Ty}; use rustc_middle::{bug, span_bug}; -use rustc_target::abi::HasDataLayout; - -use rustc_codegen_ssa::common::span_invalid_monomorphization_error; -use rustc_codegen_ssa::traits::*; - use rustc_span::Span; +use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive}; use std::cmp::Ordering; use std::{i128, iter, u128}; @@ -145,7 +144,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { } "va_arg" => { match fn_abi.ret.layout.abi { - layout::Abi::Scalar(ref scalar) => { + abi::Abi::Scalar(ref scalar) => { match scalar.value { Primitive::Int(..) => { if self.cx().size_of(ret_ty).bytes() < 4 { diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index a7a9d0c8a07..29389b44adc 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -7,11 +7,11 @@ use crate::type_of::LayoutLlvmExt; use log::debug; use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_middle::mir::mono::{Linkage, Visibility}; -use rustc_middle::ty::layout::{FnAbiExt, LayoutOf}; -use rustc_middle::ty::{Instance, TypeFoldable}; - pub use rustc_middle::mir::mono::MonoItem; +use rustc_middle::mir::mono::{Linkage, Visibility}; +use rustc_middle::ty::layout::FnAbiExt; +use rustc_middle::ty::{Instance, TypeFoldable}; +use rustc_target::abi::LayoutOf; impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn predefine_static( diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index c06d2e6a01a..854eff31733 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -12,9 +12,10 @@ use rustc_codegen_ssa::common::TypeKind; use rustc_codegen_ssa::traits::*; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::bug; -use rustc_middle::ty::layout::{self, Align, Size, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::Ty; use rustc_target::abi::call::{CastTarget, FnAbi, Reg}; +use rustc_target::abi::{Align, Integer, Size}; use std::fmt; use std::ptr; @@ -114,14 +115,14 @@ impl CodegenCx<'ll, 'tcx> { crate fn type_pointee_for_align(&self, align: Align) -> &'ll Type { // FIXME(eddyb) We could find a better approximation if ity.align < align. - let ity = layout::Integer::approximate_align(self, align); + let ity = Integer::approximate_align(self, align); self.type_from_integer(ity) } /// Return a LLVM type that has at most the required alignment, /// and exactly the required size, as a best-effort padding array. crate fn type_padding_filler(&self, size: Size, align: Align) -> &'ll Type { - let unit = layout::Integer::approximate_align(self, align); + let unit = Integer::approximate_align(self, align); let size = size.bytes(); let unit_size = unit.size().bytes(); assert_eq!(size % unit_size, 0); diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 6501ba031e4..f475ea741c8 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -4,10 +4,12 @@ use crate::type_::Type; use log::debug; use rustc_codegen_ssa::traits::*; use rustc_middle::bug; -use rustc_middle::ty::layout::{self, Align, FnAbiExt, LayoutOf, PointeeInfo, Size, TyAndLayout}; +use rustc_middle::ty::layout::{FnAbiExt, TyAndLayout}; use rustc_middle::ty::print::obsolete::DefPathBasedNames; use rustc_middle::ty::{self, Ty, TypeFoldable}; -use rustc_target::abi::TyAndLayoutMethods; +use rustc_target::abi::{Abi, Align, FieldsShape}; +use rustc_target::abi::{Int, Pointer, F32, F64}; +use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants}; use std::fmt::Write; @@ -17,8 +19,8 @@ fn uncached_llvm_type<'a, 'tcx>( defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>, ) -> &'a Type { match layout.abi { - layout::Abi::Scalar(_) => bug!("handled elsewhere"), - layout::Abi::Vector { ref element, count } => { + Abi::Scalar(_) => bug!("handled elsewhere"), + Abi::Vector { ref element, count } => { // LLVM has a separate type for 64-bit SIMD vectors on X86 called // `x86_mmx` which is needed for some SIMD operations. As a bit of a // hack (all SIMD definitions are super unstable anyway) we @@ -37,7 +39,7 @@ fn uncached_llvm_type<'a, 'tcx>( return cx.type_vector(element, count); } } - layout::Abi::ScalarPair(..) => { + Abi::ScalarPair(..) => { return cx.type_struct( &[ layout.scalar_pair_element_llvm_type(cx, 0, false), @@ -46,7 +48,7 @@ fn uncached_llvm_type<'a, 'tcx>( false, ); } - layout::Abi::Uninhabited | layout::Abi::Aggregate { .. } => {} + Abi::Uninhabited | Abi::Aggregate { .. } => {} } let name = match layout.ty.kind { @@ -61,14 +63,14 @@ fn uncached_llvm_type<'a, 'tcx>( let mut name = String::with_capacity(32); let printer = DefPathBasedNames::new(cx.tcx, true, true); printer.push_type_name(layout.ty, &mut name, false); - if let (&ty::Adt(def, _), &layout::Variants::Single { index }) + if let (&ty::Adt(def, _), &Variants::Single { index }) = (&layout.ty.kind, &layout.variants) { if def.is_enum() && !def.variants.is_empty() { write!(&mut name, "::{}", def.variants[index].ident).unwrap(); } } - if let (&ty::Generator(_, substs, _), &layout::Variants::Single { index }) + if let (&ty::Generator(_, substs, _), &Variants::Single { index }) = (&layout.ty.kind, &layout.variants) { write!(&mut name, "::{}", substs.as_generator().variant_name(index)).unwrap(); @@ -79,7 +81,7 @@ fn uncached_llvm_type<'a, 'tcx>( }; match layout.fields { - layout::FieldsShape::Union(_) => { + FieldsShape::Union(_) => { let fill = cx.type_padding_filler(layout.size, layout.align.abi); let packed = false; match name { @@ -91,10 +93,8 @@ fn uncached_llvm_type<'a, 'tcx>( } } } - layout::FieldsShape::Array { count, .. } => { - cx.type_array(layout.field(cx, 0).llvm_type(cx), count) - } - layout::FieldsShape::Arbitrary { .. } => match name { + FieldsShape::Array { count, .. } => cx.type_array(layout.field(cx, 0).llvm_type(cx), count), + FieldsShape::Arbitrary { .. } => match name { None => { let (llfields, packed) = struct_llfields(cx, layout); cx.type_struct(&llfields, packed) @@ -189,7 +189,7 @@ pub trait LayoutLlvmExt<'tcx> { fn scalar_llvm_type_at<'a>( &self, cx: &CodegenCx<'a, 'tcx>, - scalar: &layout::Scalar, + scalar: &Scalar, offset: Size, ) -> &'a Type; fn scalar_pair_element_llvm_type<'a>( @@ -205,19 +205,16 @@ pub trait LayoutLlvmExt<'tcx> { impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { fn is_llvm_immediate(&self) -> bool { match self.abi { - layout::Abi::Scalar(_) | layout::Abi::Vector { .. } => true, - layout::Abi::ScalarPair(..) => false, - layout::Abi::Uninhabited | layout::Abi::Aggregate { .. } => self.is_zst(), + Abi::Scalar(_) | Abi::Vector { .. } => true, + Abi::ScalarPair(..) => false, + Abi::Uninhabited | Abi::Aggregate { .. } => self.is_zst(), } } fn is_llvm_scalar_pair(&self) -> bool { match self.abi { - layout::Abi::ScalarPair(..) => true, - layout::Abi::Uninhabited - | layout::Abi::Scalar(_) - | layout::Abi::Vector { .. } - | layout::Abi::Aggregate { .. } => false, + Abi::ScalarPair(..) => true, + Abi::Uninhabited | Abi::Scalar(_) | Abi::Vector { .. } | Abi::Aggregate { .. } => false, } } @@ -233,7 +230,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { /// of that field's type - this is useful for taking the address of /// that field and ensuring the struct has the right alignment. fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { - if let layout::Abi::Scalar(ref scalar) = self.abi { + if let Abi::Scalar(ref scalar) = self.abi { // Use a different cache for scalars because pointers to DSTs // can be either fat or thin (data pointers of fat pointers). if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) { @@ -255,7 +252,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { // Check the cache. let variant_index = match self.variants { - layout::Variants::Single { index } => Some(index), + Variants::Single { index } => Some(index), _ => None, }; if let Some(&llty) = cx.lltypes.borrow().get(&(self.ty, variant_index)) { @@ -293,7 +290,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { } fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { - if let layout::Abi::Scalar(ref scalar) = self.abi { + if let Abi::Scalar(ref scalar) = self.abi { if scalar.is_bool() { return cx.type_i1(); } @@ -304,14 +301,14 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { fn scalar_llvm_type_at<'a>( &self, cx: &CodegenCx<'a, 'tcx>, - scalar: &layout::Scalar, + scalar: &Scalar, offset: Size, ) -> &'a Type { match scalar.value { - layout::Int(i, _) => cx.type_from_integer(i), - layout::F32 => cx.type_f32(), - layout::F64 => cx.type_f64(), - layout::Pointer => { + Int(i, _) => cx.type_from_integer(i), + F32 => cx.type_f32(), + F64 => cx.type_f64(), + Pointer => { // If we know the alignment, pick something better than i8. let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) { cx.type_pointee_for_align(pointee.align) @@ -343,7 +340,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { } let (a, b) = match self.abi { - layout::Abi::ScalarPair(ref a, ref b) => (a, b), + Abi::ScalarPair(ref a, ref b) => (a, b), _ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self), }; let scalar = [a, b][index]; @@ -365,21 +362,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { fn llvm_field_index(&self, index: usize) -> u64 { match self.abi { - layout::Abi::Scalar(_) | layout::Abi::ScalarPair(..) => { + Abi::Scalar(_) | Abi::ScalarPair(..) => { bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self) } _ => {} } match self.fields { - layout::FieldsShape::Union(_) => { + FieldsShape::Union(_) => { bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self) } - layout::FieldsShape::Array { .. } => index as u64, + FieldsShape::Array { .. } => index as u64, - layout::FieldsShape::Arbitrary { .. } => { - 1 + (self.fields.memory_index(index) as u64) * 2 - } + FieldsShape::Arbitrary { .. } => 1 + (self.fields.memory_index(index) as u64) * 2, } } diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 42e9f60e95c..8bc3579800e 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -6,8 +6,9 @@ use rustc_codegen_ssa::mir::operand::OperandRef; use rustc_codegen_ssa::traits::{ BaseTypeMethods, BuilderMethods, ConstMethods, DerivedTypeMethods, }; -use rustc_middle::ty::layout::{Align, HasDataLayout, HasTyCtxt, LayoutOf, Size}; +use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::Ty; +use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size}; #[allow(dead_code)] fn round_pointer_up_to_alignment( diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 9e6a3b23323..c68694ad688 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -38,7 +38,7 @@ use rustc_middle::middle::cstore::{self, LinkagePreference}; use rustc_middle::middle::lang_items; use rustc_middle::middle::lang_items::StartFnLangItem; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; -use rustc_middle::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyAndLayout, VariantIdx}; +use rustc_middle::ty::layout::{self, HasTyCtxt, TyAndLayout}; use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; @@ -47,6 +47,7 @@ use rustc_session::config::{self, EntryFnType, Lto}; use rustc_session::Session; use rustc_span::Span; use rustc_symbol_mangling::test as symbol_names_test; +use rustc_target::abi::{Abi, Align, LayoutOf, Scalar, VariantIdx}; use std::cmp; use std::ops::{Deref, DerefMut}; @@ -343,7 +344,7 @@ pub fn to_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( val: Bx::Value, layout: layout::TyAndLayout<'_>, ) -> Bx::Value { - if let layout::Abi::Scalar(ref scalar) = layout.abi { + if let Abi::Scalar(ref scalar) = layout.abi { return to_immediate_scalar(bx, val, scalar); } val @@ -352,7 +353,7 @@ pub fn to_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn to_immediate_scalar<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, val: Bx::Value, - scalar: &layout::Scalar, + scalar: &Scalar, ) -> Bx::Value { if scalar.is_bool() { return bx.trunc(val, bx.cx().type_i1()); diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index ec3de274b8a..221f36fed36 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -12,7 +12,8 @@ use rustc_middle::mir::visit::{ }; use rustc_middle::mir::{self, Location, TerminatorKind}; use rustc_middle::ty; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf}; +use rustc_middle::ty::layout::HasTyCtxt; +use rustc_target::abi::LayoutOf; pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fx: &FunctionCx<'a, 'tcx, Bx>, diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 931fab6ae01..a09f803d027 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -13,10 +13,11 @@ use rustc_index::vec::Idx; use rustc_middle::middle::lang_items; use rustc_middle::mir; use rustc_middle::mir::AssertKind; -use rustc_middle::ty::layout::{self, FnAbiExt, HasTyCtxt, LayoutOf}; +use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt}; use rustc_middle::ty::{self, Instance, Ty, TypeFoldable}; use rustc_span::{source_map::Span, symbol::Symbol}; use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode}; +use rustc_target::abi::{self, LayoutOf}; use rustc_target::spec::abi::Abi; use std::borrow::Cow; @@ -591,7 +592,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // we can do what we like. Here, we declare that transmuting // into an uninhabited type is impossible, so anything following // it must be unreachable. - assert_eq!(fn_abi.ret.layout.abi, layout::Abi::Uninhabited); + assert_eq!(fn_abi.ret.layout.abi, abi::Abi::Uninhabited); bx.unreachable(); } return; @@ -994,7 +995,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // the load would just produce `OperandValue::Ref` instead // of the `OperandValue::Immediate` we need for the call. llval = bx.load(llval, align); - if let layout::Abi::Scalar(ref scalar) = arg.layout.abi { + if let abi::Abi::Scalar(ref scalar) = arg.layout.abi { if scalar.is_bool() { bx.range_metadata(llval, 0..2); } diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 9770d04aa99..298aa25f032 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -3,9 +3,10 @@ use crate::traits::*; use rustc_index::vec::Idx; use rustc_middle::mir; use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; -use rustc_middle::ty::layout::{self, HasTyCtxt}; +use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::{self, Ty}; use rustc_span::source_map::Span; +use rustc_target::abi::Abi; use super::FunctionCx; @@ -87,7 +88,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if let Some(prim) = field.try_to_scalar() { let layout = bx.layout_of(field_ty); let scalar = match layout.abi { - layout::Abi::Scalar(ref x) => x, + Abi::Scalar(ref x) => x, _ => bug!("from_const: invalid ByVal layout: {:#?}", layout), }; bx.scalar_to_backend(prim, scalar, bx.immediate_backend_type(layout)) diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs index 4eefb37ba0d..5501ed5128d 100644 --- a/src/librustc_codegen_ssa/mir/debuginfo.rs +++ b/src/librustc_codegen_ssa/mir/debuginfo.rs @@ -3,11 +3,10 @@ use rustc_hir::def_id::CrateNum; use rustc_index::vec::IndexVec; use rustc_middle::mir; use rustc_middle::ty; -use rustc_middle::ty::layout::{LayoutOf, Size}; use rustc_session::config::DebugInfo; - use rustc_span::symbol::{kw, Symbol}; use rustc_span::{BytePos, Span}; +use rustc_target::abi::{LayoutOf, Size}; use super::operand::OperandValue; use super::place::PlaceRef; diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index 7545882a0ea..69f11ed57ac 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -8,8 +8,9 @@ use crate::MemFlags; use rustc_middle::mir; use rustc_middle::mir::interpret::{ConstValue, ErrorHandled, Pointer, Scalar}; -use rustc_middle::ty::layout::{self, Align, LayoutOf, Size, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::Ty; +use rustc_target::abi::{Abi, Align, LayoutOf, Size}; use std::fmt; @@ -78,7 +79,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { let val = match val { ConstValue::Scalar(x) => { let scalar = match layout.abi { - layout::Abi::Scalar(ref x) => x, + Abi::Scalar(ref x) => x, _ => bug!("from_const: invalid ByVal layout: {:#?}", layout), }; let llval = bx.scalar_to_backend(x, scalar, bx.immediate_backend_type(layout)); @@ -86,7 +87,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { } ConstValue::Slice { data, start, end } => { let a_scalar = match layout.abi { - layout::Abi::ScalarPair(ref a, _) => a, + Abi::ScalarPair(ref a, _) => a, _ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout), }; let a = Scalar::from(Pointer::new( @@ -161,7 +162,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { llval: V, layout: TyAndLayout<'tcx>, ) -> Self { - let val = if let layout::Abi::ScalarPair(ref a, ref b) = layout.abi { + let val = if let Abi::ScalarPair(ref a, ref b) = layout.abi { debug!("Operand::from_immediate_or_packed_pair: unpacking {:?} @ {:?}", llval, layout); // Deconstruct the immediate aggregate. @@ -199,7 +200,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { } // Extract a scalar component from a pair. - (OperandValue::Pair(a_llval, b_llval), &layout::Abi::ScalarPair(ref a, ref b)) => { + (OperandValue::Pair(a_llval, b_llval), &Abi::ScalarPair(ref a, ref b)) => { if offset.bytes() == 0 { assert_eq!(field.size, a.value.size(bx.cx())); OperandValue::Immediate(a_llval) @@ -211,7 +212,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { } // `#[repr(simd)]` types are also immediate. - (OperandValue::Immediate(llval), &layout::Abi::Vector { .. }) => { + (OperandValue::Immediate(llval), &Abi::Vector { .. }) => { OperandValue::Immediate(bx.extract_element(llval, bx.cx().const_usize(i as u64))) } @@ -305,7 +306,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue { } OperandValue::Pair(a, b) => { let (a_scalar, b_scalar) = match dest.layout.abi { - layout::Abi::ScalarPair(ref a, ref b) => (a, b), + Abi::ScalarPair(ref a, ref b) => (a, b), _ => bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout), }; let b_offset = a_scalar.value.size(bx).align_to(b_scalar.value.align(bx).abi); diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index eca66a5704d..461695129c2 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -8,8 +8,10 @@ use crate::MemFlags; use rustc_middle::mir; use rustc_middle::mir::tcx::PlaceTy; -use rustc_middle::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyAndLayout, VariantIdx}; +use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; use rustc_middle::ty::{self, Ty}; +use rustc_target::abi::{Abi, Align, DiscriminantKind, FieldsShape, Int}; +use rustc_target::abi::{LayoutOf, VariantIdx, Variants}; #[derive(Copy, Clone, Debug)] pub struct PlaceRef<'tcx, V> { @@ -66,7 +68,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { } pub fn len>(&self, cx: &Cx) -> V { - if let layout::FieldsShape::Array { count, .. } = self.layout.fields { + if let FieldsShape::Array { count, .. } = self.layout.fields { if self.layout.is_unsized() { assert_eq!(count, 0); self.llextra.unwrap() @@ -94,7 +96,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // Unions and newtypes only use an offset of 0. let llval = if offset.bytes() == 0 { self.llval - } else if let layout::Abi::ScalarPair(ref a, ref b) = self.layout.abi { + } else if let Abi::ScalarPair(ref a, ref b) = self.layout.abi { // Offsets have to match either first or second field. assert_eq!(offset, a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi)); bx.struct_gep(self.llval, 1) @@ -198,7 +200,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { return bx.cx().const_undef(cast_to); } let (discr_scalar, discr_kind, discr_index) = match self.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { let discr_val = self .layout .ty @@ -206,7 +208,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { .map_or(index.as_u32() as u128, |discr| discr.val); return bx.cx().const_uint_big(cast_to, discr_val); } - layout::Variants::Multiple { ref discr, ref discr_kind, discr_index, .. } => { + Variants::Multiple { ref discr, ref discr_kind, discr_index, .. } => { (discr, discr_kind, discr_index) } }; @@ -217,22 +219,18 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // Decode the discriminant (specifically if it's niche-encoded). match *discr_kind { - layout::DiscriminantKind::Tag => { + DiscriminantKind::Tag => { let signed = match discr_scalar.value { // We use `i1` for bytes that are always `0` or `1`, // e.g., `#[repr(i8)] enum E { A, B }`, but we can't // let LLVM interpret the `i1` as signed, because // then `i1 1` (i.e., `E::B`) is effectively `i8 -1`. - layout::Int(_, signed) => !discr_scalar.is_bool() && signed, + Int(_, signed) => !discr_scalar.is_bool() && signed, _ => false, }; bx.intcast(encoded_discr.immediate(), cast_to, signed) } - layout::DiscriminantKind::Niche { - dataful_variant, - ref niche_variants, - niche_start, - } => { + DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start } => { // Rebase from niche values to discriminants, and check // whether the result is in range for the niche variants. let niche_llty = bx.cx().immediate_backend_type(encoded_discr.layout); @@ -311,14 +309,10 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { return; } match self.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { assert_eq!(index, variant_index); } - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, - discr_index, - .. - } => { + Variants::Multiple { discr_kind: DiscriminantKind::Tag, discr_index, .. } => { let ptr = self.project_field(bx, discr_index); let to = self.layout.ty.discriminant_for_variant(bx.tcx(), variant_index).unwrap().val; @@ -328,9 +322,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { ptr.align, ); } - layout::Variants::Multiple { + Variants::Multiple { discr_kind: - layout::DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start }, + DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start }, discr_index, .. } => { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index ce681c729b2..23420c85c95 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -11,10 +11,11 @@ use rustc_apfloat::{ieee, Float, Round, Status}; use rustc_middle::middle::lang_items::ExchangeMallocFnLangItem; use rustc_middle::mir; use rustc_middle::ty::cast::{CastTy, IntTy}; -use rustc_middle::ty::layout::{self, HasTyCtxt, LayoutOf}; +use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt}; use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::sym; +use rustc_target::abi::{Abi, Int, LayoutOf, Variants}; use std::{i128, u128}; @@ -292,7 +293,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let r_t_out = CastTy::from_ty(cast.ty).expect("bad output type for cast"); let ll_t_in = bx.cx().immediate_backend_type(operand.layout); match operand.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { if let Some(discr) = operand.layout.ty.discriminant_for_variant(bx.tcx(), index) { @@ -311,13 +312,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ); } } - layout::Variants::Multiple { .. } => {} + Variants::Multiple { .. } => {} } let llval = operand.immediate(); let mut signed = false; - if let layout::Abi::Scalar(ref scalar) = operand.layout.abi { - if let layout::Int(_, s) = scalar.value { + if let Abi::Scalar(ref scalar) = operand.layout.abi { + if let Int(_, s) = scalar.value { // We use `i1` for bytes that are always `0` or `1`, // e.g., `#[repr(i8)] enum E { A, B }`, but we can't // let LLVM interpret the `i1` as signed, because diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index 1474edd8aa0..bfba463907f 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -5,7 +5,7 @@ use crate::ModuleCodegen; use rustc_ast::expand::allocator::AllocatorKind; use rustc_middle::dep_graph::DepGraph; use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_middle::util::common::ErrorReported; @@ -14,6 +14,7 @@ use rustc_session::{ Session, }; use rustc_span::symbol::Symbol; +use rustc_target::abi::LayoutOf; pub use rustc_data_structures::sync::MetadataRef; diff --git a/src/librustc_codegen_ssa/traits/builder.rs b/src/librustc_codegen_ssa/traits/builder.rs index d59ea387b86..caba7ebef59 100644 --- a/src/librustc_codegen_ssa/traits/builder.rs +++ b/src/librustc_codegen_ssa/traits/builder.rs @@ -12,8 +12,9 @@ use crate::mir::operand::OperandRef; use crate::mir::place::PlaceRef; use crate::MemFlags; -use rustc_middle::ty::layout::{Align, HasParamEnv, Size}; +use rustc_middle::ty::layout::HasParamEnv; use rustc_middle::ty::Ty; +use rustc_target::abi::{Align, Size}; use rustc_target::spec::HasTargetSpec; use std::iter::TrustedLen; diff --git a/src/librustc_codegen_ssa/traits/consts.rs b/src/librustc_codegen_ssa/traits/consts.rs index e5e1aa658e6..6b58dea794b 100644 --- a/src/librustc_codegen_ssa/traits/consts.rs +++ b/src/librustc_codegen_ssa/traits/consts.rs @@ -1,9 +1,9 @@ use super::BackendTypes; use crate::mir::place::PlaceRef; -use rustc_middle::mir::interpret::Allocation; -use rustc_middle::mir::interpret::Scalar; -use rustc_middle::ty::layout; +use rustc_middle::mir::interpret::{Allocation, Scalar}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_span::Symbol; +use rustc_target::abi::{self, Size}; pub trait ConstMethods<'tcx>: BackendTypes { // Constant constructors @@ -26,17 +26,12 @@ pub trait ConstMethods<'tcx>: BackendTypes { fn const_to_opt_uint(&self, v: Self::Value) -> Option; fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option; - fn scalar_to_backend( - &self, - cv: Scalar, - layout: &layout::Scalar, - llty: Self::Type, - ) -> Self::Value; + fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: Self::Type) -> Self::Value; fn from_const_alloc( &self, - layout: layout::TyAndLayout<'tcx>, + layout: TyAndLayout<'tcx>, alloc: &Allocation, - offset: layout::Size, + offset: Size, ) -> PlaceRef<'tcx, Self::Value>; fn const_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value; diff --git a/src/librustc_codegen_ssa/traits/debuginfo.rs b/src/librustc_codegen_ssa/traits/debuginfo.rs index 4e84c096822..34be1cfdd88 100644 --- a/src/librustc_codegen_ssa/traits/debuginfo.rs +++ b/src/librustc_codegen_ssa/traits/debuginfo.rs @@ -3,10 +3,10 @@ use crate::mir::debuginfo::{FunctionDebugContext, VariableKind}; use rustc_ast::ast::Name; use rustc_hir::def_id::CrateNum; use rustc_middle::mir; -use rustc_middle::ty::layout::Size; use rustc_middle::ty::{Instance, Ty}; use rustc_span::{SourceFile, Span}; use rustc_target::abi::call::FnAbi; +use rustc_target::abi::Size; pub trait DebugInfoMethods<'tcx>: BackendTypes { fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value); diff --git a/src/librustc_codegen_ssa/traits/statics.rs b/src/librustc_codegen_ssa/traits/statics.rs index 50df0861434..a6462b35834 100644 --- a/src/librustc_codegen_ssa/traits/statics.rs +++ b/src/librustc_codegen_ssa/traits/statics.rs @@ -1,6 +1,6 @@ use super::BackendTypes; use rustc_hir::def_id::DefId; -use rustc_middle::ty::layout::Align; +use rustc_target::abi::Align; pub trait StaticMethods: BackendTypes { fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value; diff --git a/src/librustc_codegen_ssa/traits/type_.rs b/src/librustc_codegen_ssa/traits/type_.rs index 383be6dfcb5..703479b74be 100644 --- a/src/librustc_codegen_ssa/traits/type_.rs +++ b/src/librustc_codegen_ssa/traits/type_.rs @@ -3,10 +3,11 @@ use super::Backend; use super::HasCodegen; use crate::common::TypeKind; use crate::mir::place::PlaceRef; -use rustc_middle::ty::layout::{self, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, Ty}; use rustc_span::DUMMY_SP; use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg}; +use rustc_target::abi::Integer; // This depends on `Backend` and not `BackendTypes`, because consumers will probably want to use // `LayoutOf` or `HasTyCtxt`. This way, they don't have to add a constraint on it themselves. @@ -53,8 +54,8 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> { } } - fn type_from_integer(&self, i: layout::Integer) -> Self::Type { - use rustc_middle::ty::layout::Integer::*; + fn type_from_integer(&self, i: Integer) -> Self::Type { + use Integer::*; match i { I8 => self.type_i8(), I16 => self.type_i16(), diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 646febec723..cff86e8f218 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -36,12 +36,13 @@ use rustc_hir::def_id::DefId; use rustc_hir::{GenericParamKind, PatKind}; use rustc_hir::{HirIdSet, Node}; use rustc_middle::lint::LintDiagnosticBuilder; -use rustc_middle::ty::{self, layout::VariantIdx, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::lint::FutureIncompatibleInfo; use rustc_span::edition::Edition; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{BytePos, Span}; +use rustc_target::abi::VariantIdx; use rustc_trait_selection::traits::misc::can_type_implement_copy; use crate::nonstandard_style::{method_context, MethodLateContext}; diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index 12543cf83dd..1747a78d36a 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -29,12 +29,13 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::stability; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use rustc_session::lint::{add_elided_lifetime_in_path_suggestion, BuiltinLintDiagnostics}; use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId}; use rustc_session::Session; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; +use rustc_target::abi::LayoutOf; use std::slice; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 52ec8cd9381..a6e1ed84c87 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -10,12 +10,13 @@ use rustc_hir::def_id::DefId; use rustc_hir::{is_range_literal, ExprKind, Node}; use rustc_index::vec::Idx; use rustc_middle::mir::interpret::{sign_extend, truncate}; -use rustc_middle::ty::layout::{self, IntegerExt, LayoutOf, SizeSkeleton, VariantIdx}; +use rustc_middle::ty::layout::{IntegerExt, SizeSkeleton}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::Span; +use rustc_target::abi::{DiscriminantKind, Integer, LayoutOf, VariantIdx, Variants}; use rustc_target::spec::abi::Abi; use log::debug; @@ -150,7 +151,7 @@ fn report_bin_hex_error( val: u128, negative: bool, ) { - let size = layout::Integer::from_attr(&cx.tcx, ty).size(); + let size = Integer::from_attr(&cx.tcx, ty).size(); cx.struct_span_lint(OVERFLOWING_LITERALS, expr.span, |lint| { let (t, actually) = match ty { attr::IntType::SignedInt(t) => { @@ -1034,8 +1035,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { | Err(ty::layout::LayoutError::SizeOverflow(_)) => return, }; let (variants, tag) = match layout.variants { - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, + Variants::Multiple { + discr_kind: DiscriminantKind::Tag, ref discr, ref variants, .. diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index f6e2730cb57..b71f5c98487 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -29,13 +29,13 @@ use rustc_middle::middle::lang_items; use rustc_middle::mir::{self, interpret}; use rustc_middle::traits::specialization_graph; use rustc_middle::ty::codec::{self as ty_codec, TyEncoder}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt}; use rustc_serialize::{opaque, Encodable, Encoder, SpecializedEncoder}; use rustc_session::config::{self, CrateType}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{self, ExternalSource, FileName, SourceFile, Span}; +use rustc_target::abi::VariantIdx; use std::hash::Hash; use std::num::NonZeroUsize; use std::path::Path; diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index fcf6989043a..d13ad246db7 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -11,7 +11,7 @@ macro_rules! arena_types { ($macro:path, $args:tt, $tcx:lifetime) => ( $macro!($args, [ - [] layouts: rustc_middle::ty::layout::Layout, + [] layouts: rustc_target::abi::Layout, [] generics: rustc_middle::ty::Generics, [] trait_def: rustc_middle::ty::TraitDef, [] adt_def: rustc_middle::ty::AdtDef, diff --git a/src/librustc_middle/mir/interpret/allocation.rs b/src/librustc_middle/mir/interpret/allocation.rs index 0e75f34629e..8b9f0977485 100644 --- a/src/librustc_middle/mir/interpret/allocation.rs +++ b/src/librustc_middle/mir/interpret/allocation.rs @@ -7,14 +7,12 @@ use std::ops::{Deref, DerefMut, Range}; use rustc_ast::ast::Mutability; use rustc_data_structures::sorted_map::SortedMap; -use rustc_target::abi::HasDataLayout; +use rustc_target::abi::{Align, HasDataLayout, Size}; use super::{ read_target_uint, write_target_uint, AllocId, InterpResult, Pointer, Scalar, ScalarMaybeUndef, }; -use crate::ty::layout::{Align, Size}; - // NOTE: When adding new fields, make sure to adjust the `Snapshot` impl in // `src/librustc_mir/interpret/snapshot.rs`. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] diff --git a/src/librustc_middle/mir/interpret/error.rs b/src/librustc_middle/mir/interpret/error.rs index d46f1bc4cc4..7844fb10840 100644 --- a/src/librustc_middle/mir/interpret/error.rs +++ b/src/librustc_middle/mir/interpret/error.rs @@ -1,7 +1,7 @@ use super::{AllocId, CheckInAllocMsg, Pointer, RawConst, ScalarMaybeUndef}; use crate::mir::interpret::ConstValue; -use crate::ty::layout::{Align, LayoutError, Size}; +use crate::ty::layout::LayoutError; use crate::ty::query::TyCtxtAt; use crate::ty::tls; use crate::ty::{self, layout, Ty}; @@ -14,6 +14,7 @@ use rustc_hir::definitions::DefPathData; use rustc_macros::HashStable; use rustc_session::CtfeBacktrace; use rustc_span::{def_id::DefId, Pos, Span}; +use rustc_target::abi::{Align, Size}; use std::{any::Any, fmt, mem}; #[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)] diff --git a/src/librustc_middle/mir/interpret/mod.rs b/src/librustc_middle/mir/interpret/mod.rs index 10c3a06da08..96bf694d8fa 100644 --- a/src/librustc_middle/mir/interpret/mod.rs +++ b/src/librustc_middle/mir/interpret/mod.rs @@ -109,10 +109,10 @@ use rustc_data_structures::tiny_list::TinyList; use rustc_hir::def_id::DefId; use rustc_macros::HashStable; use rustc_serialize::{Decodable, Encodable, Encoder}; +use rustc_target::abi::{Endian, Size}; use crate::mir; use crate::ty::codec::TyDecoder; -use crate::ty::layout::{self, Size}; use crate::ty::subst::GenericArgKind; use crate::ty::{self, Instance, Ty, TyCtxt}; @@ -521,22 +521,22 @@ impl<'tcx> AllocMap<'tcx> { #[inline] pub fn write_target_uint( - endianness: layout::Endian, + endianness: Endian, mut target: &mut [u8], data: u128, ) -> Result<(), io::Error> { let len = target.len(); match endianness { - layout::Endian::Little => target.write_uint128::(data, len), - layout::Endian::Big => target.write_uint128::(data, len), + Endian::Little => target.write_uint128::(data, len), + Endian::Big => target.write_uint128::(data, len), } } #[inline] -pub fn read_target_uint(endianness: layout::Endian, mut source: &[u8]) -> Result { +pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result { match endianness { - layout::Endian::Little => source.read_uint128::(source.len()), - layout::Endian::Big => source.read_uint128::(source.len()), + Endian::Little => source.read_uint128::(source.len()), + Endian::Big => source.read_uint128::(source.len()), } } diff --git a/src/librustc_middle/mir/interpret/pointer.rs b/src/librustc_middle/mir/interpret/pointer.rs index d22207bd816..7549d902dfb 100644 --- a/src/librustc_middle/mir/interpret/pointer.rs +++ b/src/librustc_middle/mir/interpret/pointer.rs @@ -1,8 +1,7 @@ use super::{AllocId, InterpResult}; -use crate::ty::layout::{self, HasDataLayout, Size}; - use rustc_macros::HashStable; +use rustc_target::abi::{HasDataLayout, Size}; use std::convert::TryFrom; use std::fmt::{self, Display}; @@ -37,7 +36,7 @@ impl Display for CheckInAllocMsg { // Pointer arithmetic //////////////////////////////////////////////////////////////////////////////// -pub trait PointerArithmetic: layout::HasDataLayout { +pub trait PointerArithmetic: HasDataLayout { // These are not supposed to be overridden. #[inline(always)] @@ -100,7 +99,7 @@ pub trait PointerArithmetic: layout::HasDataLayout { } } -impl PointerArithmetic for T {} +impl PointerArithmetic for T {} /// `Pointer` is generic over the type that represents a reference to `Allocation`s, /// thus making it possible for the most convenient representation to be used in diff --git a/src/librustc_middle/mir/interpret/value.rs b/src/librustc_middle/mir/interpret/value.rs index bf4ee848823..f3c1c87dad4 100644 --- a/src/librustc_middle/mir/interpret/value.rs +++ b/src/librustc_middle/mir/interpret/value.rs @@ -6,12 +6,9 @@ use rustc_apfloat::{ Float, }; use rustc_macros::HashStable; -use rustc_target::abi::TargetDataLayout; +use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout}; -use crate::ty::{ - layout::{HasDataLayout, Size}, - ParamEnv, Ty, TyCtxt, -}; +use crate::ty::{ParamEnv, Ty, TyCtxt}; use super::{sign_extend, truncate, AllocId, Allocation, InterpResult, Pointer, PointerArithmetic}; diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 216fe43e819..36e10f8759d 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -6,7 +6,6 @@ use crate::mir::interpret::{GlobalAlloc, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; -use crate::ty::layout::VariantIdx; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{ @@ -16,6 +15,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::DefId; use rustc_hir::{self, GeneratorKind}; +use rustc_target::abi::VariantIdx; use polonius_engine::Atom; pub use rustc_ast::ast::Mutability; diff --git a/src/librustc_middle/mir/tcx.rs b/src/librustc_middle/mir/tcx.rs index feb66319267..06b27c5e8b3 100644 --- a/src/librustc_middle/mir/tcx.rs +++ b/src/librustc_middle/mir/tcx.rs @@ -4,11 +4,11 @@ */ use crate::mir::*; -use crate::ty::layout::VariantIdx; use crate::ty::subst::Subst; use crate::ty::util::IntTypeExt; use crate::ty::{self, Ty, TyCtxt}; use rustc_hir as hir; +use rustc_target::abi::VariantIdx; #[derive(Copy, Clone, Debug, TypeFoldable)] pub struct PlaceTy<'tcx> { diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index c1ece627509..2ffbbfb1762 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -738,7 +738,7 @@ rustc_queries! { query layout_raw( env: ty::ParamEnvAnd<'tcx, Ty<'tcx>> - ) -> Result<&'tcx ty::layout::Layout, ty::layout::LayoutError<'tcx>> { + ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> { desc { "computing layout of `{}`", env.value } } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index be889f66228..ba6a47dc640 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -21,7 +21,6 @@ use crate::mir::{ }; use crate::traits; use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals}; -use crate::ty::layout::{Layout, TargetDataLayout, VariantIdx}; use crate::ty::query; use crate::ty::steal::Steal; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; @@ -65,6 +64,7 @@ use rustc_session::Session; use rustc_span::source_map::MultiSpan; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; +use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx}; use rustc_target::spec::abi; use smallvec::SmallVec; diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 727d302d53f..520793c69fd 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -15,7 +15,7 @@ use rustc_span::DUMMY_SP; use rustc_target::abi::call::{ ArgAbi, ArgAttribute, ArgAttributes, Conv, FnAbi, PassMode, Reg, RegKind, }; -pub use rustc_target::abi::*; +use rustc_target::abi::*; use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy}; use std::cmp; diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 43982439d47..539a52529fb 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -18,7 +18,6 @@ use crate::mir::GeneratorLayout; use crate::mir::ReadOnlyBodyAndCache; use crate::traits::{self, Reveal}; use crate::ty; -use crate::ty::layout::VariantIdx; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use crate::ty::walk::TypeWalker; @@ -43,7 +42,7 @@ use rustc_session::DataTypeKind; use rustc_span::hygiene::ExpnId; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; -use rustc_target::abi::Align; +use rustc_target::abi::{Align, VariantIdx}; use std::cell::RefCell; use std::cmp::{self, Ordering}; @@ -2078,7 +2077,7 @@ pub struct AdtDef { /// The `DefId` of the struct, enum or union item. pub did: DefId, /// Variants of the ADT. If this is a struct or union, then there will be a single variant. - pub variants: IndexVec, + pub variants: IndexVec, /// Flags of the ADT (e.g., is this a struct? is this non-exhaustive?). flags: AdtFlags, /// Repr options provided by the user. diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 5c365a57cd1..a8b7b6a4b97 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -1,7 +1,7 @@ use crate::middle::cstore::{ExternCrate, ExternCrateSource}; use crate::middle::region; use crate::mir::interpret::{sign_extend, truncate, AllocId, ConstValue, Pointer, Scalar}; -use crate::ty::layout::{Integer, IntegerExt, Size}; +use crate::ty::layout::IntegerExt; use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::ieee::{Double, Single}; @@ -13,6 +13,7 @@ use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_span::symbol::{kw, Symbol}; +use rustc_target::abi::{Integer, Size}; use rustc_target::spec::abi::Abi; use std::cell::Cell; diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 429791d09a4..0ac4466d34f 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -254,7 +254,7 @@ CloneTypeFoldableAndLiftImpls! { (), bool, usize, - crate::ty::layout::VariantIdx, + ::rustc_target::abi::VariantIdx, u64, String, crate::middle::region::Scope, diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 57df50dc1a0..99e3b88f505 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -10,7 +10,6 @@ use crate::middle::region; use crate::mir::interpret::ConstValue; use crate::mir::interpret::{LitToConstInput, Scalar}; use crate::mir::Promoted; -use crate::ty::layout::VariantIdx; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::{ self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable, WithConstness, @@ -24,6 +23,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::vec::Idx; use rustc_macros::HashStable; use rustc_span::symbol::{kw, Symbol}; +use rustc_target::abi::{Size, VariantIdx}; use rustc_target::spec::abi; use smallvec::SmallVec; use std::borrow::Cow; @@ -2501,7 +2501,7 @@ impl<'tcx> ConstKind<'tcx> { } #[inline] - pub fn try_to_bits(&self, size: ty::layout::Size) -> Option { + pub fn try_to_bits(&self, size: Size) -> Option { if let ConstKind::Value(val) = self { val.try_to_bits(size) } else { None } } } diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index dab367a6639..42a63ba5b9c 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -2,7 +2,7 @@ use crate::ich::NodeIdHashingMode; use crate::mir::interpret::{sign_extend, truncate}; -use crate::ty::layout::{Integer, IntegerExt, Size}; +use crate::ty::layout::IntegerExt; use crate::ty::query::TyCtxtAt; use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef}; use crate::ty::TyKind::*; @@ -19,7 +19,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::definitions::DefPathData; use rustc_macros::HashStable; use rustc_span::Span; -use rustc_target::abi::TargetDataLayout; +use rustc_target::abi::{Integer, Size, TargetDataLayout}; use smallvec::SmallVec; use std::{cmp, fmt}; diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index 2991f29949a..619ae0ff8fa 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -9,10 +9,10 @@ use rustc_middle::mir::{ AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::print::Print; use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt}; use rustc_span::Span; +use rustc_target::abi::VariantIdx; use super::borrow_set::BorrowData; use super::MirBorrowckCtxt; diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 1d66bd13c6f..cedae94ab89 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -24,13 +24,13 @@ use rustc_middle::mir::*; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::fold::TypeFoldable; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts}; use rustc_middle::ty::{ self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPolyTraitRef, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, }; use rustc_span::{Span, DUMMY_SP}; +use rustc_target::abi::VariantIdx; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::opaque_types::{GenerateMemberConstraints, InferCtxtExt}; use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index af79198ef64..97cdb32e2cd 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -9,8 +9,9 @@ use rustc_hir::def::DefKind; use rustc_middle::mir; use rustc_middle::mir::interpret::{ConstEvalErr, ErrorHandled}; use rustc_middle::traits::Reveal; -use rustc_middle::ty::{self, layout, layout::LayoutOf, subst::Subst, TyCtxt}; +use rustc_middle::ty::{self, subst::Subst, TyCtxt}; use rustc_span::source_map::Span; +use rustc_target::abi::{Abi, LayoutOf}; use std::convert::TryInto; pub fn note_on_undefined_behavior_error() -> &'static str { @@ -105,8 +106,8 @@ pub(super) fn op_to_const<'tcx>( // the usual cases of extracting e.g. a `usize`, without there being a real use case for the // `Undef` situation. let try_as_immediate = match op.layout.abi { - layout::Abi::Scalar(..) => true, - layout::Abi::ScalarPair(..) => match op.layout.ty.kind { + Abi::Scalar(..) => true, + Abi::ScalarPair(..) => match op.layout.ty.kind { ty::Ref(_, inner, _) => match inner.kind { ty::Slice(elem) => elem == ecx.tcx.types.u8, ty::Str => true, diff --git a/src/librustc_mir/const_eval/mod.rs b/src/librustc_mir/const_eval/mod.rs index 78d1e8989a2..e1146ef30d1 100644 --- a/src/librustc_mir/const_eval/mod.rs +++ b/src/librustc_mir/const_eval/mod.rs @@ -3,9 +3,9 @@ use std::convert::TryFrom; use rustc_middle::mir; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{source_map::DUMMY_SP, symbol::Symbol}; +use rustc_target::abi::VariantIdx; use crate::interpret::{intern_const_alloc_recursive, ConstValue, InternKind, InterpCx}; diff --git a/src/librustc_mir/dataflow/framework/mod.rs b/src/librustc_mir/dataflow/framework/mod.rs index fd2a3d5ea28..06da8799dd4 100644 --- a/src/librustc_mir/dataflow/framework/mod.rs +++ b/src/librustc_mir/dataflow/framework/mod.rs @@ -36,8 +36,8 @@ use rustc_hir::def_id::DefId; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{self, BasicBlock, Location}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, TyCtxt}; +use rustc_target::abi::VariantIdx; mod cursor; mod engine; diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index 1c85226b122..b5f1a2d4eb9 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -5,8 +5,8 @@ use rustc_index::bit_set::BitSet; use rustc_index::vec::Idx; use rustc_middle::mir::{self, Body, Location}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, TyCtxt}; +use rustc_target::abi::VariantIdx; use super::MoveDataParamEnv; diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 215c7bb7475..67696aa2da8 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -7,10 +7,10 @@ use rustc_ast::ast::FloatTy; use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar}; use rustc_middle::mir::CastKind; use rustc_middle::ty::adjustment::PointerCast; -use rustc_middle::ty::layout::{self, Size, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, Ty, TypeAndMut, TypeFoldable}; use rustc_span::symbol::sym; -use rustc_target::abi::LayoutOf; +use rustc_target::abi::{LayoutOf, Size, Variants}; impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn cast( @@ -132,7 +132,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Handle cast from a univariant (ZST) enum. match src.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { if let Some(discr) = src.layout.ty.discriminant_for_variant(*self.tcx, index) { assert!(src.layout.is_zst()); let discr_layout = self.layout_of(discr.ty)?; @@ -141,7 +141,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .into()); } } - layout::Variants::Multiple { .. } => {} + Variants::Multiple { .. } => {} } // Handle casting the metadata away from a fat pointer. diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 8f24fc451bc..9aa42e107dc 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -13,11 +13,12 @@ use rustc_middle::mir; use rustc_middle::mir::interpret::{ sign_extend, truncate, AllocId, FrameInfo, GlobalId, InterpResult, Pointer, Scalar, }; -use rustc_middle::ty::layout::{self, Align, HasDataLayout, LayoutOf, Size, TyAndLayout}; +use rustc_middle::ty::layout::{self, TyAndLayout}; use rustc_middle::ty::query::TyCtxtAt; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map::DUMMY_SP; +use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout}; use super::{ Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy, @@ -173,7 +174,7 @@ impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpCx<'mir, 'tcx, M> { #[inline] - fn data_layout(&self) -> &layout::TargetDataLayout { + fn data_layout(&self) -> &TargetDataLayout { &self.tcx.data_layout } } diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index b60377fbcd6..d976df82577 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -11,10 +11,10 @@ use rustc_middle::mir::{ BinOp, }; use rustc_middle::ty; -use rustc_middle::ty::layout::{LayoutOf, Primitive, Size}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::{sym, Symbol}; +use rustc_target::abi::{Abi, LayoutOf as _, Primitive, Size}; use super::{ImmTy, InterpCx, Machine, OpTy, PlaceTy}; @@ -134,7 +134,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let val = self.read_scalar(args[0])?.not_undef()?; let bits = self.force_bits(val, layout_of.size)?; let kind = match layout_of.abi { - ty::layout::Abi::Scalar(ref scalar) => scalar.value, + Abi::Scalar(ref scalar) => scalar.value, _ => bug!("{} called on invalid type {:?}", intrinsic_name, ty), }; let (nonzero, intrinsic_name) = match intrinsic_name { diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 9443ae116fc..04a927c69a6 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -11,11 +11,10 @@ use std::collections::VecDeque; use std::convert::TryFrom; use std::ptr; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_middle::ty::layout::{Align, HasDataLayout, Size, TargetDataLayout}; -use rustc_middle::ty::{self, query::TyCtxtAt, Instance, ParamEnv}; - use rustc_ast::ast::Mutability; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_middle::ty::{self, query::TyCtxtAt, Instance, ParamEnv}; +use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; use super::{ AllocId, AllocMap, Allocation, AllocationExtra, CheckInAllocMsg, ErrorHandled, GlobalAlloc, diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 7191198b6c0..999d0d26ab3 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -10,12 +10,12 @@ pub use rustc_middle::mir::interpret::ScalarMaybeUndef; use rustc_middle::mir::interpret::{ sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpResult, Pointer, Scalar, }; -use rustc_middle::ty::layout::{ - self, HasDataLayout, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, -}; +use rustc_middle::ty::layout::{IntegerExt, PrimitiveExt, TyAndLayout}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer}; use rustc_middle::ty::Ty; use rustc_middle::{mir, ty}; +use rustc_target::abi::{Abi, DiscriminantKind, HasDataLayout, Integer, LayoutOf, Size}; +use rustc_target::abi::{VariantIdx, Variants}; use std::fmt::Write; /// An `Immediate` represents a single immediate self-contained Rust value. @@ -266,7 +266,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }; match mplace.layout.abi { - layout::Abi::Scalar(..) => { + Abi::Scalar(..) => { let scalar = self.memory.get_raw(ptr.alloc_id)?.read_scalar( self, ptr, @@ -274,7 +274,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { )?; Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout })) } - layout::Abi::ScalarPair(ref a, ref b) => { + Abi::ScalarPair(ref a, ref b) => { // We checked `ptr_align` above, so all fields will have the alignment they need. // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. @@ -587,7 +587,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { trace!("read_discriminant_value {:#?}", rval.layout); let (discr_layout, discr_kind, discr_index) = match rval.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { let discr_val = rval .layout .ty @@ -595,12 +595,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .map_or(u128::from(index.as_u32()), |discr| discr.val); return Ok((discr_val, index)); } - layout::Variants::Multiple { - discr: ref discr_layout, - ref discr_kind, - discr_index, - .. - } => (discr_layout, discr_kind, discr_index), + Variants::Multiple { discr: ref discr_layout, ref discr_kind, discr_index, .. } => { + (discr_layout, discr_kind, discr_index) + } }; // read raw discriminant value @@ -610,7 +607,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { trace!("discr value: {:?}", raw_discr); // post-process Ok(match *discr_kind { - layout::DiscriminantKind::Tag => { + DiscriminantKind::Tag => { let bits_discr = raw_discr .not_undef() .and_then(|raw_discr| self.force_bits(raw_discr, discr_val.layout.size)) @@ -627,7 +624,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .expect("tagged layout corresponds to adt") .repr .discr_type(); - let size = layout::Integer::from_attr(self, discr_ty).size(); + let size = Integer::from_attr(self, discr_ty).size(); truncate(sexted, size) } else { bits_discr @@ -648,11 +645,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .ok_or_else(|| err_ub!(InvalidDiscriminant(raw_discr.erase_tag())))?; (real_discr, index.0) } - layout::DiscriminantKind::Niche { - dataful_variant, - ref niche_variants, - niche_start, - } => { + DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start } => { let variants_start = niche_variants.start().as_u32(); let variants_end = niche_variants.end().as_u32(); let raw_discr = raw_discr diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index e81cd8b3d00..0aa7e98f3ed 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -4,11 +4,8 @@ use rustc_apfloat::Float; use rustc_ast::ast::FloatTy; use rustc_middle::mir; use rustc_middle::mir::interpret::{InterpResult, Scalar}; -use rustc_middle::ty::{ - self, - layout::{LayoutOf, TyAndLayout}, - Ty, -}; +use rustc_middle::ty::{self, layout::TyAndLayout, Ty}; +use rustc_target::abi::LayoutOf; use super::{ImmTy, Immediate, InterpCx, Machine, PlaceTy}; diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index a8e65a7e7f5..ece54daf4c6 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -8,10 +8,10 @@ use std::hash::Hash; use rustc_macros::HashStable; use rustc_middle::mir; use rustc_middle::mir::interpret::truncate; -use rustc_middle::ty::layout::{ - self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, -}; +use rustc_middle::ty::layout::{PrimitiveExt, TyAndLayout}; use rustc_middle::ty::{self, Ty}; +use rustc_target::abi::{Abi, Align, DiscriminantKind, FieldsShape}; +use rustc_target::abi::{HasDataLayout, LayoutOf, Size, VariantIdx, Variants}; use super::{ AllocId, AllocMap, Allocation, AllocationExtra, ImmTy, Immediate, InterpCx, InterpResult, @@ -219,7 +219,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { // Go through the layout. There are lots of types that support a length, // e.g., SIMD types. match self.layout.fields { - layout::FieldsShape::Array { count, .. } => Ok(count), + FieldsShape::Array { count, .. } => Ok(count), _ => bug!("len not supported on sized type {:?}", self.layout.ty), } } @@ -437,7 +437,7 @@ where ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { // Not using the layout method because we want to compute on u64 match base.layout.fields { - layout::FieldsShape::Array { stride, .. } => { + FieldsShape::Array { stride, .. } => { let len = base.len(self)?; if index >= len { // This can only be reached in ConstProp and non-rustc-MIR. @@ -463,7 +463,7 @@ where { let len = base.len(self)?; // also asserts that we have a type where this makes sense let stride = match base.layout.fields { - layout::FieldsShape::Array { stride, .. } => stride, + FieldsShape::Array { stride, .. } => stride, _ => bug!("mplace_array_fields: expected an array layout"), }; let layout = base.layout.field(self, 0)?; @@ -493,7 +493,7 @@ where // Not using layout method because that works with usize, and does not work with slices // (that have count 0 in their layout). let from_offset = match base.layout.fields { - layout::FieldsShape::Array { stride, .. } => stride * from, // `Size` multiplication is checked + FieldsShape::Array { stride, .. } => stride * from, // `Size` multiplication is checked _ => bug!("Unexpected layout of index access: {:#?}", base.layout), }; @@ -802,7 +802,7 @@ where match value { Immediate::Scalar(scalar) => { match dest.layout.abi { - layout::Abi::Scalar(_) => {} // fine + Abi::Scalar(_) => {} // fine _ => { bug!("write_immediate_to_mplace: invalid Scalar layout: {:#?}", dest.layout) } @@ -819,7 +819,7 @@ where // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. let (a, b) = match dest.layout.abi { - layout::Abi::ScalarPair(ref a, ref b) => (&a.value, &b.value), + Abi::ScalarPair(ref a, ref b) => (&a.value, &b.value), _ => bug!( "write_immediate_to_mplace: invalid ScalarPair layout: {:#?}", dest.layout @@ -1067,11 +1067,11 @@ where } match dest.layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { assert_eq!(index, variant_index); } - layout::Variants::Multiple { - discr_kind: layout::DiscriminantKind::Tag, + Variants::Multiple { + discr_kind: DiscriminantKind::Tag, discr: ref discr_layout, discr_index, .. @@ -1091,9 +1091,9 @@ where let discr_dest = self.place_field(dest, discr_index)?; self.write_scalar(Scalar::from_uint(discr_val, size), discr_dest)?; } - layout::Variants::Multiple { + Variants::Multiple { discr_kind: - layout::DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start }, + DiscriminantKind::Niche { dataful_variant, ref niche_variants, niche_start }, discr: ref discr_layout, discr_index, .. diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 961b0f4d189..407849c2ce2 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -4,7 +4,7 @@ use rustc_middle::mir; use rustc_middle::mir::interpret::{InterpResult, Scalar}; -use rustc_middle::ty::layout::LayoutOf; +use rustc_target::abi::LayoutOf; use super::{InterpCx, Machine}; diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 6ca6f50b0ee..8ad743d2b8b 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -1,9 +1,10 @@ use std::borrow::Cow; use std::convert::TryFrom; -use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::Instance; use rustc_middle::{mir, ty}; +use rustc_target::abi::{self, LayoutOf as _}; use rustc_target::spec::abi::Abi; use super::{ @@ -142,12 +143,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Different valid ranges are okay (once we enforce validity, // that will take care to make it UB to leave the range, just // like for transmute). - (layout::Abi::Scalar(ref caller), layout::Abi::Scalar(ref callee)) => { + (abi::Abi::Scalar(ref caller), abi::Abi::Scalar(ref callee)) => { caller.value == callee.value } ( - layout::Abi::ScalarPair(ref caller1, ref caller2), - layout::Abi::ScalarPair(ref callee1, ref callee2), + abi::Abi::ScalarPair(ref caller1, ref caller2), + abi::Abi::ScalarPair(ref callee1, ref callee2), ) => caller1.value == callee1.value && caller2.value == callee2.value, // Be conservative _ => false, diff --git a/src/librustc_mir/interpret/traits.rs b/src/librustc_mir/interpret/traits.rs index ed882e10741..fb9401c7d8f 100644 --- a/src/librustc_mir/interpret/traits.rs +++ b/src/librustc_mir/interpret/traits.rs @@ -1,8 +1,8 @@ use std::convert::TryFrom; use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic, Scalar}; -use rustc_middle::ty::layout::{Align, HasDataLayout, LayoutOf, Size}; use rustc_middle::ty::{self, Instance, Ty, TypeFoldable}; +use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size}; use super::{FnVal, InterpCx, Machine, MemoryKind}; diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 0ca565d8678..701e394415b 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -11,8 +11,9 @@ use std::ops::RangeInclusive; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_middle::ty; -use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout, VariantIdx}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_span::symbol::{sym, Symbol}; +use rustc_target::abi::{Abi, LayoutOf, Scalar, VariantIdx, Variants}; use std::hash::Hash; @@ -180,7 +181,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M fn aggregate_field_path_elem(&mut self, layout: TyAndLayout<'tcx>, field: usize) -> PathElem { // First, check if we are projecting to a variant. match layout.variants { - layout::Variants::Multiple { discr_index, .. } => { + Variants::Multiple { discr_index, .. } => { if discr_index == field { return match layout.ty.kind { ty::Adt(def, ..) if def.is_enum() => PathElem::EnumTag, @@ -189,7 +190,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M }; } } - layout::Variants::Single { .. } => {} + Variants::Single { .. } => {} } // Now we know we are projecting to a field, so figure out which one. @@ -226,11 +227,11 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M ty::Adt(def, ..) if def.is_enum() => { // we might be projecting *to* a variant, or to a field *in* a variant. match layout.variants { - layout::Variants::Single { index } => { + Variants::Single { index } => { // Inside a variant PathElem::Field(def.variants[index].fields[field].ident.name) } - layout::Variants::Multiple { .. } => bug!("we handled variants above"), + Variants::Multiple { .. } => bug!("we handled variants above"), } } @@ -539,7 +540,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M fn visit_scalar( &mut self, op: OpTy<'tcx, M::PointerTag>, - scalar_layout: &layout::Scalar, + scalar_layout: &Scalar, ) -> InterpResult<'tcx> { let value = self.ecx.read_scalar(op)?; let valid_range = &scalar_layout.valid_range; @@ -685,22 +686,22 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> // scalars, we do the same check on every "level" (e.g., first we check // MyNewtype and then the scalar in there). match op.layout.abi { - layout::Abi::Uninhabited => { + Abi::Uninhabited => { throw_validation_failure!( format_args!("a value of uninhabited type {:?}", op.layout.ty), self.path ); } - layout::Abi::Scalar(ref scalar_layout) => { + Abi::Scalar(ref scalar_layout) => { self.visit_scalar(op, scalar_layout)?; } - layout::Abi::ScalarPair { .. } | layout::Abi::Vector { .. } => { + Abi::ScalarPair { .. } | Abi::Vector { .. } => { // These have fields that we already visited above, so we already checked // all their scalar-level restrictions. // There is also no equivalent to `rustc_layout_scalar_valid_range_start` // that would make skipping them here an issue. } - layout::Abi::Aggregate { .. } => { + Abi::Aggregate { .. } => { // Nothing to do. } } diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index 66a46c12c06..e03984f4d0b 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -3,7 +3,8 @@ use rustc_middle::mir::interpret::InterpResult; use rustc_middle::ty; -use rustc_middle::ty::layout::{self, TyAndLayout, VariantIdx}; +use rustc_middle::ty::layout::TyAndLayout; +use rustc_target::abi::{FieldsShape, VariantIdx, Variants}; use super::{InterpCx, MPlaceTy, Machine, OpTy}; @@ -207,10 +208,10 @@ macro_rules! make_value_visitor { // Visit the fields of this value. match v.layout().fields { - layout::FieldsShape::Union(fields) => { + FieldsShape::Union(fields) => { self.visit_union(v, fields)?; }, - layout::FieldsShape::Arbitrary { ref offsets, .. } => { + FieldsShape::Arbitrary { ref offsets, .. } => { // FIXME: We collect in a vec because otherwise there are lifetime // errors: Projecting to a field needs access to `ecx`. let fields: Vec> = @@ -220,7 +221,7 @@ macro_rules! make_value_visitor { .collect(); self.visit_aggregate(v, fields.into_iter())?; }, - layout::FieldsShape::Array { .. } => { + FieldsShape::Array { .. } => { // Let's get an mplace first. let mplace = v.to_op(self.ecx())?.assert_mem_place(self.ecx()); // Now we can go over all the fields. @@ -237,7 +238,7 @@ macro_rules! make_value_visitor { match v.layout().variants { // If this is a multi-variant layout, find the right variant and proceed // with *its* fields. - layout::Variants::Multiple { .. } => { + Variants::Multiple { .. } => { let op = v.to_op(self.ecx())?; let idx = self.ecx().read_discriminant(op)?.1; let inner = v.project_downcast(self.ecx(), idx)?; @@ -246,7 +247,7 @@ macro_rules! make_value_visitor { self.visit_variant(v, idx, inner) } // For single-variant layouts, we already did anything there is to do. - layout::Variants::Single { .. } => Ok(()) + Variants::Single { .. } => Ok(()) } } } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 0a998bbfe70..67de81ed77b 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -1,10 +1,10 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; +use rustc_target::abi::VariantIdx; use rustc_index::vec::{Idx, IndexVec}; diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index f4cba875620..c7f63d24c28 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -19,13 +19,12 @@ use rustc_middle::mir::{ SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; -use rustc_middle::ty::layout::{ - HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyAndLayout, -}; +use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_session::lint; use rustc_span::{def_id::DefId, Span}; +use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout}; use rustc_trait_selection::traits; use crate::const_eval::error_to_const_error; diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index d3971c9a45c..a7c6b5a98bb 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -13,9 +13,9 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_index::bit_set::BitSet; use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::Span; +use rustc_target::abi::VariantIdx; use std::fmt; pub struct ElaborateDrops; diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 390d927a854..53eec1f6dc3 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -63,10 +63,10 @@ use rustc_index::bit_set::{BitMatrix, BitSet}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::GeneratorSubsts; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; +use rustc_target::abi::VariantIdx; use std::borrow::Cow; use std::iter; diff --git a/src/librustc_mir/transform/uninhabited_enum_branching.rs b/src/librustc_mir/transform/uninhabited_enum_branching.rs index 38a9194e5c5..0a08c13b479 100644 --- a/src/librustc_mir/transform/uninhabited_enum_branching.rs +++ b/src/librustc_mir/transform/uninhabited_enum_branching.rs @@ -5,8 +5,9 @@ use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Operand, Rvalue, StatementKind, TerminatorKind, }; -use rustc_middle::ty::layout::{Abi, TyAndLayout, Variants}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_target::abi::{Abi, Variants}; pub struct UninhabitedEnumBranching; diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index b22dbf40b50..e77d264b7ce 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -1,7 +1,7 @@ use rustc_index::vec::Idx; use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_target::abi::VariantIdx; use std::iter::TrustedLen; diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index f6d67abcef0..e6dee043a1b 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -4,10 +4,10 @@ use rustc_index::vec::Idx; use rustc_middle::middle::lang_items; use rustc_middle::mir::*; use rustc_middle::traits::Reveal; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_target::abi::VariantIdx; use std::fmt; use std::convert::TryInto; diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index df7df6a0809..a81fcb54580 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -9,7 +9,8 @@ use rustc_middle::mir::interpret::{ }; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; -use rustc_middle::ty::{self, layout::Size, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_target::abi::Size; use std::collections::BTreeSet; use std::fmt::Display; use std::fmt::Write as _; diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index a98b18c0cf1..a4a9271669e 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -16,9 +16,9 @@ use rustc_hir::HirId; use rustc_index::bit_set::BitSet; use rustc_middle::middle::region; use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc_span::Span; +use rustc_target::abi::VariantIdx; use smallvec::{smallvec, SmallVec}; // helper functions, broken out by category: diff --git a/src/librustc_mir_build/build/matches/simplify.rs b/src/librustc_mir_build/build/matches/simplify.rs index 664f56ae5e4..d74d8b5c7f3 100644 --- a/src/librustc_mir_build/build/matches/simplify.rs +++ b/src/librustc_mir_build/build/matches/simplify.rs @@ -15,12 +15,13 @@ use crate::build::matches::{Ascription, Binding, Candidate, MatchPair}; use crate::build::Builder; use crate::hair::{self, *}; +use rustc_attr::{SignedInt, UnsignedInt}; +use rustc_hir::RangeEnd; use rustc_middle::mir::interpret::truncate; use rustc_middle::mir::Place; use rustc_middle::ty; -use rustc_middle::ty::layout::{Integer, IntegerExt, Size}; -use rustc_attr::{SignedInt, UnsignedInt}; -use rustc_hir::RangeEnd; +use rustc_middle::ty::layout::IntegerExt; +use rustc_target::abi::{Integer, Size}; use std::mem; diff --git a/src/librustc_mir_build/build/matches/test.rs b/src/librustc_mir_build/build/matches/test.rs index 450bb0a861d..3da4bb26779 100644 --- a/src/librustc_mir_build/build/matches/test.rs +++ b/src/librustc_mir_build/build/matches/test.rs @@ -9,14 +9,14 @@ use crate::build::matches::{Candidate, MatchPair, Test, TestKind}; use crate::build::Builder; use crate::hair::pattern::compare_const_vals; use crate::hair::*; -use rustc_middle::mir::*; -use rustc_middle::ty::layout::VariantIdx; -use rustc_middle::ty::util::IntTypeExt; -use rustc_middle::ty::{self, adjustment::PointerCast, Ty}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::RangeEnd; use rustc_index::bit_set::BitSet; +use rustc_middle::mir::*; +use rustc_middle::ty::util::IntTypeExt; +use rustc_middle::ty::{self, adjustment::PointerCast, Ty}; use rustc_span::symbol::sym; +use rustc_target::abi::VariantIdx; use std::cmp::Ordering; diff --git a/src/librustc_mir_build/hair/constant.rs b/src/librustc_mir_build/hair/constant.rs index 667f29337c2..e5af0b5bd6b 100644 --- a/src/librustc_mir_build/hair/constant.rs +++ b/src/librustc_mir_build/hair/constant.rs @@ -2,8 +2,9 @@ use rustc_ast::ast; use rustc_middle::mir::interpret::{ truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar, }; -use rustc_middle::ty::{self, layout::Size, ParamEnv, TyCtxt, TyS}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt, TyS}; use rustc_span::symbol::Symbol; +use rustc_target::abi::Size; crate fn lit_to_const<'tcx>( tcx: TyCtxt<'tcx>, diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index 13a476775db..503bd26d51f 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -14,11 +14,11 @@ use rustc_index::vec::Idx; use rustc_infer::infer::InferCtxt; use rustc_middle::middle::region; use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::{GenericArg, InternalSubsts}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; +use rustc_target::abi::VariantIdx; use rustc_trait_selection::infer::InferCtxtExt; #[derive(Clone)] diff --git a/src/librustc_mir_build/hair/mod.rs b/src/librustc_mir_build/hair/mod.rs index fadfc7660d4..601e4412512 100644 --- a/src/librustc_mir_build/hair/mod.rs +++ b/src/librustc_mir_build/hair/mod.rs @@ -11,10 +11,10 @@ use rustc_middle::infer::canonical::Canonical; use rustc_middle::middle::region; use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp}; use rustc_middle::ty::adjustment::PointerCast; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{AdtDef, Const, Ty, UpvarSubsts, UserType}; use rustc_span::Span; +use rustc_target::abi::VariantIdx; crate mod constant; crate mod cx; diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 03f668d562e..cfd5ba544bb 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -240,11 +240,12 @@ use rustc_hir::def_id::DefId; use rustc_hir::{HirId, RangeEnd}; use rustc_middle::mir::interpret::{truncate, AllocId, ConstValue, Pointer, Scalar}; use rustc_middle::mir::Field; -use rustc_middle::ty::layout::{Integer, IntegerExt, Size, VariantIdx}; +use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeFoldable, VariantDef}; use rustc_middle::util::common::ErrorReported; use rustc_session::lint; use rustc_span::{Span, DUMMY_SP}; +use rustc_target::abi::{Integer, Size, VariantIdx}; use arena::TypedArena; diff --git a/src/librustc_mir_build/hair/pattern/mod.rs b/src/librustc_mir_build/hair/pattern/mod.rs index f15d2fc5caa..2b6d8e920f5 100644 --- a/src/librustc_mir_build/hair/pattern/mod.rs +++ b/src/librustc_mir_build/hair/pattern/mod.rs @@ -19,13 +19,13 @@ use rustc_middle::mir::interpret::{get_slice_bytes, sign_extend, ConstValue, Err use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::mir::UserTypeProjection; use rustc_middle::mir::{BorrowKind, Field, Mutability}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::subst::{GenericArg, SubstsRef}; use rustc_middle::ty::{self, AdtDef, DefIdTree, Region, Ty, TyCtxt, UserType}; use rustc_middle::ty::{ CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, }; use rustc_span::{Span, DUMMY_SP}; +use rustc_target::abi::VariantIdx; use std::cmp::Ordering; use std::fmt; @@ -1047,8 +1047,8 @@ crate fn compare_const_vals<'tcx>( } ty::Int(ity) => { use rustc_attr::SignedInt; - use rustc_middle::ty::layout::{Integer, IntegerExt}; - let size = Integer::from_attr(&tcx, SignedInt(ity)).size(); + use rustc_middle::ty::layout::IntegerExt; + let size = rustc_target::abi::Integer::from_attr(&tcx, SignedInt(ity)).size(); let a = sign_extend(a, size); let b = sign_extend(b, size); Some((a as i128).cmp(&(b as i128))) diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index 11096c693e6..cc1af630cdd 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -4,10 +4,11 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_index::vec::Idx; -use rustc_middle::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; +use rustc_middle::ty::layout::{LayoutError, SizeSkeleton}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::{sym, Span}; +use rustc_target::abi::{Pointer, VariantIdx}; use rustc_target::spec::abi::Abi::RustIntrinsic; fn check_mod_intrinsics(tcx: TyCtxt<'_>, module_def_id: DefId) { diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 9fa3225851b..da8ab727ed3 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -3,16 +3,10 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::ItemKind; -use rustc_middle::ty::layout::HasDataLayout; -use rustc_middle::ty::layout::HasParamEnv; -use rustc_middle::ty::layout::HasTyCtxt; -use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::layout::TargetDataLayout; -use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::ParamEnv; -use rustc_middle::ty::Ty; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, TyAndLayout}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_span::symbol::sym; +use rustc_target::abi::{HasDataLayout, LayoutOf, TargetDataLayout}; pub fn test_layout(tcx: TyCtxt<'_>) { if tcx.features().rustc_attrs { diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 3877c7f8a8c..20b3fa908d2 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -420,7 +420,7 @@ fn virtual_call_violation_for_method<'tcx>( } else { // Do sanity check to make sure the receiver actually has the layout of a pointer. - use rustc_middle::ty::layout::Abi; + use rustc_target::abi::Abi; let param_env = tcx.param_env(method.def_id); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3823efe9d92..96fc2693ed7 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -114,7 +114,6 @@ use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast, }; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; -use rustc_middle::ty::layout::VariantIdx; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{ GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSelfTy, UserSubsts, @@ -132,6 +131,7 @@ use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::{original_sp, DUMMY_SP}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{self, BytePos, MultiSpan, Span}; +use rustc_target::abi::VariantIdx; use rustc_target::spec::abi::Abi; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::opaque_types::{InferCtxtExt as _, OpaqueTypeDecl}; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 7b3fd82479e..e844abfc62c 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -19,11 +19,11 @@ use rustc_hir::Mutability; use rustc_index::vec::IndexVec; use rustc_middle::middle::lang_items; use rustc_middle::middle::stability; -use rustc_middle::ty::layout::VariantIdx; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::DUMMY_SP; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{self, FileName}; +use rustc_target::abi::VariantIdx; use rustc_target::spec::abi::Abi; use crate::clean::cfg::Cfg; From 86c0fca44bc0b49085b177d0244bc300f6cd4655 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Mar 2020 21:18:30 +0200 Subject: [PATCH 09/12] use direct import for ErrorReported --- src/librustc_codegen_llvm/lib.rs | 3 +-- src/librustc_codegen_ssa/traits/backend.rs | 2 +- src/librustc_driver/lib.rs | 7 ++----- src/librustc_driver/pretty.rs | 2 +- .../nice_region_error/different_lifetimes.rs | 3 +-- .../infer/error_reporting/nice_region_error/mod.rs | 3 +-- .../error_reporting/nice_region_error/outlives_closure.rs | 2 +- .../error_reporting/nice_region_error/static_impl_trait.rs | 3 +-- .../nice_region_error/trait_impl_difference.rs | 2 +- src/librustc_interface/interface.rs | 2 +- src/librustc_interface/passes.rs | 3 +-- src/librustc_interface/queries.rs | 2 +- src/librustc_middle/ty/context.rs | 2 +- src/librustc_middle/ty/query/mod.rs | 2 +- src/librustc_middle/ty/util.rs | 2 +- src/librustc_middle/util/common.rs | 2 -- src/librustc_mir_build/hair/pattern/_match.rs | 2 +- src/librustc_trait_selection/traits/mod.rs | 2 +- src/librustc_trait_selection/traits/on_unimplemented.rs | 6 ++---- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/cast.rs | 3 +-- src/librustc_typeck/check/compare_method.rs | 3 +-- src/librustc_typeck/check/dropck.rs | 3 +-- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/mod.rs | 3 ++- src/librustc_typeck/lib.rs | 3 +-- src/librustdoc/test.rs | 2 +- 27 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 8a16d098a8b..939f9e9c2a0 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -23,11 +23,10 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLTOInput, ModuleConfig}; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::ModuleCodegen; use rustc_codegen_ssa::{CodegenResults, CompiledModule}; -use rustc_errors::{FatalError, Handler}; +use rustc_errors::{ErrorReported, FatalError, Handler}; use rustc_middle::dep_graph::{DepGraph, WorkProduct}; use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_serialize::json; use rustc_session::config::{self, OptLevel, OutputFilenames, PrintRequest}; use rustc_session::Session; diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index bfba463907f..91be123beb0 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -3,12 +3,12 @@ use super::CodegenObject; use crate::ModuleCodegen; use rustc_ast::expand::allocator::AllocatorKind; +use rustc_errors::ErrorReported; use rustc_middle::dep_graph::DepGraph; use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_session::{ config::{self, OutputFilenames, PrintRequest}, Session, diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 8f8c2eae6e2..ccbce01d6c1 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -22,10 +22,8 @@ use rustc_ast::ast; use rustc_codegen_ssa::{traits::CodegenBackend, CodegenResults}; use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::sync::SeqCst; -use rustc_errors::{ - registry::{InvalidErrorCode, Registry}, - PResult, -}; +use rustc_errors::registry::{InvalidErrorCode, Registry}; +use rustc_errors::{ErrorReported, PResult}; use rustc_feature::{find_gated_cfg, UnstableFeatures}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_interface::util::{collect_crate_types, get_builtin_codegen_backend}; @@ -34,7 +32,6 @@ use rustc_lint::LintStore; use rustc_metadata::locator; use rustc_middle::middle::cstore::MetadataLoader; use rustc_middle::ty::TyCtxt; -use rustc_middle::util::common::ErrorReported; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; use rustc_serialize::json::{self, ToJson}; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 87777bd674b..78a271810b2 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -2,12 +2,12 @@ use rustc_ast::ast; use rustc_ast_pretty::pprust; +use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir_pretty as pprust_hir; use rustc_middle::hir::map as hir_map; use rustc_middle::ty::{self, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_mir::util::{write_mir_graphviz, write_mir_pretty}; use rustc_session::config::{Input, PpMode, PpSourceMode}; use rustc_session::Session; diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/different_lifetimes.rs index 3836bd9afa8..d206a30d526 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -5,9 +5,8 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::SubregionOrigin; -use rustc_middle::util::common::ErrorReported; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, ErrorReported}; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when both the concerned regions are anonymous. diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/mod.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/mod.rs index 4613c43ba07..2aed3d9a469 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/mod.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/mod.rs @@ -1,9 +1,8 @@ use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::lexical_region_resolve::RegionResolutionError::*; use crate::infer::InferCtxt; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_span::source_map::Span; mod different_lifetimes; diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs index 028148b17db..70c30271043 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -4,9 +4,9 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError::SubSupConflict; use crate::infer::SubregionOrigin; +use rustc_errors::ErrorReported; use rustc_hir::{Expr, ExprKind::Closure, Node}; use rustc_middle::ty::RegionKind; -use rustc_middle::util::common::ErrorReported; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when binding escapes a closure. diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs index 34653f2dc0d..7f3ec852e41 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -3,9 +3,8 @@ use crate::infer::error_reporting::msg_span_from_free_region; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; -use rustc_errors::Applicability; +use rustc_errors::{Applicability, ErrorReported}; use rustc_middle::ty::{BoundRegion, FreeRegion, RegionKind}; -use rustc_middle::util::common::ErrorReported; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when the return type is a static impl Trait. diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs index a2cd54b48d5..695f3e47fb5 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -4,8 +4,8 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::{Subtype, ValuePairs}; use crate::traits::ObligationCauseCode::CompareImplMethodObligation; +use rustc_errors::ErrorReported; use rustc_middle::ty::Ty; -use rustc_middle::util::common::ErrorReported; use rustc_span::Span; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index a50e802ac2e..8e929b7daa8 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -8,9 +8,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::OnDrop; use rustc_errors::registry::Registry; +use rustc_errors::ErrorReported; use rustc_lint::LintStore; use rustc_middle::ty; -use rustc_middle::util::common::ErrorReported; use rustc_parse::new_parser_from_source_str; use rustc_session::config::{self, ErrorOutputType, Input, OutputFilenames}; use rustc_session::early_error; diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index e3fc4fa52fb..609c80a2b79 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -9,7 +9,7 @@ use rustc_codegen_ssa::back::link::emit_metadata; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::sync::{par_iter, Lrc, Once, ParallelIterator, WorkerLocal}; use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel}; -use rustc_errors::PResult; +use rustc_errors::{ErrorReported, PResult}; use rustc_expand::base::ExtCtxt; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_hir::definitions::Definitions; @@ -21,7 +21,6 @@ use rustc_middle::middle; use rustc_middle::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn}; use rustc_middle::ty::steal::Steal; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_mir as mir; use rustc_mir_build as mir_build; use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str}; diff --git a/src/librustc_interface/queries.rs b/src/librustc_interface/queries.rs index 995776552dd..6a62d754f28 100644 --- a/src/librustc_interface/queries.rs +++ b/src/librustc_interface/queries.rs @@ -4,6 +4,7 @@ use crate::passes::{self, BoxedResolver, QueryContext}; use rustc_ast::{self, ast}; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::sync::{Lrc, Once, WorkerLocal}; +use rustc_errors::ErrorReported; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::Crate; use rustc_incremental::DepGraphFuture; @@ -12,7 +13,6 @@ use rustc_middle::arena::Arena; use rustc_middle::dep_graph::DepGraph; use rustc_middle::ty::steal::Steal; use rustc_middle::ty::{GlobalCtxt, ResolverOutputs, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_session::config::{OutputFilenames, OutputType}; use rustc_session::{output::find_crate_name, Session}; use rustc_span::symbol::sym; diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index ba6a47dc640..cfc9e00b26e 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -37,7 +37,6 @@ use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid}; use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, ProjectionTy}; use crate::ty::{InferConst, ParamConst}; use crate::ty::{List, TyKind, TyS}; -use crate::util::common::ErrorReported; use rustc_ast::ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::node_id::NodeMap; @@ -49,6 +48,7 @@ use rustc_data_structures::stable_hasher::{ hash_stable_hashmap, HashStable, StableHasher, StableVec, }; use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal}; +use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE}; diff --git a/src/librustc_middle/ty/query/mod.rs b/src/librustc_middle/ty/query/mod.rs index 744237520fb..612abe32b6e 100644 --- a/src/librustc_middle/ty/query/mod.rs +++ b/src/librustc_middle/ty/query/mod.rs @@ -34,13 +34,13 @@ use crate::ty::steal::Steal; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::util::AlwaysRequiresDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; -use crate::util::common::ErrorReported; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::profiling::ProfileCategory::*; use rustc_data_structures::stable_hasher::StableVec; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; +use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index 42a63ba5b9c..86575b01333 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -7,12 +7,12 @@ use crate::ty::query::TyCtxtAt; use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef}; use crate::ty::TyKind::*; use crate::ty::{self, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable}; -use crate::util::common::ErrorReported; use rustc_apfloat::Float as _; use rustc_ast::ast; use rustc_attr::{self as attr, SignedInt, UnsignedInt}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; diff --git a/src/librustc_middle/util/common.rs b/src/librustc_middle/util/common.rs index 19b43bfd162..1e09702bf27 100644 --- a/src/librustc_middle/util/common.rs +++ b/src/librustc_middle/util/common.rs @@ -8,8 +8,6 @@ use std::time::{Duration, Instant}; #[cfg(test)] mod tests; -pub use rustc_errors::ErrorReported; - pub fn to_readable_str(mut val: usize) -> String { let mut groups = vec![]; loop { diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index cfd5ba544bb..8c0843124f4 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -236,13 +236,13 @@ use super::{compare_const_vals, PatternFoldable, PatternFolder}; use super::{FieldPat, Pat, PatKind, PatRange}; use rustc_attr::{SignedInt, UnsignedInt}; +use rustc_errors::ErrorReported; use rustc_hir::def_id::DefId; use rustc_hir::{HirId, RangeEnd}; use rustc_middle::mir::interpret::{truncate, AllocId, ConstValue, Pointer, Scalar}; use rustc_middle::mir::Field; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeFoldable, VariantDef}; -use rustc_middle::util::common::ErrorReported; use rustc_session::lint; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{Integer, Size, VariantIdx}; diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 5f988506330..9a853c32eaa 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -24,13 +24,13 @@ use crate::infer::outlives::env::OutlivesEnvironment; use crate::infer::{InferCtxt, RegionckMode, TyCtxtInferExt}; use crate::traits::error_reporting::InferCtxtExt as _; use crate::traits::query::evaluate_obligation::InferCtxtExt as _; +use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::middle::region; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::{InternalSubsts, SubstsRef}; use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, WithConstness}; -use rustc_middle::util::common::ErrorReported; use rustc_span::{Span, DUMMY_SP}; use std::fmt::Debug; diff --git a/src/librustc_trait_selection/traits/on_unimplemented.rs b/src/librustc_trait_selection/traits/on_unimplemented.rs index 23c3bd46d2d..cf29c4249c0 100644 --- a/src/librustc_trait_selection/traits/on_unimplemented.rs +++ b/src/librustc_trait_selection/traits/on_unimplemented.rs @@ -1,13 +1,11 @@ use fmt_macros::{Parser, Piece, Position}; -use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt}; -use rustc_middle::util::common::ErrorReported; - use rustc_ast::ast::{MetaItem, NestedMetaItem}; use rustc_attr as attr; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, ErrorReported}; use rustc_hir::def_id::DefId; +use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 932032bb2b4..9e2a6fb1d83 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -9,10 +9,10 @@ use crate::collect::PlaceholderHirTyCollector; use crate::middle::lang_items::SizedTraitLangItem; use crate::middle::resolve_lifetime as rl; use crate::require_c_abi_if_c_variadic; -use crate::util::common::ErrorReported; use rustc_ast::ast; use rustc_ast::util::lev_distance::find_best_match_for_name; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::ErrorReported; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, FatalError}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 7f1631a6204..c726ae41ff0 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -32,9 +32,8 @@ use super::FnCtxt; use crate::hir::def_id::DefId; use crate::type_error_struct; -use crate::util::common::ErrorReported; use rustc_ast::ast; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; use rustc_middle::middle::lang_items; use rustc_middle::ty::adjustment::AllowTwoPhase; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 9e45793fcdc..24db25a1f34 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,4 +1,4 @@ -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorReported}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit; @@ -8,7 +8,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::util::ExplicitSelf; use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt}; -use rustc_middle::util::common::ErrorReported; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index a44a607a703..72220d93d92 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -1,8 +1,7 @@ use crate::check::regionck::RegionCtxt; use crate::hir; use crate::hir::def_id::DefId; -use crate::util::common::ErrorReported; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, ErrorReported}; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::{InferOk, RegionckMode, TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index bfcb6fe35fe..2986a952aa9 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -15,11 +15,11 @@ use crate::check::FnCtxt; use crate::check::Needs; use crate::check::TupleArgumentsFlag::DontTupleArguments; use crate::type_error_struct; -use crate::util::common::ErrorReported; use rustc_ast::ast; use rustc_ast::util::lev_distance::find_best_match_for_name; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::ErrorReported; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 96fc2693ed7..113107a810d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -94,6 +94,7 @@ use rustc_ast::util::parser::ExprPrecedence; use rustc_attr as attr; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::ErrorReported; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -151,7 +152,7 @@ use std::ops::{self, Deref}; use std::slice; use crate::require_c_abi_if_c_variadic; -use crate::util::common::{indenter, ErrorReported}; +use crate::util::common::indenter; use crate::TypeAndSubsts; use self::autoderef::Autoderef; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 1927b9c99e1..7ea6c1c1786 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -89,7 +89,7 @@ mod outlives; mod structured_errors; mod variance; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Node; @@ -100,7 +100,6 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util; -use rustc_middle::util::common::ErrorReported; use rustc_session::config::EntryFnType; use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index f9e9a07914d..7841d5eef58 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -1,12 +1,12 @@ use rustc_ast::ast; use rustc_ast::with_globals; use rustc_data_structures::sync::Lrc; +use rustc_errors::ErrorReported; use rustc_feature::UnstableFeatures; use rustc_hir as hir; use rustc_hir::intravisit; use rustc_interface::interface; use rustc_middle::hir::map::Map; -use rustc_middle::util::common::ErrorReported; use rustc_session::{self, config, DiagnosticOutput, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; From 6daff1400a28fef4616a23a6c04cb5569df2b8d6 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Mar 2020 21:38:14 +0200 Subject: [PATCH 10/12] direct imports for langitem stuff --- src/librustc_codegen_ssa/base.rs | 2 +- src/librustc_codegen_ssa/common.rs | 9 ++++----- src/librustc_codegen_ssa/lib.rs | 2 +- src/librustc_codegen_ssa/mir/block.rs | 2 +- src/librustc_codegen_ssa/mir/rvalue.rs | 2 +- src/librustc_metadata/rmeta/decoder.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 2 +- src/librustc_metadata/rmeta/mod.rs | 2 +- src/librustc_middle/arena.rs | 2 +- src/librustc_middle/middle/lang_items.rs | 6 +----- src/librustc_middle/ty/context.rs | 6 +++--- src/librustc_middle/ty/instance.rs | 2 +- src/librustc_middle/ty/mod.rs | 2 +- src/librustc_middle/ty/query/mod.rs | 2 +- src/librustc_mir/borrow_check/universal_regions.rs | 2 +- .../interpret/intrinsics/caller_location.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- .../transform/check_consts/validation.rs | 2 +- src/librustc_mir/util/elaborate_drops.rs | 2 +- src/librustc_mir_build/build/matches/test.rs | 2 +- src/librustc_mir_build/build/mod.rs | 14 +++++++------- src/librustc_passes/weak_lang_items.rs | 2 +- src/librustc_trait_selection/infer.rs | 2 +- src/librustc_trait_selection/traits/select.rs | 2 +- src/librustc_trait_selection/traits/wf.rs | 2 +- src/librustc_ty/common_traits.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/closure.rs | 3 ++- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 2 +- src/librustc_typeck/collect.rs | 4 ++-- src/librustdoc/clean/auto_trait.rs | 1 + src/librustdoc/clean/mod.rs | 1 - src/librustdoc/clean/types.rs | 2 +- 38 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index c68694ad688..02974151555 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -31,12 +31,12 @@ use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::lang_items::StartFnLangItem; use rustc_index::vec::Idx; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::cstore::{self, LinkagePreference}; use rustc_middle::middle::lang_items; -use rustc_middle::middle::lang_items::StartFnLangItem; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::ty::layout::{self, HasTyCtxt, TyAndLayout}; use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index 8de04b730e1..0d0321ec4ae 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -1,17 +1,16 @@ #![allow(non_camel_case_types, non_snake_case)] use rustc_errors::struct_span_err; +use rustc_hir as hir; +use rustc_hir::def_id::DefId; +use rustc_hir::LangItem; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_session::Session; use rustc_span::Span; use crate::base; -use crate::traits::*; -use rustc_hir::def_id::DefId; -use rustc_middle::middle::lang_items::LangItem; - use crate::traits::BuilderMethods; -use rustc_hir as hir; +use crate::traits::*; pub enum IntPredicate { IntEQ, diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index bf2f92a473f..bf8441562c5 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -21,10 +21,10 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::CrateNum; +use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLibrary}; use rustc_middle::middle::dependency_format::Dependencies; -use rustc_middle::middle::lang_items::LangItem; use rustc_middle::ty::query::Providers; use rustc_session::config::{OutputFilenames, OutputType, RUST_CGU_EXT}; use rustc_span::symbol::Symbol; diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index a09f803d027..219d5aa77ea 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -9,8 +9,8 @@ use crate::meth; use crate::traits::*; use crate::MemFlags; +use rustc_hir::lang_items; use rustc_index::vec::Idx; -use rustc_middle::middle::lang_items; use rustc_middle::mir; use rustc_middle::mir::AssertKind; use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt}; diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 23420c85c95..33f449ed270 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -8,7 +8,7 @@ use crate::traits::*; use crate::MemFlags; use rustc_apfloat::{ieee, Float, Round, Status}; -use rustc_middle::middle::lang_items::ExchangeMallocFnLangItem; +use rustc_hir::lang_items::ExchangeMallocFnLangItem; use rustc_middle::mir; use rustc_middle::ty::cast::{CastTy, IntTy}; use rustc_middle::ty::layout::HasTyCtxt; diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 004c5f2ebb7..1cb5dcb465c 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -18,13 +18,13 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::DefPathTable; use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash}; +use rustc_hir::lang_items; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::dep_graph::{self, DepNode, DepNodeExt, DepNodeIndex}; use rustc_middle::hir::exports::Export; use rustc_middle::middle::cstore::{CrateSource, ExternCrate}; use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLibrary}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; -use rustc_middle::middle::lang_items; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::mir::{self, interpret, BodyAndCache, Promoted}; use rustc_middle::ty::codec::TyDecoder; diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index b71f5c98487..417c5486907 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -15,6 +15,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, use rustc_hir::definitions::DefPathTable; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor}; +use rustc_hir::lang_items; use rustc_hir::{AnonConst, GenericParamKind}; use rustc_index::vec::Idx; use rustc_middle::hir::map::Map; @@ -25,7 +26,6 @@ use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, }; -use rustc_middle::middle::lang_items; use rustc_middle::mir::{self, interpret}; use rustc_middle::traits::specialization_graph; use rustc_middle::ty::codec::{self as ty_codec, TyEncoder}; diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index d0ad76b0fc7..d6260c536aa 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -8,11 +8,11 @@ use rustc_data_structures::sync::MetadataRef; use rustc_hir as hir; use rustc_hir::def::CtorKind; use rustc_hir::def_id::{DefId, DefIndex}; +use rustc_hir::lang_items; use rustc_index::vec::IndexVec; use rustc_middle::hir::exports::Export; use rustc_middle::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLibrary}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; -use rustc_middle::middle::lang_items; use rustc_middle::mir; use rustc_middle::ty::{self, ReprOptions, Ty}; use rustc_serialize::opaque::Encoder; diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index d13ad246db7..e3dec59478c 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -106,7 +106,7 @@ macro_rules! arena_types { String >, [few] get_lib_features: rustc_middle::middle::lib_features::LibFeatures, - [few] defined_lib_features: rustc_middle::middle::lang_items::LanguageItems, + [few] defined_lib_features: rustc_hir::lang_items::LanguageItems, [few] visible_parent_map: rustc_hir::def_id::DefIdMap, [few] foreign_module: rustc_middle::middle::cstore::ForeignModule, [few] foreign_modules: Vec, diff --git a/src/librustc_middle/middle/lang_items.rs b/src/librustc_middle/middle/lang_items.rs index 36560371587..0f98c338c16 100644 --- a/src/librustc_middle/middle/lang_items.rs +++ b/src/librustc_middle/middle/lang_items.rs @@ -7,17 +7,13 @@ //! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`. //! * Functions called by the compiler itself. -pub use self::LangItem::*; - use crate::ty::{self, TyCtxt}; use rustc_hir::def_id::DefId; +use rustc_hir::LangItem; use rustc_span::Span; use rustc_target::spec::PanicStrategy; -pub use rustc_hir::weak_lang_items::link_name; -pub use rustc_hir::{LangItem, LanguageItems}; - impl<'tcx> TyCtxt<'tcx> { /// Returns the `DefId` for a given `LangItem`. /// If not found, fatally aborts compilation. diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index cfc9e00b26e..95d0c758d08 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -11,8 +11,6 @@ use crate::lint::{struct_lint_level, LintSource}; use crate::middle; use crate::middle::cstore::CrateStoreDyn; use crate::middle::cstore::EncodedMetadata; -use crate::middle::lang_items; -use crate::middle::lang_items::PanicLocationLangItem; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::interpret::{Allocation, ConstValue, Scalar}; @@ -53,6 +51,8 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::definitions::{DefPathData, DefPathHash, Definitions}; +use rustc_hir::lang_items; +use rustc_hir::lang_items::PanicLocationLangItem; use rustc_hir::{HirId, Node, TraitCandidate}; use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet}; use rustc_index::vec::{Idx, IndexVec}; @@ -1203,7 +1203,7 @@ impl<'tcx> TyCtxt<'tcx> { } /// Obtain all lang items of this crate and all dependencies (recursively) - pub fn lang_items(self) -> &'tcx middle::lang_items::LanguageItems { + pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems { self.get_lang_items(LOCAL_CRATE) } diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index fcfee0fea85..5d47a6e13f4 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -1,10 +1,10 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use crate::middle::lang_items::DropInPlaceFnLangItem; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::AtomicRef; use rustc_hir::def::Namespace; use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::lang_items::DropInPlaceFnLangItem; use rustc_macros::HashStable; use std::fmt; diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 539a52529fb..3d1893d3bd0 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -11,7 +11,6 @@ use crate::hir::exports::ExportMap; use crate::ich::StableHashingContext; use crate::infer::canonical::Canonical; use crate::middle::cstore::CrateStoreDyn; -use crate::middle::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem}; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; use crate::mir::interpret::ErrorHandled; use crate::mir::GeneratorLayout; @@ -34,6 +33,7 @@ use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem}; use rustc_hir::{Constness, GlobMap, Node, TraitMap}; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; diff --git a/src/librustc_middle/ty/query/mod.rs b/src/librustc_middle/ty/query/mod.rs index 612abe32b6e..9986eb88dc3 100644 --- a/src/librustc_middle/ty/query/mod.rs +++ b/src/librustc_middle/ty/query/mod.rs @@ -7,7 +7,6 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::cstore::{CrateSource, DepKind, NativeLibraryKind}; use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLibrary}; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; -use crate::middle::lang_items::{LangItem, LanguageItems}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; use crate::middle::region; @@ -44,6 +43,7 @@ use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; +use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{Crate, HirIdSet, ItemLocalId, TraitCandidate}; use rustc_index::vec::IndexVec; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index c31f5a57ebc..4d67d7204ca 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -17,10 +17,10 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::lang_items; use rustc_hir::{BodyOwnerKind, HirId}; use rustc_index::vec::{Idx, IndexVec}; use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin}; -use rustc_middle::middle::lang_items; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; diff --git a/src/librustc_mir/interpret/intrinsics/caller_location.rs b/src/librustc_mir/interpret/intrinsics/caller_location.rs index f7e264b01d1..754f45d9ec0 100644 --- a/src/librustc_mir/interpret/intrinsics/caller_location.rs +++ b/src/librustc_mir/interpret/intrinsics/caller_location.rs @@ -1,6 +1,6 @@ use std::convert::TryFrom; -use rustc_middle::middle::lang_items::PanicLocationLangItem; +use rustc_hir::lang_items::PanicLocationLangItem; use rustc_middle::ty::subst::Subst; use rustc_span::{Span, Symbol}; use rustc_target::abi::LayoutOf; diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 1106eba1046..1032ff413af 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -181,9 +181,9 @@ use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; +use rustc_hir::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem}; use rustc_index::bit_set::GrowableBitSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem}; use rustc_middle::mir::interpret::{AllocId, ConstValue}; use rustc_middle::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 649cc0a79d6..e4a0b9cdb48 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -1,10 +1,10 @@ //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. use rustc_errors::struct_span_err; +use rustc_hir::lang_items; use rustc_hir::{def_id::DefId, HirId}; use rustc_index::bit_set::BitSet; use rustc_infer::infer::TyCtxtInferExt; -use rustc_middle::middle::lang_items; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::cast::CastTy; diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index e6dee043a1b..e3a96ca7896 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -1,7 +1,7 @@ use crate::util::patch::MirPatch; use rustc_hir as hir; +use rustc_hir::lang_items; use rustc_index::vec::Idx; -use rustc_middle::middle::lang_items; use rustc_middle::mir::*; use rustc_middle::traits::Reveal; use rustc_middle::ty::subst::SubstsRef; diff --git a/src/librustc_mir_build/build/matches/test.rs b/src/librustc_mir_build/build/matches/test.rs index 3da4bb26779..c049842d061 100644 --- a/src/librustc_mir_build/build/matches/test.rs +++ b/src/librustc_mir_build/build/matches/test.rs @@ -362,7 +362,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { place: Place<'tcx>, mut ty: Ty<'tcx>, ) { - use rustc_middle::middle::lang_items::EqTraitLangItem; + use rustc_hir::lang_items::EqTraitLangItem; let mut expect = self.literal_operand(source_info.span, value); let mut val = Operand::Copy(place); diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index cec7e5bc199..24395702020 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -2,17 +2,17 @@ use crate::build; use crate::build::scope::DropKind; use crate::hair::cx::Cx; use crate::hair::{BindingMode, LintLevel, PatKind}; -use rustc_middle::middle::lang_items; +use rustc_attr::{self as attr, UnwindAttr}; +use rustc_hir as hir; +use rustc_hir::def_id::DefId; +use rustc_hir::lang_items; +use rustc_hir::{GeneratorKind, HirIdMap, Node}; +use rustc_index::vec::{Idx, IndexVec}; +use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::middle::region; use rustc_middle::mir::*; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; -use rustc_attr::{self as attr, UnwindAttr}; -use rustc_hir as hir; -use rustc_hir::def_id::DefId; -use rustc_hir::{GeneratorKind, HirIdMap, Node}; -use rustc_index::vec::{Idx, IndexVec}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_span::symbol::kw; use rustc_span::Span; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_passes/weak_lang_items.rs b/src/librustc_passes/weak_lang_items.rs index 8d11af15b56..8e56ef0da52 100644 --- a/src/librustc_passes/weak_lang_items.rs +++ b/src/librustc_passes/weak_lang_items.rs @@ -4,8 +4,8 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::lang_items; use rustc_hir::weak_lang_items::WEAK_ITEMS_REFS; -use rustc_middle::middle::lang_items; use rustc_middle::middle::lang_items::whitelisted; use rustc_middle::ty::TyCtxt; use rustc_session::config; diff --git a/src/librustc_trait_selection/infer.rs b/src/librustc_trait_selection/infer.rs index d7a2e720a6d..24eb22fbd00 100644 --- a/src/librustc_trait_selection/infer.rs +++ b/src/librustc_trait_selection/infer.rs @@ -2,11 +2,11 @@ use crate::traits::query::outlives_bounds::InferCtxtExt as _; use crate::traits::{self, TraitEngine, TraitEngineExt}; use rustc_hir as hir; +use rustc_hir::lang_items; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::traits::ObligationCause; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse}; -use rustc_middle::middle::lang_items; use rustc_middle::traits::query::Fallible; use rustc_middle::ty::{self, Ty, TypeFoldable}; use rustc_span::{Span, DUMMY_SP}; diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 1e5a1edd4d8..3d95824cdf0 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -39,9 +39,9 @@ use rustc_ast::attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::lang_items; use rustc_index::bit_set::GrowableBitSet; use rustc_middle::dep_graph::{DepKind, DepNodeIndex}; -use rustc_middle::middle::lang_items; use rustc_middle::ty::fast_reject; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::subst::{Subst, SubstsRef}; diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 59b56d673fb..1eb41e0b4d1 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -3,7 +3,7 @@ use crate::opaque_types::required_region_bounds; use crate::traits::{self, AssocTypeBoundData}; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_middle::middle::lang_items; +use rustc_hir::lang_items; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness}; use rustc_span::symbol::{kw, Ident}; diff --git a/src/librustc_ty/common_traits.rs b/src/librustc_ty/common_traits.rs index 597bc854604..265b811571a 100644 --- a/src/librustc_ty/common_traits.rs +++ b/src/librustc_ty/common_traits.rs @@ -1,7 +1,7 @@ //! Queries for checking whether a type implements one of a few common traits. +use rustc_hir::lang_items; use rustc_infer::infer::TyCtxtInferExt; -use rustc_middle::middle::lang_items; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9e2a6fb1d83..c3ebcbfc832 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -6,7 +6,6 @@ // ignore-tidy-filelength use crate::collect::PlaceholderHirTyCollector; -use crate::middle::lang_items::SizedTraitLangItem; use crate::middle::resolve_lifetime as rl; use crate::require_c_abi_if_c_variadic; use rustc_ast::ast; @@ -18,6 +17,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_generics, Visitor as _}; +use rustc_hir::lang_items::SizedTraitLangItem; use rustc_hir::{Constness, GenericArg, GenericArgs}; use rustc_middle::ty::subst::{self, InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{ diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index c726ae41ff0..5de0184f2bb 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -35,7 +35,7 @@ use crate::type_error_struct; use rustc_ast::ast; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; -use rustc_middle::middle::lang_items; +use rustc_hir::lang_items; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::cast::{CastKind, CastTy}; use rustc_middle::ty::error::TypeError; diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 415b5103104..922d9ca6485 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -3,9 +3,10 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes}; use crate::astconv::AstConv; -use crate::middle::{lang_items, region}; +use crate::middle::region; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::lang_items; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::{InferOk, InferResult}; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 2986a952aa9..9c57ffaf055 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -24,10 +24,10 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::lang_items; use rustc_hir::{ExprKind, QPath}; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_middle::middle::lang_items; use rustc_middle::ty; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index c8632086771..add706b5fcc 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -2,7 +2,6 @@ //! found or is otherwise invalid. use crate::check::FnCtxt; -use crate::middle::lang_items::FnOnceTraitLangItem; use rustc_ast::ast; use rustc_ast::util::lev_distance; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -11,6 +10,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::intravisit; +use rustc_hir::lang_items::FnOnceTraitLangItem; use rustc_hir::{ExprKind, Node, QPath}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_middle::hir::map as hir_map; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 113107a810d..293c4feac62 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -88,7 +88,6 @@ mod wfcheck; pub mod writeback; use crate::astconv::{AstConv, GenericArgCountMismatch, PathSeg}; -use crate::middle::lang_items; use rustc_ast::ast; use rustc_ast::util::parser::ExprPrecedence; use rustc_attr as attr; @@ -101,6 +100,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; +use rustc_hir::lang_items; use rustc_hir::{ExprKind, GenericArg, HirIdMap, Item, ItemKind, Node, PatKind, QPath}; use rustc_index::vec::Idx; use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 64191132191..30a53cbc397 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -7,8 +7,8 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ParItemLikeVisitor; +use rustc_hir::lang_items; use rustc_hir::ItemKind; -use rustc_middle::middle::lang_items; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 32963b6a1f0..384a22d010e 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -4,11 +4,11 @@ use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::lang_items::UnsizeTraitLangItem; use rustc_hir::ItemKind; use rustc_infer::infer; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::{RegionckMode, TyCtxtInferExt}; -use rustc_middle::middle::lang_items::UnsizeTraitLangItem; use rustc_middle::middle::region; use rustc_middle::ty::adjustment::CoerceUnsizedInfo; use rustc_middle::ty::TypeFoldable; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 30887f84032..13c6670f6b2 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -17,7 +17,6 @@ use crate::astconv::{AstConv, Bounds, SizedByDefault}; use crate::check::intrinsic::intrinsic_operation_unsafety; use crate::constrained_generic_params as cgp; -use crate::middle::lang_items; use crate::middle::resolve_lifetime as rl; use rustc_ast::ast; use rustc_ast::ast::{Ident, MetaItemKind}; @@ -29,6 +28,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::weak_lang_items; use rustc_hir::{GenericParamKind, Node, Unsafety}; use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::hir::map::Map; @@ -2569,7 +2569,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if tcx.is_weak_lang_item(id) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL; } - if let Some(name) = lang_items::link_name(&attrs) { + if let Some(name) = weak_lang_items::link_name(&attrs) { codegen_fn_attrs.export_name = Some(name); codegen_fn_attrs.link_name = Some(name); } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 9f327b0b743..73df844a91b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -1,5 +1,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; +use rustc_hir::lang_items; use rustc_middle::ty::{self, Region, RegionVid, TypeFoldable}; use rustc_trait_selection::traits::auto_trait::{self, AutoTraitResult}; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f8e44bc5a1a..e027db8b56c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -17,7 +17,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; use rustc_index::vec::{Idx, IndexVec}; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; -use rustc_middle::middle::lang_items; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::middle::stability; use rustc_middle::ty::fold::TypeFolder; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index e844abfc62c..2e5ecacee12 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -15,9 +15,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::lang_items; use rustc_hir::Mutability; use rustc_index::vec::IndexVec; -use rustc_middle::middle::lang_items; use rustc_middle::middle::stability; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::DUMMY_SP; From 4dfec59edad7d3d82797f9e4830e214d870ca3d3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Mar 2020 21:51:04 +0200 Subject: [PATCH 11/12] nix CachingSourceMapView reexport --- src/librustc_middle/ich/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc_middle/ich/mod.rs b/src/librustc_middle/ich/mod.rs index 516e3ed979c..c8fb2bf39cc 100644 --- a/src/librustc_middle/ich/mod.rs +++ b/src/librustc_middle/ich/mod.rs @@ -4,7 +4,6 @@ pub use self::hcx::{ hash_stable_trait_impls, NodeIdHashingMode, StableHashingContext, StableHashingContextProvider, }; use rustc_span::symbol::{sym, Symbol}; -pub use rustc_span::CachingSourceMapView; mod hcx; From 0826009638b46a0066a183e24f431d8730823ed5 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Mar 2020 23:02:59 +0200 Subject: [PATCH 12/12] fix fulldeps test fallout --- .../run-make-fulldeps/hotplug_codegen_backend/the_backend.rs | 3 ++- src/test/ui-fulldeps/undef_mask.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs index 76341240718..2875ee57930 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs @@ -1,6 +1,7 @@ #![feature(rustc_private)] extern crate rustc_codegen_ssa; +extern crate rustc_errors; extern crate rustc_middle; #[macro_use] extern crate rustc_data_structures; @@ -14,11 +15,11 @@ extern crate rustc_target; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::sync::MetadataRef; +use rustc_errors::ErrorReported; use rustc_middle::dep_graph::DepGraph; use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; -use rustc_middle::util::common::ErrorReported; use rustc_session::config::OutputFilenames; use rustc_session::Session; use rustc_span::symbol::Symbol; diff --git a/src/test/ui-fulldeps/undef_mask.rs b/src/test/ui-fulldeps/undef_mask.rs index cbf1b63d22b..656d0b451bc 100644 --- a/src/test/ui-fulldeps/undef_mask.rs +++ b/src/test/ui-fulldeps/undef_mask.rs @@ -5,9 +5,10 @@ #![feature(rustc_private)] extern crate rustc_middle; +extern crate rustc_target; use rustc_middle::mir::interpret::UndefMask; -use rustc_middle::ty::layout::Size; +use rustc_target::abi::Size; fn main() { let mut mask = UndefMask::new(Size::from_bytes(500), false);