Skip to content

Commit

Permalink
Auto merge of rust-lang#100708 - matthiaskrgr:rollup-vl0olnj, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#97962 (Make must_not_suspend lint see through references when drop tracking is enabled)
 - rust-lang#99966 (avoid assertion failures in try_to_scalar_int)
 - rust-lang#100637 (Improving Fuchsia rustc support documentation)
 - rust-lang#100643 (Point at a type parameter shadowing another type)
 - rust-lang#100651 (Migrations for rustc_expand transcribe.rs)
 - rust-lang#100669 (Attribute cleanups)
 - rust-lang#100670 (Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_recovery)
 - rust-lang#100674 (Migrate lint reports in typeck::check_unused to LintDiagnostic)
 - rust-lang#100688 (`ty::Error` does not match other types for region constraints)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 18, 2022
2 parents 9c20b2a + c7a4942 commit f241c0c
Show file tree
Hide file tree
Showing 39 changed files with 314 additions and 102 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub fn expand_deriving_copy(
) {
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(marker::Copy),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub fn expand_deriving_clone(
let attrs = vec![cx.attribute(inline)];
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(clone::Clone),
additional_bounds: bounds,
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub fn expand_deriving_eq(
let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)];
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cmp::Eq),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub fn expand_deriving_ord(
let attrs = vec![cx.attribute(inline)];
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cmp::Ord),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub fn expand_deriving_partial_eq(

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cmp::PartialEq),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub fn expand_deriving_partial_ord(

let trait_def = TraitDef {
span,
attributes: vec![],
path: path_std!(cmp::PartialOrd),
additional_bounds: vec![],
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn expand_deriving_debug(

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(fmt::Debug),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn expand_deriving_rustc_decodable(

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub fn expand_deriving_default(
let attrs = vec![cx.attribute(inline)];
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: Path::new(vec![kw::Default, sym::Default]),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ pub fn expand_deriving_rustc_encodable(

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ pub struct TraitDef<'a> {
/// The span for the current #[derive(Foo)] header.
pub span: Span,

pub attributes: Vec<ast::Attribute>,

/// Path of the trait, including any type parameters
pub path: Path,

Expand Down Expand Up @@ -605,7 +603,7 @@ impl<'a> TraitDef<'a> {
param.bounds.iter().cloned()
).collect();

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

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

let mut a = vec![attr];
a.extend(self.attributes.iter().cloned());

cx.item(
self.span,
Ident::empty(),
a,
attrs,
ast::ItemKind::Impl(Box::new(ast::Impl {
unsafety: ast::Unsafe::No,
polarity: ast::ImplPolarity::Positive,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ fn mk_ty_param(
cx: &ExtCtxt<'_>,
span: Span,
name: Symbol,
attrs: &[ast::Attribute],
bounds: &[Path],
self_ident: Ident,
self_generics: &Generics,
Expand All @@ -158,7 +157,7 @@ fn mk_ty_param(
cx.trait_bound(path)
})
.collect();
cx.typaram(span, Ident::new(name, span), attrs.to_owned(), bounds, None)
cx.typaram(span, Ident::new(name, span), bounds, None)
}

/// Bounds on type parameters.
Expand All @@ -183,7 +182,7 @@ impl Bounds {
.iter()
.map(|t| {
let (name, ref bounds) = *t;
mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics)
mk_ty_param(cx, span, name, &bounds, self_ty, self_generics)
})
.collect();

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn expand_deriving_hash(
let arg = Path::new_local(typaram);
let hash_trait_def = TraitDef {
span,
attributes: Vec::new(),
path,
additional_bounds: Vec::new(),
generics: Bounds::empty(),
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/expand.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@ expand_explain_doc_comment_outer =
expand_explain_doc_comment_inner =
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
expand_expr_repeat_no_syntax_vars =
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
expand_must_repeat_once =
this must repeat at least once
expand_count_repetition_misplaced =
`count` can not be placed inside the inner-most repetition
expand_meta_var_expr_unrecognized_var =
variable `{$key}` is not recognized in meta-variable expression
expand_var_still_repeating =
variable '{$ident}' is still repeating at this depth
expand_meta_var_dif_seq_matchers = {$msg}
8 changes: 8 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,11 @@ typeck_manual_implementation =
.help = add `#![feature(unboxed_closures)]` to the crate attributes to enable
typeck_substs_on_overridden_impl = could not resolve substs on overridden impl
typeck_unused_extern_crate =
unused extern crate
.suggestion = remove it
typeck_extern_crate_not_idiomatic =
`extern crate` is not idiomatic in the new edition
.suggestion = convert it to a `{$msg_code}`
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
use rustc_hir as hir;
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_span::edition::LATEST_STABLE_EDITION;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_span::{edition::Edition, Span, DUMMY_SP};
use std::borrow::Cow;
use std::fmt;
Expand Down Expand Up @@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!(
hir::Target,
Edition,
Ident,
MacroRulesNormalizedIdent,
);

impl IntoDiagnosticArg for bool {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ impl<'a> ExtCtxt<'a> {
&self,
span: Span,
ident: Ident,
attrs: Vec<ast::Attribute>,
bounds: ast::GenericBounds,
default: Option<P<ast::Ty>>,
) -> ast::GenericParam {
ast::GenericParam {
ident: ident.with_span_pos(span),
id: ast::DUMMY_NODE_ID,
attrs: attrs.into(),
attrs: AttrVec::new(),
bounds,
kind: ast::GenericParamKind::Type { default },
is_placeholder: false,
Expand Down
48 changes: 48 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use rustc_macros::SessionDiagnostic;
use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(expand::expr_repeat_no_syntax_vars)]
pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::must_repeat_once)]
pub(crate) struct MustRepeatOnce {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::count_repetition_misplaced)]
pub(crate) struct CountRepetitionMisplaced {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::meta_var_expr_unrecognized_var)]
pub(crate) struct MetaVarExprUnrecognizedVar {
#[primary_span]
pub span: Span,
pub key: MacroRulesNormalizedIdent,
}

#[derive(SessionDiagnostic)]
#[error(expand::var_still_repeating)]
pub(crate) struct VarStillRepeating {
#[primary_span]
pub span: Span,
pub ident: MacroRulesNormalizedIdent,
}

#[derive(SessionDiagnostic)]
#[error(expand::meta_var_dif_seq_matchers)]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
pub msg: String,
}
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod base;
pub mod build;
#[macro_use]
pub mod config;
pub mod errors;
pub mod expand;
pub mod module;
pub mod proc_macro;
Expand Down
34 changes: 10 additions & 24 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::base::ExtCtxt;
use crate::errors::{
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
NoSyntaxVarsExprRepeat, VarStillRepeating,
};
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch};
use crate::mbe::{self, MetaVarExpr};
use rustc_ast::mut_visit::{self, MutVisitor};
Expand Down Expand Up @@ -165,19 +169,15 @@ pub(super) fn transcribe<'a>(
seq @ mbe::TokenTree::Sequence(_, delimited) => {
match lockstep_iter_size(&seq, interp, &repeats) {
LockstepIterSize::Unconstrained => {
return Err(cx.struct_span_err(
seq.span(), /* blame macro writer */
"attempted to repeat an expression containing no syntax variables \
matched as repeating at this depth",
));
return Err(cx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
}

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

LockstepIterSize::Constraint(len, _) => {
Expand All @@ -193,10 +193,7 @@ pub(super) fn transcribe<'a>(
// FIXME: this really ought to be caught at macro definition
// time... It happens when the Kleene operator in the matcher and
// the body for the same meta-variable do not match.
return Err(cx.struct_span_err(
sp.entire(),
"this must repeat at least once",
));
return Err(cx.create_err(MustRepeatOnce { span: sp.entire() }));
}
} else {
// 0 is the initial counter (we have done 0 repetitions so far). `len`
Expand Down Expand Up @@ -239,10 +236,7 @@ pub(super) fn transcribe<'a>(
}
MatchedSeq(..) => {
// We were unable to descend far enough. This is an error.
return Err(cx.struct_span_err(
sp, /* blame the macro writer */
&format!("variable '{}' is still repeating at this depth", ident),
));
return Err(cx.create_err(VarStillRepeating { span: sp, ident }));
}
}
} else {
Expand Down Expand Up @@ -448,10 +442,7 @@ fn count_repetitions<'a>(
match matched {
MatchedTokenTree(_) | MatchedNonterminal(_) => {
if declared_lhs_depth == 0 {
return Err(cx.struct_span_err(
sp.entire(),
"`count` can not be placed inside the inner-most repetition",
));
return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
}
match depth_opt {
None => Ok(1),
Expand Down Expand Up @@ -499,12 +490,7 @@ where
{
let span = ident.span;
let key = MacroRulesNormalizedIdent::new(ident);
interp.get(&key).ok_or_else(|| {
cx.struct_span_err(
span,
&format!("variable `{}` is not recognized in meta-variable expression", key),
)
})
interp.get(&key).ok_or_else(|| cx.create_err(MetaVarExprUnrecognizedVar { span, key }))
}

/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_infer/src/infer/outlives/test_type_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {

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

#[instrument(skip(self), level = "debug")]
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> {
}

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

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

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

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

0 comments on commit f241c0c

Please sign in to comment.