Auto merge of #72905 - JohnTitor:rollup-phtyo5i, r=JohnTitor

Rollup of 10 pull requests

Successful merges:

 - #72775 (Return early to avoid ICE)
 - #72795 (Add a test for `$:ident` in proc macro input)
 - #72822 (remove trivial calls to mk_const)
 - #72825 (Clarify errors and warnings about the transition to the new asm!)
 - #72827 (changed *nix to Unix-like)
 - #72880 (Clean up E0637 explanation)
 - #72886 (Remove allow missing_debug_implementations for MaybeUninit)
 - #72889 (rustc: Remove the `--passive-segments` LLD flag on wasm)
 - #72891 (Add associated consts MIN/MAX for Wrapping<Int>)
 - #72893 (test miri-unleash TLS accesses)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-06-02 04:10:49 +00:00
commit 10c2316a6b
32 changed files with 238 additions and 87 deletions

View File

@ -23,7 +23,7 @@ or reading the [rustc dev guide][rustcguidebuild].
[rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
### Building on *nix
### Building on Unix-like system
1. Make sure you have installed the dependencies:
* `g++` 5.1 or later or `clang++` 3.5 or later

View File

@ -1315,7 +1315,7 @@ pub(crate) mod builtin {
#[unstable(
feature = "llvm_asm",
issue = "70173",
reason = "LLVM-style inline assembly will never be stabilized, prefer using asm! instead"
reason = "prefer using the new asm! syntax instead"
)]
#[rustc_builtin_macro]
#[macro_export]

View File

@ -214,7 +214,6 @@ use crate::mem::ManuallyDrop;
/// remain `#[repr(transparent)]`. That said, `MaybeUninit<T>` will *always* guarantee that it has
/// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that
/// guarantee may evolve.
#[allow(missing_debug_implementations)]
#[stable(feature = "maybe_uninit", since = "1.36.0")]
// Lang item so we can wrap other types in it. This is useful for generators.
#[lang = "maybe_uninit"]

View File

@ -337,14 +337,10 @@ Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<", stringify!($t), ">>::min_value(), ",
"Wrapping(", stringify!($t), "::min_value()));
assert_eq!(<Wrapping<", stringify!($t), ">>::MIN, Wrapping(", stringify!($t), "::MIN));
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
#[inline]
pub const fn min_value() -> Self {
Wrapping(<$t>::min_value())
}
pub const MIN: Self = Self(<$t>::MIN);
}
doc_comment! {
@ -358,14 +354,10 @@ Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<", stringify!($t), ">>::max_value(), ",
"Wrapping(", stringify!($t), "::max_value()));
assert_eq!(<Wrapping<", stringify!($t), ">>::MAX, Wrapping(", stringify!($t), "::MAX));
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
#[inline]
pub const fn max_value() -> Self {
Wrapping(<$t>::max_value())
}
pub const MAX: Self = Self(<$t>::MAX);
}
doc_comment! {

View File

@ -33,7 +33,10 @@ fn parse_args<'a>(
// Detect use of the legacy llvm_asm! syntax (which used to be called asm!)
if p.look_ahead(1, |t| *t == token::Colon || *t == token::ModSep) {
let mut err = ecx.struct_span_err(sp, "legacy asm! syntax is no longer supported");
let mut err =
ecx.struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported");
err.note("consider migrating to the new asm! syntax specified in RFC 2873");
err.note("alternatively, switch to llvm_asm! to keep your code working as it is");
// Find the span of the "asm!" so that we can offer an automatic suggestion
let asm_span = sp.from_inner(InnerSpan::new(0, 4));

View File

@ -1010,9 +1010,6 @@ impl<'a> WasmLd<'a> {
// sharing memory and instantiating the module multiple times. As a
// result if it were exported then we'd just have no sharing.
//
// * `--passive-segments` - all memory segments should be passive to
// prevent each module instantiation from reinitializing memory.
//
// * `--export=__wasm_init_memory` - when using `--passive-segments` the
// linker will synthesize this function, and so we need to make sure
// that our usage of `--export` below won't accidentally cause this
@ -1026,7 +1023,6 @@ impl<'a> WasmLd<'a> {
cmd.arg("--shared-memory");
cmd.arg("--max-memory=1073741824");
cmd.arg("--import-memory");
cmd.arg("--passive-segments");
cmd.arg("--export=__wasm_init_memory");
cmd.arg("--export=__wasm_init_tls");
cmd.arg("--export=__tls_size");

View File

@ -1,6 +1,7 @@
An underscore `_` character has been used as the identifier for a lifetime.
Erroneous example:
Erroneous code example:
```compile_fail,E0106,E0637
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
@ -11,6 +12,7 @@ fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
}
}
```
`'_`, cannot be used as a lifetime identifier because it is a reserved for the
anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
of lowercase letters such as `'foo`. For more information, see [the
@ -18,6 +20,7 @@ book][bk-no]. For more information on using the anonymous lifetime in rust
nightly, see [the nightly book][bk-al].
Corrected example:
```
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
if str1.len() > str2.len() {

View File

@ -523,12 +523,12 @@ impl fmt::Display for UnsupportedOpInfo {
match self {
Unsupported(ref msg) => write!(f, "{}", msg),
ReadForeignStatic(did) => {
write!(f, "cannot read from foreign (extern) static {:?}", did)
write!(f, "cannot read from foreign (extern) static ({:?})", did)
}
NoMirFor(did) => write!(f, "no MIR body is available for {:?}", did),
ReadPointerAsBytes => write!(f, "unable to turn pointer into raw bytes",),
ReadBytesAsPointer => write!(f, "unable to turn bytes into a pointer"),
ThreadLocalStatic(did) => write!(f, "accessing thread local static {:?}", did),
ThreadLocalStatic(did) => write!(f, "cannot access thread local static ({:?})", did),
}
}
}

View File

@ -1019,7 +1019,11 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
let ty = self.ty.fold_with(folder);
let val = self.val.fold_with(folder);
folder.tcx().mk_const(ty::Const { ty, val })
if ty != self.ty || val != self.val {
folder.tcx().mk_const(ty::Const { ty, val })
} else {
*self
}
}
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {

View File

@ -12,9 +12,6 @@ use super::ConstCx;
/// An operation that is not *always* allowed in a const context.
pub trait NonConstOp: std::fmt::Debug {
/// Whether this operation can be evaluated by miri.
const IS_SUPPORTED_IN_MIRI: bool = true;
/// Returns the `Symbol` corresponding to the feature gate that would enable this operation,
/// or `None` if such a feature gate does not exist.
fn feature_gate() -> Option<Symbol> {
@ -356,8 +353,6 @@ impl NonConstOp for StaticAccess {
#[derive(Debug)]
pub struct ThreadLocalAccess;
impl NonConstOp for ThreadLocalAccess {
const IS_SUPPORTED_IN_MIRI: bool = false;
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
struct_span_err!(
ccx.tcx.sess,

View File

@ -244,11 +244,7 @@ impl Validator<'mir, 'tcx> {
return;
}
// If an operation is supported in miri it can be turned on with
// `-Zunleash-the-miri-inside-of-you`.
let is_unleashable = O::IS_SUPPORTED_IN_MIRI;
if is_unleashable && self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
if self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
self.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
return;
}

View File

@ -1909,6 +1909,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty());
// Do not check on infer_types to avoid panic in evaluate_obligation.
if self_ty.has_infer_types() {
return;
}
let self_ty = self.tcx.erase_regions(&self_ty);
let impls_future = self.tcx.type_implements_trait((
future_trait,
self_ty,

View File

@ -540,13 +540,6 @@ fn type_implements_trait<'tcx>(
trait_def_id, ty, params, param_env
);
// Do not check on infer_types to avoid panic in evaluate_obligation.
if ty.has_infer_types() {
return false;
}
let ty = tcx.erase_regions(&ty);
let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, params) };
let obligation = Obligation {

View File

@ -8,9 +8,9 @@ fn main() {
let x = 1;
let y: i32;
llvm_asm!("" :: "r" (x));
//~^ ERROR legacy asm! syntax is no longer supported
//~^ ERROR the legacy LLVM-style asm! syntax is no longer supported
llvm_asm!("" : "=r" (y));
//~^ ERROR legacy asm! syntax is no longer supported
//~^ ERROR the legacy LLVM-style asm! syntax is no longer supported
let _ = y;
}
}

View File

@ -8,9 +8,9 @@ fn main() {
let x = 1;
let y: i32;
asm!("" :: "r" (x));
//~^ ERROR legacy asm! syntax is no longer supported
//~^ ERROR the legacy LLVM-style asm! syntax is no longer supported
asm!("" : "=r" (y));
//~^ ERROR legacy asm! syntax is no longer supported
//~^ ERROR the legacy LLVM-style asm! syntax is no longer supported
let _ = y;
}
}

View File

@ -1,18 +1,24 @@
error: legacy asm! syntax is no longer supported
error: the legacy LLVM-style asm! syntax is no longer supported
--> $DIR/rustfix-asm.rs:10:9
|
LL | asm!("" :: "r" (x));
| ----^^^^^^^^^^^^^^^^
| |
| help: replace with: `llvm_asm!`
|
= note: consider migrating to the new asm! syntax specified in RFC 2873
= note: alternatively, switch to llvm_asm! to keep your code working as it is
error: legacy asm! syntax is no longer supported
error: the legacy LLVM-style asm! syntax is no longer supported
--> $DIR/rustfix-asm.rs:12:9
|
LL | asm!("" : "=r" (y));
| ----^^^^^^^^^^^^^^^^
| |
| help: replace with: `llvm_asm!`
|
= note: consider migrating to the new asm! syntax specified in RFC 2873
= note: alternatively, switch to llvm_asm! to keep your code working as it is
error: aborting due to 2 previous errors

View File

@ -1,15 +1,22 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// only-x86_64
#![feature(llvm_asm)]
#![feature(asm,llvm_asm)]
#![allow(const_err)]
fn main() {}
// Make sure we catch executing inline assembly.
static TEST_BAD: () = {
static TEST_BAD1: () = {
unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
//~^ ERROR could not evaluate static initializer
//~| NOTE inline assembly is not supported
//~| NOTE in this expansion of llvm_asm!
//~| NOTE in this expansion of llvm_asm!
};
// Make sure we catch executing inline assembly.
static TEST_BAD2: () = {
unsafe { asm!("nop"); }
//~^ ERROR could not evaluate static initializer
//~| NOTE inline assembly is not supported
};

View File

@ -6,6 +6,12 @@ LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: could not evaluate static initializer
--> $DIR/inline_asm.rs:19:14
|
LL | unsafe { asm!("nop"); }
| ^^^^^^^^^^^^ inline assembly is not supported
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
@ -13,8 +19,13 @@ help: skipping check that does not even have a feature gate
|
LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/inline_asm.rs:19:14
|
LL | unsafe { asm!("nop"); }
| ^^^^^^^^^^^^
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error; 1 warning emitted
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.

View File

@ -0,0 +1,17 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(thread_local)]
#![allow(const_err)]
use std::thread;
#[thread_local]
static A: u8 = 0;
// Make sure we catch accessing thread-local storage.
static TEST_BAD: () = {
unsafe { let _val = A; }
//~^ ERROR could not evaluate static initializer
//~| NOTE cannot access thread local static
};
fn main() {}

View File

@ -0,0 +1,17 @@
error[E0080]: could not evaluate static initializer
--> $DIR/tls.rs:12:25
|
LL | unsafe { let _val = A; }
| ^ cannot access thread local static (DefId(0:4 ~ tls[317d]::A[0]))
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/tls.rs:12:25
|
LL | unsafe { let _val = A; }
| ^
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.

View File

@ -5,6 +5,6 @@ fn main() {
asm!("");
//~^ ERROR inline assembly is not stable enough
llvm_asm!("");
//~^ ERROR LLVM-style inline assembly will never be stabilized
//~^ ERROR prefer using the new asm! syntax instead
}
}

View File

@ -7,7 +7,7 @@ LL | asm!("");
= note: see issue #72016 <https://github.com/rust-lang/rust/issues/72016> for more information
= help: add `#![feature(asm)]` to the crate attributes to enable
error[E0658]: use of unstable library feature 'llvm_asm': LLVM-style inline assembly will never be stabilized, prefer using asm! instead
error[E0658]: use of unstable library feature 'llvm_asm': prefer using the new asm! syntax instead
--> $DIR/feature-gate-asm.rs:7:9
|
LL | llvm_asm!("");

View File

@ -5,6 +5,6 @@ fn main() {
println!("{:?}", asm!(""));
//~^ ERROR inline assembly is not stable enough
println!("{:?}", llvm_asm!(""));
//~^ ERROR LLVM-style inline assembly will never be stabilized
//~^ ERROR prefer using the new asm! syntax instead
}
}

View File

@ -7,7 +7,7 @@ LL | println!("{:?}", asm!(""));
= note: see issue #72016 <https://github.com/rust-lang/rust/issues/72016> for more information
= help: add `#![feature(asm)]` to the crate attributes to enable
error[E0658]: use of unstable library feature 'llvm_asm': LLVM-style inline assembly will never be stabilized, prefer using asm! instead
error[E0658]: use of unstable library feature 'llvm_asm': prefer using the new asm! syntax instead
--> $DIR/feature-gate-asm2.rs:7:26
|
LL | println!("{:?}", llvm_asm!(""));

View File

@ -108,5 +108,6 @@ pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream {
#[proc_macro_derive(Print, attributes(print_helper))]
pub fn print_derive(input: TokenStream) -> TokenStream {
print_helper(input, "DERIVE")
print_helper(input, "DERIVE");
TokenStream::new()
}

View File

@ -1,3 +1,4 @@
// check-pass
// edition:2018
// aux-build:test-macros.rs
// aux-build:dollar-crate-external.rs
@ -23,7 +24,7 @@ mod local {
struct A($crate::S);
#[derive(Print)]
struct D($crate::S); //~ ERROR the name `D` is defined multiple times
struct D($crate::S);
};
}
@ -33,7 +34,7 @@ mod local {
mod external {
use crate::dollar_crate_external;
dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times
dollar_crate_external::external!();
}
fn main() {}

View File

@ -1,30 +0,0 @@
error[E0428]: the name `D` is defined multiple times
--> $DIR/dollar-crate.rs:26:13
|
LL | struct D($crate::S);
| ^^^^^^^^^^^^^^^^^^^^
| |
| `D` redefined here
| previous definition of the type `D` here
...
LL | local!();
| --------- in this macro invocation
|
= note: `D` must be defined only once in the type namespace of this module
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0428]: the name `D` is defined multiple times
--> $DIR/dollar-crate.rs:36:5
|
LL | dollar_crate_external::external!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `D` redefined here
| previous definition of the type `D` here
|
= note: `D` must be defined only once in the type namespace of this module
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0428`.

View File

@ -0,0 +1,25 @@
// Check what token streams proc macros see when interpolated tokens are passed to them as input.
// check-pass
// aux-build:test-macros.rs
#[macro_use]
extern crate test_macros;
macro_rules! pass_ident {
($i:ident) => {
fn f() {
print_bang!($i);
}
#[print_attr]
const $i: u8 = 0;
#[derive(Print)]
struct $i {}
};
}
pass_ident!(A);
fn main() {}

View File

@ -0,0 +1,69 @@
PRINT-BANG INPUT (DISPLAY): A
PRINT-BANG RE-COLLECTED (DISPLAY): A
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "A",
span: #0 bytes(402..403),
},
],
span: #3 bytes(269..271),
},
]
PRINT-ATTR INPUT (DISPLAY): const A: u8 = 0;
PRINT-ATTR RE-COLLECTED (DISPLAY): const A : u8 = 0 ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "const",
span: #0 bytes(0..0),
},
Ident {
ident: "A",
span: #0 bytes(0..0),
},
Punct {
ch: ':',
spacing: Alone,
span: #0 bytes(0..0),
},
Ident {
ident: "u8",
span: #0 bytes(0..0),
},
Punct {
ch: '=',
spacing: Alone,
span: #0 bytes(0..0),
},
Literal {
kind: Integer,
symbol: "0",
suffix: None,
span: #0 bytes(0..0),
},
Punct {
ch: ';',
spacing: Alone,
span: #0 bytes(0..0),
},
]
PRINT-DERIVE INPUT (DISPLAY): struct A {
}
PRINT-DERIVE RE-COLLECTED (DISPLAY): struct A { }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: #0 bytes(0..0),
},
Ident {
ident: "A",
span: #0 bytes(0..0),
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: #0 bytes(0..0),
},
]

View File

@ -0,0 +1,20 @@
// edition:2018
// compile-flags: -Cincremental=tmp/issue-72766
pub struct SadGirl;
impl SadGirl {
pub async fn call(&self) -> Result<(), ()> {
Ok(())
}
}
async fn async_main() -> Result<(), ()> {
// should be `.call().await?`
SadGirl {}.call()?; //~ ERROR: the `?` operator can only be applied to values
Ok(())
}
fn main() {
let _ = async_main();
}

View File

@ -0,0 +1,15 @@
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> $DIR/issue-72766.rs:14:5
|
LL | SadGirl {}.call()?;
| ^^^^^^^^^^^^^^^^^^
| |
| the `?` operator cannot be applied to type `impl std::future::Future`
| help: consider using `.await` here: `SadGirl {}.call().await?`
|
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
= note: required by `std::ops::Try::into_result`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -323,6 +323,11 @@ pub fn implements_trait<'a, 'tcx>(
trait_id: DefId,
ty_params: &[GenericArg<'tcx>],
) -> bool {
// Do not check on infer_types to avoid panic in evaluate_obligation.
if ty.has_infer_types() {
return false;
}
let ty = cx.tcx.erase_regions(&ty);
let ty_params = cx.tcx.mk_substs(ty_params.iter());
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
}