Skip to content

Commit 208ced6

Browse files
committed
Auto merge of rust-lang#92059 - matthiaskrgr:rollup-bainfyh, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#87901 (Fix suggestion of additional `pub` when using `pub pub fn ...`) - rust-lang#89090 (Lint bare traits in AstConv.) - rust-lang#91818 (Show the unused type for `unused_results` lint) - rust-lang#91910 (miri: lift restriction on extern types being the only field in a struct) - rust-lang#91928 (Constify (most) `Option` methods) - rust-lang#91975 (Move generator check earlier in inlining.) - rust-lang#92016 (builtin_macros: allow external consumers for AsmArgs parsing) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dde825d + fd445dd commit 208ced6

File tree

82 files changed

+1325
-520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1325
-520
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-45
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_data_structures::fx::FxHashSet;
4646
use rustc_data_structures::sorted_map::SortedMap;
4747
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4848
use rustc_data_structures::sync::Lrc;
49-
use rustc_errors::{struct_span_err, Applicability};
49+
use rustc_errors::struct_span_err;
5050
use rustc_hir as hir;
5151
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
5252
use rustc_hir::def_id::{DefId, DefPathHash, LocalDefId, CRATE_DEF_ID};
@@ -55,11 +55,9 @@ use rustc_hir::intravisit;
5555
use rustc_hir::{ConstArg, GenericArg, ParamName};
5656
use rustc_index::vec::{Idx, IndexVec};
5757
use rustc_query_system::ich::StableHashingContext;
58-
use rustc_session::lint::builtin::BARE_TRAIT_OBJECTS;
59-
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
58+
use rustc_session::lint::LintBuffer;
6059
use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
6160
use rustc_session::Session;
62-
use rustc_span::edition::Edition;
6361
use rustc_span::hygiene::ExpnId;
6462
use rustc_span::source_map::{respan, DesugaringKind};
6563
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1184,11 +1182,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11841182
) -> hir::Ty<'hir> {
11851183
let id = self.lower_node_id(t.id);
11861184
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
1187-
let ty = self.ty_path(id, t.span, qpath);
1188-
if let hir::TyKind::TraitObject(..) = ty.kind {
1189-
self.maybe_lint_bare_trait(t.span, t.id, qself.is_none() && path.is_global());
1190-
}
1191-
ty
1185+
self.ty_path(id, t.span, qpath)
11921186
}
11931187

11941188
fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
@@ -1285,9 +1279,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12851279
lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
12861280
(bounds, lifetime_bound)
12871281
});
1288-
if kind != TraitObjectSyntax::Dyn {
1289-
self.maybe_lint_bare_trait(t.span, t.id, false);
1290-
}
12911282
hir::TyKind::TraitObject(bounds, lifetime_bound, kind)
12921283
}
12931284
TyKind::ImplTrait(def_node_id, ref bounds) => {
@@ -2380,39 +2371,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23802371
name: hir::LifetimeName::Implicit(missing),
23812372
}
23822373
}
2383-
2384-
fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) {
2385-
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
2386-
// call site which do not have a macro backtrace. See #61963.
2387-
let is_macro_callsite = self
2388-
.sess
2389-
.source_map()
2390-
.span_to_snippet(span)
2391-
.map(|snippet| snippet.starts_with("#["))
2392-
.unwrap_or(true);
2393-
if !is_macro_callsite {
2394-
if span.edition() < Edition::Edition2021 {
2395-
self.resolver.lint_buffer().buffer_lint_with_diagnostic(
2396-
BARE_TRAIT_OBJECTS,
2397-
id,
2398-
span,
2399-
"trait objects without an explicit `dyn` are deprecated",
2400-
BuiltinLintDiagnostics::BareTraitObject(span, is_global),
2401-
)
2402-
} else {
2403-
let msg = "trait objects must include the `dyn` keyword";
2404-
let label = "add `dyn` keyword before this trait";
2405-
let mut err = struct_span_err!(self.sess, span, E0782, "{}", msg,);
2406-
err.span_suggestion_verbose(
2407-
span.shrink_to_lo(),
2408-
label,
2409-
String::from("dyn "),
2410-
Applicability::MachineApplicable,
2411-
);
2412-
err.emit();
2413-
}
2414-
}
2415-
}
24162374
}
24172375

24182376
/// Helper struct for delayed construction of GenericArgs.

compiler/rustc_builtin_macros/src/asm.rs

+43-29
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ use rustc_expand::base::{self, *};
88
use rustc_parse::parser::Parser;
99
use rustc_parse_format as parse;
1010
use rustc_session::lint;
11+
use rustc_session::parse::ParseSess;
1112
use rustc_span::symbol::Ident;
1213
use rustc_span::symbol::{kw, sym, Symbol};
1314
use rustc_span::{InnerSpan, Span};
1415
use rustc_target::asm::InlineAsmArch;
1516
use smallvec::smallvec;
1617

17-
struct AsmArgs {
18+
pub struct AsmArgs {
1819
templates: Vec<P<ast::Expr>>,
1920
operands: Vec<(ast::InlineAsmOperand, Span)>,
2021
named_args: FxHashMap<Symbol, usize>,
@@ -31,15 +32,28 @@ fn parse_args<'a>(
3132
is_global_asm: bool,
3233
) -> Result<AsmArgs, DiagnosticBuilder<'a>> {
3334
let mut p = ecx.new_parser_from_tts(tts);
35+
let sess = &ecx.sess.parse_sess;
36+
parse_asm_args(&mut p, sess, sp, is_global_asm)
37+
}
38+
39+
// Primarily public for rustfmt consumption.
40+
// Internal consumers should continue to leverage `expand_asm`/`expand__global_asm`
41+
pub fn parse_asm_args<'a>(
42+
p: &mut Parser<'a>,
43+
sess: &'a ParseSess,
44+
sp: Span,
45+
is_global_asm: bool,
46+
) -> Result<AsmArgs, DiagnosticBuilder<'a>> {
47+
let diag = &sess.span_diagnostic;
3448

3549
if p.token == token::Eof {
36-
return Err(ecx.struct_span_err(sp, "requires at least a template string argument"));
50+
return Err(diag.struct_span_err(sp, "requires at least a template string argument"));
3751
}
3852

3953
// Detect use of the legacy llvm_asm! syntax (which used to be called asm!)
4054
if !is_global_asm && p.look_ahead(1, |t| *t == token::Colon || *t == token::ModSep) {
4155
let mut err =
42-
ecx.struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported");
56+
diag.struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported");
4357
err.note("consider migrating to the new asm! syntax specified in RFC 2873");
4458
err.note("alternatively, switch to llvm_asm! to keep your code working as it is");
4559
return Err(err);
@@ -61,7 +75,7 @@ fn parse_args<'a>(
6175
if !p.eat(&token::Comma) {
6276
if allow_templates {
6377
// After a template string, we always expect *only* a comma...
64-
let mut err = ecx.struct_span_err(p.token.span, "expected token: `,`");
78+
let mut err = diag.struct_span_err(p.token.span, "expected token: `,`");
6579
err.span_label(p.token.span, "expected `,`");
6680
p.maybe_annotate_with_ascription(&mut err, false);
6781
return Err(err);
@@ -76,14 +90,14 @@ fn parse_args<'a>(
7690

7791
// Parse clobber_abi
7892
if p.eat_keyword(sym::clobber_abi) {
79-
parse_clobber_abi(&mut p, &mut args)?;
93+
parse_clobber_abi(p, &mut args)?;
8094
allow_templates = false;
8195
continue;
8296
}
8397

8498
// Parse options
8599
if p.eat_keyword(sym::options) {
86-
parse_options(&mut p, &mut args, is_global_asm)?;
100+
parse_options(p, &mut args, is_global_asm)?;
87101
allow_templates = false;
88102
continue;
89103
}
@@ -103,25 +117,25 @@ fn parse_args<'a>(
103117

104118
let mut explicit_reg = false;
105119
let op = if !is_global_asm && p.eat_keyword(kw::In) {
106-
let reg = parse_reg(&mut p, &mut explicit_reg)?;
120+
let reg = parse_reg(p, &mut explicit_reg)?;
107121
if p.eat_keyword(kw::Underscore) {
108-
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
122+
let err = diag.struct_span_err(p.token.span, "_ cannot be used for input operands");
109123
return Err(err);
110124
}
111125
let expr = p.parse_expr()?;
112126
ast::InlineAsmOperand::In { reg, expr }
113127
} else if !is_global_asm && p.eat_keyword(sym::out) {
114-
let reg = parse_reg(&mut p, &mut explicit_reg)?;
128+
let reg = parse_reg(p, &mut explicit_reg)?;
115129
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
116130
ast::InlineAsmOperand::Out { reg, expr, late: false }
117131
} else if !is_global_asm && p.eat_keyword(sym::lateout) {
118-
let reg = parse_reg(&mut p, &mut explicit_reg)?;
132+
let reg = parse_reg(p, &mut explicit_reg)?;
119133
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
120134
ast::InlineAsmOperand::Out { reg, expr, late: true }
121135
} else if !is_global_asm && p.eat_keyword(sym::inout) {
122-
let reg = parse_reg(&mut p, &mut explicit_reg)?;
136+
let reg = parse_reg(p, &mut explicit_reg)?;
123137
if p.eat_keyword(kw::Underscore) {
124-
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
138+
let err = diag.struct_span_err(p.token.span, "_ cannot be used for input operands");
125139
return Err(err);
126140
}
127141
let expr = p.parse_expr()?;
@@ -133,9 +147,9 @@ fn parse_args<'a>(
133147
ast::InlineAsmOperand::InOut { reg, expr, late: false }
134148
}
135149
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
136-
let reg = parse_reg(&mut p, &mut explicit_reg)?;
150+
let reg = parse_reg(p, &mut explicit_reg)?;
137151
if p.eat_keyword(kw::Underscore) {
138-
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
152+
let err = diag.struct_span_err(p.token.span, "_ cannot be used for input operands");
139153
return Err(err);
140154
}
141155
let expr = p.parse_expr()?;
@@ -154,7 +168,7 @@ fn parse_args<'a>(
154168
match expr.kind {
155169
ast::ExprKind::Path(..) => {}
156170
_ => {
157-
let err = ecx
171+
let err = diag
158172
.struct_span_err(expr.span, "argument to `sym` must be a path expression");
159173
return Err(err);
160174
}
@@ -173,7 +187,7 @@ fn parse_args<'a>(
173187
} else {
174188
"expected operand, clobber_abi, options, or additional template string"
175189
};
176-
let mut err = ecx.struct_span_err(template.span, errstr);
190+
let mut err = diag.struct_span_err(template.span, errstr);
177191
err.span_label(template.span, errstr);
178192
return Err(err);
179193
}
@@ -193,31 +207,31 @@ fn parse_args<'a>(
193207
// clobber_abi/options. We do this at the end once we have the full span
194208
// of the argument available.
195209
if !args.options_spans.is_empty() {
196-
ecx.struct_span_err(span, "arguments are not allowed after options")
210+
diag.struct_span_err(span, "arguments are not allowed after options")
197211
.span_labels(args.options_spans.clone(), "previous options")
198212
.span_label(span, "argument")
199213
.emit();
200214
} else if let Some((_, abi_span)) = args.clobber_abis.last() {
201-
ecx.struct_span_err(span, "arguments are not allowed after clobber_abi")
215+
diag.struct_span_err(span, "arguments are not allowed after clobber_abi")
202216
.span_label(*abi_span, "clobber_abi")
203217
.span_label(span, "argument")
204218
.emit();
205219
}
206220
if explicit_reg {
207221
if name.is_some() {
208-
ecx.struct_span_err(span, "explicit register arguments cannot have names").emit();
222+
diag.struct_span_err(span, "explicit register arguments cannot have names").emit();
209223
}
210224
args.reg_args.insert(slot);
211225
} else if let Some(name) = name {
212226
if let Some(&prev) = args.named_args.get(&name) {
213-
ecx.struct_span_err(span, &format!("duplicate argument named `{}`", name))
227+
diag.struct_span_err(span, &format!("duplicate argument named `{}`", name))
214228
.span_label(args.operands[prev].1, "previously here")
215229
.span_label(span, "duplicate argument")
216230
.emit();
217231
continue;
218232
}
219233
if !args.reg_args.is_empty() {
220-
let mut err = ecx.struct_span_err(
234+
let mut err = diag.struct_span_err(
221235
span,
222236
"named arguments cannot follow explicit register arguments",
223237
);
@@ -230,7 +244,7 @@ fn parse_args<'a>(
230244
args.named_args.insert(name, slot);
231245
} else {
232246
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
233-
let mut err = ecx.struct_span_err(
247+
let mut err = diag.struct_span_err(
234248
span,
235249
"positional arguments cannot follow named arguments \
236250
or explicit register arguments",
@@ -251,21 +265,21 @@ fn parse_args<'a>(
251265
&& args.options.contains(ast::InlineAsmOptions::READONLY)
252266
{
253267
let spans = args.options_spans.clone();
254-
ecx.struct_span_err(spans, "the `nomem` and `readonly` options are mutually exclusive")
268+
diag.struct_span_err(spans, "the `nomem` and `readonly` options are mutually exclusive")
255269
.emit();
256270
}
257271
if args.options.contains(ast::InlineAsmOptions::PURE)
258272
&& args.options.contains(ast::InlineAsmOptions::NORETURN)
259273
{
260274
let spans = args.options_spans.clone();
261-
ecx.struct_span_err(spans, "the `pure` and `noreturn` options are mutually exclusive")
275+
diag.struct_span_err(spans, "the `pure` and `noreturn` options are mutually exclusive")
262276
.emit();
263277
}
264278
if args.options.contains(ast::InlineAsmOptions::PURE)
265279
&& !args.options.intersects(ast::InlineAsmOptions::NOMEM | ast::InlineAsmOptions::READONLY)
266280
{
267281
let spans = args.options_spans.clone();
268-
ecx.struct_span_err(
282+
diag.struct_span_err(
269283
spans,
270284
"the `pure` option must be combined with either `nomem` or `readonly`",
271285
)
@@ -296,14 +310,14 @@ fn parse_args<'a>(
296310
}
297311
}
298312
if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output {
299-
ecx.struct_span_err(
313+
diag.struct_span_err(
300314
args.options_spans.clone(),
301315
"asm with the `pure` option must have at least one output",
302316
)
303317
.emit();
304318
}
305319
if args.options.contains(ast::InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() {
306-
let err = ecx
320+
let err = diag
307321
.struct_span_err(outputs_sp, "asm outputs are not allowed with the `noreturn` option");
308322

309323
// Bail out now since this is likely to confuse MIR
@@ -312,7 +326,7 @@ fn parse_args<'a>(
312326

313327
if args.clobber_abis.len() > 0 {
314328
if is_global_asm {
315-
let err = ecx.struct_span_err(
329+
let err = diag.struct_span_err(
316330
args.clobber_abis.iter().map(|(_, span)| *span).collect::<Vec<Span>>(),
317331
"`clobber_abi` cannot be used with `global_asm!`",
318332
);
@@ -321,7 +335,7 @@ fn parse_args<'a>(
321335
return Err(err);
322336
}
323337
if !regclass_outputs.is_empty() {
324-
ecx.struct_span_err(
338+
diag.struct_span_err(
325339
regclass_outputs.clone(),
326340
"asm with `clobber_abi` must specify explicit registers for outputs",
327341
)

compiler/rustc_const_eval/src/interpret/eval_context.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -616,19 +616,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
616616
match self.size_and_align_of(metadata, &field)? {
617617
Some(size_and_align) => size_and_align,
618618
None => {
619-
// A field with extern type. If this field is at offset 0, we behave
620-
// like the underlying extern type.
621-
// FIXME: Once we have made decisions for how to handle size and alignment
622-
// of `extern type`, this should be adapted. It is just a temporary hack
623-
// to get some code to work that probably ought to work.
624-
if sized_size == Size::ZERO {
625-
return Ok(None);
626-
} else {
627-
span_bug!(
628-
self.cur_span(),
629-
"Fields cannot be extern types, unless they are at offset 0"
630-
)
631-
}
619+
// A field with an extern type. We don't know the actual dynamic size
620+
// or the alignment.
621+
return Ok(None);
632622
}
633623
};
634624

compiler/rustc_const_eval/src/interpret/place.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,15 @@ where
362362
// Re-use parent metadata to determine dynamic field layout.
363363
// With custom DSTS, this *will* execute user-defined code, but the same
364364
// happens at run-time so that's okay.
365-
let align = match self.size_and_align_of(&base.meta, &field_layout)? {
366-
Some((_, align)) => align,
367-
None if offset == Size::ZERO => {
368-
// An extern type at offset 0, we fall back to its static alignment.
369-
// FIXME: Once we have made decisions for how to handle size and alignment
370-
// of `extern type`, this should be adapted. It is just a temporary hack
371-
// to get some code to work that probably ought to work.
372-
field_layout.align.abi
365+
match self.size_and_align_of(&base.meta, &field_layout)? {
366+
Some((_, align)) => (base.meta, offset.align_to(align)),
367+
None => {
368+
// For unsized types with an extern type tail we perform no adjustments.
369+
// NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend.
370+
assert!(matches!(base.meta, MemPlaceMeta::None));
371+
(base.meta, offset)
373372
}
374-
None => span_bug!(
375-
self.cur_span(),
376-
"cannot compute offset for extern type field at non-0 offset"
377-
),
378-
};
379-
(base.meta, offset.align_to(align))
373+
}
380374
} else {
381375
// base.meta could be present; we might be accessing a sized field of an unsized
382376
// struct.

compiler/rustc_lint/src/context.rs

-10
Original file line numberDiff line numberDiff line change
@@ -633,16 +633,6 @@ pub trait LintContext: Sized {
633633
}
634634
},
635635
BuiltinLintDiagnostics::Normal => (),
636-
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
637-
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
638-
Ok(s) if is_global => {
639-
(format!("dyn ({})", s), Applicability::MachineApplicable)
640-
}
641-
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
642-
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
643-
};
644-
db.span_suggestion(span, "use `dyn`", sugg, app);
645-
}
646636
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
647637
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
648638
Ok(ref s) => {

0 commit comments

Comments
 (0)