From 18694126b18c9f6472fb147b6647826d0c6deee2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Nov 2021 14:11:45 +0000 Subject: [PATCH] Perform Sync check on static items in wf-check instead of during const checks --- .../src/transform/check_consts/check.rs | 29 ++-------------- compiler/rustc_typeck/src/check/wfcheck.rs | 14 ++++++++ .../ui/consts/const-cast-different-types.rs | 6 ++-- .../consts/const-cast-different-types.stderr | 12 +++---- src/test/ui/consts/const-cast-wrong-type.rs | 4 +-- .../ui/consts/const-cast-wrong-type.stderr | 6 ++-- src/test/ui/impl-trait/issues/issue-86201.rs | 4 +-- src/test/ui/issues/issue-16538.mir.stderr | 29 ++++++++-------- src/test/ui/issues/issue-16538.rs | 5 +-- src/test/ui/issues/issue-16538.thir.stderr | 31 ++++++++--------- .../ui/issues/issue-17718-static-sync.stderr | 4 +-- src/test/ui/issues/issue-24446.rs | 1 + src/test/ui/issues/issue-24446.stderr | 11 +++++- src/test/ui/issues/issue-5216.rs | 4 +-- src/test/ui/issues/issue-5216.stderr | 4 +-- src/test/ui/issues/issue-7364.rs | 3 +- src/test/ui/issues/issue-7364.stderr | 15 +++----- src/test/ui/rfc1623.nll.stderr | 34 ++++--------------- src/test/ui/rfc1623.rs | 4 +++ src/test/ui/rfc1623.stderr | 2 +- .../static-const-types.rs | 9 ++--- .../static-const-types.stderr | 6 ++-- 22 files changed, 103 insertions(+), 134 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 4e3a8b64094af..274665ccd9836 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -1,8 +1,8 @@ //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. use rustc_errors::{Applicability, Diagnostic, ErrorReported}; +use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::{self as hir, HirId, LangItem}; use rustc_index::bit_set::BitSet; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; @@ -14,8 +14,7 @@ use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, use rustc_middle::ty::{Binder, TraitPredicate, TraitRef}; use rustc_mir_dataflow::{self, Analysis}; use rustc_span::{sym, Span, Symbol}; -use rustc_trait_selection::traits::error_reporting::InferCtxtExt; -use rustc_trait_selection::traits::{self, SelectionContext, TraitEngine}; +use rustc_trait_selection::traits::SelectionContext; use std::mem; use std::ops::Deref; @@ -255,16 +254,6 @@ impl Checker<'mir, 'tcx> { self.visit_body(&body); } - // Ensure that the end result is `Sync` in a non-thread local `static`. - let should_check_for_sync = self.const_kind() - == hir::ConstContext::Static(hir::Mutability::Not) - && !tcx.is_thread_local_static(def_id.to_def_id()); - - if should_check_for_sync { - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - check_return_ty_is_sync(tcx, &body, hir_id); - } - // If we got through const-checking without emitting any "primary" errors, emit any // "secondary" errors if they occurred. let secondary_errors = mem::take(&mut self.secondary_errors); @@ -1054,20 +1043,6 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { } } -fn check_return_ty_is_sync(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, hir_id: HirId) { - let ty = body.return_ty(); - tcx.infer_ctxt().enter(|infcx| { - let cause = traits::ObligationCause::new(body.span, hir_id, traits::SharedStatic); - let mut fulfillment_cx = traits::FulfillmentContext::new(); - let sync_def_id = tcx.require_lang_item(LangItem::Sync, Some(body.span)); - fulfillment_cx.register_bound(&infcx, ty::ParamEnv::empty(), ty, sync_def_id, cause); - let errors = fulfillment_cx.select_all_or_error(&infcx); - if !errors.is_empty() { - infcx.report_fulfillment_errors(&errors, None, false); - } - }); -} - fn place_as_reborrow( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 0050ac99cb19a..78088b9bd0c38 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1060,6 +1060,20 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo ); } + // Ensure that the end result is `Sync` in a non-thread local `static`. + let should_check_for_sync = tcx.static_mutability(item_id.to_def_id()) + == Some(hir::Mutability::Not) + && !tcx.is_foreign_item(item_id.to_def_id()) + && !tcx.is_thread_local_static(item_id.to_def_id()); + + if should_check_for_sync { + fcx.register_bound( + item_ty, + tcx.require_lang_item(LangItem::Sync, Some(ty_span)), + traits::ObligationCause::new(ty_span, fcx.body_id, traits::SharedStatic), + ); + } + // No implied bounds in a const, etc. FxHashSet::default() }); diff --git a/src/test/ui/consts/const-cast-different-types.rs b/src/test/ui/consts/const-cast-different-types.rs index 3bd5ed8f8c924..5e6d7d899ec1e 100644 --- a/src/test/ui/consts/const-cast-different-types.rs +++ b/src/test/ui/consts/const-cast-different-types.rs @@ -1,6 +1,6 @@ -static a: &'static str = "foo"; -static b: *const u8 = a as *const u8; //~ ERROR casting -static c: *const u8 = &a as *const u8; //~ ERROR casting +const a: &str = "foo"; +const b: *const u8 = a as *const u8; //~ ERROR casting +const c: *const u8 = &a as *const u8; //~ ERROR casting fn main() { } diff --git a/src/test/ui/consts/const-cast-different-types.stderr b/src/test/ui/consts/const-cast-different-types.stderr index 9960ccb4166b5..9e622de2eb004 100644 --- a/src/test/ui/consts/const-cast-different-types.stderr +++ b/src/test/ui/consts/const-cast-different-types.stderr @@ -1,14 +1,14 @@ error[E0606]: casting `&'static str` as `*const u8` is invalid - --> $DIR/const-cast-different-types.rs:2:23 + --> $DIR/const-cast-different-types.rs:2:22 | -LL | static b: *const u8 = a as *const u8; - | ^^^^^^^^^^^^^^ +LL | const b: *const u8 = a as *const u8; + | ^^^^^^^^^^^^^^ error[E0606]: casting `&&'static str` as `*const u8` is invalid - --> $DIR/const-cast-different-types.rs:3:23 + --> $DIR/const-cast-different-types.rs:3:22 | -LL | static c: *const u8 = &a as *const u8; - | ^^^^^^^^^^^^^^^ +LL | const c: *const u8 = &a as *const u8; + | ^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-cast-wrong-type.rs b/src/test/ui/consts/const-cast-wrong-type.rs index c250cc53dbc2b..6e055a2bcd340 100644 --- a/src/test/ui/consts/const-cast-wrong-type.rs +++ b/src/test/ui/consts/const-cast-wrong-type.rs @@ -1,5 +1,5 @@ -static a: [u8; 3] = ['h' as u8, 'i' as u8, 0 as u8]; -static b: *const i8 = &a as *const i8; //~ ERROR mismatched types +const a: [u8; 3] = ['h' as u8, 'i' as u8, 0 as u8]; +const b: *const i8 = &a as *const i8; //~ ERROR mismatched types fn main() { } diff --git a/src/test/ui/consts/const-cast-wrong-type.stderr b/src/test/ui/consts/const-cast-wrong-type.stderr index 282f5ccde772f..ee186636e4ebe 100644 --- a/src/test/ui/consts/const-cast-wrong-type.stderr +++ b/src/test/ui/consts/const-cast-wrong-type.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/const-cast-wrong-type.rs:2:23 + --> $DIR/const-cast-wrong-type.rs:2:22 | -LL | static b: *const i8 = &a as *const i8; - | ^^^^^^^^^^^^^^^ expected `u8`, found `i8` +LL | const b: *const i8 = &a as *const i8; + | ^^^^^^^^^^^^^^^ expected `u8`, found `i8` error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-86201.rs b/src/test/ui/impl-trait/issues/issue-86201.rs index 8cc4fef890abf..e3386d29def02 100644 --- a/src/test/ui/impl-trait/issues/issue-86201.rs +++ b/src/test/ui/impl-trait/issues/issue-86201.rs @@ -2,9 +2,9 @@ #![feature(type_alias_impl_trait)] type FunType = impl Fn<()>; -//~^ could not find defining uses +//~^ ERROR could not find defining uses static STATIC_FN: FunType = some_fn; -//~^ mismatched types +//~^ ERROR mismatched types fn some_fn() {} diff --git a/src/test/ui/issues/issue-16538.mir.stderr b/src/test/ui/issues/issue-16538.mir.stderr index d7e8c08bb01b2..5a276f27886d2 100644 --- a/src/test/ui/issues/issue-16538.mir.stderr +++ b/src/test/ui/issues/issue-16538.mir.stderr @@ -1,27 +1,26 @@ error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-16538.rs:14:27 + --> $DIR/issue-16538.rs:15:23 | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0277]: `*const usize` cannot be shared between threads safely - --> $DIR/issue-16538.rs:14:1 +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:15:30 | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^ use of extern static | - = help: the trait `Sync` is not implemented for `*const usize` - = note: shared static variables must have a type that implements `Sync` + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-16538.rs:14:34 +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:15:21 | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^ use of extern static +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior error: aborting due to 3 previous errors -Some errors have detailed explanations: E0015, E0133, E0277. +Some errors have detailed explanations: E0015, E0133. For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-16538.rs b/src/test/ui/issues/issue-16538.rs index 1e8ecf015c85a..b6891deb937da 100644 --- a/src/test/ui/issues/issue-16538.rs +++ b/src/test/ui/issues/issue-16538.rs @@ -1,6 +1,7 @@ // revisions: mir thir // [thir]compile-flags: -Z thir-unsafeck +#![feature(const_raw_ptr_deref)] mod Y { pub type X = usize; extern "C" { @@ -11,8 +12,8 @@ mod Y { } } -static foo: *const Y::X = Y::foo(Y::x as *const Y::X); -//~^ ERROR `*const usize` cannot be shared between threads safely [E0277] +static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); +//~^ ERROR dereference of raw pointer //~| ERROR E0015 //~| ERROR use of extern static is unsafe and requires diff --git a/src/test/ui/issues/issue-16538.thir.stderr b/src/test/ui/issues/issue-16538.thir.stderr index 435334c322808..8365a1dbf6e5e 100644 --- a/src/test/ui/issues/issue-16538.thir.stderr +++ b/src/test/ui/issues/issue-16538.thir.stderr @@ -1,27 +1,26 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:15:22 + | +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-16538.rs:14:34 + --> $DIR/issue-16538.rs:15:30 | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^ use of extern static +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^ use of extern static | = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-16538.rs:14:27 - | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: `*const usize` cannot be shared between threads safely - --> $DIR/issue-16538.rs:14:1 - | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely + --> $DIR/issue-16538.rs:15:23 | - = help: the trait `Sync` is not implemented for `*const usize` - = note: shared static variables must have a type that implements `Sync` +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors -Some errors have detailed explanations: E0015, E0133, E0277. +Some errors have detailed explanations: E0015, E0133. For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-17718-static-sync.stderr b/src/test/ui/issues/issue-17718-static-sync.stderr index 4cd85124c3507..bc6e45e59258f 100644 --- a/src/test/ui/issues/issue-17718-static-sync.stderr +++ b/src/test/ui/issues/issue-17718-static-sync.stderr @@ -1,8 +1,8 @@ error[E0277]: `Foo` cannot be shared between threads safely - --> $DIR/issue-17718-static-sync.rs:9:1 + --> $DIR/issue-17718-static-sync.rs:9:13 | LL | static BAR: Foo = Foo; - | ^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be shared between threads safely + | ^^^ `Foo` cannot be shared between threads safely | = help: the trait `Sync` is not implemented for `Foo` = note: shared static variables must have a type that implements `Sync` diff --git a/src/test/ui/issues/issue-24446.rs b/src/test/ui/issues/issue-24446.rs index ffd6dfabc2890..9ab952ade9cf4 100644 --- a/src/test/ui/issues/issue-24446.rs +++ b/src/test/ui/issues/issue-24446.rs @@ -1,6 +1,7 @@ fn main() { static foo: dyn Fn() -> u32 = || -> u32 { //~^ ERROR the size for values of type + //~| ERROR cannot be shared between threads safely 0 }; } diff --git a/src/test/ui/issues/issue-24446.stderr b/src/test/ui/issues/issue-24446.stderr index 1674fa8af2845..4afb87c482549 100644 --- a/src/test/ui/issues/issue-24446.stderr +++ b/src/test/ui/issues/issue-24446.stderr @@ -6,6 +6,15 @@ LL | static foo: dyn Fn() -> u32 = || -> u32 { | = help: the trait `Sized` is not implemented for `(dyn Fn() -> u32 + 'static)` -error: aborting due to previous error +error[E0277]: `(dyn Fn() -> u32 + 'static)` cannot be shared between threads safely + --> $DIR/issue-24446.rs:2:17 + | +LL | static foo: dyn Fn() -> u32 = || -> u32 { + | ^^^^^^^^^^^^^^^ `(dyn Fn() -> u32 + 'static)` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `(dyn Fn() -> u32 + 'static)` + = note: shared static variables must have a type that implements `Sync` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-5216.rs b/src/test/ui/issues/issue-5216.rs index 35b343edfbdbe..4072a57cb1052 100644 --- a/src/test/ui/issues/issue-5216.rs +++ b/src/test/ui/issues/issue-5216.rs @@ -1,10 +1,10 @@ fn f() { } -struct S(Box); +struct S(Box); pub static C: S = S(f); //~ ERROR mismatched types fn g() { } -type T = Box; +type T = Box; pub static D: T = g; //~ ERROR mismatched types fn main() {} diff --git a/src/test/ui/issues/issue-5216.stderr b/src/test/ui/issues/issue-5216.stderr index 7a1f42adf65d4..29c95e4fb62b8 100644 --- a/src/test/ui/issues/issue-5216.stderr +++ b/src/test/ui/issues/issue-5216.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | pub static C: S = S(f); | ^ expected struct `Box`, found fn item | - = note: expected struct `Box<(dyn FnMut() + 'static)>` + = note: expected struct `Box<(dyn FnMut() + Sync + 'static)>` found fn item `fn() {f}` error[E0308]: mismatched types @@ -13,7 +13,7 @@ error[E0308]: mismatched types LL | pub static D: T = g; | ^ expected struct `Box`, found fn item | - = note: expected struct `Box<(dyn FnMut() + 'static)>` + = note: expected struct `Box<(dyn FnMut() + Sync + 'static)>` found fn item `fn() {g}` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-7364.rs b/src/test/ui/issues/issue-7364.rs index 29a1644673d4e..83c52d286a199 100644 --- a/src/test/ui/issues/issue-7364.rs +++ b/src/test/ui/issues/issue-7364.rs @@ -4,7 +4,6 @@ use std::cell::RefCell; // Regression test for issue 7364 static boxed: Box> = box RefCell::new(0); -//~^ ERROR allocations are not allowed in statics -//~| ERROR `RefCell` cannot be shared between threads safely [E0277] +//~^ ERROR `RefCell` cannot be shared between threads safely [E0277] fn main() { } diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr index 8ceb3be7ec913..f2e80f451695a 100644 --- a/src/test/ui/issues/issue-7364.stderr +++ b/src/test/ui/issues/issue-7364.stderr @@ -1,21 +1,14 @@ -error[E0010]: allocations are not allowed in statics - --> $DIR/issue-7364.rs:6:37 - | -LL | static boxed: Box> = box RefCell::new(0); - | ^^^^^^^^^^^^^^^^^^^ allocation not allowed in statics - error[E0277]: `RefCell` cannot be shared between threads safely - --> $DIR/issue-7364.rs:6:1 + --> $DIR/issue-7364.rs:6:15 | LL | static boxed: Box> = box RefCell::new(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `RefCell` cannot be shared between threads safely + | ^^^^^^^^^^^^^^^^^^^ `RefCell` cannot be shared between threads safely | = help: the trait `Sync` is not implemented for `RefCell` = note: required because of the requirements on the impl of `Sync` for `Unique>` = note: required because it appears within the type `Box>` = note: shared static variables must have a type that implements `Sync` -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0010, E0277. -For more information about an error, try `rustc --explain E0010`. +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc1623.nll.stderr b/src/test/ui/rfc1623.nll.stderr index 7f15c1c1f5770..86513b6064d2d 100644 --- a/src/test/ui/rfc1623.nll.stderr +++ b/src/test/ui/rfc1623.nll.stderr @@ -1,26 +1,5 @@ -error[E0277]: `dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>` cannot be shared between threads safely - --> $DIR/rfc1623.rs:21:1 - | -LL | / static SOME_STRUCT: &SomeStruct = &SomeStruct { -LL | | foo: &Foo { bools: &[false, true] }, -LL | | bar: &Bar { bools: &[true, true] }, -LL | | f: &id, -LL | | -LL | | }; - | |__^ `dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>` cannot be shared between threads safely - | - = help: within `&SomeStruct`, the trait `Sync` is not implemented for `dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>` - = note: required because it appears within the type `&dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>` -note: required because it appears within the type `SomeStruct` - --> $DIR/rfc1623.rs:11:8 - | -LL | struct SomeStruct<'x, 'y, 'z: 'x> { - | ^^^^^^^^^^ - = note: required because it appears within the type `&SomeStruct` - = note: shared static variables must have a type that implements `Sync` - error[E0308]: mismatched types - --> $DIR/rfc1623.rs:21:35 + --> $DIR/rfc1623.rs:25:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ @@ -35,7 +14,7 @@ LL | | }; found type `Fn<(&Foo<'_>,)>` error[E0308]: mismatched types - --> $DIR/rfc1623.rs:21:35 + --> $DIR/rfc1623.rs:25:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ @@ -50,7 +29,7 @@ LL | | }; found type `Fn<(&Foo<'_>,)>` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:21:35 + --> $DIR/rfc1623.rs:25:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ @@ -65,7 +44,7 @@ LL | | }; = note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:21:35 + --> $DIR/rfc1623.rs:25:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ @@ -79,7 +58,6 @@ LL | | }; = note: `fn(&Foo<'2>) -> &Foo<'2> {id::<&Foo<'2>>}` must implement `FnOnce<(&'a Foo<'1>,)>`, for any lifetime `'1`... = note: ...but it actually implements `FnOnce<(&Foo<'2>,)>`, for some specific lifetime `'2` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/rfc1623.rs b/src/test/ui/rfc1623.rs index 9ff4813d11286..32e00f9cb76c3 100644 --- a/src/test/ui/rfc1623.rs +++ b/src/test/ui/rfc1623.rs @@ -14,6 +14,10 @@ struct SomeStruct<'x, 'y, 'z: 'x> { f: &'y dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>, } +// Without this, the wf-check will fail early so we'll never see the +// error in SOME_STRUCT's body. +unsafe impl<'x, 'y, 'z: 'x> Sync for SomeStruct<'x, 'y, 'z> {} + fn id(t: T) -> T { t } diff --git a/src/test/ui/rfc1623.stderr b/src/test/ui/rfc1623.stderr index e95e68c8e6d26..16829b5caa0b6 100644 --- a/src/test/ui/rfc1623.stderr +++ b/src/test/ui/rfc1623.stderr @@ -1,5 +1,5 @@ error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:24:8 + --> $DIR/rfc1623.rs:28:8 | LL | f: &id, | ^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.rs b/src/test/ui/type-alias-impl-trait/static-const-types.rs index f630d27833503..86b685022b20e 100644 --- a/src/test/ui/type-alias-impl-trait/static-const-types.rs +++ b/src/test/ui/type-alias-impl-trait/static-const-types.rs @@ -5,12 +5,9 @@ use std::fmt::Debug; -type Foo = impl Debug; -//~^ ERROR: could not find defining uses +type Foo = impl Debug; //~ ERROR could not find defining uses -static FOO1: Foo = 22_u32; -//~^ ERROR: mismatched types [E0308] -const FOO2: Foo = 22_u32; -//~^ ERROR: mismatched types [E0308] +static FOO1: Foo = 22_u32; //~ ERROR mismatched types +const FOO2: Foo = 22_u32; //~ ERROR mismatched types fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.stderr b/src/test/ui/type-alias-impl-trait/static-const-types.stderr index 72083d014fe3a..6f4c2944f7285 100644 --- a/src/test/ui/type-alias-impl-trait/static-const-types.stderr +++ b/src/test/ui/type-alias-impl-trait/static-const-types.stderr @@ -1,9 +1,9 @@ error[E0308]: mismatched types - --> $DIR/static-const-types.rs:11:20 + --> $DIR/static-const-types.rs:10:20 | LL | type Foo = impl Debug; | ---------- the expected opaque type -... +LL | LL | static FOO1: Foo = 22_u32; | ^^^^^^ expected opaque type, found `u32` | @@ -11,7 +11,7 @@ LL | static FOO1: Foo = 22_u32; found type `u32` error[E0308]: mismatched types - --> $DIR/static-const-types.rs:13:19 + --> $DIR/static-const-types.rs:11:19 | LL | type Foo = impl Debug; | ---------- the expected opaque type