From 21aa149b0bc7f6321bf03f5f5df75b4d16bdb406 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 24 May 2019 14:59:19 +0200 Subject: Move existing `#[linkage]` tests to a subdirectory where I can add more tests. --- src/test/ui/linkage-attr/linkage2.rs | 15 +++++++++++++++ src/test/ui/linkage-attr/linkage2.stderr | 8 ++++++++ src/test/ui/linkage-attr/linkage3.rs | 14 ++++++++++++++ src/test/ui/linkage-attr/linkage3.stderr | 8 ++++++++ src/test/ui/linkage-attr/linkage4.rs | 5 +++++ src/test/ui/linkage-attr/linkage4.stderr | 12 ++++++++++++ src/test/ui/linkage2.rs | 15 --------------- src/test/ui/linkage2.stderr | 8 -------- src/test/ui/linkage3.rs | 14 -------------- src/test/ui/linkage3.stderr | 8 -------- src/test/ui/linkage4.rs | 5 ----- src/test/ui/linkage4.stderr | 12 ------------ 12 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 src/test/ui/linkage-attr/linkage2.rs create mode 100644 src/test/ui/linkage-attr/linkage2.stderr create mode 100644 src/test/ui/linkage-attr/linkage3.rs create mode 100644 src/test/ui/linkage-attr/linkage3.stderr create mode 100644 src/test/ui/linkage-attr/linkage4.rs create mode 100644 src/test/ui/linkage-attr/linkage4.stderr delete mode 100644 src/test/ui/linkage2.rs delete mode 100644 src/test/ui/linkage2.stderr delete mode 100644 src/test/ui/linkage3.rs delete mode 100644 src/test/ui/linkage3.stderr delete mode 100644 src/test/ui/linkage4.rs delete mode 100644 src/test/ui/linkage4.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/linkage-attr/linkage2.rs b/src/test/ui/linkage-attr/linkage2.rs new file mode 100644 index 00000000000..f9ea5319d54 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage2.rs @@ -0,0 +1,15 @@ +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +// ignore-sgx no weak linkages permitted + +#![feature(linkage)] + +extern { + #[linkage = "extern_weak"] static foo: i32; + //~^ ERROR: must have type `*const T` or `*mut T` +} + +fn main() { + println!("{}", unsafe { foo }); +} diff --git a/src/test/ui/linkage-attr/linkage2.stderr b/src/test/ui/linkage-attr/linkage2.stderr new file mode 100644 index 00000000000..8326c0baccc --- /dev/null +++ b/src/test/ui/linkage-attr/linkage2.stderr @@ -0,0 +1,8 @@ +error: must have type `*const T` or `*mut T` + --> $DIR/linkage2.rs:9:32 + | +LL | #[linkage = "extern_weak"] static foo: i32; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/linkage-attr/linkage3.rs b/src/test/ui/linkage-attr/linkage3.rs new file mode 100644 index 00000000000..1462079acf7 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage3.rs @@ -0,0 +1,14 @@ +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" + +#![feature(linkage)] + +extern { + #[linkage = "foo"] static foo: *const i32; + //~^ ERROR: invalid linkage specified +} + +fn main() { + println!("{:?}", unsafe { foo }); +} diff --git a/src/test/ui/linkage-attr/linkage3.stderr b/src/test/ui/linkage-attr/linkage3.stderr new file mode 100644 index 00000000000..b74fdc91429 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage3.stderr @@ -0,0 +1,8 @@ +error: invalid linkage specified + --> $DIR/linkage3.rs:8:24 + | +LL | #[linkage = "foo"] static foo: *const i32; + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/linkage-attr/linkage4.rs b/src/test/ui/linkage-attr/linkage4.rs new file mode 100644 index 00000000000..3b935f9723d --- /dev/null +++ b/src/test/ui/linkage-attr/linkage4.rs @@ -0,0 +1,5 @@ +#[linkage = "external"] +static foo: isize = 0; +//~^^ ERROR: the `linkage` attribute is experimental and not portable + +fn main() {} diff --git a/src/test/ui/linkage-attr/linkage4.stderr b/src/test/ui/linkage-attr/linkage4.stderr new file mode 100644 index 00000000000..f2aab164bd7 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage4.stderr @@ -0,0 +1,12 @@ +error[E0658]: the `linkage` attribute is experimental and not portable across platforms + --> $DIR/linkage4.rs:1:1 + | +LL | #[linkage = "external"] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29603 + = help: add #![feature(linkage)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/linkage2.rs b/src/test/ui/linkage2.rs deleted file mode 100644 index f9ea5319d54..00000000000 --- a/src/test/ui/linkage2.rs +++ /dev/null @@ -1,15 +0,0 @@ -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -// ignore-sgx no weak linkages permitted - -#![feature(linkage)] - -extern { - #[linkage = "extern_weak"] static foo: i32; - //~^ ERROR: must have type `*const T` or `*mut T` -} - -fn main() { - println!("{}", unsafe { foo }); -} diff --git a/src/test/ui/linkage2.stderr b/src/test/ui/linkage2.stderr deleted file mode 100644 index 8326c0baccc..00000000000 --- a/src/test/ui/linkage2.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: must have type `*const T` or `*mut T` - --> $DIR/linkage2.rs:9:32 - | -LL | #[linkage = "extern_weak"] static foo: i32; - | ^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/linkage3.rs b/src/test/ui/linkage3.rs deleted file mode 100644 index 1462079acf7..00000000000 --- a/src/test/ui/linkage3.rs +++ /dev/null @@ -1,14 +0,0 @@ -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" - -#![feature(linkage)] - -extern { - #[linkage = "foo"] static foo: *const i32; - //~^ ERROR: invalid linkage specified -} - -fn main() { - println!("{:?}", unsafe { foo }); -} diff --git a/src/test/ui/linkage3.stderr b/src/test/ui/linkage3.stderr deleted file mode 100644 index b74fdc91429..00000000000 --- a/src/test/ui/linkage3.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: invalid linkage specified - --> $DIR/linkage3.rs:8:24 - | -LL | #[linkage = "foo"] static foo: *const i32; - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/linkage4.rs b/src/test/ui/linkage4.rs deleted file mode 100644 index 3b935f9723d..00000000000 --- a/src/test/ui/linkage4.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[linkage = "external"] -static foo: isize = 0; -//~^^ ERROR: the `linkage` attribute is experimental and not portable - -fn main() {} diff --git a/src/test/ui/linkage4.stderr b/src/test/ui/linkage4.stderr deleted file mode 100644 index f2aab164bd7..00000000000 --- a/src/test/ui/linkage4.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: the `linkage` attribute is experimental and not portable across platforms - --> $DIR/linkage4.rs:1:1 - | -LL | #[linkage = "external"] - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/29603 - = help: add #![feature(linkage)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. -- cgit 1.4.1-3-g733a5 From 444f2bae5920a93677a9de6063897e5ce00491e7 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 24 May 2019 14:55:15 +0200 Subject: Refine the message to at least *mention* the attribute itself. Update pre-existing test's diagnostic output accordingly. --- src/librustc_codegen_llvm/consts.rs | 3 ++- src/test/ui/linkage-attr/linkage2.rs | 2 +- src/test/ui/linkage-attr/linkage2.stderr | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/test/ui') diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 23e2bfe1ad1..99b5cf42551 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -116,7 +116,8 @@ fn check_and_apply_linkage( let llty2 = if let ty::RawPtr(ref mt) = ty.sty { cx.layout_of(mt.ty).llvm_type(cx) } else { - cx.sess().span_fatal(span, "must have type `*const T` or `*mut T`") + cx.sess().span_fatal( + span, "must have type `*const T` or `*mut T` due to `#[linkage]` attribute") }; unsafe { // Declare a symbol `foo` with the desired linkage. diff --git a/src/test/ui/linkage-attr/linkage2.rs b/src/test/ui/linkage-attr/linkage2.rs index f9ea5319d54..c8af1a69979 100644 --- a/src/test/ui/linkage-attr/linkage2.rs +++ b/src/test/ui/linkage-attr/linkage2.rs @@ -7,7 +7,7 @@ extern { #[linkage = "extern_weak"] static foo: i32; - //~^ ERROR: must have type `*const T` or `*mut T` + //~^ ERROR: must have type `*const T` or `*mut T` due to `#[linkage]` attribute } fn main() { diff --git a/src/test/ui/linkage-attr/linkage2.stderr b/src/test/ui/linkage-attr/linkage2.stderr index 8326c0baccc..2654ffd67b6 100644 --- a/src/test/ui/linkage-attr/linkage2.stderr +++ b/src/test/ui/linkage-attr/linkage2.stderr @@ -1,4 +1,4 @@ -error: must have type `*const T` or `*mut T` +error: must have type `*const T` or `*mut T` due to `#[linkage]` attribute --> $DIR/linkage2.rs:9:32 | LL | #[linkage = "extern_weak"] static foo: i32; -- cgit 1.4.1-3-g733a5 From 4e60f53280c34d35c29b007b28e32b9a6f695d1b Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 24 May 2019 15:13:16 +0200 Subject: Regression test for issue #59548. --- src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs | 5 +++++ src/test/ui/linkage-attr/linkage-requires-raw-ptr.rs | 10 ++++++++++ src/test/ui/linkage-attr/linkage-requires-raw-ptr.stderr | 8 ++++++++ 3 files changed, 23 insertions(+) create mode 100644 src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs create mode 100644 src/test/ui/linkage-attr/linkage-requires-raw-ptr.rs create mode 100644 src/test/ui/linkage-attr/linkage-requires-raw-ptr.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs b/src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs new file mode 100644 index 00000000000..2300930e513 --- /dev/null +++ b/src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs @@ -0,0 +1,5 @@ +#![feature(linkage)] +#![crate_type = "lib"] + +#[linkage="external"] +pub static EXTERN: u32 = 0; diff --git a/src/test/ui/linkage-attr/linkage-requires-raw-ptr.rs b/src/test/ui/linkage-attr/linkage-requires-raw-ptr.rs new file mode 100644 index 00000000000..014c715be0d --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-requires-raw-ptr.rs @@ -0,0 +1,10 @@ +// rust-lang/rust#59548: We used to ICE when trying to use a static +// with a type that violated its own `#[linkage]`. + +// aux-build:def_illtyped_external.rs + +extern crate def_illtyped_external as dep; + +fn main() { + println!("{:p}", &dep::EXTERN); +} diff --git a/src/test/ui/linkage-attr/linkage-requires-raw-ptr.stderr b/src/test/ui/linkage-attr/linkage-requires-raw-ptr.stderr new file mode 100644 index 00000000000..a80b495f97f --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-requires-raw-ptr.stderr @@ -0,0 +1,8 @@ +error: must have type `*const T` or `*mut T` due to `#[linkage]` attribute + --> $DIR/auxiliary/def_illtyped_external.rs:5:1 + | +LL | pub static EXTERN: u32 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From c8887abf20f72631eeeb72eaf14fa27fc4e550fa Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 27 May 2019 12:08:10 +0200 Subject: Tests for external linkage symbol collision check. Fix #61232 --- .../auxiliary/def_colliding_external.rs | 7 +++++++ ...nkage-detect-extern-generated-name-collision.rs | 21 ++++++++++++++++++++ ...e-detect-extern-generated-name-collision.stderr | 8 ++++++++ ...inkage-detect-local-generated-name-collision.rs | 23 ++++++++++++++++++++++ ...ge-detect-local-generated-name-collision.stderr | 8 ++++++++ 5 files changed, 67 insertions(+) create mode 100644 src/test/ui/linkage-attr/auxiliary/def_colliding_external.rs create mode 100644 src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs create mode 100644 src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr create mode 100644 src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs create mode 100644 src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/linkage-attr/auxiliary/def_colliding_external.rs b/src/test/ui/linkage-attr/auxiliary/def_colliding_external.rs new file mode 100644 index 00000000000..bbbfc485791 --- /dev/null +++ b/src/test/ui/linkage-attr/auxiliary/def_colliding_external.rs @@ -0,0 +1,7 @@ +#![feature(linkage)] +#![crate_type = "lib"] + +extern { + #[linkage="external"] + pub static collision: *const i32; +} diff --git a/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs b/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs new file mode 100644 index 00000000000..85a9a336b0d --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs @@ -0,0 +1,21 @@ +// rust-lang/rust#61232: We used to ICE when trying to detect a +// collision on the symbol generated for the external linkage item in +// an extern crate. + +// aux-build:def_colliding_external.rs + +extern crate def_colliding_external as dep1; + +#[no_mangle] +pub static _rust_extern_with_linkage_collision: i32 = 0; + +mod dep2 { + #[no_mangle] + pub static collision: usize = 0; +} + +fn main() { + unsafe { + println!("{:p}", &dep1::collision); + } +} diff --git a/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr b/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr new file mode 100644 index 00000000000..dcb954a4bc0 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr @@ -0,0 +1,8 @@ +error: symbol `collision` is already defined + --> $DIR/auxiliary/def_colliding_external.rs:6:5 + | +LL | pub static collision: *const i32; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs b/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs new file mode 100644 index 00000000000..dc15798e16a --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs @@ -0,0 +1,23 @@ +#![feature(linkage)] + +mod dep1 { + extern { + #[linkage="external"] + #[no_mangle] + pub static collision: *const i32; //~ ERROR symbol `collision` is already defined + } +} + +#[no_mangle] +pub static _rust_extern_with_linkage_collision: i32 = 0; + +mod dep2 { + #[no_mangle] + pub static collision: usize = 0; +} + +fn main() { + unsafe { + println!("{:p}", &dep1::collision); + } +} diff --git a/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr b/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr new file mode 100644 index 00000000000..117c76f7f26 --- /dev/null +++ b/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr @@ -0,0 +1,8 @@ +error: symbol `collision` is already defined + --> $DIR/linkage-detect-local-generated-name-collision.rs:7:9 + | +LL | pub static collision: *const i32; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 41aaf7bc468759b4775b28fc039ff07c538d4ccb Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 14 May 2019 21:34:43 +0100 Subject: Fix ICE with struct ctors and const generics. This commit fixes a ICE where struct constructors were resulting in an ICE with const generics. Previously, a `match` in `type_of` did not have an arm for the `DefKind::Ctor` resolutions and therefore would assume that the type did not have generics. --- src/librustc/hir/mod.rs | 7 ++ src/librustc_typeck/collect.rs | 98 +++++++++++----------- .../cannot-infer-type-for-const-param.rs | 5 +- .../cannot-infer-type-for-const-param.stderr | 21 +---- .../issue-60818-struct-constructors.rs | 10 +++ .../issue-60818-struct-constructors.stderr | 6 ++ 6 files changed, 74 insertions(+), 73 deletions(-) create mode 100644 src/test/ui/const-generics/issue-60818-struct-constructors.rs create mode 100644 src/test/ui/const-generics/issue-60818-struct-constructors.stderr (limited to 'src/test/ui') diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 1a6f5d3733e..f03a8ddc908 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -425,6 +425,13 @@ impl GenericArg { GenericArg::Const(c) => c.value.hir_id, } } + + pub fn is_const(&self) -> bool { + match self { + GenericArg::Const(_) => true, + _ => false, + } + } } #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 00990a5c5b5..3806fd0998b 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -27,7 +27,7 @@ use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::ty::util::Discr; use rustc::ty::util::IntTypeExt; use rustc::ty::subst::UnpackedKind; -use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt}; +use rustc::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, Ty, TyCtxt}; use rustc::ty::{ReprOptions, ToPredicate}; use rustc::util::captures::Captures; use rustc::util::nodemap::FxHashMap; @@ -1349,65 +1349,61 @@ pub fn checked_type_of<'a, 'tcx>( match path { QPath::Resolved(_, ref path) => { - let mut arg_index = 0; - let mut found_const = false; - for seg in &path.segments { - if let Some(generic_args) = &seg.args { - let args = &generic_args.args; - for arg in args { - if let GenericArg::Const(ct) = arg { - if ct.value.hir_id == hir_id { - found_const = true; - break; - } - arg_index += 1; - } - } - } - } - // Sanity check to make sure everything is as expected. - if !found_const { - if !fail { - return None; - } - bug!("no arg matching AnonConst in path") - } - match path.res { - // We've encountered an `AnonConst` in some path, so we need to - // figure out which generic parameter it corresponds to and return - // the relevant type. - Res::Def(DefKind::Struct, def_id) - | Res::Def(DefKind::Union, def_id) - | Res::Def(DefKind::Enum, def_id) - | Res::Def(DefKind::Fn, def_id) => { - let generics = tcx.generics_of(def_id); - let mut param_index = 0; - for param in &generics.params { - if let ty::GenericParamDefKind::Const = param.kind { - if param_index == arg_index { - return Some(tcx.type_of(param.def_id)); - } - param_index += 1; - } - } - // This is no generic parameter associated with the arg. This is - // probably from an extra arg where one is not needed. - return Some(tcx.types.err); - } - Res::Err => tcx.types.err, - x => { + let arg_index = path.segments.iter() + .filter_map(|seg| seg.args.as_ref()) + .map(|generic_args| generic_args.args.as_ref()) + .find_map(|args| { + args.iter() + .filter(|arg| arg.is_const()) + .enumerate() + .filter(|(_, arg)| arg.id() == hir_id) + .map(|(index, _)| index) + .next() + }) + .or_else(|| { if !fail { - return None; + None + } else { + bug!("no arg matching AnonConst in path") } + })?; + + // We've encountered an `AnonConst` in some path, so we need to + // figure out which generic parameter it corresponds to and return + // the relevant type. + let generics = match path.res { + Res::Def(DefKind::Ctor(..), def_id) => + tcx.generics_of(tcx.parent(def_id).unwrap()), + Res::Def(_, def_id) => + tcx.generics_of(def_id), + Res::Err => + return Some(tcx.types.err), + _ if !fail => + return None, + x => { tcx.sess.delay_span_bug( DUMMY_SP, &format!( "unexpected const parent path def {:?}", x ), ); - tcx.types.err + return Some(tcx.types.err); } - } + }; + + generics.params.iter() + .filter(|param| { + if let ty::GenericParamDefKind::Const = param.kind { + true + } else { + false + } + }) + .nth(arg_index) + .map(|param| tcx.type_of(param.def_id)) + // This is no generic parameter associated with the arg. This is + // probably from an extra arg where one is not needed. + .unwrap_or(tcx.types.err) } x => { if !fail { diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs index 26496ec4a90..f592e486be9 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs @@ -1,8 +1,9 @@ +// compile-pass #![feature(const_generics)] //~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash -// We should probably be able to infer the types here. However, this test is checking that we don't -// get an ICE in this case. It may be modified later to not be an error. +// This test confirms that the types can be inferred correctly for this example with const +// generics. Previously this would ICE, and more recently error. struct Foo(pub [u8; NUM_BYTES]); diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr index fb151648f2f..52907bbb677 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr @@ -1,25 +1,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler to crash - --> $DIR/cannot-infer-type-for-const-param.rs:1:12 + --> $DIR/cannot-infer-type-for-const-param.rs:2:12 | LL | #![feature(const_generics)] | ^^^^^^^^^^^^^^ -error[E0282]: type annotations needed - --> $DIR/cannot-infer-type-for-const-param.rs:10:19 - | -LL | let _ = Foo::<3>([1, 2, 3]); - | ^ cannot infer type for `{integer}` - -error[E0308]: mismatched types - --> $DIR/cannot-infer-type-for-const-param.rs:10:22 - | -LL | let _ = Foo::<3>([1, 2, 3]); - | ^^^^^^^^^ expected `3`, found `3usize` - | - = note: expected type `[u8; _]` - found type `[u8; 3]` - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0282, E0308. -For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/issue-60818-struct-constructors.rs b/src/test/ui/const-generics/issue-60818-struct-constructors.rs new file mode 100644 index 00000000000..0b4aeae7a4a --- /dev/null +++ b/src/test/ui/const-generics/issue-60818-struct-constructors.rs @@ -0,0 +1,10 @@ +// compile-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +struct Generic; + +fn main() { + let _ = Generic::<0>; +} diff --git a/src/test/ui/const-generics/issue-60818-struct-constructors.stderr b/src/test/ui/const-generics/issue-60818-struct-constructors.stderr new file mode 100644 index 00000000000..4b8f50b9b02 --- /dev/null +++ b/src/test/ui/const-generics/issue-60818-struct-constructors.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/issue-60818-struct-constructors.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + -- cgit 1.4.1-3-g733a5 From 998ef688a39a1b842b5d0a71ea92a8f825650975 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 30 May 2019 00:21:04 +0100 Subject: Add a regression test for const parameters with impl Trait --- src/test/ui/const-generics/apit-with-const-param.rs | 10 ++++++++++ src/test/ui/const-generics/apit-with-const-param.stderr | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/ui/const-generics/apit-with-const-param.rs create mode 100644 src/test/ui/const-generics/apit-with-const-param.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/const-generics/apit-with-const-param.rs b/src/test/ui/const-generics/apit-with-const-param.rs new file mode 100644 index 00000000000..70e718d8890 --- /dev/null +++ b/src/test/ui/const-generics/apit-with-const-param.rs @@ -0,0 +1,10 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +trait Trait {} + +fn f(_: impl Trait) {} + +fn main() {} diff --git a/src/test/ui/const-generics/apit-with-const-param.stderr b/src/test/ui/const-generics/apit-with-const-param.stderr new file mode 100644 index 00000000000..b3038ee6488 --- /dev/null +++ b/src/test/ui/const-generics/apit-with-const-param.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/apit-with-const-param.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + -- cgit 1.4.1-3-g733a5