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 #83964

Merged
merged 19 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a591d7a
Add strong_count mutation methods to Rc
mystor Mar 25, 2021
960b699
Do not emit the advanced diagnostics on macros
JohnTitor Mar 29, 2021
81f00c9
Trigger `unused_doc_comments` on macros at once
JohnTitor Apr 3, 2021
815de0e
Move a `unused_doc_comments ` test to the `unused` dir
JohnTitor Apr 3, 2021
32be124
Use AnonConst for asm! constants
Amanieu Apr 6, 2021
ee79f83
forbid `impl Trait` in generic param defaults
SNCPlay42 Apr 6, 2021
7f823e5
Add reborrow suggestion when mutable reference is moved in a for loop
SkiFire13 Apr 6, 2021
a775984
Add regression test
SkiFire13 Apr 6, 2021
b8dda53
Remove trailing `:` from E0119 message
estebank Apr 7, 2021
18cf44b
Do not ICE when closure is involved in TAIT
estebank Apr 7, 2021
4752a54
Disable using non-ascii identifiers in extern blocks.
crlf0710 Apr 6, 2021
505846e
Rollup merge of #83476 - mystor:rc_mutate_strong_count, r=m-ou-se
Dylan-DPC Apr 7, 2021
2c55bac
Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkor
Dylan-DPC Apr 7, 2021
4d5bb1c
Rollup merge of #83816 - JohnTitor:unused-doc-comments-on-macros, r=v…
Dylan-DPC Apr 7, 2021
b81c6cd
Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkov
Dylan-DPC Apr 7, 2021
d554385
Rollup merge of #83935 - SNCPlay42:param-default-impl-trait, r=varkor
Dylan-DPC Apr 7, 2021
9c688cd
Rollup merge of #83936 - crlf0710:disallow_extern_block_non_ascii, r=…
Dylan-DPC Apr 7, 2021
d7d42cc
Rollup merge of #83945 - SkiFire13:fix-83924, r=estebank
Dylan-DPC Apr 7, 2021
d82419b
Rollup merge of #83954 - estebank:issue-83613, r=varkor
Dylan-DPC Apr 7, 2021
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ pub enum InlineAsmOperand {
out_expr: Option<P<Expr>>,
},
Const {
expr: P<Expr>,
anon_const: AnonConst,
},
Sym {
expr: P<Expr>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,6 @@ pub fn noop_visit_expr<T: MutVisitor>(
match op {
InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
Expand All @@ -1265,6 +1264,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
vis.visit_expr(out_expr);
}
}
InlineAsmOperand::Const { anon_const, .. } => vis.visit_anon_const(anon_const),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
match op {
InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
Expand All @@ -848,6 +847,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
visitor.visit_expr(out_expr);
}
}
InlineAsmOperand::Const { anon_const, .. } => {
visitor.visit_anon_const(anon_const)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,9 +1411,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
}
}
InlineAsmOperand::Const { ref expr } => {
hir::InlineAsmOperand::Const { expr: self.lower_expr_mut(expr) }
}
InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const(anon_const),
},
InlineAsmOperand::Sym { ref expr } => {
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
}
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2259,13 +2259,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let kind = hir::GenericParamKind::Type {
default: default.as_ref().map(|x| {
self.lower_ty(
x,
ImplTraitContext::OtherOpaqueTy {
capturable_lifetimes: &mut FxHashSet::default(),
origin: hir::OpaqueTyOrigin::Misc,
},
)
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
}),
synthetic: param
.attrs
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,25 @@ impl<'a> AstValidator<'a> {
}
}

/// An item in `extern { ... }` cannot use non-ascii identifier.
fn check_foreign_item_ascii_only(&self, ident: Ident) {
let symbol_str = ident.as_str();
if !symbol_str.is_ascii() {
let n = 83942;
self.err_handler()
.struct_span_err(
ident.span,
"items in `extern` blocks cannot use non-ascii identifiers",
)
.span_label(self.current_extern_span(), "in this `extern` block")
.note(&format!(
"This limitation may be lifted in the future; see issue #{} <https://github.com/rust-lang/rust/issues/{}> for more information",
n, n,
))
.emit();
}
}

/// Reject C-varadic type unless the function is foreign,
/// or free and `unsafe extern "C"` semantically.
fn check_c_varadic_type(&self, fk: FnKind<'a>) {
Expand Down Expand Up @@ -592,7 +611,7 @@ impl<'a> AstValidator<'a> {
self.session,
ident.span,
E0754,
"trying to load file for module `{}` with non ascii identifer name",
"trying to load file for module `{}` with non-ascii identifier name",
ident.name
)
.help("consider using `#[path]` attribute to specify filesystem path")
Expand Down Expand Up @@ -1103,15 +1122,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.check_defaultness(fi.span, *def);
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
self.check_foreign_item_ascii_only(fi.ident);
}
ForeignItemKind::TyAlias(box TyAliasKind(def, generics, bounds, body)) => {
self.check_defaultness(fi.span, *def);
self.check_foreign_kind_bodyless(fi.ident, "type", body.as_ref().map(|b| b.span));
self.check_type_no_bounds(bounds, "`extern` blocks");
self.check_foreign_ty_genericless(generics);
self.check_foreign_item_ascii_only(fi.ident);
}
ForeignItemKind::Static(_, _, body) => {
self.check_foreign_kind_bodyless(fi.ident, "static", body.as_ref().map(|b| b.span));
self.check_foreign_item_ascii_only(fi.ident);
}
ForeignItemKind::MacCall(..) => {}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,10 @@ impl<'a> State<'a> {
None => s.word("_"),
}
}
InlineAsmOperand::Const { expr } => {
InlineAsmOperand::Const { anon_const } => {
s.word("const");
s.space();
s.print_expr(expr);
s.print_expr(&anon_const.value);
}
InlineAsmOperand::Sym { expr } => {
s.word("sym");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ fn parse_args<'a>(
ast::InlineAsmOperand::InOut { reg, expr, late: true }
}
} else if p.eat_keyword(kw::Const) {
let expr = p.parse_expr()?;
ast::InlineAsmOperand::Const { expr }
let anon_const = p.parse_anon_const_expr()?;
ast::InlineAsmOperand::Const { anon_const }
} else if p.eat_keyword(sym::sym) {
let expr = p.parse_expr()?;
match expr.kind {
Expand Down
64 changes: 30 additions & 34 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,41 +822,37 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
}
mir::InlineAsmOperand::Const { ref value } => {
if let mir::Operand::Constant(constant) = value {
let const_value = self
.eval_mir_constant(constant)
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
let ty = constant.ty();
let size = bx.layout_of(ty).size;
let scalar = match const_value {
ConstValue::Scalar(s) => s,
_ => span_bug!(
span,
"expected Scalar for promoted asm const, but got {:#?}",
const_value
),
};
let value = scalar.assert_bits(size);
let string = match ty.kind() {
ty::Uint(_) => value.to_string(),
ty::Int(int_ty) => {
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
ty::IntTy::I8 => (value as i8).to_string(),
ty::IntTy::I16 => (value as i16).to_string(),
ty::IntTy::I32 => (value as i32).to_string(),
ty::IntTy::I64 => (value as i64).to_string(),
ty::IntTy::I128 => (value as i128).to_string(),
ty::IntTy::Isize => unreachable!(),
}
let const_value = self
.eval_mir_constant(value)
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
let ty = value.ty();
let size = bx.layout_of(ty).size;
let scalar = match const_value {
ConstValue::Scalar(s) => s,
_ => span_bug!(
span,
"expected Scalar for promoted asm const, but got {:#?}",
const_value
),
};
let value = scalar.assert_bits(size);
let string = match ty.kind() {
ty::Uint(_) => value.to_string(),
ty::Int(int_ty) => {
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
ty::IntTy::I8 => (value as i8).to_string(),
ty::IntTy::I16 => (value as i16).to_string(),
ty::IntTy::I32 => (value as i32).to_string(),
ty::IntTy::I64 => (value as i64).to_string(),
ty::IntTy::I128 => (value as i128).to_string(),
ty::IntTy::Isize => unreachable!(),
}
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
_ => span_bug!(span, "asm const has bad type {}", ty),
};
InlineAsmOperandRef::Const { string }
} else {
span_bug!(span, "asm const is not a constant");
}
}
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
_ => span_bug!(span, "asm const has bad type {}", ty),
};
InlineAsmOperandRef::Const { string }
}
mir::InlineAsmOperand::SymFn { ref value } => {
let literal = self.monomorphize(value.literal);
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,13 +1067,23 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
// since they will not be detected after macro expansion.
fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
let features = self.cx.ecfg.features.unwrap();
for attr in attrs.iter() {
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_meta(&self.cx.sess.parse_sess, attr);

let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
span = Some(current_span);

if attrs.peek().map_or(false, |next_attr| next_attr.doc_str().is_some()) {
continue;
}

if attr.doc_str().is_some() {
self.cx.sess.parse_sess.buffer_lint_with_diagnostic(
&UNUSED_DOC_COMMENTS,
attr.span,
current_span,
ast::CRATE_NODE_ID,
"unused doc comment",
BuiltinLintDiagnostics::UnusedDocComment(attr.span),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ pub enum InlineAsmOperand<'hir> {
out_expr: Option<Expr<'hir>>,
},
Const {
expr: Expr<'hir>,
anon_const: AnonConst,
},
Sym {
expr: Expr<'hir>,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
match op {
InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
Expand All @@ -1202,6 +1201,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
visitor.visit_expr(out_expr);
}
}
InlineAsmOperand::Const { anon_const, .. } => {
visitor.visit_anon_const(anon_const)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,10 +1570,10 @@ impl<'a> State<'a> {
None => s.word("_"),
}
}
hir::InlineAsmOperand::Const { expr } => {
hir::InlineAsmOperand::Const { anon_const } => {
s.word("const");
s.space();
s.print_expr(expr);
s.print_anon_const(anon_const);
}
hir::InlineAsmOperand::Sym { expr } => {
s.word("sym");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
Some(sugared_span.map_or(attr.span, |span| span.with_hi(attr.span.hi())));
}

if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() {
if attrs.peek().map_or(false, |next_attr| next_attr.is_doc_comment()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ pub enum InlineAsmOperand<'tcx> {
out_place: Option<Place<'tcx>>,
},
Const {
value: Operand<'tcx>,
value: Box<Constant<'tcx>>,
},
SymFn {
value: Box<Constant<'tcx>>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ macro_rules! make_mir_visitor {
} => {
for op in operands {
match op {
InlineAsmOperand::In { value, .. }
| InlineAsmOperand::Const { value } => {
InlineAsmOperand::In { value, .. } => {
self.visit_operand(value, location);
}
InlineAsmOperand::Out { place, .. } => {
Expand All @@ -607,7 +606,8 @@ macro_rules! make_mir_visitor {
);
}
}
InlineAsmOperand::SymFn { value } => {
InlineAsmOperand::Const { value }
| InlineAsmOperand::SymFn { value } => {
self.visit_constant(value, location);
}
InlineAsmOperand::SymStatic { def_id: _ } => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

if let Some(DesugaringKind::ForLoop(_)) = move_span.desugaring_kind() {
let sess = self.infcx.tcx.sess;
if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
// If we have a `&mut` ref, we need to reborrow.
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
// If we are in a loop this will be suggested later.
if !is_loop_move {
err.span_suggestion_verbose(
move_span.shrink_to_lo(),
&format!(
"consider creating a fresh reborrow of {} here",
self.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(|| "the mutable reference".to_string()),
),
format!("&mut *"),
Applicability::MachineApplicable,
);
}
} else if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
err.span_suggestion(
move_span,
"consider borrowing to avoid moving into the for loop",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/borrow_check/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
} => {
for op in operands {
match *op {
InlineAsmOperand::In { reg: _, ref value }
| InlineAsmOperand::Const { ref value } => {
InlineAsmOperand::In { reg: _, ref value } => {
self.consume_operand(location, value);
}
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
Expand All @@ -219,7 +218,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
self.mutate_place(location, out_place, Shallow(None), JustWrite);
}
}
InlineAsmOperand::SymFn { value: _ }
InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
} => {
for op in operands {
match *op {
InlineAsmOperand::In { reg: _, ref value }
| InlineAsmOperand::Const { ref value } => {
InlineAsmOperand::In { reg: _, ref value } => {
self.consume_operand(loc, (value, span), flow_state);
}
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
Expand All @@ -761,7 +760,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
);
}
}
InlineAsmOperand::SymFn { value: _ }
InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {}
}
}
Expand Down
Loading