Skip to content
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

Don't use DesugaringKind to track desugared operators #73571

Closed
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
7 changes: 2 additions & 5 deletions src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
let mut span = e.span;
ensure_sufficient_stack(|| {
let kind = match e.kind {
ExprKind::Box(ref inner) => hir::ExprKind::Box(self.lower_expr(inner)),
Expand Down Expand Up @@ -54,7 +53,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span)
}
ExprKind::Binary(binop, ref lhs, ref rhs) => {
span = self.mark_span_with_reason(DesugaringKind::Operator, e.span, None);
let binop = self.lower_binop(binop);
let lhs = self.lower_expr(lhs);
let rhs = self.lower_expr(rhs);
Expand Down Expand Up @@ -224,7 +222,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::Expr {
hir_id: self.lower_node_id(e.id),
kind,
span,
span: e.span,
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
}
})
Expand All @@ -239,7 +237,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_binop(&mut self, b: BinOp) -> hir::BinOp {
let span = self.mark_span_with_reason(DesugaringKind::Operator, b.span, None);
Spanned {
node: match b.node {
BinOpKind::Add => hir::BinOpKind::Add,
Expand All @@ -261,7 +258,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
BinOpKind::Ge => hir::BinOpKind::Ge,
BinOpKind::Gt => hir::BinOpKind::Gt,
},
span,
span: b.span,
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc_middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ pub fn struct_lint_level<'s, 'd>(
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
let expn_data = span.ctxt().outer_expn_data();
match expn_data.kind {
ExpnKind::Root
| ExpnKind::Desugaring(DesugaringKind::ForLoop(_))
| ExpnKind::Desugaring(DesugaringKind::Operator) => false,
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop(_)) => false,
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
ExpnKind::Macro(MacroKind::Bang, _) => {
// Dummy span for the `def_site` means it's an external macro.
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ pub(super) enum FnSelfUseKind {
Normal { self_arg: Ident, implicit_into_iter: bool },
/// A call to `FnOnce::call_once`, desugared from `my_closure(a, b, c)`
FnOnceCall,
/// A call to an operator trait, desuraged from operator syntax (e.g. `a << b`)
/// A call to an operator trait, desugared from operator syntax (e.g. `a << b`)
#[allow(dead_code)] // FIXME: Detect desugared operators
Operator { self_arg: Ident },
}

Expand Down Expand Up @@ -823,8 +824,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

let kind = if is_fn_once {
FnSelfUseKind::FnOnceCall
} else if fn_call_span.is_desugaring(DesugaringKind::Operator) {
FnSelfUseKind::Operator { self_arg }
} else {
debug!(
"move_spans: method_did={:?}, fn_call_span={:?}",
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_span/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ pub enum DesugaringKind {
Async,
Await,
ForLoop(ForLoopLoc),
Operator,
}

/// A location in the desugaring of a `for` loop
Expand All @@ -844,7 +843,6 @@ impl DesugaringKind {
DesugaringKind::TryBlock => "`try` block",
DesugaringKind::OpaqueTy => "`impl Trait`",
DesugaringKind::ForLoop(_) => "`for` loop",
DesugaringKind::Operator => "operator",
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/test/ui/binop/binop-consume-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs + rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn add(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -40,11 +40,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs - rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn sub(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -76,11 +76,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs * rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn mul(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -112,11 +112,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs / rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn div(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -148,11 +148,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs % rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn rem(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -184,11 +184,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs & rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/bit.rs:LL:COL
|
LL | fn bitand(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -220,11 +220,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs | rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/bit.rs:LL:COL
|
LL | fn bitor(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -256,11 +256,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs ^ rhs;
| --------- `lhs` moved due to usage in operator
| --------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/bit.rs:LL:COL
|
LL | fn bitxor(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -292,11 +292,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs << rhs;
| ---------- `lhs` moved due to usage in operator
| ---------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/bit.rs:LL:COL
|
LL | fn shl(self, rhs: Rhs) -> Self::Output;
Expand Down Expand Up @@ -328,11 +328,11 @@ error[E0382]: use of moved value: `lhs`
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
LL | lhs >> rhs;
| ---------- `lhs` moved due to usage in operator
| ---------- `lhs` moved due to this method call
LL | drop(lhs);
| ^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `lhs`
--> $SRC_DIR/libcore/ops/bit.rs:LL:COL
|
LL | fn shr(self, rhs: Rhs) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/binop/binop-move-semantics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ LL | | x;
| | ^
| | |
| |_____value used here after move
| `x` moved due to usage in operator
| `x` moved due to this method call
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `x`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn add(self, rhs: Rhs) -> Self::Output;
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/consts/miri_unleashed/ptr_arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

static CMP: () = {
let x = &0 as *const _;
let _v = x == x; //~ NOTE in this
let _v = x == x;
//~^ ERROR could not evaluate static initializer
//~| NOTE pointer arithmetic or comparison
//~| NOTE in this
};

static INT_PTR_ARITH: () = unsafe {
let x: usize = std::mem::transmute(&0);
let _v = x + 0; //~ NOTE in this
let _v = x + 0;
//~^ ERROR could not evaluate static initializer
//~| NOTE pointer-to-integer cast
};
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/miri_unleashed/ptr_arith.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _v = x == x;
| ^^^^^^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants

error[E0080]: could not evaluate static initializer
--> $DIR/ptr_arith.rs:17:14
--> $DIR/ptr_arith.rs:16:14
|
LL | let _v = x + 0;
| ^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
Expand All @@ -18,7 +18,7 @@ help: skipping check for `const_compare_raw_pointers` feature
LL | let _v = x == x;
| ^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/ptr_arith.rs:16:20
--> $DIR/ptr_arith.rs:15:20
|
LL | let x: usize = std::mem::transmute(&0);
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/hygiene/unpretty-debug.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ fn y /* 0#0 */() { }
Expansions:
0: parent: ExpnId(0), call_site_ctxt: #0, kind: Root
1: parent: ExpnId(0), call_site_ctxt: #0, kind: Macro(Bang, "foo")
2: parent: ExpnId(0), call_site_ctxt: #1, kind: Desugaring(Operator)
3: parent: ExpnId(0), call_site_ctxt: #1, kind: Desugaring(Operator)

SyntaxContexts:
#0: parent: #0, outer_mark: (ExpnId(0), Opaque)
#1: parent: #0, outer_mark: (ExpnId(1), SemiTransparent)
#2: parent: #1, outer_mark: (ExpnId(2), Transparent)
#3: parent: #1, outer_mark: (ExpnId(3), Transparent)
*/
4 changes: 2 additions & 2 deletions src/test/ui/moves/move-fn-self-receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ error[E0382]: use of moved value: `foo_add`
LL | let foo_add = Foo;
| ------- move occurs because `foo_add` has type `Foo`, which does not implement the `Copy` trait
LL | foo_add + Foo;
| ------------- `foo_add` moved due to usage in operator
| ------------- `foo_add` moved due to this method call
LL | foo_add;
| ^^^^^^^ value used here after move
|
note: calling this operator moves the left-hand side
note: this function consumes the receiver `self` by taking ownership of it, which moves `foo_add`
--> $SRC_DIR/libcore/ops/arith.rs:LL:COL
|
LL | fn add(self, rhs: Rhs) -> Self::Output;
Expand Down