Skip to content

Commit f241c0c

Browse files
committed
Auto merge of #100708 - matthiaskrgr:rollup-vl0olnj, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #97962 (Make must_not_suspend lint see through references when drop tracking is enabled) - #99966 (avoid assertion failures in try_to_scalar_int) - #100637 (Improving Fuchsia rustc support documentation) - #100643 (Point at a type parameter shadowing another type) - #100651 (Migrations for rustc_expand transcribe.rs) - #100669 (Attribute cleanups) - #100670 (Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_recovery) - #100674 (Migrate lint reports in typeck::check_unused to LintDiagnostic) - #100688 (`ty::Error` does not match other types for region constraints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9c20b2a + c7a4942 commit f241c0c

File tree

39 files changed

+314
-102
lines changed

39 files changed

+314
-102
lines changed

compiler/rustc_builtin_macros/src/deriving/bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub fn expand_deriving_copy(
1515
) {
1616
let trait_def = TraitDef {
1717
span,
18-
attributes: Vec::new(),
1918
path: path_std!(marker::Copy),
2019
additional_bounds: Vec::new(),
2120
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/clone.rs

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ pub fn expand_deriving_clone(
7171
let attrs = vec![cx.attribute(inline)];
7272
let trait_def = TraitDef {
7373
span,
74-
attributes: Vec::new(),
7574
path: path_std!(clone::Clone),
7675
additional_bounds: bounds,
7776
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub fn expand_deriving_eq(
2323
let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)];
2424
let trait_def = TraitDef {
2525
span,
26-
attributes: Vec::new(),
2726
path: path_std!(cmp::Eq),
2827
additional_bounds: Vec::new(),
2928
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub fn expand_deriving_ord(
1818
let attrs = vec![cx.attribute(inline)];
1919
let trait_def = TraitDef {
2020
span,
21-
attributes: Vec::new(),
2221
path: path_std!(cmp::Ord),
2322
additional_bounds: Vec::new(),
2423
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub fn expand_deriving_partial_eq(
9898

9999
let trait_def = TraitDef {
100100
span,
101-
attributes: Vec::new(),
102101
path: path_std!(cmp::PartialEq),
103102
additional_bounds: Vec::new(),
104103
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub fn expand_deriving_partial_ord(
3636

3737
let trait_def = TraitDef {
3838
span,
39-
attributes: vec![],
4039
path: path_std!(cmp::PartialOrd),
4140
additional_bounds: vec![],
4241
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/debug.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn expand_deriving_debug(
1919

2020
let trait_def = TraitDef {
2121
span,
22-
attributes: Vec::new(),
2322
path: path_std!(fmt::Debug),
2423
additional_bounds: Vec::new(),
2524
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/decodable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub fn expand_deriving_rustc_decodable(
2222

2323
let trait_def = TraitDef {
2424
span,
25-
attributes: Vec::new(),
2625
path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
2726
additional_bounds: Vec::new(),
2827
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/default.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub fn expand_deriving_default(
2525
let attrs = vec![cx.attribute(inline)];
2626
let trait_def = TraitDef {
2727
span,
28-
attributes: Vec::new(),
2928
path: Path::new(vec![kw::Default, sym::Default]),
3029
additional_bounds: Vec::new(),
3130
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/encodable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ pub fn expand_deriving_rustc_encodable(
106106

107107
let trait_def = TraitDef {
108108
span,
109-
attributes: Vec::new(),
110109
path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
111110
additional_bounds: Vec::new(),
112111
generics: Bounds::empty(),

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ pub struct TraitDef<'a> {
184184
/// The span for the current #[derive(Foo)] header.
185185
pub span: Span,
186186

187-
pub attributes: Vec<ast::Attribute>,
188-
189187
/// Path of the trait, including any type parameters
190188
pub path: Path,
191189

@@ -605,7 +603,7 @@ impl<'a> TraitDef<'a> {
605603
param.bounds.iter().cloned()
606604
).collect();
607605

608-
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, vec![], bounds, None)
606+
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
609607
}
610608
GenericParamKind::Const { ty, kw_span, .. } => {
611609
let const_nodefault_kind = GenericParamKind::Const {
@@ -718,15 +716,13 @@ impl<'a> TraitDef<'a> {
718716
let self_type = cx.ty_path(path);
719717

720718
let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
719+
let attrs = vec![attr];
721720
let opt_trait_ref = Some(trait_ref);
722721

723-
let mut a = vec![attr];
724-
a.extend(self.attributes.iter().cloned());
725-
726722
cx.item(
727723
self.span,
728724
Ident::empty(),
729-
a,
725+
attrs,
730726
ast::ItemKind::Impl(Box::new(ast::Impl {
731727
unsafety: ast::Unsafe::No,
732728
polarity: ast::ImplPolarity::Positive,

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ fn mk_ty_param(
146146
cx: &ExtCtxt<'_>,
147147
span: Span,
148148
name: Symbol,
149-
attrs: &[ast::Attribute],
150149
bounds: &[Path],
151150
self_ident: Ident,
152151
self_generics: &Generics,
@@ -158,7 +157,7 @@ fn mk_ty_param(
158157
cx.trait_bound(path)
159158
})
160159
.collect();
161-
cx.typaram(span, Ident::new(name, span), attrs.to_owned(), bounds, None)
160+
cx.typaram(span, Ident::new(name, span), bounds, None)
162161
}
163162

164163
/// Bounds on type parameters.
@@ -183,7 +182,7 @@ impl Bounds {
183182
.iter()
184183
.map(|t| {
185184
let (name, ref bounds) = *t;
186-
mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics)
185+
mk_ty_param(cx, span, name, &bounds, self_ty, self_generics)
187186
})
188187
.collect();
189188

compiler/rustc_builtin_macros/src/deriving/hash.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn expand_deriving_hash(
2121
let arg = Path::new_local(typaram);
2222
let hash_trait_def = TraitDef {
2323
span,
24-
attributes: Vec::new(),
2524
path,
2625
additional_bounds: Vec::new(),
2726
generics: Bounds::empty(),

compiler/rustc_error_messages/locales/en-US/expand.ftl

+17
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,20 @@ expand_explain_doc_comment_outer =
33
44
expand_explain_doc_comment_inner =
55
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
6+
7+
expand_expr_repeat_no_syntax_vars =
8+
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
9+
10+
expand_must_repeat_once =
11+
this must repeat at least once
12+
13+
expand_count_repetition_misplaced =
14+
`count` can not be placed inside the inner-most repetition
15+
16+
expand_meta_var_expr_unrecognized_var =
17+
variable `{$key}` is not recognized in meta-variable expression
18+
19+
expand_var_still_repeating =
20+
variable '{$ident}' is still repeating at this depth
21+
22+
expand_meta_var_dif_seq_matchers = {$msg}

compiler/rustc_error_messages/locales/en-US/typeck.ftl

+8
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,11 @@ typeck_manual_implementation =
123123
.help = add `#![feature(unboxed_closures)]` to the crate attributes to enable
124124
125125
typeck_substs_on_overridden_impl = could not resolve substs on overridden impl
126+
127+
typeck_unused_extern_crate =
128+
unused extern crate
129+
.suggestion = remove it
130+
131+
typeck_extern_crate_not_idiomatic =
132+
`extern crate` is not idiomatic in the new edition
133+
.suggestion = convert it to a `{$msg_code}`

compiler/rustc_errors/src/diagnostic.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
88
use rustc_hir as hir;
99
use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_span::edition::LATEST_STABLE_EDITION;
11-
use rustc_span::symbol::{Ident, Symbol};
11+
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1212
use rustc_span::{edition::Edition, Span, DUMMY_SP};
1313
use std::borrow::Cow;
1414
use std::fmt;
@@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!(
8787
hir::Target,
8888
Edition,
8989
Ident,
90+
MacroRulesNormalizedIdent,
9091
);
9192

9293
impl IntoDiagnosticArg for bool {

compiler/rustc_expand/src/build.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ impl<'a> ExtCtxt<'a> {
107107
&self,
108108
span: Span,
109109
ident: Ident,
110-
attrs: Vec<ast::Attribute>,
111110
bounds: ast::GenericBounds,
112111
default: Option<P<ast::Ty>>,
113112
) -> ast::GenericParam {
114113
ast::GenericParam {
115114
ident: ident.with_span_pos(span),
116115
id: ast::DUMMY_NODE_ID,
117-
attrs: attrs.into(),
116+
attrs: AttrVec::new(),
118117
bounds,
119118
kind: ast::GenericParamKind::Type { default },
120119
is_placeholder: false,

compiler/rustc_expand/src/errors.rs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::symbol::MacroRulesNormalizedIdent;
3+
use rustc_span::Span;
4+
5+
#[derive(SessionDiagnostic)]
6+
#[error(expand::expr_repeat_no_syntax_vars)]
7+
pub(crate) struct NoSyntaxVarsExprRepeat {
8+
#[primary_span]
9+
pub span: Span,
10+
}
11+
12+
#[derive(SessionDiagnostic)]
13+
#[error(expand::must_repeat_once)]
14+
pub(crate) struct MustRepeatOnce {
15+
#[primary_span]
16+
pub span: Span,
17+
}
18+
19+
#[derive(SessionDiagnostic)]
20+
#[error(expand::count_repetition_misplaced)]
21+
pub(crate) struct CountRepetitionMisplaced {
22+
#[primary_span]
23+
pub span: Span,
24+
}
25+
26+
#[derive(SessionDiagnostic)]
27+
#[error(expand::meta_var_expr_unrecognized_var)]
28+
pub(crate) struct MetaVarExprUnrecognizedVar {
29+
#[primary_span]
30+
pub span: Span,
31+
pub key: MacroRulesNormalizedIdent,
32+
}
33+
34+
#[derive(SessionDiagnostic)]
35+
#[error(expand::var_still_repeating)]
36+
pub(crate) struct VarStillRepeating {
37+
#[primary_span]
38+
pub span: Span,
39+
pub ident: MacroRulesNormalizedIdent,
40+
}
41+
42+
#[derive(SessionDiagnostic)]
43+
#[error(expand::meta_var_dif_seq_matchers)]
44+
pub(crate) struct MetaVarsDifSeqMatchers {
45+
#[primary_span]
46+
pub span: Span,
47+
pub msg: String,
48+
}

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod base;
2525
pub mod build;
2626
#[macro_use]
2727
pub mod config;
28+
pub mod errors;
2829
pub mod expand;
2930
pub mod module;
3031
pub mod proc_macro;

compiler/rustc_expand/src/mbe/transcribe.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use crate::base::ExtCtxt;
2+
use crate::errors::{
3+
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
4+
NoSyntaxVarsExprRepeat, VarStillRepeating,
5+
};
26
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch};
37
use crate::mbe::{self, MetaVarExpr};
48
use rustc_ast::mut_visit::{self, MutVisitor};
@@ -165,19 +169,15 @@ pub(super) fn transcribe<'a>(
165169
seq @ mbe::TokenTree::Sequence(_, delimited) => {
166170
match lockstep_iter_size(&seq, interp, &repeats) {
167171
LockstepIterSize::Unconstrained => {
168-
return Err(cx.struct_span_err(
169-
seq.span(), /* blame macro writer */
170-
"attempted to repeat an expression containing no syntax variables \
171-
matched as repeating at this depth",
172-
));
172+
return Err(cx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
173173
}
174174

175175
LockstepIterSize::Contradiction(msg) => {
176176
// FIXME: this really ought to be caught at macro definition time... It
177177
// happens when two meta-variables are used in the same repetition in a
178178
// sequence, but they come from different sequence matchers and repeat
179179
// different amounts.
180-
return Err(cx.struct_span_err(seq.span(), &msg));
180+
return Err(cx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
181181
}
182182

183183
LockstepIterSize::Constraint(len, _) => {
@@ -193,10 +193,7 @@ pub(super) fn transcribe<'a>(
193193
// FIXME: this really ought to be caught at macro definition
194194
// time... It happens when the Kleene operator in the matcher and
195195
// the body for the same meta-variable do not match.
196-
return Err(cx.struct_span_err(
197-
sp.entire(),
198-
"this must repeat at least once",
199-
));
196+
return Err(cx.create_err(MustRepeatOnce { span: sp.entire() }));
200197
}
201198
} else {
202199
// 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -239,10 +236,7 @@ pub(super) fn transcribe<'a>(
239236
}
240237
MatchedSeq(..) => {
241238
// We were unable to descend far enough. This is an error.
242-
return Err(cx.struct_span_err(
243-
sp, /* blame the macro writer */
244-
&format!("variable '{}' is still repeating at this depth", ident),
245-
));
239+
return Err(cx.create_err(VarStillRepeating { span: sp, ident }));
246240
}
247241
}
248242
} else {
@@ -448,10 +442,7 @@ fn count_repetitions<'a>(
448442
match matched {
449443
MatchedTokenTree(_) | MatchedNonterminal(_) => {
450444
if declared_lhs_depth == 0 {
451-
return Err(cx.struct_span_err(
452-
sp.entire(),
453-
"`count` can not be placed inside the inner-most repetition",
454-
));
445+
return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
455446
}
456447
match depth_opt {
457448
None => Ok(1),
@@ -499,12 +490,7 @@ where
499490
{
500491
let span = ident.span;
501492
let key = MacroRulesNormalizedIdent::new(ident);
502-
interp.get(&key).ok_or_else(|| {
503-
cx.struct_span_err(
504-
span,
505-
&format!("variable `{}` is not recognized in meta-variable expression", key),
506-
)
507-
})
493+
interp.get(&key).ok_or_else(|| cx.create_err(MetaVarExprUnrecognizedVar { span, key }))
508494
}
509495

510496
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
174174

175175
#[instrument(skip(self), level = "debug")]
176176
fn tys(&mut self, pattern: Ty<'tcx>, value: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
177-
if pattern == value { Ok(pattern) } else { relate::super_relate_tys(self, pattern, value) }
177+
if let ty::Error(_) = pattern.kind() {
178+
// Unlike normal `TypeRelation` rules, `ty::Error` does not equal any type.
179+
self.no_match()
180+
} else if pattern == value {
181+
Ok(pattern)
182+
} else {
183+
relate::super_relate_tys(self, pattern, value)
184+
}
178185
}
179186

180187
#[instrument(skip(self), level = "debug")]

compiler/rustc_middle/src/mir/interpret/value.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> {
7979
}
8080

8181
pub fn try_to_scalar_int(&self) -> Option<ScalarInt> {
82-
Some(self.try_to_scalar()?.assert_int())
82+
self.try_to_scalar()?.try_to_int().ok()
8383
}
8484

8585
pub fn try_to_bits(&self, size: Size) -> Option<u128> {
@@ -368,6 +368,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
368368
}
369369

370370
#[inline(always)]
371+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
371372
pub fn assert_int(self) -> ScalarInt {
372373
self.try_to_int().unwrap()
373374
}
@@ -389,6 +390,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
389390
}
390391

391392
#[inline(always)]
393+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
392394
pub fn assert_bits(self, target_size: Size) -> u128 {
393395
self.to_bits(target_size).unwrap()
394396
}

0 commit comments

Comments
 (0)