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 8 pull requests #63554

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3b229f1
check that ptr is valid already when doing Deref, not only when doing…
RalfJung Jul 27, 2019
5800bec
discourage use of ref_to_mplace
RalfJung Jul 28, 2019
3677c5b
the alignment checks on access can no longer fail now
RalfJung Jul 28, 2019
e4c39e1
better name for check_in_alloc
RalfJung Jul 28, 2019
388d99d
fix tests
RalfJung Jul 28, 2019
74fbdb6
move 'get me the access-checked version of an mplace' into separate f…
RalfJung Jul 28, 2019
647c0e0
'Ref' can now be sure it gets a 'Pointer'
RalfJung Jul 28, 2019
f0e3258
rustc: implement argsfiles for command line
jsgf Jul 30, 2019
a0dbeea
Use named arguments for formatting usage message.
jsgf Aug 1, 2019
4fc66a7
Use BufReader::lines() to parse out the lines
jsgf Aug 8, 2019
892ae41
Require -Zunstable-options to use @path
jsgf Aug 10, 2019
a4af9d1
parse_pat_with_range_pat: remove unnecessary assignments.
Centril Aug 12, 2019
90793c0
extract parse_pat_deref
Centril Aug 12, 2019
c69b3ed
extract parse_pat_tuple_or_parens
Centril Aug 12, 2019
3b65133
extract recover_pat_ident_mut_first
Centril Aug 12, 2019
231da7e
extract ban_pat_range_if_ambiguous
Centril Aug 12, 2019
e32bd69
extract parse_pat_mac_invoc
Centril Aug 12, 2019
e6f980f
extract parse_pat_range_starting_with_path
Centril Aug 12, 2019
49740b7
extract parse_pat_range_starting_with_lit
Centril Aug 12, 2019
37f37a5
parser/pat: minor misc cleanup
Centril Aug 12, 2019
ddf734d
extract fatal_unexpected_non_pat
Centril Aug 12, 2019
c8fc4c1
extract parse_pat_{tuple_}struct + recover_one_fewer_dotdot
Centril Aug 12, 2019
71415ef
Parse excess semicolons as empty stmts for linting
nathanwhit Jul 25, 2019
2f6cb5f
Add lint for excess trailing semicolons
nathanwhit Jul 30, 2019
76a1345
Update tests for excess semicolon lint
nathanwhit Jul 30, 2019
c037597
Remove redundant `ty` fields from `mir::Constant` and `hair::pattern:…
eddyb Aug 12, 2019
2882bee
rustc_mir: add sanity asserts for the types of `ty::Const`s.
eddyb Aug 12, 2019
22127b1
rustc_mir: use the right type for associated const literals.
eddyb Aug 12, 2019
d30f481
Fix indentation nit in src/librustc/mir/mod.rs.
eddyb Aug 12, 2019
13fd466
Point at the right enclosing scope when using `await` in non-async fn
estebank Aug 13, 2019
376636e
syntax: Remove `DummyResult::expn_only`
petrochenkov Aug 13, 2019
b5404f0
Simplify by removing FileArgs
jsgf Aug 13, 2019
25d507f
review comment: move test
estebank Aug 13, 2019
9348af8
Add NodeId for Arm, Field and FieldPat
c410-f3r Aug 14, 2019
902cfac
Rollup merge of #62984 - nathanwhit:extra_semi_lint, r=varkor
Centril Aug 14, 2019
2697a29
Rollup merge of #63075 - RalfJung:deref-checks, r=oli-obk
Centril Aug 14, 2019
91e48b5
Rollup merge of #63175 - jsgf:argsfile, r=alexcrichton
Centril Aug 14, 2019
a607786
Rollup merge of #63490 - Centril:cleanup-pat-parser, r=petrochenkov
Centril Aug 14, 2019
baab604
Rollup merge of #63495 - eddyb:mir-constant-ty, r=oli-obk
Centril Aug 14, 2019
3c08dfc
Rollup merge of #63509 - estebank:async-span, r=Centril
Centril Aug 14, 2019
159efeb
Rollup merge of #63528 - petrochenkov:anyany, r=estebank
Centril Aug 14, 2019
82f2dad
Rollup merge of #63542 - c410-f3r:node_ids, r=petrochenkov
Centril Aug 14, 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
7 changes: 7 additions & 0 deletions src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,10 @@ to customize the output:

Note that it is invalid to combine the `--json` argument with the `--color`
argument, and it is required to combine `--json` with `--error-format=json`.

## `@path`: load command-line flags from a path

If you specify `@path` on the command-line, then it will open `path` and read
command line options from it. These options are one per line; a blank line indicates
an empty option. The file can use Unix or Windows style line endings, and must be
encoded as UTF-8.
5 changes: 4 additions & 1 deletion src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ impl LoweringContext<'_> {
let fn_decl = self.lower_fn_decl(decl, None, false, None);

self.with_new_scopes(|this| {
let prev = this.current_item;
this.current_item = Some(fn_decl_span);
let mut generator_kind = None;
let body_id = this.lower_fn_body(decl, |this| {
Expand All @@ -690,8 +691,10 @@ impl LoweringContext<'_> {
generator_kind,
movability,
);
let capture_clause = this.lower_capture_clause(capture_clause);
this.current_item = prev;
hir::ExprKind::Closure(
this.lower_capture_clause(capture_clause),
capture_clause,
fn_decl,
body_id,
fn_decl_span,
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ impl<'tcx, Tag> Pointer<Tag> {
Pointer { alloc_id: self.alloc_id, offset: self.offset, tag: () }
}

/// Test if the pointer is "inbounds" of an allocation of the given size.
/// A pointer is "inbounds" even if its offset is equal to the size; this is
/// a "one-past-the-end" pointer.
#[inline(always)]
pub fn check_in_alloc(
pub fn check_inbounds_alloc(
self,
allocation_size: Size,
msg: CheckInAllocMsg,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,6 @@ impl<'tcx> Operand<'tcx> {
let ty = tcx.type_of(def_id).subst(tcx, substs);
Operand::Constant(box Constant {
span,
ty,
user_ty: None,
literal: ty::Const::zero_sized(tcx, ty),
})
Expand Down Expand Up @@ -2476,7 +2475,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
pub struct Constant<'tcx> {
pub span: Span,
pub ty: Ty<'tcx>,

/// Optional user-given type: for something like
/// `collect::<Vec<_>>`, this would be present and would
Expand Down Expand Up @@ -3385,12 +3383,11 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
Constant {
span: self.span.clone(),
ty: self.ty.fold_with(folder),
user_ty: self.user_ty.fold_with(folder),
literal: self.literal.fold_with(folder),
}
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
self.ty.visit_with(visitor) || self.literal.visit_with(visitor)
self.literal.visit_with(visitor)
}
}
2 changes: 1 addition & 1 deletion src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'tcx> Operand<'tcx> {
match self {
&Operand::Copy(ref l) |
&Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
&Operand::Constant(ref c) => c.ty,
&Operand::Constant(ref c) => c.literal.ty,
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,11 @@ macro_rules! make_mir_visitor {
location: Location) {
let Constant {
span,
ty,
user_ty,
literal,
} = constant;

self.visit_span(span);
self.visit_ty(ty, TyContext::Location(location));
drop(user_ty); // no visit method for this
self.visit_const(literal, location);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
mir::TerminatorKind::Call {
func: mir::Operand::Constant(ref c),
ref args, ..
} => match c.ty.sty {
} => match c.literal.ty.sty {
ty::FnDef(did, _) => Some((did, args)),
_ => None,
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (llval, ty) = self.simd_shuffle_indices(
&bx,
constant.span,
constant.ty,
constant.literal.ty,
c,
);
return OperandRef {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

mir::Operand::Constant(ref constant) => {
let ty = self.monomorphize(&constant.ty);
self.eval_mir_constant(constant)
.map(|c| OperandRef::from_const(bx, c))
.unwrap_or_else(|err| {
Expand All @@ -481,6 +480,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// the above error (or silence it under some conditions) will not cause UB
bx.abort();
// We've errored, so we don't have to produce working code.
let ty = self.monomorphize(&constant.literal.ty);
let layout = bx.cx().layout_of(ty);
bx.load_operand(PlaceRef::new_sized(
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))),
Expand Down
84 changes: 84 additions & 0 deletions src/librustc_driver/args/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::env;
use std::error;
use std::fmt;
use std::fs;
use std::io;
use std::str;
use std::sync::atomic::{AtomicBool, Ordering};

#[cfg(test)]
mod tests;

static USED_ARGSFILE_FEATURE: AtomicBool = AtomicBool::new(false);

pub fn used_unstable_argsfile() -> bool {
USED_ARGSFILE_FEATURE.load(Ordering::Relaxed)
}

pub struct ArgsIter {
base: env::ArgsOs,
file: std::vec::IntoIter<String>,
}

impl ArgsIter {
pub fn new() -> Self {
ArgsIter { base: env::args_os(), file: vec![].into_iter() }
}
}

impl Iterator for ArgsIter {
type Item = Result<String, Error>;

fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(line) = self.file.next() {
return Some(Ok(line));
}

let arg =
self.base.next().map(|arg| arg.into_string().map_err(|_| Error::Utf8Error(None)));
match arg {
Some(Err(err)) => return Some(Err(err)),
Some(Ok(ref arg)) if arg.starts_with("@") => {
let path = &arg[1..];
let file = match fs::read_to_string(path) {
Ok(file) => {
USED_ARGSFILE_FEATURE.store(true, Ordering::Relaxed);
file
}
Err(ref err) if err.kind() == io::ErrorKind::InvalidData => {
return Some(Err(Error::Utf8Error(Some(path.to_string()))));
}
Err(err) => return Some(Err(Error::IOError(path.to_string(), err))),
};
self.file =
file.lines().map(ToString::to_string).collect::<Vec<_>>().into_iter();
}
Some(Ok(arg)) => return Some(Ok(arg)),
None => return None,
}
}
}
}

#[derive(Debug)]
pub enum Error {
Utf8Error(Option<String>),
IOError(String, io::Error),
}

impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Utf8Error(None) => write!(fmt, "Utf8 error"),
Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {}", path),
Error::IOError(path, err) => write!(fmt, "IO Error: {}: {}", path, err),
}
}
}

impl error::Error for Error {
fn description(&self) -> &'static str {
"argument error"
}
}
145 changes: 145 additions & 0 deletions src/librustc_driver/args/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
use super::*;

use std::str;

fn want_args(v: impl IntoIterator<Item = &'static str>) -> Vec<String> {
v.into_iter().map(String::from).collect()
}

fn got_args(file: &[u8]) -> Result<Vec<String>, Error> {
let ret = str::from_utf8(file)
.map_err(|_| Error::Utf8Error(None))?
.lines()
.map(ToString::to_string)
.collect::<Vec<_>>();
Ok(ret)
}

#[test]
fn nothing() {
let file = b"";

assert_eq!(got_args(file).unwrap(), want_args(vec![]));
}

#[test]
fn empty() {
let file = b"\n";

assert_eq!(got_args(file).unwrap(), want_args(vec![""]));
}

#[test]
fn simple() {
let file = b"foo";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo"]));
}

#[test]
fn simple_eol() {
let file = b"foo\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo"]));
}

#[test]
fn multi() {
let file = b"foo\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar"]));
}

#[test]
fn multi_eol() {
let file = b"foo\nbar\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar"]));
}

#[test]
fn multi_empty() {
let file = b"foo\n\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "", "bar"]));
}

#[test]
fn multi_empty_eol() {
let file = b"foo\n\nbar\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "", "bar"]));
}

#[test]
fn multi_empty_start() {
let file = b"\nfoo\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["", "foo", "bar"]));
}

#[test]
fn multi_empty_end() {
let file = b"foo\nbar\n\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar", ""]));
}

#[test]
fn simple_eol_crlf() {
let file = b"foo\r\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo"]));
}

#[test]
fn multi_crlf() {
let file = b"foo\r\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar"]));
}

#[test]
fn multi_eol_crlf() {
let file = b"foo\r\nbar\r\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar"]));
}

#[test]
fn multi_empty_crlf() {
let file = b"foo\r\n\r\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "", "bar"]));
}

#[test]
fn multi_empty_eol_crlf() {
let file = b"foo\r\n\r\nbar\r\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "", "bar"]));
}

#[test]
fn multi_empty_start_crlf() {
let file = b"\r\nfoo\r\nbar";

assert_eq!(got_args(file).unwrap(), want_args(vec!["", "foo", "bar"]));
}

#[test]
fn multi_empty_end_crlf() {
let file = b"foo\r\nbar\r\n\r\n";

assert_eq!(got_args(file).unwrap(), want_args(vec!["foo", "bar", ""]));
}

#[test]
fn bad_utf8() {
let file = b"foo\x80foo";

match got_args(file).unwrap_err() {
Error::Utf8Error(_) => (),
bad => panic!("bad err: {:?}", bad),
}
}
Loading