Skip to content

rustc_span: mark few methods as must_use #145159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope));
let _ = ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope));
ident
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
RibKind::MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => {
// If an invocation of this macro created `ident`, give up on `ident`
// and switch to `ident`'s source from the macro definition.
ident.span.remove_mark();
let _ = ident.span.remove_mark();
continue;
}
_ => continue,
Expand Down Expand Up @@ -759,7 +759,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
ModuleOrUniformRoot::ExternPrelude => {
ident.span.normalize_to_macros_2_0_and_adjust(ExpnId::root());
let _ = ident.span.normalize_to_macros_2_0_and_adjust(ExpnId::root());
}
ModuleOrUniformRoot::ModuleAndExternPrelude(..) | ModuleOrUniformRoot::CurrentScope => {
// No adjustments
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
// and switch to `ident`'s source from the macro definition.
&& def == self.r.macro_def(label.span.ctxt())
{
label.span.remove_mark();
let _ = label.span.remove_mark();
}

let ident = label.normalize_to_macro_rules();
Expand Down Expand Up @@ -3426,7 +3426,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
let Some((module, _)) = self.current_trait_ref else {
return;
};
ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
let _ = ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
let key = BindingKey::new(ident, ns);
let mut binding = self.r.resolution(module, key).and_then(|r| r.best_binding());
debug!(?binding);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
{
// If an invocation of this macro created `ident`, give up on `ident`
// and switch to `ident`'s source from the macro definition.
ctxt.remove_mark();
let _ = ctxt.remove_mark();
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ impl HygieneData {
ret_span
}

#[must_use]
fn adjust(&self, ctxt: &mut SyntaxContext, expn_id: ExpnId) -> Option<ExpnId> {
let mut scope = None;
while !self.is_descendant_of(expn_id, self.outer_expn(*ctxt)) {
Expand Down Expand Up @@ -754,6 +755,7 @@ impl SyntaxContext {
/// invocation of f that created g1.
/// Returns the mark that was removed.
#[inline]
#[must_use]
pub fn remove_mark(&mut self) -> ExpnId {
HygieneData::with(|data| data.remove_mark(self).0)
}
Expand Down Expand Up @@ -885,7 +887,7 @@ impl SyntaxContext {
pub fn hygienic_eq(self, other: SyntaxContext, expn_id: ExpnId) -> bool {
HygieneData::with(|data| {
let mut self_normalized = data.normalize_to_macros_2_0(self);
data.adjust(&mut self_normalized, expn_id);
let _ = data.adjust(&mut self_normalized, expn_id);
self_normalized == data.normalize_to_macros_2_0(other)
})
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ impl Span {
}

#[inline]
#[must_use]
pub fn remove_mark(&mut self) -> ExpnId {
let mut mark = ExpnId::root();
*self = self.map_ctxt(|mut ctxt| {
Expand All @@ -1136,6 +1137,7 @@ impl Span {
}

#[inline]
#[must_use]
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
let mut mark = None;
*self = self.map_ctxt(|mut ctxt| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let mut span = obligation.cause.span;
while span.from_expansion() {
// Remove all the desugaring and macro contexts.
span.remove_mark();
let _ = span.remove_mark();
}
let mut expr_finder = FindExprBySpan::new(span, self.tcx);
let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
Expand Down Expand Up @@ -1533,7 +1533,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
while span.desugaring_kind().is_some() {
// Remove all the hir desugaring contexts while maintaining the macro contexts.
span.remove_mark();
let _ = span.remove_mark();
}
let mut expr_finder = super::FindExprBySpan::new(span, self.tcx);
let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
Expand Down
Loading