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 16 pull requests #77366

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2ad46ac
EarlyOtherwiseBranch::run_pass(): don't convert Place to Place (clipp…
matthiaskrgr Sep 21, 2020
d7a5c57
use std::mem::take(x) instead of std::mem::replace(x, Default::defaul…
matthiaskrgr Sep 21, 2020
6d0390c
Add regression test
JulianKnodt Sep 2, 2020
3e485d7
BTreeMap: keep an eye out on the size of the main components
ssomers Sep 26, 2020
37f7956
libary: Forward compiler-builtins "mem" feature
josephlr Sep 28, 2020
db5b70f
move candidate_from_obligation_no_cache
lcnr Sep 28, 2020
63bb51d
Add unstable book docs for `-Zunsound-mir-opts`
wesleywiser Sep 29, 2020
c6107c5
Don't fire `const_item_mutation` lint on writes through a pointer
Aaron1011 Sep 29, 2020
a2526b4
Use `rtassert!` instead of `assert!` from the child process after for…
Sep 29, 2020
9340ee4
Ensure that all LLVM components requested by tests are available on CI
petrochenkov Sep 27, 2020
2c38504
Add test for async/await combined with const-generics.
hameerabbasi Sep 29, 2020
b141e49
Fix typo in alloc vec comment
pickfire Sep 29, 2020
f9b625f
Alloc vec use imported path
pickfire Sep 29, 2020
f4d5275
Update books
ehuss Sep 29, 2020
93e3db3
liveness: Use Option::None to represent absent live nodes
tmiasko Sep 30, 2020
607d30d
Add test for issue #74761
samlich Sep 29, 2020
609786d
Validate `rustc_args_required_const`
varkor Sep 29, 2020
5c20326
Rollup merge of #76257 - JulianKnodt:i75777, r=Dylan-DPC
jonas-schievink Sep 30, 2020
277da4b
Rollup merge of #77037 - matthiaskrgr:cl42ppy, r=Dylan-DPC
jonas-schievink Sep 30, 2020
d2f3329
Rollup merge of #77233 - ssomers:btree_size_matters, r=Mark-Simulacrum
jonas-schievink Sep 30, 2020
ca6ba02
Rollup merge of #77280 - petrochenkov:llvmcomp, r=Mark-Simulacrum
jonas-schievink Sep 30, 2020
2edc7a3
Rollup merge of #77284 - josephlr:mem, r=Mark-Simulacrum
jonas-schievink Sep 30, 2020
dba0930
Rollup merge of #77296 - tmiasko:liveness-option, r=ecstatic-morse
jonas-schievink Sep 30, 2020
a489686
Rollup merge of #77305 - lcnr:candidate_from_obligation, r=davidtwco
jonas-schievink Sep 30, 2020
87c438e
Rollup merge of #77322 - rust-lang:wesleywiser-patch-1, r=steveklabnik
jonas-schievink Sep 30, 2020
840be97
Rollup merge of #77324 - Aaron1011:fix/const-item-mutation-ptr, r=pet…
jonas-schievink Sep 30, 2020
f007b5a
Rollup merge of #77328 - hyd-dev:assert-to-rtassert, r=Amanieu
jonas-schievink Sep 30, 2020
fa8b401
Rollup merge of #77331 - hameerabbasi:issue-74906, r=lcnr
jonas-schievink Sep 30, 2020
2bd5dd8
Rollup merge of #77338 - pickfire:patch-7, r=jyn514
jonas-schievink Sep 30, 2020
d9284c2
Rollup merge of #77340 - pickfire:patch-9, r=kennytm
jonas-schievink Sep 30, 2020
f19a5e7
Rollup merge of #77343 - varkor:rustc_args_required_const-validation,…
jonas-schievink Sep 30, 2020
1e7e3eb
Rollup merge of #77345 - samlich:test-issue-74761, r=lcnr
jonas-schievink Sep 30, 2020
71e4b21
Rollup merge of #77348 - ehuss:update-books, r=ehuss
jonas-schievink Sep 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
// `self.constraints`, but we also want to be mutating
// `self.member_constraints`. For now, just swap out the value
// we want and replace at the end.
let mut tmp =
std::mem::replace(&mut self.constraints.member_constraints, Default::default());
let mut tmp = std::mem::take(&mut self.constraints.member_constraints);
for member_constraint in member_constraints {
tmp.push_constraint(member_constraint, |r| self.to_region_vid(r));
}
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_mir/src/transform/check_const_item_mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
// so emitting a lint would be redundant.
if !lhs.projection.is_empty() {
if let Some(def_id) = self.is_const_item(lhs.local) {
self.lint_const_item_usage(def_id, loc, |lint| {
let mut lint = lint.build("attempting to modify a `const` item");
lint.note("each usage of a `const` item creates a new temporary - the original `const` item will not be modified");
lint
})
// Don't lint on writes through a pointer
// (e.g. `unsafe { *FOO = 0; *BAR.field = 1; }`)
if !matches!(lhs.projection.last(), Some(PlaceElem::Deref)) {
self.lint_const_item_usage(def_id, loc, |lint| {
let mut lint = lint.build("attempting to modify a `const` item");
lint.note("each usage of a `const` item creates a new temporary - the original `const` item will not be modified");
lint
})
}
}
}
// We are looking for MIR of the form:
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
let not_equal_rvalue = Rvalue::BinaryOp(
not_equal,
Operand::Copy(Place::from(second_discriminant_temp)),
Operand::Copy(Place::from(first_descriminant_place)),
Operand::Copy(first_descriminant_place),
);
patch.add_statement(
end_of_block_location,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
LitKind::Int(a, _) => {
ret.push(a as usize);
}
_ => return None,
_ => bug!("invalid arg index"),
}
}
Some(ret)
Expand Down
110 changes: 101 additions & 9 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use rustc_middle::hir::map::Map;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;

use rustc_ast::{Attribute, NestedMetaItem};
use rustc_errors::struct_span_err;
use rustc_ast::{Attribute, LitKind, NestedMetaItem};
use rustc_errors::{pluralize, struct_span_err};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem};
use rustc_hir::{MethodKind, Target};
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use rustc_session::parse::feature_err;
Expand Down Expand Up @@ -43,6 +43,12 @@ pub(crate) fn target_from_impl_item<'tcx>(
}
}

#[derive(Clone, Copy)]
enum ItemLike<'tcx> {
Item(&'tcx Item<'tcx>),
ForeignItem(&'tcx ForeignItem<'tcx>),
}

struct CheckAttrVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
}
Expand All @@ -55,7 +61,7 @@ impl CheckAttrVisitor<'tcx> {
attrs: &'hir [Attribute],
span: &Span,
target: Target,
item: Option<&Item<'_>>,
item: Option<ItemLike<'_>>,
) {
let mut is_valid = true;
for attr in attrs {
Expand All @@ -75,6 +81,8 @@ impl CheckAttrVisitor<'tcx> {
self.check_no_link(&attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::export_name) {
self.check_export_name(&attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::rustc_args_required_const) {
self.check_rustc_args_required_const(&attr, span, target, item)
} else {
// lint-only checks
if self.tcx.sess.check_name(attr, sym::cold) {
Expand Down Expand Up @@ -400,6 +408,71 @@ impl CheckAttrVisitor<'tcx> {
}
}

/// Checks if `#[rustc_args_required_const]` is applied to a function and has a valid argument.
fn check_rustc_args_required_const(
&self,
attr: &Attribute,
span: &Span,
target: Target,
item: Option<ItemLike<'_>>,
) -> bool {
if let Target::Fn | Target::Method(..) | Target::ForeignFn = target {
let mut invalid_args = vec![];
for meta in attr.meta_item_list().expect("no meta item list") {
if let Some(LitKind::Int(val, _)) = meta.literal().map(|lit| &lit.kind) {
if let Some(ItemLike::Item(Item {
kind: ItemKind::Fn(FnSig { decl, .. }, ..),
..
}))
| Some(ItemLike::ForeignItem(ForeignItem {
kind: ForeignItemKind::Fn(decl, ..),
..
})) = item
{
let arg_count = decl.inputs.len() as u128;
if *val >= arg_count {
let span = meta.span();
self.tcx
.sess
.struct_span_err(span, "index exceeds number of arguments")
.span_label(
span,
format!(
"there {} only {} argument{}",
if arg_count != 1 { "are" } else { "is" },
arg_count,
pluralize!(arg_count)
),
)
.emit();
return false;
}
} else {
bug!("should be a function item");
}
} else {
invalid_args.push(meta.span());
}
}
if !invalid_args.is_empty() {
self.tcx
.sess
.struct_span_err(invalid_args, "arguments should be non-negative integers")
.emit();
false
} else {
true
}
} else {
self.tcx
.sess
.struct_span_err(attr.span, "attribute should be applied to a function")
.span_label(*span, "not a function")
.emit();
false
}
}

/// Checks if `#[link_section]` is applied to a function or static.
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
match target {
Expand Down Expand Up @@ -448,7 +521,7 @@ impl CheckAttrVisitor<'tcx> {
attrs: &'hir [Attribute],
span: &Span,
target: Target,
item: Option<&Item<'_>>,
item: Option<ItemLike<'_>>,
hir_id: HirId,
) {
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
Expand Down Expand Up @@ -564,7 +637,14 @@ impl CheckAttrVisitor<'tcx> {
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
if (int_reprs > 1)
|| (is_simd && is_c)
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
|| (int_reprs == 1
&& is_c
&& item.map_or(false, |item| {
if let ItemLike::Item(item) = item {
return is_c_like_enum(item);
}
return false;
}))
{
self.tcx.struct_span_lint_hir(
CONFLICTING_REPR_HINTS,
Expand Down Expand Up @@ -649,7 +729,13 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {

fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let target = Target::from_item(item);
self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item));
self.check_attributes(
item.hir_id,
item.attrs,
&item.span,
target,
Some(ItemLike::Item(item)),
);
intravisit::walk_item(self, item)
}

Expand All @@ -659,9 +745,15 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
intravisit::walk_trait_item(self, trait_item)
}

fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) {
fn visit_foreign_item(&mut self, f_item: &'tcx ForeignItem<'tcx>) {
let target = Target::from_foreign_item(f_item);
self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None);
self.check_attributes(
f_item.hir_id,
&f_item.attrs,
&f_item.span,
target,
Some(ItemLike::ForeignItem(f_item)),
);
intravisit::walk_foreign_item(self, f_item)
}

Expand Down
Loading