Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #67479

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2bd28d9
Add regression tests
TommasoBianchi Nov 24, 2019
042d855
Fix too restrictive checks on Drop impls
TommasoBianchi Dec 16, 2019
b08d697
Formatting fixes
TommasoBianchi Dec 16, 2019
020be74
Clean up E0120 long explanation
GuillaumeGomez Dec 19, 2019
94d207f
Clean up E0121 long explanation
GuillaumeGomez Dec 19, 2019
7f0741d
Update E0120.md
Dylan-DPC Dec 20, 2019
dce0f06
Update E0121.md
Dylan-DPC Dec 20, 2019
963f20d
Allow -Cllvm-args to override rustc's default LLVM args.
michaelwoerister Dec 18, 2019
1ca145c
Remove rarely used -Zdisable_instrumentation_preinliner flag.
michaelwoerister Dec 18, 2019
382d370
Make ptr::slice_from_raw_parts a const fn available under a feature flag
DutchGhost Dec 20, 2019
c59588f
extract parse_ty_tuple_or_parens
Centril Dec 8, 2019
e68db0a
refactor parse_ty_tuple_or_parens
Centril Dec 8, 2019
6d678b1
parse_ptr -> parse_ty_ptr & refactor
Centril Dec 8, 2019
f085637
extract parse_array_or_slice_ty
Centril Dec 8, 2019
b42b85f
extract parse_typeof_ty
Centril Dec 8, 2019
d47de3e
extract parse_impl_ty
Centril Dec 8, 2019
1fa8f70
extract parse_dyn_ty
Centril Dec 8, 2019
c0561cf
extract parse_path_start_ty
Centril Dec 8, 2019
6b92be2
extract error_illegal_c_variadic_ty
Centril Dec 8, 2019
0e74022
parse_ty_common: .fatal -> .struct_span_err
Centril Dec 8, 2019
3b63465
parser/ty.rs: minor formatting tweaks
Centril Dec 8, 2019
8e8ac02
extract error_opt_out_lifetime
Centril Dec 8, 2019
56b54fb
extract recover_paren_lifetime
Centril Dec 8, 2019
e8b6769
parse_generic_bounds_common: dedent
Centril Dec 8, 2019
7294804
extract can_begin_bound
Centril Dec 8, 2019
229560b
extract parse_generic_bound
Centril Dec 8, 2019
2ca6181
functionalize parse_generic_bound
Centril Dec 8, 2019
f87ff0f
parse_generic_bound: leave a FIXME
Centril Dec 8, 2019
8f33bdc
extract parse_generic_ty_bound
Centril Dec 8, 2019
8123211
extract parse_generic_lt_bound
Centril Dec 8, 2019
90f7d8b
simplify negative bound diagnostic
Centril Dec 8, 2019
765df3a
simplify 'let question = ...;'
Centril Dec 8, 2019
51bbdeb
parse_generic_bounds: account for negative lifetime bounds
Centril Dec 8, 2019
f02fd50
extract error_negative_bounds
Centril Dec 8, 2019
0ebd421
document parse_late_bound_lifetime_defs
Centril Dec 8, 2019
d977e5b
parse_ty_bare_fn: improve docs
Centril Dec 8, 2019
cabe665
unwrap -> expect
Centril Dec 21, 2019
690b0b3
span_suggestion_hidden -> tool_only_span_suggestion
Centril Dec 21, 2019
abb4234
Rollup merge of #67059 - TommasoBianchi:dropck_fix_pr, r=pnkfelix
Centril Dec 21, 2019
2e44898
Rollup merge of #67148 - Centril:ty-polish, r=estebank
Centril Dec 21, 2019
97d88ed
Rollup merge of #67393 - michaelwoerister:llvm-args-override, r=varkor
Centril Dec 21, 2019
dfe712c
Rollup merge of #67422 - GuillaumeGomez:cleanup-err-codes, r=Dylan-DPC
Centril Dec 21, 2019
a3cc9b4
Rollup merge of #67462 - DutchGhost:const_slice_from_raw_parts, r=dto…
Centril Dec 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ pub(crate) struct FatPtr<T> {
/// ```
#[inline]
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
unsafe { Repr { raw: FatPtr { data, len } }.rust }
}

Expand All @@ -275,7 +276,8 @@ pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
/// [`from_raw_parts_mut`]: ../../std/slice/fn.from_raw_parts_mut.html
#[inline]
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
pub fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
unsafe { Repr { raw: FatPtr { data, len } }.rust_mut }
}

Expand Down
3 changes: 3 additions & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#![feature(iter_is_partitioned)]
#![feature(iter_order_by)]
#![feature(cmp_min_max_by)]
#![feature(slice_from_raw_parts)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_raw_ptr_deref)]

extern crate test;

Expand Down
11 changes: 11 additions & 0 deletions src/libcore/tests/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use core::cell::RefCell;
use core::ptr::*;

#[test]
fn test_const_from_raw_parts() {
const SLICE: &[u8] = &[1, 2, 3, 4];
const FROM_RAW: &[u8] = unsafe { &*slice_from_raw_parts(SLICE.as_ptr(), SLICE.len()) };
assert_eq!(SLICE, FROM_RAW);

let slice = &[1, 2, 3, 4, 5];
let from_raw = unsafe { &*slice_from_raw_parts(slice.as_ptr(), 2) } ;
assert_eq!(&slice[..2], from_raw);
}

#[test]
fn test() {
unsafe {
Expand Down
48 changes: 33 additions & 15 deletions src/librustc_codegen_llvm/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::llvm;
use syntax_pos::symbol::Symbol;
use rustc::session::Session;
use rustc::session::config::PrintRequest;
use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use libc::c_int;
use std::ffi::CString;
Expand Down Expand Up @@ -51,43 +52,60 @@ unsafe fn configure_llvm(sess: &Session) {

llvm::LLVMRustInstallFatalErrorHandler();

fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
full_arg.trim().split(|c: char| {
c == '=' || c.is_whitespace()
}).next().unwrap_or("")
}

let user_specified_args: FxHashSet<_> = sess
.opts
.cg
.llvm_args
.iter()
.map(|s| llvm_arg_to_arg_name(s))
.filter(|s| s.len() > 0)
.collect();

{
let mut add = |arg: &str| {
let s = CString::new(arg).unwrap();
llvm_args.push(s.as_ptr());
llvm_c_strs.push(s);
// This adds the given argument to LLVM. Unless `force` is true
// user specified arguments are *not* overridden.
let mut add = |arg: &str, force: bool| {
if force || !user_specified_args.contains(llvm_arg_to_arg_name(arg)) {
let s = CString::new(arg).unwrap();
llvm_args.push(s.as_ptr());
llvm_c_strs.push(s);
}
};
add("rustc"); // fake program name
if sess.time_llvm_passes() { add("-time-passes"); }
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
if sess.opts.debugging_opts.disable_instrumentation_preinliner {
add("-disable-preinline");
}
add("rustc", true); // fake program name
if sess.time_llvm_passes() { add("-time-passes", false); }
if sess.print_llvm_passes() { add("-debug-pass=Structure", false); }

if sess.opts.debugging_opts.generate_arange_section {
add("-generate-arange-section");
add("-generate-arange-section", false);
}
if get_major_version() >= 8 {
match sess.opts.debugging_opts.merge_functions
.unwrap_or(sess.target.target.options.merge_functions) {
MergeFunctions::Disabled |
MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
add("-mergefunc-use-aliases");
add("-mergefunc-use-aliases", false);
}
}
}

if sess.target.target.target_os == "emscripten" &&
sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions");
add("-enable-emscripten-cxx-exceptions", false);
}

// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
// during inlining. Unfortunately these may block other optimizations.
add("-preserve-alignment-assumptions-during-inlining=false");
add("-preserve-alignment-assumptions-during-inlining=false", false);

for arg in &sess.opts.cg.llvm_args {
add(&(*arg));
add(&(*arg), true);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/librustc_error_codes/error_codes/E0120.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
An attempt was made to implement Drop on a trait, which is not allowed: only
structs and enums can implement Drop. An example causing this error:
Drop was implemented on a trait, which is not allowed: only structs and
enums can implement Drop.

Erroneous code example:

```compile_fail,E0120
trait MyTrait {}
Expand All @@ -10,7 +12,7 @@ impl Drop for MyTrait {
```

A workaround for this problem is to wrap the trait up in a struct, and implement
Drop on that. An example is shown below:
Drop on that:

```
trait MyTrait {}
Expand All @@ -22,7 +24,7 @@ impl <T: MyTrait> Drop for MyWrapper<T> {

```

Alternatively, wrapping trait objects requires something like the following:
Alternatively, wrapping trait objects requires something:

```
trait MyTrait {}
Expand Down
24 changes: 19 additions & 5 deletions src/librustc_error_codes/error_codes/E0121.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
In order to be consistent with Rust's lack of global type inference,
type and const placeholders are disallowed by design in item signatures.
The type placeholder `_` was used within a type on an item's signature.

Examples of this error include:
Erroneous code example:

```compile_fail,E0121
fn foo() -> _ { 5 } // error, explicitly write out the return type instead
fn foo() -> _ { 5 } // error

static BAR: _ = "test"; // error, explicitly write out the type instead
static BAR: _ = "test"; // error
```

In those cases, you need to provide the type explicitly:

```
fn foo() -> i32 { 5 } // ok!

static BAR: &str = "test"; // ok!
```

The type placeholder `_` can be used outside item's signature as follows:

```
let x = "a4a".split('4')
.collect::<Vec<_>>(); // No need to precise the Vec's generic type.
```
9 changes: 5 additions & 4 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl<'a> Parser<'a> {
self.parse_expr_res(Restrictions::empty(), None)
}

pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
}

fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
self.parse_paren_comma_seq(|p| {
match p.parse_expr() {
Expand Down Expand Up @@ -883,10 +887,7 @@ impl<'a> Parser<'a> {
let first_expr = self.parse_expr()?;
if self.eat(&token::Semi) {
// Repeating array syntax: `[ 0; 512 ]`
let count = AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
};
let count = self.parse_anon_const_expr()?;
self.expect(&token::CloseDelim(token::Bracket))?;
ex = ExprKind::Repeat(first_expr, count);
} else if self.eat(&token::Comma) {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::maybe_whole;

use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
use rustc_error_codes::*;
use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item};
use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, Item};
use syntax::ast::{AssocItem, AssocItemKind, ItemKind, UseTree, UseTreeKind};
use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit};
use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
Expand Down Expand Up @@ -1318,10 +1318,7 @@ impl<'a> Parser<'a> {
};

let disr_expr = if self.eat(&token::Eq) {
Some(AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
})
Some(self.parse_anon_const_expr()?)
} else {
None
};
Expand Down
Loading