mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Remove useless borrows and derefs
This commit is contained in:
parent
9c0bc3028a
commit
f2b97a8bfe
@ -354,7 +354,7 @@ pub trait LayoutCalculator {
|
|||||||
if !always_sized { StructKind::MaybeUnsized } else { StructKind::AlwaysSized }
|
if !always_sized { StructKind::MaybeUnsized } else { StructKind::AlwaysSized }
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut st = self.univariant(dl, &variants[v], &repr, kind)?;
|
let mut st = self.univariant(dl, &variants[v], repr, kind)?;
|
||||||
st.variants = Variants::Single { index: v };
|
st.variants = Variants::Single { index: v };
|
||||||
|
|
||||||
if is_unsafe_cell {
|
if is_unsafe_cell {
|
||||||
@ -457,7 +457,7 @@ pub trait LayoutCalculator {
|
|||||||
let mut variant_layouts = variants
|
let mut variant_layouts = variants
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.map(|(j, v)| {
|
.map(|(j, v)| {
|
||||||
let mut st = self.univariant(dl, v, &repr, StructKind::AlwaysSized)?;
|
let mut st = self.univariant(dl, v, repr, StructKind::AlwaysSized)?;
|
||||||
st.variants = Variants::Single { index: j };
|
st.variants = Variants::Single { index: j };
|
||||||
|
|
||||||
align = align.max(st.align);
|
align = align.max(st.align);
|
||||||
@ -647,8 +647,8 @@ pub trait LayoutCalculator {
|
|||||||
.map(|(i, field_layouts)| {
|
.map(|(i, field_layouts)| {
|
||||||
let mut st = self.univariant(
|
let mut st = self.univariant(
|
||||||
dl,
|
dl,
|
||||||
&field_layouts,
|
field_layouts,
|
||||||
&repr,
|
repr,
|
||||||
StructKind::Prefixed(min_ity.size(), prefix_align),
|
StructKind::Prefixed(min_ity.size(), prefix_align),
|
||||||
)?;
|
)?;
|
||||||
st.variants = Variants::Single { index: i };
|
st.variants = Variants::Single { index: i };
|
||||||
@ -755,7 +755,7 @@ pub trait LayoutCalculator {
|
|||||||
// Try to use a ScalarPair for all tagged enums.
|
// Try to use a ScalarPair for all tagged enums.
|
||||||
let mut common_prim = None;
|
let mut common_prim = None;
|
||||||
let mut common_prim_initialized_in_all_variants = true;
|
let mut common_prim_initialized_in_all_variants = true;
|
||||||
for (field_layouts, layout_variant) in iter::zip(&*variants, &layout_variants) {
|
for (field_layouts, layout_variant) in iter::zip(variants, &layout_variants) {
|
||||||
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
|
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
|
||||||
panic!();
|
panic!();
|
||||||
};
|
};
|
||||||
|
@ -1179,7 +1179,7 @@ impl Expr {
|
|||||||
pub fn peel_parens(&self) -> &Expr {
|
pub fn peel_parens(&self) -> &Expr {
|
||||||
let mut expr = self;
|
let mut expr = self;
|
||||||
while let ExprKind::Paren(inner) = &expr.kind {
|
while let ExprKind::Paren(inner) = &expr.kind {
|
||||||
expr = &inner;
|
expr = inner;
|
||||||
}
|
}
|
||||||
expr
|
expr
|
||||||
}
|
}
|
||||||
@ -2027,7 +2027,7 @@ impl Ty {
|
|||||||
pub fn peel_refs(&self) -> &Self {
|
pub fn peel_refs(&self) -> &Self {
|
||||||
let mut final_ty = self;
|
let mut final_ty = self;
|
||||||
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
|
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
|
||||||
final_ty = &ty;
|
final_ty = ty;
|
||||||
}
|
}
|
||||||
final_ty
|
final_ty
|
||||||
}
|
}
|
||||||
|
@ -740,8 +740,7 @@ pub fn visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
|
|||||||
return; // Avoid visiting the span for the second time.
|
return; // Avoid visiting the span for the second time.
|
||||||
}
|
}
|
||||||
token::Interpolated(nt) => {
|
token::Interpolated(nt) => {
|
||||||
let mut nt = Lrc::make_mut(nt);
|
visit_nonterminal(Lrc::make_mut(nt), vis);
|
||||||
visit_nonterminal(&mut nt, vis);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ impl TokenTree {
|
|||||||
match (self, other) {
|
match (self, other) {
|
||||||
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
|
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
|
||||||
(TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
|
(TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
|
||||||
delim == delim2 && tts.eq_unspanned(&tts2)
|
delim == delim2 && tts.eq_unspanned(tts2)
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ impl TokenStream {
|
|||||||
let mut t1 = self.trees();
|
let mut t1 = self.trees();
|
||||||
let mut t2 = other.trees();
|
let mut t2 = other.trees();
|
||||||
for (t1, t2) in iter::zip(&mut t1, &mut t2) {
|
for (t1, t2) in iter::zip(&mut t1, &mut t2) {
|
||||||
if !t1.eq_unspanned(&t2) {
|
if !t1.eq_unspanned(t2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,7 +475,7 @@ impl TokenStream {
|
|||||||
token::Interpolated(nt) => TokenTree::Delimited(
|
token::Interpolated(nt) => TokenTree::Delimited(
|
||||||
DelimSpan::from_single(token.span),
|
DelimSpan::from_single(token.span),
|
||||||
Delimiter::Invisible,
|
Delimiter::Invisible,
|
||||||
TokenStream::from_nonterminal_ast(&nt).flattened(),
|
TokenStream::from_nonterminal_ast(nt).flattened(),
|
||||||
),
|
),
|
||||||
_ => TokenTree::Token(token.clone(), spacing),
|
_ => TokenTree::Token(token.clone(), spacing),
|
||||||
}
|
}
|
||||||
@ -511,7 +511,7 @@ impl TokenStream {
|
|||||||
fn try_glue_to_last(vec: &mut Vec<TokenTree>, tt: &TokenTree) -> bool {
|
fn try_glue_to_last(vec: &mut Vec<TokenTree>, tt: &TokenTree) -> bool {
|
||||||
if let Some(TokenTree::Token(last_tok, Spacing::Joint)) = vec.last()
|
if let Some(TokenTree::Token(last_tok, Spacing::Joint)) = vec.last()
|
||||||
&& let TokenTree::Token(tok, spacing) = tt
|
&& let TokenTree::Token(tok, spacing) = tt
|
||||||
&& let Some(glued_tok) = last_tok.glue(&tok)
|
&& let Some(glued_tok) = last_tok.glue(tok)
|
||||||
{
|
{
|
||||||
// ...then overwrite the last token tree in `vec` with the
|
// ...then overwrite the last token tree in `vec` with the
|
||||||
// glued token, and skip the first token tree from `stream`.
|
// glued token, and skip the first token tree from `stream`.
|
||||||
|
@ -110,7 +110,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
|
|||||||
} else {
|
} else {
|
||||||
&mut lines
|
&mut lines
|
||||||
};
|
};
|
||||||
if let Some(horizontal) = get_horizontal_trim(&lines, kind) {
|
if let Some(horizontal) = get_horizontal_trim(lines, kind) {
|
||||||
changes = true;
|
changes = true;
|
||||||
// remove a "[ \t]*\*" block from each line, if possible
|
// remove a "[ \t]*\*" block from each line, if possible
|
||||||
for line in lines.iter_mut() {
|
for line in lines.iter_mut() {
|
||||||
@ -147,7 +147,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
|
|||||||
|
|
||||||
fn trim_whitespace_prefix(s: &str, col: CharPos) -> &str {
|
fn trim_whitespace_prefix(s: &str, col: CharPos) -> &str {
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
match all_whitespace(&s, col) {
|
match all_whitespace(s, col) {
|
||||||
Some(col) => {
|
Some(col) => {
|
||||||
if col < len {
|
if col < len {
|
||||||
&s[col..]
|
&s[col..]
|
||||||
|
@ -52,14 +52,14 @@ impl LitKind {
|
|||||||
// new symbol because the string in the LitKind is different to the
|
// new symbol because the string in the LitKind is different to the
|
||||||
// string in the token.
|
// string in the token.
|
||||||
let s = symbol.as_str();
|
let s = symbol.as_str();
|
||||||
let symbol = if s.contains(&['\\', '\r']) {
|
let symbol = if s.contains(['\\', '\r']) {
|
||||||
let mut buf = String::with_capacity(s.len());
|
let mut buf = String::with_capacity(s.len());
|
||||||
let mut error = Ok(());
|
let mut error = Ok(());
|
||||||
// Force-inlining here is aggressive but the closure is
|
// Force-inlining here is aggressive but the closure is
|
||||||
// called on every char in the string, so it can be
|
// called on every char in the string, so it can be
|
||||||
// hot in programs with many long strings.
|
// hot in programs with many long strings.
|
||||||
unescape_literal(
|
unescape_literal(
|
||||||
&s,
|
s,
|
||||||
Mode::Str,
|
Mode::Str,
|
||||||
&mut #[inline(always)]
|
&mut #[inline(always)]
|
||||||
|_, unescaped_char| match unescaped_char {
|
|_, unescaped_char| match unescaped_char {
|
||||||
@ -85,7 +85,7 @@ impl LitKind {
|
|||||||
if s.contains('\r') {
|
if s.contains('\r') {
|
||||||
let mut buf = String::with_capacity(s.len());
|
let mut buf = String::with_capacity(s.len());
|
||||||
let mut error = Ok(());
|
let mut error = Ok(());
|
||||||
unescape_literal(&s, Mode::RawStr, &mut |_, unescaped_char| {
|
unescape_literal(s, Mode::RawStr, &mut |_, unescaped_char| {
|
||||||
match unescaped_char {
|
match unescaped_char {
|
||||||
Ok(c) => buf.push(c),
|
Ok(c) => buf.push(c),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -106,7 +106,7 @@ impl LitKind {
|
|||||||
let s = symbol.as_str();
|
let s = symbol.as_str();
|
||||||
let mut buf = Vec::with_capacity(s.len());
|
let mut buf = Vec::with_capacity(s.len());
|
||||||
let mut error = Ok(());
|
let mut error = Ok(());
|
||||||
unescape_literal(&s, Mode::ByteStr, &mut |_, c| match c {
|
unescape_literal(s, Mode::ByteStr, &mut |_, c| match c {
|
||||||
Ok(c) => buf.push(byte_from_char(c)),
|
Ok(c) => buf.push(byte_from_char(c)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err.is_fatal() {
|
if err.is_fatal() {
|
||||||
@ -122,7 +122,7 @@ impl LitKind {
|
|||||||
let bytes = if s.contains('\r') {
|
let bytes = if s.contains('\r') {
|
||||||
let mut buf = Vec::with_capacity(s.len());
|
let mut buf = Vec::with_capacity(s.len());
|
||||||
let mut error = Ok(());
|
let mut error = Ok(());
|
||||||
unescape_literal(&s, Mode::RawByteStr, &mut |_, c| match c {
|
unescape_literal(s, Mode::RawByteStr, &mut |_, c| match c {
|
||||||
Ok(c) => buf.push(byte_from_char(c)),
|
Ok(c) => buf.push(byte_from_char(c)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err.is_fatal() {
|
if err.is_fatal() {
|
||||||
|
@ -384,7 +384,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
|
|||||||
| ast::ExprKind::AssignOp(_, lhs, rhs)
|
| ast::ExprKind::AssignOp(_, lhs, rhs)
|
||||||
| ast::ExprKind::Binary(_, lhs, rhs) => {
|
| ast::ExprKind::Binary(_, lhs, rhs) => {
|
||||||
// X { y: 1 } + X { y: 2 }
|
// X { y: 1 } + X { y: 2 }
|
||||||
contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
|
contains_exterior_struct_lit(lhs) || contains_exterior_struct_lit(rhs)
|
||||||
}
|
}
|
||||||
ast::ExprKind::Await(x)
|
ast::ExprKind::Await(x)
|
||||||
| ast::ExprKind::Unary(_, x)
|
| ast::ExprKind::Unary(_, x)
|
||||||
@ -393,12 +393,12 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
|
|||||||
| ast::ExprKind::Field(x, _)
|
| ast::ExprKind::Field(x, _)
|
||||||
| ast::ExprKind::Index(x, _) => {
|
| ast::ExprKind::Index(x, _) => {
|
||||||
// &X { y: 1 }, X { y: 1 }.y
|
// &X { y: 1 }, X { y: 1 }.y
|
||||||
contains_exterior_struct_lit(&x)
|
contains_exterior_struct_lit(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::ExprKind::MethodCall(box ast::MethodCall { receiver, .. }) => {
|
ast::ExprKind::MethodCall(box ast::MethodCall { receiver, .. }) => {
|
||||||
// X { y: 1 }.bar(...)
|
// X { y: 1 }.bar(...)
|
||||||
contains_exterior_struct_lit(&receiver)
|
contains_exterior_struct_lit(receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -17,7 +17,7 @@ pub fn contains_text_flow_control_chars(s: &str) -> bool {
|
|||||||
// U+2069 - E2 81 A9
|
// U+2069 - E2 81 A9
|
||||||
let mut bytes = s.as_bytes();
|
let mut bytes = s.as_bytes();
|
||||||
loop {
|
loop {
|
||||||
match core::slice::memchr::memchr(0xE2, &bytes) {
|
match core::slice::memchr::memchr(0xE2, bytes) {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
// bytes are valid UTF-8 -> E2 must be followed by two bytes
|
// bytes are valid UTF-8 -> E2 must be followed by two bytes
|
||||||
let ch = &bytes[idx..idx + 3];
|
let ch = &bytes[idx..idx + 3];
|
||||||
|
@ -519,7 +519,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||||||
ast::MetaItemKind::List(items) => {
|
ast::MetaItemKind::List(items) => {
|
||||||
self.print_path(&item.path, false, 0);
|
self.print_path(&item.path, false, 0);
|
||||||
self.popen();
|
self.popen();
|
||||||
self.commasep(Consistent, &items, |s, i| s.print_meta_list_item(i));
|
self.commasep(Consistent, items, |s, i| s.print_meta_list_item(i));
|
||||||
self.pclose();
|
self.pclose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||||||
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) {
|
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) {
|
||||||
match tt {
|
match tt {
|
||||||
TokenTree::Token(token, _) => {
|
TokenTree::Token(token, _) => {
|
||||||
let token_str = self.token_to_string_ext(&token, convert_dollar_crate);
|
let token_str = self.token_to_string_ext(token, convert_dollar_crate);
|
||||||
self.word(token_str);
|
self.word(token_str);
|
||||||
if let token::DocComment(..) = token.kind {
|
if let token::DocComment(..) = token.kind {
|
||||||
self.hardbreak()
|
self.hardbreak()
|
||||||
@ -998,7 +998,7 @@ impl<'a> State<'a> {
|
|||||||
ast::AssocConstraintKind::Bound { bounds } => {
|
ast::AssocConstraintKind::Bound { bounds } => {
|
||||||
if !bounds.is_empty() {
|
if !bounds.is_empty() {
|
||||||
self.word_nbsp(":");
|
self.word_nbsp(":");
|
||||||
self.print_type_bounds(&bounds);
|
self.print_type_bounds(bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1035,7 +1035,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
ast::TyKind::Tup(elts) => {
|
ast::TyKind::Tup(elts) => {
|
||||||
self.popen();
|
self.popen();
|
||||||
self.commasep(Inconsistent, &elts, |s, ty| s.print_type(ty));
|
self.commasep(Inconsistent, elts, |s, ty| s.print_type(ty));
|
||||||
if elts.len() == 1 {
|
if elts.len() == 1 {
|
||||||
self.word(",");
|
self.word(",");
|
||||||
}
|
}
|
||||||
@ -1254,7 +1254,7 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
self.popen();
|
self.popen();
|
||||||
self.commasep(Consistent, &args, |s, arg| match arg {
|
self.commasep(Consistent, &args, |s, arg| match arg {
|
||||||
AsmArg::Template(template) => s.print_string(&template, ast::StrStyle::Cooked),
|
AsmArg::Template(template) => s.print_string(template, ast::StrStyle::Cooked),
|
||||||
AsmArg::Operand(op) => {
|
AsmArg::Operand(op) => {
|
||||||
let print_reg_or_class = |s: &mut Self, r: &InlineAsmRegOrRegClass| match r {
|
let print_reg_or_class = |s: &mut Self, r: &InlineAsmRegOrRegClass| match r {
|
||||||
InlineAsmRegOrRegClass::Reg(r) => s.print_symbol(*r, ast::StrStyle::Cooked),
|
InlineAsmRegOrRegClass::Reg(r) => s.print_symbol(*r, ast::StrStyle::Cooked),
|
||||||
@ -1424,11 +1424,11 @@ impl<'a> State<'a> {
|
|||||||
self.print_path(path, true, 0);
|
self.print_path(path, true, 0);
|
||||||
}
|
}
|
||||||
self.popen();
|
self.popen();
|
||||||
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
|
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
|
||||||
self.pclose();
|
self.pclose();
|
||||||
}
|
}
|
||||||
PatKind::Or(pats) => {
|
PatKind::Or(pats) => {
|
||||||
self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(p));
|
self.strsep("|", true, Inconsistent, pats, |s, p| s.print_pat(p));
|
||||||
}
|
}
|
||||||
PatKind::Path(None, path) => {
|
PatKind::Path(None, path) => {
|
||||||
self.print_path(path, true, 0);
|
self.print_path(path, true, 0);
|
||||||
@ -1450,7 +1450,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
self.commasep_cmnt(
|
self.commasep_cmnt(
|
||||||
Consistent,
|
Consistent,
|
||||||
&fields,
|
fields,
|
||||||
|s, f| {
|
|s, f| {
|
||||||
s.cbox(INDENT_UNIT);
|
s.cbox(INDENT_UNIT);
|
||||||
if !f.is_shorthand {
|
if !f.is_shorthand {
|
||||||
@ -1475,7 +1475,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
PatKind::Tuple(elts) => {
|
PatKind::Tuple(elts) => {
|
||||||
self.popen();
|
self.popen();
|
||||||
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
|
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
|
||||||
if elts.len() == 1 {
|
if elts.len() == 1 {
|
||||||
self.word(",");
|
self.word(",");
|
||||||
}
|
}
|
||||||
@ -1498,7 +1498,7 @@ impl<'a> State<'a> {
|
|||||||
self.print_pat(inner);
|
self.print_pat(inner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PatKind::Lit(e) => self.print_expr(&**e),
|
PatKind::Lit(e) => self.print_expr(e),
|
||||||
PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
|
PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
|
||||||
if let Some(e) = begin {
|
if let Some(e) = begin {
|
||||||
self.print_expr(e);
|
self.print_expr(e);
|
||||||
@ -1514,7 +1514,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
PatKind::Slice(elts) => {
|
PatKind::Slice(elts) => {
|
||||||
self.word("[");
|
self.word("[");
|
||||||
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
|
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
|
||||||
self.word("]");
|
self.word("]");
|
||||||
}
|
}
|
||||||
PatKind::Rest => self.word(".."),
|
PatKind::Rest => self.word(".."),
|
||||||
@ -1600,7 +1600,7 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
self.word("<");
|
self.word("<");
|
||||||
|
|
||||||
self.commasep(Inconsistent, &generic_params, |s, param| {
|
self.commasep(Inconsistent, generic_params, |s, param| {
|
||||||
s.print_outer_attributes_inline(¶m.attrs);
|
s.print_outer_attributes_inline(¶m.attrs);
|
||||||
|
|
||||||
match ¶m.kind {
|
match ¶m.kind {
|
||||||
|
@ -305,10 +305,10 @@ impl<'a> State<'a> {
|
|||||||
self.print_expr_tup(exprs);
|
self.print_expr_tup(exprs);
|
||||||
}
|
}
|
||||||
ast::ExprKind::Call(func, args) => {
|
ast::ExprKind::Call(func, args) => {
|
||||||
self.print_expr_call(func, &args);
|
self.print_expr_call(func, args);
|
||||||
}
|
}
|
||||||
ast::ExprKind::MethodCall(box ast::MethodCall { seg, receiver, args, .. }) => {
|
ast::ExprKind::MethodCall(box ast::MethodCall { seg, receiver, args, .. }) => {
|
||||||
self.print_expr_method_call(seg, &receiver, &args);
|
self.print_expr_method_call(seg, receiver, args);
|
||||||
}
|
}
|
||||||
ast::ExprKind::Binary(op, lhs, rhs) => {
|
ast::ExprKind::Binary(op, lhs, rhs) => {
|
||||||
self.print_expr_binary(*op, lhs, rhs);
|
self.print_expr_binary(*op, lhs, rhs);
|
||||||
@ -605,7 +605,7 @@ impl<'a> State<'a> {
|
|||||||
match binder {
|
match binder {
|
||||||
ast::ClosureBinder::NotPresent => {}
|
ast::ClosureBinder::NotPresent => {}
|
||||||
ast::ClosureBinder::For { generic_params, .. } => {
|
ast::ClosureBinder::For { generic_params, .. } => {
|
||||||
self.print_formal_generic_params(&generic_params)
|
self.print_formal_generic_params(generic_params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ impl<'a, T: PartialOrd> PartialOrd for Interned<'a, T> {
|
|||||||
if ptr::eq(self.0, other.0) {
|
if ptr::eq(self.0, other.0) {
|
||||||
Some(Ordering::Equal)
|
Some(Ordering::Equal)
|
||||||
} else {
|
} else {
|
||||||
let res = self.0.partial_cmp(&other.0);
|
let res = self.0.partial_cmp(other.0);
|
||||||
debug_assert_ne!(res, Some(Ordering::Equal));
|
debug_assert_ne!(res, Some(Ordering::Equal));
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
|
|||||||
if ptr::eq(self.0, other.0) {
|
if ptr::eq(self.0, other.0) {
|
||||||
Ordering::Equal
|
Ordering::Equal
|
||||||
} else {
|
} else {
|
||||||
let res = self.0.cmp(&other.0);
|
let res = self.0.cmp(other.0);
|
||||||
debug_assert_ne!(res, Ordering::Equal);
|
debug_assert_ne!(res, Ordering::Equal);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ impl Deref for Mmap {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &[u8] {
|
fn deref(&self) -> &[u8] {
|
||||||
&*self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,13 +96,13 @@ impl Deref for MmapMut {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &[u8] {
|
fn deref(&self) -> &[u8] {
|
||||||
&*self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for MmapMut {
|
impl DerefMut for MmapMut {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut [u8] {
|
fn deref_mut(&mut self) -> &mut [u8] {
|
||||||
&mut *self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ impl SelfProfilerRef {
|
|||||||
F: for<'a> FnOnce(&'a SelfProfiler) -> TimingGuard<'a>,
|
F: for<'a> FnOnce(&'a SelfProfiler) -> TimingGuard<'a>,
|
||||||
{
|
{
|
||||||
let profiler = profiler_ref.profiler.as_ref().unwrap();
|
let profiler = profiler_ref.profiler.as_ref().unwrap();
|
||||||
f(&**profiler)
|
f(profiler)
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.event_filter_mask.contains(event_filter) {
|
if self.event_filter_mask.contains(event_filter) {
|
||||||
@ -466,7 +466,7 @@ impl SelfProfilerRef {
|
|||||||
|
|
||||||
pub fn with_profiler(&self, f: impl FnOnce(&SelfProfiler)) {
|
pub fn with_profiler(&self, f: impl FnOnce(&SelfProfiler)) {
|
||||||
if let Some(profiler) = &self.profiler {
|
if let Some(profiler) = &self.profiler {
|
||||||
f(&profiler)
|
f(profiler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,7 +733,7 @@ impl Drop for VerboseTimingGuard<'_> {
|
|||||||
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
|
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
|
||||||
let end_rss = get_resident_set_size();
|
let end_rss = get_resident_set_size();
|
||||||
let dur = start_time.elapsed();
|
let dur = start_time.elapsed();
|
||||||
print_time_passes_entry(&message, dur, start_rss, end_rss);
|
print_time_passes_entry(message, dur, start_rss, end_rss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ impl<CTX> HashStable<CTX> for [u8] {
|
|||||||
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T> {
|
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
(&self[..]).hash_stable(ctx, hasher);
|
self[..].hash_stable(ctx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ where
|
|||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
(&self[..]).hash_stable(ctx, hasher);
|
self[..].hash_stable(ctx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ impl<CTX> HashStable<CTX> for str {
|
|||||||
impl<CTX> HashStable<CTX> for String {
|
impl<CTX> HashStable<CTX> for String {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
(&self[..]).hash_stable(hcx, hasher);
|
self[..].hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ cfg_if! {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
&*self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ impl Translate for AnnotateSnippetEmitterWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
&**self.fallback_bundle
|
&self.fallback_bundle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ impl Emitter for AnnotateSnippetEmitterWriter {
|
|||||||
let fluent_args = to_fluent_args(diag.args());
|
let fluent_args = to_fluent_args(diag.args());
|
||||||
|
|
||||||
let mut children = diag.children.clone();
|
let mut children = diag.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag, &fluent_args);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
|
||||||
|
|
||||||
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||||
&mut primary_span,
|
&mut primary_span,
|
||||||
@ -65,7 +65,7 @@ impl Emitter for AnnotateSnippetEmitterWriter {
|
|||||||
&diag.code,
|
&diag.code,
|
||||||
&primary_span,
|
&primary_span,
|
||||||
&children,
|
&children,
|
||||||
&suggestions,
|
suggestions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ impl Diagnostic {
|
|||||||
let lint_index = expectation_id.get_lint_index();
|
let lint_index = expectation_id.get_lint_index();
|
||||||
expectation_id.set_lint_index(None);
|
expectation_id.set_lint_index(None);
|
||||||
let mut stable_id = unstable_to_stable
|
let mut stable_id = unstable_to_stable
|
||||||
.get(&expectation_id)
|
.get(expectation_id)
|
||||||
.expect("each unstable `LintExpectationId` must have a matching stable id")
|
.expect("each unstable `LintExpectationId` must have a matching stable id")
|
||||||
.normalize();
|
.normalize();
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ pub trait Emitter: Translate {
|
|||||||
if self
|
if self
|
||||||
.source_map()
|
.source_map()
|
||||||
.map(|sm| is_case_difference(
|
.map(|sm| is_case_difference(
|
||||||
&**sm,
|
sm,
|
||||||
substitution,
|
substitution,
|
||||||
sugg.substitutions[0].parts[0].span,
|
sugg.substitutions[0].parts[0].span,
|
||||||
))
|
))
|
||||||
@ -525,7 +525,7 @@ impl Translate for EmitterWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
&**self.fallback_bundle
|
&self.fallback_bundle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ impl Emitter for EmitterWriter {
|
|||||||
let fluent_args = to_fluent_args(diag.args());
|
let fluent_args = to_fluent_args(diag.args());
|
||||||
|
|
||||||
let mut children = diag.children.clone();
|
let mut children = diag.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag, &fluent_args);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
|
||||||
debug!("emit_diagnostic: suggestions={:?}", suggestions);
|
debug!("emit_diagnostic: suggestions={:?}", suggestions);
|
||||||
|
|
||||||
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||||
@ -555,7 +555,7 @@ impl Emitter for EmitterWriter {
|
|||||||
&diag.code,
|
&diag.code,
|
||||||
&primary_span,
|
&primary_span,
|
||||||
&children,
|
&children,
|
||||||
&suggestions,
|
suggestions,
|
||||||
self.track_diagnostics.then_some(&diag.emitted_at),
|
self.track_diagnostics.then_some(&diag.emitted_at),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -801,7 +801,7 @@ impl EmitterWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let source_string = match file.get_line(line.line_index - 1) {
|
let source_string = match file.get_line(line.line_index - 1) {
|
||||||
Some(s) => normalize_whitespace(&*s),
|
Some(s) => normalize_whitespace(&s),
|
||||||
None => return Vec::new(),
|
None => return Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1148,7 +1148,7 @@ impl EmitterWriter {
|
|||||||
(pos + 2, annotation.start_col.saturating_sub(left))
|
(pos + 2, annotation.start_col.saturating_sub(left))
|
||||||
};
|
};
|
||||||
if let Some(ref label) = annotation.label {
|
if let Some(ref label) = annotation.label {
|
||||||
buffer.puts(line_offset + pos, code_offset + col, &label, style);
|
buffer.puts(line_offset + pos, code_offset + col, label, style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1358,7 +1358,7 @@ impl EmitterWriter {
|
|||||||
// only render error codes, not lint codes
|
// only render error codes, not lint codes
|
||||||
if let Some(DiagnosticId::Error(ref code)) = *code {
|
if let Some(DiagnosticId::Error(ref code)) = *code {
|
||||||
buffer.append(0, "[", Style::Level(*level));
|
buffer.append(0, "[", Style::Level(*level));
|
||||||
buffer.append(0, &code, Style::Level(*level));
|
buffer.append(0, code, Style::Level(*level));
|
||||||
buffer.append(0, "]", Style::Level(*level));
|
buffer.append(0, "]", Style::Level(*level));
|
||||||
label_width += 2 + code.len();
|
label_width += 2 + code.len();
|
||||||
}
|
}
|
||||||
@ -1683,7 +1683,7 @@ impl EmitterWriter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Render the replacements for each suggestion
|
// Render the replacements for each suggestion
|
||||||
let suggestions = suggestion.splice_lines(&**sm);
|
let suggestions = suggestion.splice_lines(sm);
|
||||||
debug!("emit_suggestion_default: suggestions={:?}", suggestions);
|
debug!("emit_suggestion_default: suggestions={:?}", suggestions);
|
||||||
|
|
||||||
if suggestions.is_empty() {
|
if suggestions.is_empty() {
|
||||||
@ -1784,7 +1784,7 @@ impl EmitterWriter {
|
|||||||
buffer.puts(
|
buffer.puts(
|
||||||
row_num - 1 + line - line_start,
|
row_num - 1 + line - line_start,
|
||||||
max_line_num_len + 3,
|
max_line_num_len + 3,
|
||||||
&normalize_whitespace(&*file_lines.file.get_line(line - 1).unwrap()),
|
&normalize_whitespace(&file_lines.file.get_line(line - 1).unwrap()),
|
||||||
Style::Removal,
|
Style::Removal,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1926,7 +1926,7 @@ impl EmitterWriter {
|
|||||||
buffer.putc(
|
buffer.putc(
|
||||||
row_num,
|
row_num,
|
||||||
(padding as isize + p) as usize,
|
(padding as isize + p) as usize,
|
||||||
if part.is_addition(&sm) { '+' } else { '~' },
|
if part.is_addition(sm) { '+' } else { '~' },
|
||||||
Style::Addition,
|
Style::Addition,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1973,7 +1973,7 @@ impl EmitterWriter {
|
|||||||
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
|
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
|
||||||
} else if notice_capitalization {
|
} else if notice_capitalization {
|
||||||
let msg = "notice the capitalization difference";
|
let msg = "notice the capitalization difference";
|
||||||
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
|
buffer.puts(row_num, max_line_num_len + 3, msg, Style::NoStyle);
|
||||||
}
|
}
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -2028,7 +2028,7 @@ impl EmitterWriter {
|
|||||||
for child in children {
|
for child in children {
|
||||||
let span = child.render_span.as_ref().unwrap_or(&child.span);
|
let span = child.render_span.as_ref().unwrap_or(&child.span);
|
||||||
if let Err(err) = self.emit_message_default(
|
if let Err(err) = self.emit_message_default(
|
||||||
&span,
|
span,
|
||||||
&child.message,
|
&child.message,
|
||||||
args,
|
args,
|
||||||
&None,
|
&None,
|
||||||
@ -2113,7 +2113,7 @@ impl EmitterWriter {
|
|||||||
*row_num - 1,
|
*row_num - 1,
|
||||||
max_line_num_len + 3,
|
max_line_num_len + 3,
|
||||||
&normalize_whitespace(
|
&normalize_whitespace(
|
||||||
&*file_lines.file.get_line(file_lines.lines[line_pos].line_index).unwrap(),
|
&file_lines.file.get_line(file_lines.lines[line_pos].line_index).unwrap(),
|
||||||
),
|
),
|
||||||
Style::NoStyle,
|
Style::NoStyle,
|
||||||
);
|
);
|
||||||
|
@ -136,7 +136,7 @@ impl Translate for JsonEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
&**self.fallback_bundle
|
&self.fallback_bundle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1328,7 +1328,7 @@ impl HandlerInner {
|
|||||||
|
|
||||||
diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {});
|
diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {});
|
||||||
|
|
||||||
self.emitter.emit_diagnostic(&diagnostic);
|
self.emitter.emit_diagnostic(diagnostic);
|
||||||
if diagnostic.is_error() {
|
if diagnostic.is_error() {
|
||||||
self.deduplicated_err_count += 1;
|
self.deduplicated_err_count += 1;
|
||||||
} else if let Warning(_) = diagnostic.level {
|
} else if let Warning(_) = diagnostic.level {
|
||||||
|
@ -59,13 +59,13 @@ pub trait Translate {
|
|||||||
trace!(?message, ?args);
|
trace!(?message, ?args);
|
||||||
let (identifier, attr) = match message {
|
let (identifier, attr) = match message {
|
||||||
DiagnosticMessage::Str(msg) | DiagnosticMessage::Eager(msg) => {
|
DiagnosticMessage::Str(msg) | DiagnosticMessage::Eager(msg) => {
|
||||||
return Cow::Borrowed(&msg);
|
return Cow::Borrowed(msg);
|
||||||
}
|
}
|
||||||
DiagnosticMessage::FluentIdentifier(identifier, attr) => (identifier, attr),
|
DiagnosticMessage::FluentIdentifier(identifier, attr) => (identifier, attr),
|
||||||
};
|
};
|
||||||
|
|
||||||
let translate_with_bundle = |bundle: &'a FluentBundle| -> Option<(Cow<'_, str>, Vec<_>)> {
|
let translate_with_bundle = |bundle: &'a FluentBundle| -> Option<(Cow<'_, str>, Vec<_>)> {
|
||||||
let message = bundle.get_message(&identifier)?;
|
let message = bundle.get_message(identifier)?;
|
||||||
let value = match attr {
|
let value = match attr {
|
||||||
Some(attr) => message.get_attribute(attr)?.value(),
|
Some(attr) => message.get_attribute(attr)?.value(),
|
||||||
None => message.value()?,
|
None => message.value()?,
|
||||||
@ -73,7 +73,7 @@ pub trait Translate {
|
|||||||
debug!(?message, ?value);
|
debug!(?message, ?value);
|
||||||
|
|
||||||
let mut errs = vec![];
|
let mut errs = vec![];
|
||||||
let translated = bundle.format_pattern(value, Some(&args), &mut errs);
|
let translated = bundle.format_pattern(value, Some(args), &mut errs);
|
||||||
debug!(?translated, ?errs);
|
debug!(?translated, ?errs);
|
||||||
Some((translated, errs))
|
Some((translated, errs))
|
||||||
};
|
};
|
||||||
|
@ -65,7 +65,7 @@ pub enum LinkOrCopy {
|
|||||||
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> {
|
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> {
|
||||||
let p = p.as_ref();
|
let p = p.as_ref();
|
||||||
let q = q.as_ref();
|
let q = q.as_ref();
|
||||||
match fs::remove_file(&q) {
|
match fs::remove_file(q) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
|
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
|
@ -410,7 +410,7 @@ impl<'a> Id<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_slice(&'a self) -> &'a str {
|
pub fn as_slice(&'a self) -> &'a str {
|
||||||
&*self.name
|
&self.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ impl<'a> LabelText<'a> {
|
|||||||
pub fn to_dot_string(&self) -> String {
|
pub fn to_dot_string(&self) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
|
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
|
||||||
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
|
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(s)),
|
||||||
HtmlStr(ref s) => format!("<{}>", s),
|
HtmlStr(ref s) => format!("<{}>", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,7 +529,7 @@ impl<'a> LabelText<'a> {
|
|||||||
EscStr(s) => s,
|
EscStr(s) => s,
|
||||||
LabelStr(s) => {
|
LabelStr(s) => {
|
||||||
if s.contains('\\') {
|
if s.contains('\\') {
|
||||||
(&*s).escape_default().to_string().into()
|
s.escape_default().to_string().into()
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
@ -2431,7 +2431,7 @@ impl<'hir> Ty<'hir> {
|
|||||||
pub fn peel_refs(&self) -> &Self {
|
pub fn peel_refs(&self) -> &Self {
|
||||||
let mut final_ty = self;
|
let mut final_ty = self;
|
||||||
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
|
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
|
||||||
final_ty = &ty;
|
final_ty = ty;
|
||||||
}
|
}
|
||||||
final_ty
|
final_ty
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ impl Ord for HirId {
|
|||||||
|
|
||||||
impl PartialOrd for HirId {
|
impl PartialOrd for HirId {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
Some(self.cmp(&other))
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ pub trait Visitor<'v>: Sized {
|
|||||||
|
|
||||||
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
|
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
|
||||||
visitor.visit_id(param.hir_id);
|
visitor.visit_id(param.hir_id);
|
||||||
visitor.visit_pat(¶m.pat);
|
visitor.visit_pat(param.pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
||||||
@ -470,7 +470,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
|||||||
}
|
}
|
||||||
ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
|
ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
|
||||||
FnKind::ItemFn(item.ident, generics, sig.header),
|
FnKind::ItemFn(item.ident, generics, sig.header),
|
||||||
&sig.decl,
|
sig.decl,
|
||||||
body_id,
|
body_id,
|
||||||
item.span,
|
item.span,
|
||||||
item.hir_id(),
|
item.hir_id(),
|
||||||
@ -544,7 +544,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
|||||||
|
|
||||||
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
|
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
|
||||||
walk_list!(visitor, visit_param, body.params);
|
walk_list!(visitor, visit_param, body.params);
|
||||||
visitor.visit_expr(&body.value);
|
visitor.visit_expr(body.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
||||||
@ -580,7 +580,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
|
|||||||
// dominates the local's definition.
|
// dominates the local's definition.
|
||||||
walk_list!(visitor, visit_expr, &local.init);
|
walk_list!(visitor, visit_expr, &local.init);
|
||||||
visitor.visit_id(local.hir_id);
|
visitor.visit_id(local.hir_id);
|
||||||
visitor.visit_pat(&local.pat);
|
visitor.visit_pat(local.pat);
|
||||||
if let Some(els) = local.els {
|
if let Some(els) = local.els {
|
||||||
visitor.visit_block(els);
|
visitor.visit_block(els);
|
||||||
}
|
}
|
||||||
@ -606,7 +606,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
|
|||||||
|
|
||||||
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
|
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
|
||||||
visitor.visit_id(arm.hir_id);
|
visitor.visit_id(arm.hir_id);
|
||||||
visitor.visit_pat(&arm.pat);
|
visitor.visit_pat(arm.pat);
|
||||||
if let Some(ref g) = arm.guard {
|
if let Some(ref g) = arm.guard {
|
||||||
match g {
|
match g {
|
||||||
Guard::If(ref e) => visitor.visit_expr(e),
|
Guard::If(ref e) => visitor.visit_expr(e),
|
||||||
@ -615,7 +615,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitor.visit_expr(&arm.body);
|
visitor.visit_expr(arm.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
||||||
@ -660,7 +660,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
|||||||
pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'v>) {
|
pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'v>) {
|
||||||
visitor.visit_id(field.hir_id);
|
visitor.visit_id(field.hir_id);
|
||||||
visitor.visit_ident(field.ident);
|
visitor.visit_ident(field.ident);
|
||||||
visitor.visit_pat(&field.pat)
|
visitor.visit_pat(field.pat)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
|
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
|
||||||
@ -799,7 +799,7 @@ pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>)
|
|||||||
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
|
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
|
||||||
visitor.visit_id(field.hir_id);
|
visitor.visit_id(field.hir_id);
|
||||||
visitor.visit_ident(field.ident);
|
visitor.visit_ident(field.ident);
|
||||||
visitor.visit_expr(&field.expr)
|
visitor.visit_expr(field.expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
||||||
@ -807,10 +807,10 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
|||||||
|
|
||||||
match typ.kind {
|
match typ.kind {
|
||||||
TyKind::Slice(ref ty) => visitor.visit_ty(ty),
|
TyKind::Slice(ref ty) => visitor.visit_ty(ty),
|
||||||
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
|
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(mutable_type.ty),
|
||||||
TyKind::Rptr(ref lifetime, ref mutable_type) => {
|
TyKind::Rptr(ref lifetime, ref mutable_type) => {
|
||||||
visitor.visit_lifetime(lifetime);
|
visitor.visit_lifetime(lifetime);
|
||||||
visitor.visit_ty(&mutable_type.ty)
|
visitor.visit_ty(mutable_type.ty)
|
||||||
}
|
}
|
||||||
TyKind::Never => {}
|
TyKind::Never => {}
|
||||||
TyKind::Tup(tuple_element_types) => {
|
TyKind::Tup(tuple_element_types) => {
|
||||||
@ -818,7 +818,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
|||||||
}
|
}
|
||||||
TyKind::BareFn(ref function_declaration) => {
|
TyKind::BareFn(ref function_declaration) => {
|
||||||
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
|
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
|
||||||
visitor.visit_fn_decl(&function_declaration.decl);
|
visitor.visit_fn_decl(function_declaration.decl);
|
||||||
}
|
}
|
||||||
TyKind::Path(ref qpath) => {
|
TyKind::Path(ref qpath) => {
|
||||||
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
|
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
|
||||||
@ -948,8 +948,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
|||||||
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
|
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
|
||||||
let hir_id = trait_item.hir_id();
|
let hir_id = trait_item.hir_id();
|
||||||
visitor.visit_ident(ident);
|
visitor.visit_ident(ident);
|
||||||
visitor.visit_generics(&generics);
|
visitor.visit_generics(generics);
|
||||||
visitor.visit_defaultness(&defaultness);
|
visitor.visit_defaultness(defaultness);
|
||||||
match *kind {
|
match *kind {
|
||||||
TraitItemKind::Const(ref ty, default) => {
|
TraitItemKind::Const(ref ty, default) => {
|
||||||
visitor.visit_id(hir_id);
|
visitor.visit_id(hir_id);
|
||||||
@ -958,13 +958,13 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
|||||||
}
|
}
|
||||||
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
|
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
|
||||||
visitor.visit_id(hir_id);
|
visitor.visit_id(hir_id);
|
||||||
visitor.visit_fn_decl(&sig.decl);
|
visitor.visit_fn_decl(sig.decl);
|
||||||
for ¶m_name in param_names {
|
for ¶m_name in param_names {
|
||||||
visitor.visit_ident(param_name);
|
visitor.visit_ident(param_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
|
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
|
||||||
visitor.visit_fn(FnKind::Method(ident, sig), &sig.decl, body_id, span, hir_id);
|
visitor.visit_fn(FnKind::Method(ident, sig), sig.decl, body_id, span, hir_id);
|
||||||
}
|
}
|
||||||
TraitItemKind::Type(bounds, ref default) => {
|
TraitItemKind::Type(bounds, ref default) => {
|
||||||
visitor.visit_id(hir_id);
|
visitor.visit_id(hir_id);
|
||||||
@ -1006,7 +1006,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
|||||||
ImplItemKind::Fn(ref sig, body_id) => {
|
ImplItemKind::Fn(ref sig, body_id) => {
|
||||||
visitor.visit_fn(
|
visitor.visit_fn(
|
||||||
FnKind::Method(impl_item.ident, sig),
|
FnKind::Method(impl_item.ident, sig),
|
||||||
&sig.decl,
|
sig.decl,
|
||||||
body_id,
|
body_id,
|
||||||
impl_item.span,
|
impl_item.span,
|
||||||
impl_item.hir_id(),
|
impl_item.hir_id(),
|
||||||
@ -1039,7 +1039,7 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'
|
|||||||
|
|
||||||
pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
|
pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
|
||||||
visitor.visit_id(trait_ref.hir_ref_id);
|
visitor.visit_id(trait_ref.hir_ref_id);
|
||||||
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
|
visitor.visit_path(trait_ref.path, trait_ref.hir_ref_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
|
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
|
||||||
@ -1071,7 +1071,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(
|
|||||||
pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
|
pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
|
||||||
visitor.visit_id(field.hir_id);
|
visitor.visit_id(field.hir_id);
|
||||||
visitor.visit_ident(field.ident);
|
visitor.visit_ident(field.ident);
|
||||||
visitor.visit_ty(&field.ty);
|
visitor.visit_ty(field.ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_enum_def<'v, V: Visitor<'v>>(
|
pub fn walk_enum_def<'v, V: Visitor<'v>>(
|
||||||
|
@ -29,8 +29,8 @@ impl<'a> DiagnosticDerive<'a> {
|
|||||||
let DiagnosticDerive { mut structure, mut builder } = self;
|
let DiagnosticDerive { mut structure, mut builder } = self;
|
||||||
|
|
||||||
let implementation = builder.each_variant(&mut structure, |mut builder, variant| {
|
let implementation = builder.each_variant(&mut structure, |mut builder, variant| {
|
||||||
let preamble = builder.preamble(&variant);
|
let preamble = builder.preamble(variant);
|
||||||
let body = builder.body(&variant);
|
let body = builder.body(variant);
|
||||||
|
|
||||||
let diag = &builder.parent.diag;
|
let diag = &builder.parent.diag;
|
||||||
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.parent.kind else {
|
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.parent.kind else {
|
||||||
@ -39,7 +39,7 @@ impl<'a> DiagnosticDerive<'a> {
|
|||||||
let init = match builder.slug.value_ref() {
|
let init = match builder.slug.value_ref() {
|
||||||
None => {
|
None => {
|
||||||
span_err(builder.span, "diagnostic slug not specified")
|
span_err(builder.span, "diagnostic slug not specified")
|
||||||
.help(&format!(
|
.help(format!(
|
||||||
"specify the slug as the first argument to the `#[diag(...)]` \
|
"specify the slug as the first argument to the `#[diag(...)]` \
|
||||||
attribute, such as `#[diag(hir_analysis_example_error)]`",
|
attribute, such as `#[diag(hir_analysis_example_error)]`",
|
||||||
))
|
))
|
||||||
@ -48,10 +48,10 @@ impl<'a> DiagnosticDerive<'a> {
|
|||||||
}
|
}
|
||||||
Some(slug) if let Some( Mismatch { slug_name, crate_name, slug_prefix }) = Mismatch::check(slug) => {
|
Some(slug) if let Some( Mismatch { slug_name, crate_name, slug_prefix }) = Mismatch::check(slug) => {
|
||||||
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
|
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
|
||||||
.note(&format!(
|
.note(format!(
|
||||||
"slug is `{slug_name}` but the crate name is `{crate_name}`"
|
"slug is `{slug_name}` but the crate name is `{crate_name}`"
|
||||||
))
|
))
|
||||||
.help(&format!(
|
.help(format!(
|
||||||
"expected a slug starting with `{slug_prefix}_...`"
|
"expected a slug starting with `{slug_prefix}_...`"
|
||||||
))
|
))
|
||||||
.emit();
|
.emit();
|
||||||
@ -113,8 +113,8 @@ impl<'a> LintDiagnosticDerive<'a> {
|
|||||||
let LintDiagnosticDerive { mut structure, mut builder } = self;
|
let LintDiagnosticDerive { mut structure, mut builder } = self;
|
||||||
|
|
||||||
let implementation = builder.each_variant(&mut structure, |mut builder, variant| {
|
let implementation = builder.each_variant(&mut structure, |mut builder, variant| {
|
||||||
let preamble = builder.preamble(&variant);
|
let preamble = builder.preamble(variant);
|
||||||
let body = builder.body(&variant);
|
let body = builder.body(variant);
|
||||||
|
|
||||||
let diag = &builder.parent.diag;
|
let diag = &builder.parent.diag;
|
||||||
let formatting_init = &builder.formatting_init;
|
let formatting_init = &builder.formatting_init;
|
||||||
@ -128,28 +128,28 @@ impl<'a> LintDiagnosticDerive<'a> {
|
|||||||
|
|
||||||
let msg = builder.each_variant(&mut structure, |mut builder, variant| {
|
let msg = builder.each_variant(&mut structure, |mut builder, variant| {
|
||||||
// Collect the slug by generating the preamble.
|
// Collect the slug by generating the preamble.
|
||||||
let _ = builder.preamble(&variant);
|
let _ = builder.preamble(variant);
|
||||||
|
|
||||||
match builder.slug.value_ref() {
|
match builder.slug.value_ref() {
|
||||||
None => {
|
None => {
|
||||||
span_err(builder.span, "diagnostic slug not specified")
|
span_err(builder.span, "diagnostic slug not specified")
|
||||||
.help(&format!(
|
.help(format!(
|
||||||
"specify the slug as the first argument to the attribute, such as \
|
"specify the slug as the first argument to the attribute, such as \
|
||||||
`#[diag(compiletest_example)]`",
|
`#[diag(compiletest_example)]`",
|
||||||
))
|
))
|
||||||
.emit();
|
.emit();
|
||||||
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
|
DiagnosticDeriveError::ErrorHandled.to_compile_error()
|
||||||
}
|
}
|
||||||
Some(slug) if let Some( Mismatch { slug_name, crate_name, slug_prefix }) = Mismatch::check(slug) => {
|
Some(slug) if let Some( Mismatch { slug_name, crate_name, slug_prefix }) = Mismatch::check(slug) => {
|
||||||
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
|
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
|
||||||
.note(&format!(
|
.note(format!(
|
||||||
"slug is `{slug_name}` but the crate name is `{crate_name}`"
|
"slug is `{slug_name}` but the crate name is `{crate_name}`"
|
||||||
))
|
))
|
||||||
.help(&format!(
|
.help(format!(
|
||||||
"expected a slug starting with `{slug_prefix}_...`"
|
"expected a slug starting with `{slug_prefix}_...`"
|
||||||
))
|
))
|
||||||
.emit();
|
.emit();
|
||||||
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
|
DiagnosticDeriveError::ErrorHandled.to_compile_error()
|
||||||
}
|
}
|
||||||
Some(slug) => {
|
Some(slug) => {
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -100,7 +100,7 @@ impl DiagnosticDeriveBuilder {
|
|||||||
_ => variant.ast().ident.span().unwrap(),
|
_ => variant.ast().ident.span().unwrap(),
|
||||||
};
|
};
|
||||||
let builder = DiagnosticDeriveVariantBuilder {
|
let builder = DiagnosticDeriveVariantBuilder {
|
||||||
parent: &self,
|
parent: self,
|
||||||
span,
|
span,
|
||||||
field_map: build_field_mapping(variant),
|
field_map: build_field_mapping(variant),
|
||||||
formatting_init: TokenStream::new(),
|
formatting_init: TokenStream::new(),
|
||||||
@ -211,7 +211,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
nested_iter.next();
|
nested_iter.next();
|
||||||
}
|
}
|
||||||
Some(NestedMeta::Meta(Meta::NameValue { .. })) => {}
|
Some(NestedMeta::Meta(Meta::NameValue { .. })) => {}
|
||||||
Some(nested_attr) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| diag
|
Some(nested_attr) => throw_invalid_nested_attr!(attr, nested_attr, |diag| diag
|
||||||
.help("a diagnostic slug is required as the first argument")),
|
.help("a diagnostic slug is required as the first argument")),
|
||||||
None => throw_invalid_attr!(attr, &meta, |diag| diag
|
None => throw_invalid_attr!(attr, &meta, |diag| diag
|
||||||
.help("a diagnostic slug is required as the first argument")),
|
.help("a diagnostic slug is required as the first argument")),
|
||||||
@ -227,13 +227,13 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
..
|
..
|
||||||
})) => (value, path),
|
})) => (value, path),
|
||||||
NestedMeta::Meta(Meta::Path(_)) => {
|
NestedMeta::Meta(Meta::Path(_)) => {
|
||||||
invalid_nested_attr(attr, &nested_attr)
|
invalid_nested_attr(attr, nested_attr)
|
||||||
.help("diagnostic slug must be the first argument")
|
.help("diagnostic slug must be the first argument")
|
||||||
.emit();
|
.emit();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
invalid_nested_attr(attr, &nested_attr).emit();
|
invalid_nested_attr(attr, nested_attr).emit();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -251,7 +251,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
#diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
|
#diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => invalid_nested_attr(attr, &nested_attr)
|
_ => invalid_nested_attr(attr, nested_attr)
|
||||||
.help("only `code` is a valid nested attributes following the slug")
|
.help("only `code` is a valid nested attributes following the slug")
|
||||||
.emit(),
|
.emit(),
|
||||||
}
|
}
|
||||||
@ -427,9 +427,9 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
||||||
}
|
}
|
||||||
SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => {
|
SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => {
|
||||||
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
|
if type_matches_path(info.ty, &["rustc_span", "Span"]) {
|
||||||
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
||||||
} else if type_is_unit(&info.ty) {
|
} else if type_is_unit(info.ty) {
|
||||||
Ok(self.add_subdiagnostic(&fn_ident, slug))
|
Ok(self.add_subdiagnostic(&fn_ident, slug))
|
||||||
} else {
|
} else {
|
||||||
report_type_error(attr, "`Span` or `()`")?
|
report_type_error(attr, "`Span` or `()`")?
|
||||||
|
@ -409,7 +409,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
let mut code = None;
|
let mut code = None;
|
||||||
for nested_attr in list.nested.iter() {
|
for nested_attr in list.nested.iter() {
|
||||||
let NestedMeta::Meta(ref meta) = nested_attr else {
|
let NestedMeta::Meta(ref meta) = nested_attr else {
|
||||||
throw_invalid_nested_attr!(attr, &nested_attr);
|
throw_invalid_nested_attr!(attr, nested_attr);
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = meta.span().unwrap();
|
let span = meta.span().unwrap();
|
||||||
@ -427,7 +427,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
);
|
);
|
||||||
code.set_once((code_field, formatting_init), span);
|
code.set_once((code_field, formatting_init), span);
|
||||||
}
|
}
|
||||||
_ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
_ => throw_invalid_nested_attr!(attr, nested_attr, |diag| {
|
||||||
diag.help("`code` is the only valid nested attribute")
|
diag.help("`code` is the only valid nested attribute")
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ fn report_error_if_not_applied_to_ty(
|
|||||||
path: &[&str],
|
path: &[&str],
|
||||||
ty_name: &str,
|
ty_name: &str,
|
||||||
) -> Result<(), DiagnosticDeriveError> {
|
) -> Result<(), DiagnosticDeriveError> {
|
||||||
if !type_matches_path(&info.ty, path) {
|
if !type_matches_path(info.ty, path) {
|
||||||
report_type_error(attr, ty_name)?;
|
report_type_error(attr, ty_name)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ pub(crate) fn report_error_if_not_applied_to_span(
|
|||||||
attr: &Attribute,
|
attr: &Attribute,
|
||||||
info: &FieldInfo<'_>,
|
info: &FieldInfo<'_>,
|
||||||
) -> Result<(), DiagnosticDeriveError> {
|
) -> Result<(), DiagnosticDeriveError> {
|
||||||
if !type_matches_path(&info.ty, &["rustc_span", "Span"])
|
if !type_matches_path(info.ty, &["rustc_span", "Span"])
|
||||||
&& !type_matches_path(&info.ty, &["rustc_errors", "MultiSpan"])
|
&& !type_matches_path(info.ty, &["rustc_errors", "MultiSpan"])
|
||||||
{
|
{
|
||||||
report_type_error(attr, "`Span` or `MultiSpan`")?;
|
report_type_error(attr, "`Span` or `MultiSpan`")?;
|
||||||
}
|
}
|
||||||
@ -686,7 +686,7 @@ impl SubdiagnosticKind {
|
|||||||
let meta = match nested_attr {
|
let meta = match nested_attr {
|
||||||
NestedMeta::Meta(ref meta) => meta,
|
NestedMeta::Meta(ref meta) => meta,
|
||||||
NestedMeta::Lit(_) => {
|
NestedMeta::Lit(_) => {
|
||||||
invalid_nested_attr(attr, &nested_attr).emit();
|
invalid_nested_attr(attr, nested_attr).emit();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -698,7 +698,7 @@ impl SubdiagnosticKind {
|
|||||||
let string_value = match meta {
|
let string_value = match meta {
|
||||||
Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) => Some(value),
|
Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) => Some(value),
|
||||||
|
|
||||||
Meta::Path(_) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| {
|
Meta::Path(_) => throw_invalid_nested_attr!(attr, nested_attr, |diag| {
|
||||||
diag.help("a diagnostic slug must be the first argument to the attribute")
|
diag.help("a diagnostic slug must be the first argument to the attribute")
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -720,7 +720,7 @@ impl SubdiagnosticKind {
|
|||||||
| SubdiagnosticKind::MultipartSuggestion { ref mut applicability, .. },
|
| SubdiagnosticKind::MultipartSuggestion { ref mut applicability, .. },
|
||||||
) => {
|
) => {
|
||||||
let Some(value) = string_value else {
|
let Some(value) = string_value else {
|
||||||
invalid_nested_attr(attr, &nested_attr).emit();
|
invalid_nested_attr(attr, nested_attr).emit();
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -736,7 +736,7 @@ impl SubdiagnosticKind {
|
|||||||
| SubdiagnosticKind::MultipartSuggestion { .. },
|
| SubdiagnosticKind::MultipartSuggestion { .. },
|
||||||
) => {
|
) => {
|
||||||
let Some(value) = string_value else {
|
let Some(value) = string_value else {
|
||||||
invalid_nested_attr(attr, &nested_attr).emit();
|
invalid_nested_attr(attr, nested_attr).emit();
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -752,19 +752,19 @@ impl SubdiagnosticKind {
|
|||||||
|
|
||||||
// Invalid nested attribute
|
// Invalid nested attribute
|
||||||
(_, SubdiagnosticKind::Suggestion { .. }) => {
|
(_, SubdiagnosticKind::Suggestion { .. }) => {
|
||||||
invalid_nested_attr(attr, &nested_attr)
|
invalid_nested_attr(attr, nested_attr)
|
||||||
.help(
|
.help(
|
||||||
"only `style`, `code` and `applicability` are valid nested attributes",
|
"only `style`, `code` and `applicability` are valid nested attributes",
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
(_, SubdiagnosticKind::MultipartSuggestion { .. }) => {
|
(_, SubdiagnosticKind::MultipartSuggestion { .. }) => {
|
||||||
invalid_nested_attr(attr, &nested_attr)
|
invalid_nested_attr(attr, nested_attr)
|
||||||
.help("only `style` and `applicability` are valid nested attributes")
|
.help("only `style` and `applicability` are valid nested attributes")
|
||||||
.emit()
|
.emit()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
invalid_nested_attr(attr, &nested_attr).emit();
|
invalid_nested_attr(attr, nested_attr).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ impl CguReuseTracker {
|
|||||||
let at_least = if at_least { 1 } else { 0 };
|
let at_least = if at_least { 1 } else { 0 };
|
||||||
IncorrectCguReuseType {
|
IncorrectCguReuseType {
|
||||||
span: error_span.0,
|
span: error_span.0,
|
||||||
cgu_user_name: &cgu_user_name,
|
cgu_user_name,
|
||||||
actual_reuse,
|
actual_reuse,
|
||||||
expected_reuse,
|
expected_reuse,
|
||||||
at_least,
|
at_least,
|
||||||
|
@ -622,7 +622,7 @@ impl OutputFilenames {
|
|||||||
/// should be placed on disk.
|
/// should be placed on disk.
|
||||||
pub fn output_path(&self, flavor: OutputType) -> PathBuf {
|
pub fn output_path(&self, flavor: OutputType) -> PathBuf {
|
||||||
let extension = flavor.extension();
|
let extension = flavor.extension();
|
||||||
self.with_directory_and_extension(&self.out_directory, &extension)
|
self.with_directory_and_extension(&self.out_directory, extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the path where a compilation artifact of the given type for the
|
/// Gets the path where a compilation artifact of the given type for the
|
||||||
@ -659,7 +659,7 @@ impl OutputFilenames {
|
|||||||
|
|
||||||
let temps_directory = self.temps_directory.as_ref().unwrap_or(&self.out_directory);
|
let temps_directory = self.temps_directory.as_ref().unwrap_or(&self.out_directory);
|
||||||
|
|
||||||
self.with_directory_and_extension(&temps_directory, &extension)
|
self.with_directory_and_extension(temps_directory, &extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_extension(&self, extension: &str) -> PathBuf {
|
pub fn with_extension(&self, extension: &str) -> PathBuf {
|
||||||
@ -1159,7 +1159,7 @@ impl CrateCheckConfig {
|
|||||||
values_target_family
|
values_target_family
|
||||||
.extend(target.options.families.iter().map(|family| Symbol::intern(family)));
|
.extend(target.options.families.iter().map(|family| Symbol::intern(family)));
|
||||||
values_target_arch.insert(Symbol::intern(&target.arch));
|
values_target_arch.insert(Symbol::intern(&target.arch));
|
||||||
values_target_endian.insert(Symbol::intern(&target.options.endian.as_str()));
|
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));
|
||||||
values_target_env.insert(Symbol::intern(&target.options.env));
|
values_target_env.insert(Symbol::intern(&target.options.env));
|
||||||
values_target_abi.insert(Symbol::intern(&target.options.abi));
|
values_target_abi.insert(Symbol::intern(&target.options.abi));
|
||||||
values_target_vendor.insert(Symbol::intern(&target.options.vendor));
|
values_target_vendor.insert(Symbol::intern(&target.options.vendor));
|
||||||
@ -1846,7 +1846,7 @@ pub fn parse_target_triple(
|
|||||||
match matches.opt_str("target") {
|
match matches.opt_str("target") {
|
||||||
Some(target) if target.ends_with(".json") => {
|
Some(target) if target.ends_with(".json") => {
|
||||||
let path = Path::new(&target);
|
let path = Path::new(&target);
|
||||||
TargetTriple::from_path(&path).unwrap_or_else(|_| {
|
TargetTriple::from_path(path).unwrap_or_else(|_| {
|
||||||
early_error(error_format, &format!("target file {path:?} does not exist"))
|
early_error(error_format, &format!("target file {path:?} does not exist"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1992,7 +1992,7 @@ fn parse_native_lib_modifiers(
|
|||||||
) -> (NativeLibKind, Option<bool>) {
|
) -> (NativeLibKind, Option<bool>) {
|
||||||
let mut verbatim = None;
|
let mut verbatim = None;
|
||||||
for modifier in modifiers.split(',') {
|
for modifier in modifiers.split(',') {
|
||||||
let (modifier, value) = match modifier.strip_prefix(&['+', '-']) {
|
let (modifier, value) = match modifier.strip_prefix(['+', '-']) {
|
||||||
Some(m) => (m, modifier.starts_with('+')),
|
Some(m) => (m, modifier.starts_with('+')),
|
||||||
None => early_error(
|
None => early_error(
|
||||||
error_format,
|
error_format,
|
||||||
@ -2421,7 +2421,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||||||
|
|
||||||
let mut search_paths = vec![];
|
let mut search_paths = vec![];
|
||||||
for s in &matches.opt_strs("L") {
|
for s in &matches.opt_strs("L") {
|
||||||
search_paths.push(SearchPath::from_cli_opt(&s, error_format));
|
search_paths.push(SearchPath::from_cli_opt(s, error_format));
|
||||||
}
|
}
|
||||||
|
|
||||||
let libs = parse_libs(matches, error_format);
|
let libs = parse_libs(matches, error_format);
|
||||||
|
@ -321,7 +321,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
|
|||||||
LitError::InvalidIntSuffix => {
|
LitError::InvalidIntSuffix => {
|
||||||
let suf = suffix.expect("suffix error with no suffix");
|
let suf = suffix.expect("suffix error with no suffix");
|
||||||
let suf = suf.as_str();
|
let suf = suf.as_str();
|
||||||
if looks_like_width_suffix(&['i', 'u'], &suf) {
|
if looks_like_width_suffix(&['i', 'u'], suf) {
|
||||||
// If it looks like a width, try to be helpful.
|
// If it looks like a width, try to be helpful.
|
||||||
sess.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() });
|
sess.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() });
|
||||||
} else if let Some(fixed) = fix_base_capitalisation(suf) {
|
} else if let Some(fixed) = fix_base_capitalisation(suf) {
|
||||||
|
@ -247,7 +247,7 @@ fn analyze_source_file_generic(
|
|||||||
// The slow path:
|
// The slow path:
|
||||||
// This is either ASCII control character "DEL" or the beginning of
|
// This is either ASCII control character "DEL" or the beginning of
|
||||||
// a multibyte char. Just decode to `char`.
|
// a multibyte char. Just decode to `char`.
|
||||||
let c = (&src[i..]).chars().next().unwrap();
|
let c = src[i..].chars().next().unwrap();
|
||||||
char_len = c.len_utf8();
|
char_len = c.len_utf8();
|
||||||
|
|
||||||
let pos = BytePos::from_usize(i) + output_offset;
|
let pos = BytePos::from_usize(i) + output_offset;
|
||||||
|
@ -165,7 +165,7 @@ impl<'sm> CachingSourceMapView<'sm> {
|
|||||||
Some(new_file_and_idx)
|
Some(new_file_and_idx)
|
||||||
} else {
|
} else {
|
||||||
let file = &self.line_cache[oldest].file;
|
let file = &self.line_cache[oldest].file;
|
||||||
if !file_contains(&file, span_data.hi) {
|
if !file_contains(file, span_data.hi) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ impl HygieneData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
|
pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
|
||||||
with_session_globals(|session_globals| f(&mut *session_globals.hygiene_data.borrow_mut()))
|
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -238,7 +238,7 @@ impl RealFileName {
|
|||||||
pub fn remapped_path_if_available(&self) -> &Path {
|
pub fn remapped_path_if_available(&self) -> &Path {
|
||||||
match self {
|
match self {
|
||||||
RealFileName::LocalPath(p)
|
RealFileName::LocalPath(p)
|
||||||
| RealFileName::Remapped { local_path: _, virtual_name: p } => &p,
|
| RealFileName::Remapped { local_path: _, virtual_name: p } => p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,5 +166,5 @@ impl SpanInterner {
|
|||||||
// If an interner exists, return it. Otherwise, prepare a fresh one.
|
// If an interner exists, return it. Otherwise, prepare a fresh one.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_span_interner<T, F: FnOnce(&mut SpanInterner) -> T>(f: F) -> T {
|
fn with_span_interner<T, F: FnOnce(&mut SpanInterner) -> T>(f: F) -> T {
|
||||||
crate::with_session_globals(|session_globals| f(&mut *session_globals.span_interner.lock()))
|
crate::with_session_globals(|session_globals| f(&mut session_globals.span_interner.lock()))
|
||||||
}
|
}
|
||||||
|
@ -1876,7 +1876,7 @@ impl<S: Encoder> Encodable<S> for Symbol {
|
|||||||
impl<D: Decoder> Decodable<D> for Symbol {
|
impl<D: Decoder> Decodable<D> for Symbol {
|
||||||
#[inline]
|
#[inline]
|
||||||
default fn decode(d: &mut D) -> Symbol {
|
default fn decode(d: &mut D) -> Symbol {
|
||||||
Symbol::intern(&d.read_str())
|
Symbol::intern(d.read_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ fn arg_scalar_pair<C>(
|
|||||||
where
|
where
|
||||||
C: HasDataLayout,
|
C: HasDataLayout,
|
||||||
{
|
{
|
||||||
data = arg_scalar(cx, &scalar1, offset, data);
|
data = arg_scalar(cx, scalar1, offset, data);
|
||||||
match (scalar1.primitive(), scalar2.primitive()) {
|
match (scalar1.primitive(), scalar2.primitive()) {
|
||||||
(abi::F32, _) => offset += Reg::f32().size,
|
(abi::F32, _) => offset += Reg::f32().size,
|
||||||
(_, abi::F64) => offset += Reg::f64().size,
|
(_, abi::F64) => offset += Reg::f64().size,
|
||||||
@ -90,7 +90,7 @@ where
|
|||||||
if (offset.bytes() % 4) != 0 && scalar2.primitive().is_float() {
|
if (offset.bytes() % 4) != 0 && scalar2.primitive().is_float() {
|
||||||
offset += Size::from_bytes(4 - (offset.bytes() % 4));
|
offset += Size::from_bytes(4 - (offset.bytes() % 4));
|
||||||
}
|
}
|
||||||
data = arg_scalar(cx, &scalar2, offset, data);
|
data = arg_scalar(cx, scalar2, offset, data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2746,7 +2746,7 @@ impl Target {
|
|||||||
|
|
||||||
// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
|
// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
|
||||||
// as a fallback.
|
// as a fallback.
|
||||||
let rustlib_path = crate::target_rustlib_path(&sysroot, &target_triple);
|
let rustlib_path = crate::target_rustlib_path(sysroot, target_triple);
|
||||||
let p = PathBuf::from_iter([
|
let p = PathBuf::from_iter([
|
||||||
Path::new(sysroot),
|
Path::new(sysroot),
|
||||||
Path::new(&rustlib_path),
|
Path::new(&rustlib_path),
|
||||||
|
Loading…
Reference in New Issue
Block a user