Skip to content

Commit e874e28

Browse files
committed
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.
1 parent 51856fd commit e874e28

File tree

4 files changed

+5
-38
lines changed

4 files changed

+5
-38
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use crate::{AssocItem, Expr, ForeignItem, Item, NodeId};
1010
use crate::{AttrKind, Block, Meta, Pat, Path, Ty, Visibility};
1111
use crate::{AttrVec, Attribute, Stmt, StmtKind};
1212

13-
use rustc_span::Span;
14-
1513
use std::fmt;
1614
use std::marker::PhantomData;
1715

@@ -91,37 +89,6 @@ impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {
9189
}
9290
}
9391

94-
/// A trait for AST nodes having a span.
95-
pub trait HasSpan {
96-
fn span(&self) -> Span;
97-
}
98-
99-
macro_rules! impl_has_span {
100-
($($T:ty),+ $(,)?) => {
101-
$(
102-
impl HasSpan for $T {
103-
fn span(&self) -> Span {
104-
self.span
105-
}
106-
}
107-
)+
108-
};
109-
}
110-
111-
impl_has_span!(AssocItem, Block, Expr, ForeignItem, Item, Pat, Path, Stmt, Ty, Visibility);
112-
113-
impl<T: AstDeref<Target: HasSpan>> HasSpan for T {
114-
fn span(&self) -> Span {
115-
self.ast_deref().span()
116-
}
117-
}
118-
119-
impl HasSpan for Meta {
120-
fn span(&self) -> Span {
121-
self.span()
122-
}
123-
}
124-
12592
/// A trait for AST nodes having (or not having) collected tokens.
12693
pub trait HasTokens {
12794
fn tokens(&self) -> Option<&LazyAttrTokenStream>;

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod tokenstream;
4444
pub mod visit;
4545

4646
pub use self::ast::*;
47-
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasSpan, HasTokens};
47+
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
4848

4949
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5050

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! ownership of the original.
1515
1616
use crate::ast::{AttrStyle, StmtKind};
17-
use crate::ast_traits::{HasAttrs, HasSpan, HasTokens};
17+
use crate::ast_traits::{HasAttrs, HasTokens};
1818
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
1919
use crate::AttrVec;
2020

@@ -436,9 +436,9 @@ impl TokenStream {
436436
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
437437
}
438438

439-
pub fn from_ast(node: &(impl HasAttrs + HasSpan + HasTokens + fmt::Debug)) -> TokenStream {
439+
pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
440440
let Some(tokens) = node.tokens() else {
441-
panic!("missing tokens for node at {:?}: {:?}", node.span(), node);
441+
panic!("missing tokens for node: {:?}", node);
442442
};
443443
let attrs = node.attrs();
444444
let attr_stream = if attrs.is_empty() {

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17441744
) {
17451745
self.r.dcx().emit_err(errors::LendingIteratorReportError {
17461746
lifetime: lifetime.ident.span,
1747-
ty: ty.span(),
1747+
ty: ty.span,
17481748
});
17491749
} else {
17501750
self.r.dcx().emit_err(errors::AnonymousLivetimeNonGatReportError {

0 commit comments

Comments
 (0)