Skip to content

Commit

Permalink
Auto merge of #66242 - Centril:rollup-h73ztr1, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #65949 (Move promotion into its own pass)
 - #65994 (Point at where clauses where the associated item was restricted)
 - #66050 (Fix C aggregate-passing ABI on powerpc)
 - #66134 (Point at formatting descriptor string when it is invalid)
 - #66172 (Stabilize @file command line arguments)
 - #66226 (add link to unstable book for asm! macro)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Nov 9, 2019
2 parents 98c173a + 3ef975d commit 5a50275
Show file tree
Hide file tree
Showing 29 changed files with 453 additions and 323 deletions.
4 changes: 4 additions & 0 deletions src/libcore/macros.rs
Expand Up @@ -1274,6 +1274,10 @@ pub(crate) mod builtin {
}

/// Inline assembly.
///
/// Read the [unstable book] for the usage.
///
/// [unstable book]: ../unstable-book/library-features/asm.html
#[unstable(feature = "asm", issue = "29722",
reason = "inline assembly is not stable enough for use and is subject to change")]
#[rustc_builtin_macro]
Expand Down
24 changes: 17 additions & 7 deletions src/libfmt_macros/lib.rs
Expand Up @@ -35,7 +35,7 @@ impl InnerOffset {

/// A piece is a portion of the format string which represents the next part
/// to emit. These are emitted as a stream by the `Parser` class.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Piece<'a> {
/// A literal string which should directly be emitted
String(&'a str),
Expand All @@ -45,7 +45,7 @@ pub enum Piece<'a> {
}

/// Representation of an argument specification.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Argument<'a> {
/// Where to find this argument
pub position: Position,
Expand All @@ -54,7 +54,7 @@ pub struct Argument<'a> {
}

/// Specification for the formatting of an argument in the format string.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct FormatSpec<'a> {
/// Optionally specified character to fill alignment with.
pub fill: Option<char>,
Expand All @@ -74,10 +74,12 @@ pub struct FormatSpec<'a> {
/// this argument, this can be empty or any number of characters, although
/// it is required to be one word.
pub ty: &'a str,
/// The span of the descriptor string (for diagnostics).
pub ty_span: Option<InnerSpan>,
}

/// Enum describing where an argument for a format can be located.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Position {
/// The argument is implied to be located at an index
ArgumentImplicitlyIs(usize),
Expand All @@ -97,7 +99,7 @@ impl Position {
}

/// Enum of alignments which are supported.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Alignment {
/// The value will be aligned to the left.
AlignLeft,
Expand All @@ -111,7 +113,7 @@ pub enum Alignment {

/// Various flags which can be applied to format strings. The meaning of these
/// flags is defined by the formatters themselves.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Flag {
/// A `+` will be used to denote positive numbers.
FlagSignPlus,
Expand All @@ -131,7 +133,7 @@ pub enum Flag {

/// A count is used for the precision and width parameters of an integer, and
/// can reference either an argument or a literal integer.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Count {
/// The count is specified explicitly.
CountIs(usize),
Expand Down Expand Up @@ -475,6 +477,7 @@ impl<'a> Parser<'a> {
width: CountImplied,
width_span: None,
ty: &self.input[..0],
ty_span: None,
};
if !self.consume(':') {
return spec;
Expand Down Expand Up @@ -548,6 +551,7 @@ impl<'a> Parser<'a> {
spec.precision_span = sp;
}
}
let ty_span_start = self.cur.peek().map(|(pos, _)| *pos);
// Optional radix followed by the actual format specifier
if self.consume('x') {
if self.consume('?') {
Expand All @@ -567,6 +571,12 @@ impl<'a> Parser<'a> {
spec.ty = "?";
} else {
spec.ty = self.word();
let ty_span_end = self.cur.peek().map(|(pos, _)| *pos);
if !spec.ty.is_empty() {
spec.ty_span = ty_span_start
.and_then(|s| ty_span_end.map(|e| (s, e)))
.map(|(start, end)| self.to_span_index(start).to(self.to_span_index(end)));
}
}
spec
}
Expand Down
43 changes: 28 additions & 15 deletions src/libfmt_macros/tests.rs
Expand Up @@ -2,7 +2,7 @@ use super::*;

fn same(fmt: &'static str, p: &[Piece<'static>]) {
let parser = Parser::new(fmt, None, vec![], false);
assert!(parser.collect::<Vec<Piece<'static>>>() == p);
assert_eq!(parser.collect::<Vec<Piece<'static>>>(), p);
}

fn fmtdflt() -> FormatSpec<'static> {
Expand All @@ -15,6 +15,7 @@ fn fmtdflt() -> FormatSpec<'static> {
precision_span: None,
width_span: None,
ty: "",
ty_span: None,
};
}

Expand Down Expand Up @@ -82,7 +83,7 @@ fn format_position_nothing_else() {
#[test]
fn format_type() {
same(
"{3:a}",
"{3:x}",
&[NextArgument(Argument {
position: ArgumentIs(3),
format: FormatSpec {
Expand All @@ -93,7 +94,8 @@ fn format_type() {
width: CountImplied,
precision_span: None,
width_span: None,
ty: "a",
ty: "x",
ty_span: None,
},
})]);
}
Expand All @@ -112,6 +114,7 @@ fn format_align_fill() {
precision_span: None,
width_span: None,
ty: "",
ty_span: None,
},
})]);
same(
Expand All @@ -127,6 +130,7 @@ fn format_align_fill() {
precision_span: None,
width_span: None,
ty: "",
ty_span: None,
},
})]);
same(
Expand All @@ -142,6 +146,7 @@ fn format_align_fill() {
precision_span: None,
width_span: None,
ty: "abcd",
ty_span: Some(InnerSpan::new(6, 10)),
},
})]);
}
Expand All @@ -150,7 +155,7 @@ fn format_counts() {
use syntax_pos::{GLOBALS, Globals, edition};
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
same(
"{:10s}",
"{:10x}",
&[NextArgument(Argument {
position: ArgumentImplicitlyIs(0),
format: FormatSpec {
Expand All @@ -161,11 +166,12 @@ fn format_counts() {
width: CountIs(10),
precision_span: None,
width_span: None,
ty: "s",
ty: "x",
ty_span: None,
},
})]);
same(
"{:10$.10s}",
"{:10$.10x}",
&[NextArgument(Argument {
position: ArgumentImplicitlyIs(0),
format: FormatSpec {
Expand All @@ -176,11 +182,12 @@ fn format_counts() {
width: CountIsParam(10),
precision_span: None,
width_span: Some(InnerSpan::new(3, 6)),
ty: "s",
ty: "x",
ty_span: None,
},
})]);
same(
"{:.*s}",
"{:.*x}",
&[NextArgument(Argument {
position: ArgumentImplicitlyIs(1),
format: FormatSpec {
Expand All @@ -191,11 +198,12 @@ fn format_counts() {
width: CountImplied,
precision_span: Some(InnerSpan::new(3, 5)),
width_span: None,
ty: "s",
ty: "x",
ty_span: None,
},
})]);
same(
"{:.10$s}",
"{:.10$x}",
&[NextArgument(Argument {
position: ArgumentImplicitlyIs(0),
format: FormatSpec {
Expand All @@ -206,11 +214,12 @@ fn format_counts() {
width: CountImplied,
precision_span: Some(InnerSpan::new(3, 7)),
width_span: None,
ty: "s",
ty: "x",
ty_span: None,
},
})]);
same(
"{:a$.b$s}",
"{:a$.b$?}",
&[NextArgument(Argument {
position: ArgumentImplicitlyIs(0),
format: FormatSpec {
Expand All @@ -221,7 +230,8 @@ fn format_counts() {
width: CountIsName(Symbol::intern("a")),
precision_span: None,
width_span: None,
ty: "s",
ty: "?",
ty_span: None,
},
})]);
});
Expand All @@ -241,6 +251,7 @@ fn format_flags() {
precision_span: None,
width_span: None,
ty: "",
ty_span: None,
},
})]);
same(
Expand All @@ -256,13 +267,14 @@ fn format_flags() {
precision_span: None,
width_span: None,
ty: "",
ty_span: None,
},
})]);
}
#[test]
fn format_mixture() {
same(
"abcd {3:a} efg",
"abcd {3:x} efg",
&[
String("abcd "),
NextArgument(Argument {
Expand All @@ -275,7 +287,8 @@ fn format_mixture() {
width: CountImplied,
precision_span: None,
width_span: None,
ty: "a",
ty: "x",
ty_span: None,
},
}),
String(" efg"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Expand Up @@ -93,7 +93,7 @@ rustc_queries! {
/// Maps DefId's that have an associated `mir::Body` to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet<mir::Local>) {
query mir_const_qualif(key: DefId) -> u8 {
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
}
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -2287,11 +2287,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
}
}
ObligationCauseCode::AssocTypeBound(impl_span, orig) => {
err.span_label(orig, "associated type defined here");
if let Some(sp) = impl_span {
ObligationCauseCode::AssocTypeBound(ref data) => {
err.span_label(data.original, "associated type defined here");
if let Some(sp) = data.impl_span {
err.span_label(sp, "in this `impl` item");
}
for sp in &data.bounds {
err.span_label(*sp, "restricted in this bound");
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/traits/mod.rs
Expand Up @@ -276,7 +276,14 @@ pub enum ObligationCauseCode<'tcx> {
/// #[feature(trivial_bounds)] is not enabled
TrivialBound,

AssocTypeBound(/*impl*/ Option<Span>, /*original*/ Span),
AssocTypeBound(Box<AssocTypeBoundData>),
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AssocTypeBoundData {
pub impl_span: Option<Span>,
pub original: Span,
pub bounds: Vec<Span>,
}

// `ObligationCauseCode` is used a lot. Make sure it doesn't unintentionally get bigger.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/structural_impls.rs
Expand Up @@ -549,7 +549,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::MethodReceiver => Some(super::MethodReceiver),
super::BlockTailExpression(id) => Some(super::BlockTailExpression(id)),
super::TrivialBound => Some(super::TrivialBound),
super::AssocTypeBound(impl_sp, sp) => Some(super::AssocTypeBound(impl_sp, sp)),
super::AssocTypeBound(ref data) => Some(super::AssocTypeBound(data.clone())),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/query/mod.rs
Expand Up @@ -42,7 +42,6 @@ use crate::util::common::ErrorReported;
use crate::util::profiling::ProfileCategory::*;

use rustc_data_structures::svh::Svh;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec;
use rustc_data_structures::fx::{FxIndexMap, FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::StableVec;
Expand Down

0 comments on commit 5a50275

Please sign in to comment.