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 14 pull requests #78954

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d72d5f4
Dogfood Duration API in std::time tests
workingjubilee Oct 22, 2020
ef027a1
Duration::zero() -> Duration::ZERO
workingjubilee Oct 22, 2020
b989d46
Support enable/disable sanitizers/profiler per target
12101111 Oct 25, 2020
af4d178
Fixup tests: Duration::MIN -> ::ZERO
workingjubilee Oct 27, 2020
82f3a23
Remove Duration::MIN entirely
workingjubilee Oct 27, 2020
439171e
look at assoc ct, check the type of nodes
lcnr Nov 7, 2020
685fd53
BTreeMap: split off most code of append, slightly improve interfaces
ssomers Oct 26, 2020
ffa70d7
Support inlining diverging function calls
tmiasko Nov 9, 2020
3e012e2
add error_occured field to ConstQualifs, fix #76064
vn-ki Nov 6, 2020
b57fe64
fix tests and formatting
vn-ki Nov 6, 2020
26f0f12
Upgrading dlmalloc to 0.2.1
raoulstrackx Nov 9, 2020
b3fc46c
check mir exists before validation; fix tests
vn-ki Nov 9, 2020
c8943c6
Add flags customizing behaviour of MIR inlining
tmiasko Nov 10, 2020
0c56372
review comments
vn-ki Nov 10, 2020
03eec5c
Cleanup and comment intra-doc link pass
jyn514 Nov 10, 2020
ce91c68
rustc_taret: Remove `TargetOptions::is_like_android`
petrochenkov Nov 10, 2020
ca17a91
rustc_target: Move target env "gnu" from `linux_base` to `linux_gnu_b…
petrochenkov Nov 10, 2020
1854425
Fix typo in comment
eltociear Nov 11, 2020
de84ad9
Implement destructuring assignment for structs and slices
fanzier Nov 7, 2020
2453ce7
Ship llvm-cov through llvm-tools
dalance Nov 11, 2020
50cbd7b
Rollup merge of #78138 - fortanix:raoul/dlmalloc0.2, r=Mark-Simulacrum
jonas-schievink Nov 11, 2020
2446a26
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
jonas-schievink Nov 11, 2020
85c1193
Rollup merge of #78354 - 12101111:rustbuild_profiler, r=Mark-Simulacrum
jonas-schievink Nov 11, 2020
0ecd045
Rollup merge of #78417 - ssomers:btree_chop_up_2, r=Mark-Simulacrum
jonas-schievink Nov 11, 2020
052834f
Rollup merge of #78809 - vn-ki:fix-issue-76064, r=oli-obk
jonas-schievink Nov 11, 2020
49ffe3c
Rollup merge of #78832 - lcnr:const-evaluatable-unevaluated, r=oli-obk
jonas-schievink Nov 11, 2020
ce3f729
Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=pe…
jonas-schievink Nov 11, 2020
46bf94c
Rollup merge of #78873 - tmiasko:inline-opts, r=oli-obk
jonas-schievink Nov 11, 2020
84316e6
Rollup merge of #78899 - tmiasko:inline-diverging, r=oli-obk
jonas-schievink Nov 11, 2020
d7291c0
Rollup merge of #78923 - jyn514:intra-doc-comments, r=Manishearth
jonas-schievink Nov 11, 2020
7549d0d
Rollup merge of #78929 - petrochenkov:linuxbase, r=joshtriplett
jonas-schievink Nov 11, 2020
1acb5bb
Rollup merge of #78930 - petrochenkov:notlikeandroid, r=Mark-Simulacrum
jonas-schievink Nov 11, 2020
496ee33
Rollup merge of #78942 - eltociear:patch-1, r=jonas-schievink
jonas-schievink Nov 11, 2020
492d616
Rollup merge of #78947 - dalance:llvm_cov, r=Mark-Simulacrum
jonas-schievink Nov 11, 2020
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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ dependencies = [

[[package]]
name = "dlmalloc"
version = "0.1.4"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35055b1021724f4eb5262eb49130eebff23fc59fc5a14160e05faad8eeb36673"
checksum = "332570860c2edf2d57914987bf9e24835425f75825086b6ba7d1e6a3e4f1f254"
dependencies = [
"compiler_builtins",
"libc",
Expand Down
19 changes: 14 additions & 5 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ pub struct Expr {

// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(Expr, 112);
rustc_data_structures::static_assert_size!(Expr, 120);

impl Expr {
/// Returns `true` if this expression would be valid somewhere that expects a value;
Expand Down Expand Up @@ -1218,6 +1218,16 @@ pub enum RangeLimits {
Closed,
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub enum StructRest {
/// `..x`.
Base(P<Expr>),
/// `..`.
Rest(Span),
/// No trailing `..` or expression.
None,
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub enum ExprKind {
/// A `box x` expression.
Expand Down Expand Up @@ -1312,7 +1322,7 @@ pub enum ExprKind {
Field(P<Expr>, Ident),
/// An indexing operation (e.g., `foo[2]`).
Index(P<Expr>, P<Expr>),
/// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
/// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assingment).
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),

/// Variable reference, possibly containing `::` and/or type
Expand Down Expand Up @@ -1340,9 +1350,8 @@ pub enum ExprKind {

/// A struct literal expression.
///
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`,
/// where `base` is the `Option<Expr>`.
Struct(Path, Vec<Field>, Option<P<Expr>>),
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. rest}`.
Struct(Path, Vec<Field>, StructRest),

/// An array literal constructed from one repeated element.
///
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,11 @@ pub fn noop_visit_expr<T: MutVisitor>(
ExprKind::Struct(path, fields, expr) => {
vis.visit_path(path);
fields.flat_map_in_place(|field| vis.flat_map_field(field));
visit_opt(expr, |expr| vis.visit_expr(expr));
match expr {
StructRest::Base(expr) => vis.visit_expr(expr),
StructRest::Rest(_span) => {}
StructRest::None => {}
}
}
ExprKind::Paren(expr) => {
vis.visit_expr(expr);
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
ExprKind::Struct(ref path, ref fields, ref optional_base) => {
visitor.visit_path(path, expression.id);
walk_list!(visitor, visit_field, fields);
walk_list!(visitor, visit_expr, optional_base);
match optional_base {
StructRest::Base(expr) => visitor.visit_expr(expr),
StructRest::Rest(_span) => {}
StructRest::None => {}
}
}
ExprKind::Tup(ref subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions);
Expand Down
126 changes: 119 additions & 7 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(e.span, asm),
ExprKind::LlvmInlineAsm(ref asm) => self.lower_expr_llvm_asm(asm),
ExprKind::Struct(ref path, ref fields, ref maybe_expr) => {
let maybe_expr = maybe_expr.as_ref().map(|x| self.lower_expr(x));
ExprKind::Struct(ref path, ref fields, ref rest) => {
let rest = match rest {
StructRest::Base(e) => Some(self.lower_expr(e)),
StructRest::Rest(sp) => {
self.sess
.struct_span_err(*sp, "base expression required after `..`")
.span_label(*sp, "add a base expression here")
.emit();
Some(&*self.arena.alloc(self.expr_err(*sp)))
}
StructRest::None => None,
};
hir::ExprKind::Struct(
self.arena.alloc(self.lower_qpath(
e.id,
Expand All @@ -198,7 +208,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::disallowed(),
)),
self.arena.alloc_from_iter(fields.iter().map(|x| self.lower_field(x))),
maybe_expr,
rest,
)
}
ExprKind::Yield(ref opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
Expand Down Expand Up @@ -851,20 +861,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
whole_span: Span,
) -> hir::ExprKind<'hir> {
// Return early in case of an ordinary assignment.
fn is_ordinary(lhs: &Expr) -> bool {
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
match &lhs.kind {
ExprKind::Tup(..) => false,
ExprKind::Array(..) | ExprKind::Struct(..) | ExprKind::Tup(..) => false,
// Check for tuple struct constructor.
ExprKind::Call(callee, ..) => lower_ctx.extract_tuple_struct_path(callee).is_none(),
ExprKind::Paren(e) => {
match e.kind {
// We special-case `(..)` for consistency with patterns.
ExprKind::Range(None, None, RangeLimits::HalfOpen) => false,
_ => is_ordinary(e),
_ => is_ordinary(lower_ctx, e),
}
}
_ => true,
}
}
if is_ordinary(lhs) {
if is_ordinary(self, lhs) {
return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span);
}
if !self.sess.features_untracked().destructuring_assignment {
Expand Down Expand Up @@ -902,6 +914,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::Block(&self.block_all(whole_span, stmts, None), None)
}

/// If the given expression is a path to a tuple struct, returns that path.
/// It is not a complete check, but just tries to reject most paths early
/// if they are not tuple structs.
/// Type checking will take care of the full validation later.
fn extract_tuple_struct_path<'a>(&mut self, expr: &'a Expr) -> Option<&'a Path> {
// For tuple struct destructuring, it must be a non-qualified path (like in patterns).
if let ExprKind::Path(None, path) = &expr.kind {
// Does the path resolves to something disallowed in a tuple struct/variant pattern?
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
if partial_res.unresolved_segments() == 0
&& !partial_res.base_res().expected_in_tuple_struct_pat()
{
return None;
}
}
return Some(path);
}
None
}

/// Convert the LHS of a destructuring assignment to a pattern.
/// Each sub-assignment is recorded in `assignments`.
fn destructure_assign(
Expand All @@ -911,6 +943,86 @@ impl<'hir> LoweringContext<'_, 'hir> {
assignments: &mut Vec<hir::Stmt<'hir>>,
) -> &'hir hir::Pat<'hir> {
match &lhs.kind {
// Slice patterns.
ExprKind::Array(elements) => {
let (pats, rest) =
self.destructure_sequence(elements, "slice", eq_sign_span, assignments);
let slice_pat = if let Some((i, span)) = rest {
let (before, after) = pats.split_at(i);
hir::PatKind::Slice(
before,
Some(self.pat_without_dbm(span, hir::PatKind::Wild)),
after,
)
} else {
hir::PatKind::Slice(pats, None, &[])
};
return self.pat_without_dbm(lhs.span, slice_pat);
}
// Tuple structs.
ExprKind::Call(callee, args) => {
if let Some(path) = self.extract_tuple_struct_path(callee) {
let (pats, rest) = self.destructure_sequence(
args,
"tuple struct or variant",
eq_sign_span,
assignments,
);
let qpath = self.lower_qpath(
callee.id,
&None,
path,
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
// Destructure like a tuple struct.
let tuple_struct_pat =
hir::PatKind::TupleStruct(qpath, pats, rest.map(|r| r.0));
return self.pat_without_dbm(lhs.span, tuple_struct_pat);
}
}
// Structs.
ExprKind::Struct(path, fields, rest) => {
let field_pats = self.arena.alloc_from_iter(fields.iter().map(|f| {
let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments);
hir::FieldPat {
hir_id: self.next_id(),
ident: f.ident,
pat,
is_shorthand: f.is_shorthand,
span: f.span,
}
}));
let qpath = self.lower_qpath(
lhs.id,
&None,
path,
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
let fields_omitted = match rest {
StructRest::Base(e) => {
self.sess
.struct_span_err(
e.span,
"functional record updates are not allowed in destructuring \
assignments",
)
.span_suggestion(
e.span,
"consider removing the trailing pattern",
String::new(),
rustc_errors::Applicability::MachineApplicable,
)
.emit();
true
}
StructRest::Rest(_) => true,
StructRest::None => false,
};
let struct_pat = hir::PatKind::Struct(qpath, field_pats, fields_omitted);
return self.pat_without_dbm(lhs.span, struct_pat);
}
// Tuples.
ExprKind::Tup(elements) => {
let (pats, rest) =
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(inline_const, "inline-const is experimental");
gate_all!(destructuring_assignment, "destructuring assignments are unstable");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ impl<'a> State<'a> {
&mut self,
path: &ast::Path,
fields: &[ast::Field],
wth: &Option<P<ast::Expr>>,
rest: &ast::StructRest,
attrs: &[ast::Attribute],
) {
self.print_path(path, true, 0);
Expand All @@ -1750,22 +1750,21 @@ impl<'a> State<'a> {
},
|f| f.span,
);
match *wth {
Some(ref expr) => {
match rest {
ast::StructRest::Base(_) | ast::StructRest::Rest(_) => {
self.ibox(INDENT_UNIT);
if !fields.is_empty() {
self.s.word(",");
self.s.space();
}
self.s.word("..");
self.print_expr(expr);
self.end();
}
_ => {
if !fields.is_empty() {
self.s.word(",")
if let ast::StructRest::Base(ref expr) = *rest {
self.print_expr(expr);
}
self.end();
}
ast::StructRest::None if !fields.is_empty() => self.s.word(","),
_ => {}
}
self.s.word("}");
}
Expand Down Expand Up @@ -1891,8 +1890,8 @@ impl<'a> State<'a> {
ast::ExprKind::Repeat(ref element, ref count) => {
self.print_expr_repeat(element, count, attrs);
}
ast::ExprKind::Struct(ref path, ref fields, ref wth) => {
self.print_expr_struct(path, &fields[..], wth, attrs);
ast::ExprKind::Struct(ref path, ref fields, ref rest) => {
self.print_expr_struct(path, &fields[..], rest, attrs);
}
ast::ExprKind::Tup(ref exprs) => {
self.print_expr_tup(&exprs[..], attrs);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'a> ExtCtxt<'a> {
path: ast::Path,
fields: Vec<ast::Field>,
) -> P<ast::Expr> {
self.expr(span, ast::ExprKind::Struct(path, fields, None))
self.expr(span, ast::ExprKind::Struct(path, fields, ast::StructRest::None))
}
pub fn expr_struct_ident(
&self,
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,9 @@ impl<Id> Res<Id> {
pub fn matches_ns(&self, ns: Namespace) -> bool {
self.ns().map_or(true, |actual_ns| actual_ns == ns)
}

/// Returns whether such a resolved path can occur in a tuple struct/variant pattern
pub fn expected_in_tuple_struct_pat(&self) -> bool {
matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..))
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ fn test_debugging_options_tracking_hash() {
tracked!(function_sections, Some(false));
tracked!(human_readable_cgu_names, true);
tracked!(inline_in_all_cgus, Some(true));
tracked!(inline_mir_threshold, 123);
tracked!(inline_mir_hint_threshold, 123);
tracked!(insert_sideeffect, true);
tracked!(instrument_coverage, true);
tracked!(instrument_mcount, true);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,15 @@ pub struct BorrowCheckResult<'tcx> {

/// The result of the `mir_const_qualif` query.
///
/// Each field corresponds to an implementer of the `Qualif` trait in
/// `librustc_mir/transform/check_consts/qualifs.rs`. See that file for more information on each
/// Each field (except `error_occured`) corresponds to an implementer of the `Qualif` trait in
/// `rustc_mir/src/transform/check_consts/qualifs.rs`. See that file for more information on each
/// `Qualif`.
#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
pub struct ConstQualifs {
pub has_mut_interior: bool,
pub needs_drop: bool,
pub custom_eq: bool,
pub error_occured: Option<ErrorReported>,
}

/// After we borrow check a closure, we are left with various
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_mir/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::interpret::{
ScalarMaybeUninit, StackPopCleanup,
};

use rustc_errors::ErrorReported;
use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
Expand Down Expand Up @@ -274,6 +275,16 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
return Err(ErrorHandled::Reported(error_reported));
}
}
if !tcx.is_mir_available(def.did) {
tcx.sess.delay_span_bug(
tcx.def_span(def.did),
&format!("no MIR body is available for {:?}", def.did),
);
return Err(ErrorHandled::Reported(ErrorReported {}));
}
if let Some(error_reported) = tcx.mir_const_qualif_opt_const_arg(def).error_occured {
return Err(ErrorHandled::Reported(error_reported));
}
}

let is_static = tcx.is_static(def.did);
Expand Down
Loading