mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Remove HasSpan
trait.
The only place it is meaningfully used is in a panic message in `TokenStream::from_ast`. But `node.span()` doesn't need to be printed because `node` is also printed and it must contain the span.
This commit is contained in:
parent
88373e9f0c
commit
b261501b71
@ -10,8 +10,6 @@ use crate::{AssocItem, Expr, ForeignItem, Item, NodeId};
|
|||||||
use crate::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
|
use crate::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
|
||||||
use crate::{AttrVec, Attribute, Stmt, StmtKind};
|
use crate::{AttrVec, Attribute, Stmt, StmtKind};
|
||||||
|
|
||||||
use rustc_span::Span;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@ -91,37 +89,6 @@ impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for AST nodes having a span.
|
|
||||||
pub trait HasSpan {
|
|
||||||
fn span(&self) -> Span;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_has_span {
|
|
||||||
($($T:ty),+ $(,)?) => {
|
|
||||||
$(
|
|
||||||
impl HasSpan for $T {
|
|
||||||
fn span(&self) -> Span {
|
|
||||||
self.span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)+
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_has_span!(AssocItem, Block, Expr, ForeignItem, Item, Pat, Path, Stmt, Ty, Visibility);
|
|
||||||
|
|
||||||
impl<T: AstDeref<Target: HasSpan>> HasSpan for T {
|
|
||||||
fn span(&self) -> Span {
|
|
||||||
self.ast_deref().span()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasSpan for AttrItem {
|
|
||||||
fn span(&self) -> Span {
|
|
||||||
self.span()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A trait for AST nodes having (or not having) collected tokens.
|
/// A trait for AST nodes having (or not having) collected tokens.
|
||||||
pub trait HasTokens {
|
pub trait HasTokens {
|
||||||
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
|
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
|
||||||
|
@ -44,7 +44,7 @@ pub mod tokenstream;
|
|||||||
pub mod visit;
|
pub mod visit;
|
||||||
|
|
||||||
pub use self::ast::*;
|
pub use self::ast::*;
|
||||||
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasSpan, HasTokens};
|
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
|
||||||
|
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
//! ownership of the original.
|
//! ownership of the original.
|
||||||
|
|
||||||
use crate::ast::{AttrStyle, StmtKind};
|
use crate::ast::{AttrStyle, StmtKind};
|
||||||
use crate::ast_traits::{HasAttrs, HasSpan, HasTokens};
|
use crate::ast_traits::{HasAttrs, HasTokens};
|
||||||
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
|
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
|
||||||
use crate::AttrVec;
|
use crate::AttrVec;
|
||||||
|
|
||||||
@ -436,9 +436,9 @@ impl TokenStream {
|
|||||||
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
|
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_ast(node: &(impl HasAttrs + HasSpan + HasTokens + fmt::Debug)) -> TokenStream {
|
pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
|
||||||
let Some(tokens) = node.tokens() else {
|
let Some(tokens) = node.tokens() else {
|
||||||
panic!("missing tokens for node at {:?}: {:?}", node.span(), node);
|
panic!("missing tokens for node: {:?}", node);
|
||||||
};
|
};
|
||||||
let attrs = node.attrs();
|
let attrs = node.attrs();
|
||||||
let attr_stream = if attrs.is_empty() {
|
let attr_stream = if attrs.is_empty() {
|
||||||
|
@ -1744,7 +1744,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
) {
|
) {
|
||||||
self.r.dcx().emit_err(errors::LendingIteratorReportError {
|
self.r.dcx().emit_err(errors::LendingIteratorReportError {
|
||||||
lifetime: lifetime.ident.span,
|
lifetime: lifetime.ident.span,
|
||||||
ty: ty.span(),
|
ty: ty.span,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.r.dcx().emit_err(errors::AnonymousLivetimeNonGatReportError {
|
self.r.dcx().emit_err(errors::AnonymousLivetimeNonGatReportError {
|
||||||
|
Loading…
Reference in New Issue
Block a user